diff options
-rwxr-xr-x | emcc | 12 | ||||
-rw-r--r-- | src/postamble.js | 8 | ||||
-rwxr-xr-x | tests/fuzz/csmith_driver.py | 2 | ||||
-rw-r--r-- | tests/mem_init.cpp | 24 | ||||
-rw-r--r-- | tests/test_browser.py | 17 |
5 files changed, 57 insertions, 6 deletions
@@ -470,7 +470,16 @@ Options that are modified or new in %s include: 1: Emit a separate memory initialization file in binary format. This is more efficient than storing it as text inside JavaScript, but does - mean you have another file to publish. + mean you have another file to publish. The + binary file will also be loaded asynchronously, + which means main() will not be called until + the file is downloaded and applied; you cannot + call any C functions until it arrives. (Call + yourself from main() to know when all async + stuff has happened and it is safe to call + library functions, as main() will only be + called at that time. You can also call + addOnPreMain from a preRun.) -Wno-warn-absolute-paths If not specified, the compiler will warn about any uses of absolute paths in -I and -L command line @@ -1369,6 +1378,7 @@ try: if file_ending.endswith(SOURCE_ENDINGS): temp_file = temp_files[i] logging.debug('optimizing %s', input_file) + #if DEBUG: shutil.copyfile(temp_file, os.path.join(TEMP_DIR, 'to_opt.bc') # useful when LLVM opt aborts shared.Building.llvm_opt(temp_file, llvm_opts) # If we were just asked to generate bitcode, stop there diff --git a/src/postamble.js b/src/postamble.js index 603b330c..b90049bc 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -48,10 +48,6 @@ Module['callMain'] = Module.callMain = function callMain(args) { args = args || []; - if (ENVIRONMENT_IS_WEB && preloadStartTime !== null) { - Module.printErr('preload time: ' + (Date.now() - preloadStartTime) + ' ms'); - } - ensureInitRuntime(); var argc = args.length+1; @@ -130,6 +126,10 @@ function run(args) { preMain(); + if (ENVIRONMENT_IS_WEB && preloadStartTime !== null) { + Module.printErr('pre-main prep time: ' + (Date.now() - preloadStartTime) + ' ms'); + } + if (Module['_main'] && shouldRunNow) { Module['callMain'](args); } diff --git a/tests/fuzz/csmith_driver.py b/tests/fuzz/csmith_driver.py index 238acb9a..76d646dd 100755 --- a/tests/fuzz/csmith_driver.py +++ b/tests/fuzz/csmith_driver.py @@ -121,7 +121,7 @@ while 1: print "EMSCRIPTEN BUG" notes['embug'] += 1 fails += 1 - shutil.copyfile(fullname, 'newfail%d%s' % (fails, suffix)) + shutil.copyfile(fullname, 'newfail%d%s%s' % (fails, opts.replace('-', '_'), suffix)) continue #if not ok: # try: # finally, try with safe heap. if that is triggered, this is nonportable code almost certainly diff --git a/tests/mem_init.cpp b/tests/mem_init.cpp new file mode 100644 index 00000000..e642bfc9 --- /dev/null +++ b/tests/mem_init.cpp @@ -0,0 +1,24 @@ +#include <stdio.h> +#include <emscripten.h> + +extern "C" { + +int noted = 0; + +void EMSCRIPTEN_KEEPALIVE note(int n) { + EM_ASM_({ Module.print([$0, $1]) }, n, noted); + noted = noted | n; + EM_ASM_({ Module.print(['noted is now', $0]) }, noted); + if (noted == 3) { + int result = noted; + REPORT_RESULT(); + } +} + +} + +int main() { + EM_ASM( myJSCallback() ); // calls a global JS func + return 0; +} + diff --git a/tests/test_browser.py b/tests/test_browser.py index 44ad04a6..d49244e2 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -1670,6 +1670,23 @@ void *getBindBuffer() { for mem in [0, 1]: self.btest('pre_run_deps.cpp', expected='10', args=['--pre-js', 'pre.js', '--memory-init-file', str(mem)]) + def test_mem_init(self): + open(os.path.join(self.get_dir(), 'pre.js'), 'w').write(''' + function myJSCallback() { // called from main() + Module._note(1); + } + Module.preRun = function() { + addOnPreMain(function() { + Module._note(2); + }); + }; + ''') + open(os.path.join(self.get_dir(), 'post.js'), 'w').write(''' + Module._note(4); // this happens too early! and is overwritten when the mem init arrives + ''') + + self.btest('mem_init.cpp', expected='3', args=['--pre-js', 'pre.js', '--post-js', 'post.js', '--memory-init-file', '1']) + def test_worker_api(self): Popen([PYTHON, EMCC, path_from_root('tests', 'worker_api_worker.cpp'), '-o', 'worker.js', '-s', 'BUILD_AS_WORKER=1', '-s', 'EXPORTED_FUNCTIONS=["_one"]']).communicate() self.btest('worker_api_main.cpp', expected='566') |