Skip to content

Commit d996699

Browse files
authored
Allow usage of argc and argv when main is in a side module (#13474)
1 parent 8cf5ec4 commit d996699

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

emscripten.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ def update_settings_glue(metadata, DEBUG):
130130
if shared.Settings.INITIAL_TABLE == -1:
131131
shared.Settings.INITIAL_TABLE = metadata['tableSize'] + 1
132132

133-
shared.Settings.MAIN_READS_PARAMS = metadata['mainReadsParams']
133+
# When using dynamic linking the main function might be in a side module.
134+
# To be safe assume they do take input parametes.
135+
shared.Settings.MAIN_READS_PARAMS = metadata['mainReadsParams'] or shared.Settings.MAIN_MODULE
134136

135137
# Store exports for Closure compiler to be able to track these as globals in
136138
# -s DECLARE_ASM_MODULE_EXPORTS=0 builds.

tests/test_core.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4531,6 +4531,30 @@ class Bar : public Foo {
45314531
header=header,
45324532
expected='success')
45334533

4534+
@needs_dlfcn
4535+
def test_dylink_argv_argc(self):
4536+
# Verify that argc and argv can be sent to main when main is in a side module
4537+
4538+
self.emcc_args += ['--extern-pre-js', 'pre.js']
4539+
4540+
create_test_file('pre.js', '''
4541+
var Module = { arguments: ['hello', 'world!'] }
4542+
''')
4543+
4544+
self.dylink_test(
4545+
'', # main module is empty.
4546+
r'''
4547+
#include <stdio.h>
4548+
int main(int argc, char const *argv[]) {
4549+
printf("%d ", argc);
4550+
for (int i=1; i<argc; i++) printf("%s ", argv[i]);
4551+
printf("\n");
4552+
return 0;
4553+
}
4554+
''',
4555+
expected='3 hello world!',
4556+
need_reverse=False)
4557+
45344558
def test_random(self):
45354559
src = r'''#include <stdlib.h>
45364560
#include <stdio.h>

0 commit comments

Comments
 (0)