Skip to content

Allow usage of argc and argv when main is in a side module #13474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ def update_settings_glue(metadata, DEBUG):
if shared.Settings.INITIAL_TABLE == -1:
shared.Settings.INITIAL_TABLE = metadata['tableSize'] + 1

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

# Store exports for Closure compiler to be able to track these as globals in
# -s DECLARE_ASM_MODULE_EXPORTS=0 builds.
Expand Down
24 changes: 24 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4531,6 +4531,30 @@ class Bar : public Foo {
header=header,
expected='success')

@needs_dlfcn
def test_dylink_argv_argc(self):
# Verify that argc and argv can be sent to main when main is in a side module

self.emcc_args += ['--extern-pre-js', 'pre.js']

create_test_file('pre.js', '''
var Module = { arguments: ['hello', 'world!'] }
''')

self.dylink_test(
'', # main module is empty.
r'''
#include <stdio.h>
int main(int argc, char const *argv[]) {
printf("%d ", argc);
for (int i=1; i<argc; i++) printf("%s ", argv[i]);
printf("\n");
return 0;
}
''',
expected='3 hello world!',
need_reverse=False)

def test_random(self):
src = r'''#include <stdlib.h>
#include <stdio.h>
Expand Down