diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-05-12 11:35:58 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-05-12 11:35:58 -0700 |
commit | d3e3d803adce646cf169bdb361bb366c0712f598 (patch) | |
tree | 9756e033c24957be0f46a3804d7152b746cc7a43 | |
parent | af721247c243951f544a1843954b3ea958d65c76 (diff) |
warn on bad exports, fixes #2338
-rwxr-xr-x | emcc | 2 | ||||
-rwxr-xr-x | emscripten.py | 7 | ||||
-rw-r--r-- | tests/test_other.py | 11 |
3 files changed, 19 insertions, 1 deletions
@@ -1223,6 +1223,8 @@ try: value = '"@' + os.path.abspath(value[1:]) + '"' value = value.replace('\\\\', '/').replace('\\', '/') # Convert backslash paths to forward slashes on Windows as well, since the JS compiler otherwise needs the backslashes escaped (alternative is to escape all input paths passing to JS, which feels clumsier to read) exec('shared.Settings.' + key + ' = ' + value) + if key == 'EXPORTED_FUNCTIONS': + shared.Settings.ORIGINAL_EXPORTED_FUNCTIONS = shared.Settings.EXPORTED_FUNCTIONS[:] # used for warnings in emscripten.py fastcomp = os.environ.get('EMCC_FAST_COMPILER') != '0' diff --git a/emscripten.py b/emscripten.py index e2aef648..d75214d5 100755 --- a/emscripten.py +++ b/emscripten.py @@ -895,10 +895,15 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, exported_implemented_functions = set(metadata['exports']) export_bindings = settings['EXPORT_BINDINGS'] export_all = settings['EXPORT_ALL'] - for key in metadata['implementedFunctions'] + forwarded_json['Functions']['implementedFunctions'].keys(): # XXX perf + all_implemented = metadata['implementedFunctions'] + forwarded_json['Functions']['implementedFunctions'].keys() # XXX perf? + for key in all_implemented: if key in all_exported_functions or export_all or (export_bindings and key.startswith('_emscripten_bind')): exported_implemented_functions.add(key) implemented_functions = set(metadata['implementedFunctions']) + if settings['ASSERTIONS'] and settings.get('ORIGINAL_EXPORTED_FUNCTIONS'): + for requested in settings['ORIGINAL_EXPORTED_FUNCTIONS']: + if requested not in all_implemented: + logging.warning('function requested to be exported, but not implemented: "%s"', requested) # Add named globals named_globals = '\n'.join(['var %s = %s;' % (k, v) for k, v in metadata['namedGlobals'].iteritems()]) diff --git a/tests/test_other.py b/tests/test_other.py index 349a16b4..4a6296e0 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -2791,3 +2791,14 @@ int main(int argc, char **argv) { assert sizes[0] == 7 # no aliasing, all unique, fat tables assert sizes[1] == 3 # aliased once more + def test_bad_export(self): + for m in ['', ' ']: + self.clear() + cmd = [PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-s', 'EXPORTED_FUNCTIONS=["' + m + '_main"]'] + print cmd + stdout, stderr = Popen(cmd, stderr=PIPE).communicate() + if m: + assert 'function requested to be exported, but not implemented: " _main"' in stderr, stderr + else: + self.assertContained('hello, world!', run_js('a.out.js')) + |