Skip to content

Commit dfb6fda

Browse files
authored
Consistent use of err() in library code (#12902)
We had some explict references to `Module.printErr` and even `Modue.printError` (which doesn't exist). `Module.printErr` is the external name which users can use to override `err` but interally I think we should always prefer `err`. Also rename a couple of local variables to avoid name colition with printErr.
1 parent 565634d commit dfb6fda

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/library_fs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ FS.staticInit();` +
13291329
});
13301330
FS.mkdev('/dev/null', FS.makedev(1, 3));
13311331
// setup /dev/tty and /dev/tty1
1332-
// stderr needs to print output using Module['printErr']
1332+
// stderr needs to print output using err() rather than out()
13331333
// so we register a second tty just for it.
13341334
TTY.register(FS.makedev(5, 0), TTY.default_tty_ops);
13351335
TTY.register(FS.makedev(6, 0), TTY.default_tty1_ops);

src/library_pthread.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ var LibraryPThread = {
651651
}
652652
if (canvas.transferControlToOffscreen) {
653653
#if GL_DEBUG
654-
Module['printErr']('pthread_create: canvas.transferControlToOffscreen(), transferring canvas by name "' + name + '" (DOM id="' + canvas.id + '") from main thread to pthread');
654+
err('pthread_create: canvas.transferControlToOffscreen(), transferring canvas by name "' + name + '" (DOM id="' + canvas.id + '") from main thread to pthread');
655655
#endif
656656
// Create a shared information block in heap so that we can control
657657
// the canvas size from any thread.
@@ -679,7 +679,7 @@ var LibraryPThread = {
679679
// be able to transfer control to offscreen, but WebGL can be
680680
// proxied from worker to main thread.
681681
#if !OFFSCREEN_FRAMEBUFFER
682-
Module['printErr']('pthread_create: Build with -s OFFSCREEN_FRAMEBUFFER=1 to enable fallback proxying of GL commands from pthread to main thread.');
682+
err('pthread_create: Build with -s OFFSCREEN_FRAMEBUFFER=1 to enable fallback proxying of GL commands from pthread to main thread.');
683683
return {{{ cDefine('ENOSYS') }}}; // Function not implemented, browser doesn't have support for this.
684684
#endif
685685
}

src/library_webgl.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3766,18 +3766,18 @@ var LibraryGL = {
37663766
var mapping = GL.mappedBuffers[emscriptenWebGLGetBufferBinding(target)];
37673767
if (!mapping) {
37683768
GL.recordError(0x502 /* GL_INVALID_OPERATION */);
3769-
Module.printError('buffer was never mapped in glFlushMappedBufferRange');
3769+
err('buffer was never mapped in glFlushMappedBufferRange');
37703770
return;
37713771
}
37723772

37733773
if (!(mapping.access & 0x10)) {
37743774
GL.recordError(0x502 /* GL_INVALID_OPERATION */);
3775-
Module.printError('buffer was not mapped with GL_MAP_FLUSH_EXPLICIT_BIT in glFlushMappedBufferRange');
3775+
err('buffer was not mapped with GL_MAP_FLUSH_EXPLICIT_BIT in glFlushMappedBufferRange');
37763776
return;
37773777
}
37783778
if (offset < 0 || length < 0 || offset + length > mapping.length) {
37793779
GL.recordError(0x501 /* GL_INVALID_VALUE */);
3780-
Module.printError('invalid range in glFlushMappedBufferRange');
3780+
err('invalid range in glFlushMappedBufferRange');
37813781
return;
37823782
}
37833783

@@ -3800,7 +3800,7 @@ var LibraryGL = {
38003800
var mapping = GL.mappedBuffers[buffer];
38013801
if (!mapping) {
38023802
GL.recordError(0x502 /* GL_INVALID_OPERATION */);
3803-
Module.printError('buffer was never mapped in glUnmapBuffer');
3803+
err('buffer was never mapped in glUnmapBuffer');
38043804
return 0;
38053805
}
38063806
GL.mappedBuffers[buffer] = null;

src/postamble.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ function checkUnflushedContent() {
321321
// How we flush the streams depends on whether we are in SYSCALLS_REQUIRE_FILESYSTEM=0
322322
// mode (which has its own special function for this; otherwise, all
323323
// the code is inside libc)
324-
var print = out;
325-
var printErr = err;
324+
var oldOut = out;
325+
var oldErr = err;
326326
var has = false;
327327
out = err = function(x) {
328328
has = true;
@@ -349,8 +349,8 @@ function checkUnflushedContent() {
349349
});
350350
#endif
351351
} catch(e) {}
352-
out = print;
353-
err = printErr;
352+
out = oldOut;
353+
err = oldErr;
354354
if (has) {
355355
warnOnce('stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1 (see the FAQ), or make sure to emit a newline when you printf etc.');
356356
#if FILESYSTEM == 0 || SYSCALLS_REQUIRE_FILESYSTEM == 0

0 commit comments

Comments
 (0)