From 3bc7024c654dbf94b6d70e428bce1153159650a7 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Thu, 7 Oct 2021 14:42:04 -0700 Subject: [PATCH] Avoid setting EXPORTED_FUNCTIONS with MAIN_MODULE=1 This setting is meaningless with MAIN_MODULE=1 or SIDE_MODULE=1. Hopefully this will be a warning soon: https://github.com/emscripten-core/emscripten/pull/10075 Also avoid using C++ in some tests that don't need it. --- tests/test_core.py | 56 +++++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index 301ce7ae79586..9c6cdf610799f 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -2720,8 +2720,7 @@ class Bar { @needs_dylink def test_dlfcn_qsort(self): - self.set_setting('EXPORTED_FUNCTIONS', ['_get_cmp']) - create_file('liblib.cpp', ''' + create_file('liblib.c', ''' int lib_cmp(const void* left, const void* right) { const int* a = (const int*) left; const int* b = (const int*) right; @@ -2732,14 +2731,13 @@ def test_dlfcn_qsort(self): typedef int (*CMP_TYPE)(const void*, const void*); - extern "C" CMP_TYPE get_cmp() { + CMP_TYPE get_cmp() { return lib_cmp; } ''') - self.build_dlfcn_lib('liblib.cpp') + self.build_dlfcn_lib('liblib.c') self.prep_dlfcn_main() - self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc']) src = ''' #include #include @@ -2798,7 +2796,7 @@ def test_dlfcn_data_and_fptr(self): if self.is_wasm(): self.banned_js_engines = [config.V8_ENGINE] - create_file('liblib.cpp', r''' + create_file('liblib.c', r''' #include int theglobal = 42; @@ -2818,14 +2816,13 @@ def test_dlfcn_data_and_fptr(self): p_f(); } - extern "C" void (*func(int x, void(*fptr)()))() { + void (*func(int x, void(*fptr)()))() { printf("In func: %d\n", x); fptr(); return lib_fptr; } ''') - self.set_setting('EXPORTED_FUNCTIONS', ['_func']) - self.build_dlfcn_lib('liblib.cpp') + self.build_dlfcn_lib('liblib.c') self.prep_dlfcn_main() src = r''' @@ -2881,7 +2878,6 @@ def test_dlfcn_data_and_fptr(self): return 0; } ''' - self.set_setting('EXPORTED_FUNCTIONS', ['_main']) self.do_run(src, '''\ In func: 13 First calling main_fptr from lib. @@ -2889,21 +2885,20 @@ def test_dlfcn_data_and_fptr(self): parent_func called from child parent_func called from child Var: 42 -''') +''', force_c=True) @needs_dylink def test_dlfcn_varargs(self): # this test is not actually valid - it fails natively. the child should fail # to be loaded, not load and successfully see the parent print_ints func - create_file('liblib.cpp', r''' + create_file('liblib.c', r''' void print_ints(int n, ...); - extern "C" void func() { + void func() { print_ints(2, 13, 42); } ''') - self.set_setting('EXPORTED_FUNCTIONS', ['_func']) - self.build_dlfcn_lib('liblib.cpp') + self.build_dlfcn_lib('liblib.c') self.prep_dlfcn_main() src = r''' @@ -2935,8 +2930,7 @@ def test_dlfcn_varargs(self): return 0; } ''' - self.set_setting('EXPORTED_FUNCTIONS', ['_main']) - self.do_run(src, '100\n200\n13\n42\n') + self.do_run(src, '100\n200\n13\n42\n', force_c=True) @needs_dylink def test_dlfcn_alignment_and_zeroing(self): @@ -3038,7 +3032,6 @@ def test_dlfcn_unique_sig(self): return 13; } ''') - self.set_setting('EXPORTED_FUNCTIONS', ['_myfunc']) self.build_dlfcn_lib('liblib.c') self.prep_dlfcn_main() @@ -3065,7 +3058,6 @@ def test_dlfcn_unique_sig(self): return 0; } ''') - self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc']) self.do_runf('main.c', 'success') @needs_dylink @@ -3077,7 +3069,6 @@ def test_dlfcn_info(self): return 13; } ''') - self.set_setting('EXPORTED_FUNCTIONS', ['_myfunc']) self.build_dlfcn_lib('liblib.c') self.prep_dlfcn_main() @@ -3119,7 +3110,6 @@ def test_dlfcn_info(self): return 0; } ''') - self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc']) self.do_runf('main.c', 'success') @needs_dylink @@ -3139,7 +3129,6 @@ def test_dlfcn_stacks(self): return strlen(bigstack); } ''') - self.set_setting('EXPORTED_FUNCTIONS', ['_myfunc']) self.build_dlfcn_lib('liblib.c') self.prep_dlfcn_main() @@ -3174,7 +3163,6 @@ def test_dlfcn_stacks(self): return 0; } ''') - self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc', '_strcmp']) self.do_runf('main.c', 'success') @needs_dylink @@ -3210,7 +3198,6 @@ def test_dlfcn_funcs(self): } } ''') - self.set_setting('EXPORTED_FUNCTIONS', ['_callvoid', '_callint', '_getvoid', '_getint']) self.build_dlfcn_lib('liblib.c') self.prep_dlfcn_main() @@ -3261,7 +3248,6 @@ def test_dlfcn_funcs(self): return 0; } ''') - self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc']) self.do_runf('main.c', '''go void_main. int_main 201 @@ -3286,11 +3272,9 @@ def test_dlfcn_mallocs(self): void *mallocproxy(int n) { return malloc(n); } void freeproxy(void *p) { free(p); } ''') - self.set_setting('EXPORTED_FUNCTIONS', ['_mallocproxy', '_freeproxy']) self.build_dlfcn_lib('liblib.c') self.prep_dlfcn_main() - self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc', '_free']) self.do_runf(test_file('dlmalloc_proxy.c'), '*294,153*') @needs_dylink @@ -3338,7 +3322,6 @@ def test_dlfcn_longjmp(self): return 0; } ''') - self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc', '_free']) self.do_runf('main.c', '''go! pre 1 pre 2 @@ -3410,7 +3393,6 @@ def zzztest_dlfcn_exceptions(self): return 0; } ''' - self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_malloc', '_free']) self.do_run(src, '''go! ok: 65 int 123 @@ -3428,8 +3410,9 @@ def indir(name): create_file('a.cpp', r''' #include - static struct a { - a() { + static class A { + public: + A() { puts("a: loaded"); } } _; @@ -3438,8 +3421,9 @@ def indir(name): create_file('b.cpp', r''' #include - static struct b { - b() { + static class B { + public: + B() { puts("b: loaded"); } } _; @@ -3488,12 +3472,12 @@ def indir(name): def test_dlfcn_feature_in_lib(self): self.emcc_args.append('-mnontrapping-fptoint') - create_file('liblib.cpp', r''' - extern "C" int magic(float x) { + create_file('liblib.c', r''' + int magic(float x) { return __builtin_wasm_trunc_saturate_s_i32_f32(x); } ''') - self.build_dlfcn_lib('liblib.cpp') + self.build_dlfcn_lib('liblib.c') self.prep_dlfcn_main() src = r'''