From 9ea85257fc5d011f7a685aaa71461abbe4ecadc1 Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Sat, 18 Jan 2025 16:52:10 +0800 Subject: [PATCH] move _vinit_caller/_vcleanup_caller fn declare forword --- vlib/v/gen/c/cgen.v | 12 ++---------- vlib/v/gen/c/cheaders.v | 6 ++++++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 36830e82cac738..395713afe288f8 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -6286,11 +6286,7 @@ fn (mut g Gen) write_init_function() { // provide a constructor/destructor pair, ensuring that all constants // are initialized just once, and that they will be freed too. // Note: os.args in this case will be []. - if g.pref.os == .windows { - g.writeln('// workaround for windows, export _vinit_caller, let dl.open() call it') - g.writeln('// NOTE: This is hardcoded in vlib/dl/dl_windows.c.v!') - g.writeln('VV_EXPORTED_SYMBOL void _vinit_caller();') - } else { + if g.pref.os != .windows { g.writeln('__attribute__ ((constructor))') } g.writeln('void _vinit_caller() {') @@ -6301,11 +6297,7 @@ fn (mut g Gen) write_init_function() { g.writeln('\t_vinit(0,0);') g.writeln('}') - if g.pref.os == .windows { - g.writeln('// workaround for windows, export _vcleanup_caller, let dl.close() call it') - g.writeln('// NOTE: This is hardcoded in vlib/dl/dl_windows.c.v!') - g.writeln('VV_EXPORTED_SYMBOL void _vcleanup_caller();') - } else { + if g.pref.os != .windows { g.writeln('__attribute__ ((destructor))') } g.writeln('void _vcleanup_caller() {') diff --git a/vlib/v/gen/c/cheaders.v b/vlib/v/gen/c/cheaders.v index 927cf260e75921..fb9c2284052253 100644 --- a/vlib/v/gen/c/cheaders.v +++ b/vlib/v/gen/c/cheaders.v @@ -536,6 +536,12 @@ typedef int (*qsort_callback_func)(const void*, const void*); int load_so(byteptr); void _vinit(int ___argc, voidptr ___argv); void _vcleanup(void); +#ifdef _WIN32 + // workaround for windows, export _vinit_caller/_vcleanup_caller, let dl.open()/dl.close() call it + // NOTE: This is hardcoded in vlib/dl/dl_windows.c.v! + VV_EXPORTED_SYMBOL void _vinit_caller(); + VV_EXPORTED_SYMBOL void _vcleanup_caller(); +#endif #define sigaction_size sizeof(sigaction); #define _ARR_LEN(a) ( (sizeof(a)) / (sizeof(a[0])) )