Skip to content
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

Add a possibility to explicitly override the soname during initialization #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions generate-wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ def write_implementation(filename, soname, sysincludes, initname, functions, sym
for sym_definition in sym_definitions:
file.write(f"{sym_definition}\n")

file.write(f"int initialize_{initname}(int verbose) {{\n")
file.write(f"int initialize_{initname}_explicit(const char* soname, int verbose) {{\n")
file.write(" void *handle;\n")
file.write(" char *error;\n")
file.write(f" handle = dlopen(\"{soname}\", RTLD_LAZY);\n")
file.write(f" handle = dlopen(soname, RTLD_LAZY);\n")
file.write(" if (!handle) {\n")
file.write(" if (verbose) {\n")
file.write(" fprintf(stderr, \"%s\\n\", dlerror());\n")
Expand All @@ -175,6 +175,10 @@ def write_implementation(filename, soname, sysincludes, initname, functions, sym
file.write("return 0;\n");
file.write("}\n")

file.write(f"int initialize_{initname}(int verbose) {{\n")
file.write(f" return initialize_{initname}_explicit(\"{soname}\", verbose);\n")
file.write("}\n")

def write_header(filename, sysincludes, initname, functions, sym_definitions):
with open(filename, 'w') as file:
file.write(f"#ifndef DYLIBLOAD_WRAPPER_{initname.upper()}\n")
Expand All @@ -191,6 +195,7 @@ def write_header(filename, sysincludes, initname, functions, sym_definitions):
file.write(f"extern {sym_definition}\n")

file.write(f"int initialize_{initname}(int verbose);\n")
file.write(f"int initialize_{initname}_explicit(const char* soname, int verbose);\n")

file.write("#ifdef __cplusplus\n")
file.write("}\n")
Expand Down