From 89ecb3e21c105df110a3c62a2d3366864fc5fe3c Mon Sep 17 00:00:00 2001 From: "tim.dawborn" Date: Thu, 23 Jun 2011 13:50:19 +1000 Subject: [PATCH 1/4] * propogated return value from main back to the return value from Module.run * improved the behaviour of ungetc * added optional argument to intArrayFromString to not add the trailing NULL -- useful when adding JS strings as the data in the virtual file system --- src/library.js | 5 +++++ src/postamble.js | 6 ++++-- src/preamble.js | 5 +++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/library.js b/src/library.js index 97f7f61efcb9a..4875c7dc77055 100644 --- a/src/library.js +++ b/src/library.js @@ -476,6 +476,11 @@ var Library = { _IO_getc: 'getc', ungetc: function(chr, stream) { + var f = STDIO.streams[stream]; + if (!f) + return -1; // EOF + if (!f.interactiveInput) + f.position--; return chr; }, diff --git a/src/postamble.js b/src/postamble.js index 98d8f5786a5e2..9b61c0a7b3188 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -17,7 +17,7 @@ Module.callMain = function callMain(args) { argv.push(0); argv = Pointer_make(argv, null, ALLOC_STATIC, 'i32'); - _main(argc, argv, 0); + return _main(argc, argv, 0); } function run(args) { @@ -29,10 +29,12 @@ function run(args) { __globalConstructor__(); + var ret = null; if (Module['_main']) { - Module.callMain(args); + ret = Module.callMain(args); __shutdownRuntime__(); } + return ret; } Module['run'] = run; diff --git a/src/preamble.js b/src/preamble.js index e7cbcce6ae79a..cfab022ea43b9 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -549,7 +549,7 @@ function jrint(label, obj) { // XXX manual debugging // This processes a JS string into a C-line array of numbers, 0-terminated. // For LLVM-originating strings, see parser.js:parseLLVMString function -function intArrayFromString(stringy) { +function intArrayFromString(stringy, dontAddNull) { var ret = []; var t; var i = 0; @@ -557,7 +557,8 @@ function intArrayFromString(stringy) { ret.push(stringy.charCodeAt(i)); i = i + 1; } - ret.push(0); + if (!dontAddNull) + ret.push(0); return ret; } Module['intArrayFromString'] = intArrayFromString; From b67ec228417909709ea67bafc6ef2ede0a9f39e9 Mon Sep 17 00:00:00 2001 From: "tim.dawborn" Date: Thu, 23 Jun 2011 16:15:56 +1000 Subject: [PATCH 2/4] * correction to fputs -- it should not add a trailing \n (puts does, fputs does not) * corrected internal filennames of stderr and stdout * added default getgid(void) implementation to go with getuid(void) --- src/library.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/library.js b/src/library.js index 4875c7dc77055..b321dbc93ec04 100644 --- a/src/library.js +++ b/src/library.js @@ -274,10 +274,10 @@ var Library = { } _stdout = Pointer_make([0], null, ALLOC_STATIC, 'void*'); - {{{ makeSetValue('_stdout', '0', "STDIO.prepare('<>', null, true)", 'i32') }}}; + {{{ makeSetValue('_stdout', '0', "STDIO.prepare('<>', null, true)", 'i32') }}}; _stderr = Pointer_make([0], null, ALLOC_STATIC, 'void*'); - {{{ makeSetValue('_stderr', '0', "STDIO.prepare('<>', null, true)", 'i32') }}}; + {{{ makeSetValue('_stderr', '0', "STDIO.prepare('<>', null, true)", 'i32') }}}; }, cleanFilename: function(filename) { return filename.replace('./', ''); @@ -456,7 +456,6 @@ var Library = { fputs__deps: ['$STDIO', 'fputc'], fputs: function(p, stream) { STDIO.write(stream, p, String_len(p)); - _fputc('\n'.charCodeAt(0), stream); }, fputc__deps: ['$STDIO'], @@ -1198,6 +1197,10 @@ var Library = { return 100; }, + getgid: function() { + return 100; + }, + getpwuid: function(uid) { return 0; // NULL }, From 86843864515e2da7b15452e56b0480512b1625e3 Mon Sep 17 00:00:00 2001 From: "tim.dawborn" Date: Fri, 24 Jun 2011 09:36:09 +1000 Subject: [PATCH 3/4] * corrected support for fileno(FILE *) --- src/library.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/library.js b/src/library.js index 99626a0c03d60..704ba8a577e18 100644 --- a/src/library.js +++ b/src/library.js @@ -226,7 +226,7 @@ var Library = { }, fileno: function(file) { - return 1; // TODO + return file; }, isatty: function(file) { From ad7d02cd33e85c656b5b1f5bdef933890bae739d Mon Sep 17 00:00:00 2001 From: "tim.dawborn" Date: Fri, 24 Jun 2011 09:49:48 +1000 Subject: [PATCH 4/4] * added myself to AUTHORS --- AUTHORS | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 3db02f2d3cb1d..24757d079506a 100644 --- a/AUTHORS +++ b/AUTHORS @@ -2,6 +2,5 @@ The following authors have all licensed their contributions to Emscripten under the licensing terms detailed in LICENSE. * Alon Zakai (copyright owned by Mozilla Foundation) -* -* +* Tim Dawborn