windows: fix module registration
The linker was optimizing the static variables that were supposed to trigger module initialization. I am making them non-static, and dllexport so that they don't get optimized away. Fixes #7116
This commit is contained in:
parent
2ca4d9d662
commit
b5f9779c2f
22
src/node.h
22
src/node.h
@ -332,7 +332,8 @@ extern "C" NODE_EXTERN void node_module_register(void* mod);
|
|||||||
#pragma section(".CRT$XCU", read)
|
#pragma section(".CRT$XCU", read)
|
||||||
#define NODE_C_CTOR(fn) \
|
#define NODE_C_CTOR(fn) \
|
||||||
static void __cdecl fn(void); \
|
static void __cdecl fn(void); \
|
||||||
__declspec(allocate(".CRT$XCU")) static void (__cdecl*fn ## _)(void) = fn; \
|
__declspec(dllexport, allocate(".CRT$XCU")) \
|
||||||
|
void (__cdecl*fn ## _)(void) = fn; \
|
||||||
static void __cdecl fn(void)
|
static void __cdecl fn(void)
|
||||||
#else
|
#else
|
||||||
#define NODE_C_CTOR(fn) \
|
#define NODE_C_CTOR(fn) \
|
||||||
@ -340,7 +341,7 @@ extern "C" NODE_EXTERN void node_module_register(void* mod);
|
|||||||
static void fn(void)
|
static void fn(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define NODE_MODULE_X(modstr, regfunc, priv, flags) \
|
#define NODE_MODULE_X(modname, regfunc, priv, flags) \
|
||||||
extern "C" { \
|
extern "C" { \
|
||||||
static node::node_module _module = \
|
static node::node_module _module = \
|
||||||
{ \
|
{ \
|
||||||
@ -350,16 +351,16 @@ extern "C" NODE_EXTERN void node_module_register(void* mod);
|
|||||||
__FILE__, \
|
__FILE__, \
|
||||||
(node::addon_register_func) (regfunc), \
|
(node::addon_register_func) (regfunc), \
|
||||||
NULL, \
|
NULL, \
|
||||||
modstr, \
|
NODE_STRINGIFY(modname), \
|
||||||
priv, \
|
priv, \
|
||||||
NULL \
|
NULL \
|
||||||
}; \
|
}; \
|
||||||
NODE_C_CTOR(_register) { \
|
NODE_C_CTOR(_register_ ## modname) { \
|
||||||
node_module_register(&_module); \
|
node_module_register(&_module); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NODE_MODULE_CONTEXT_AWARE_X(modstr, regfunc, priv, flags) \
|
#define NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, priv, flags) \
|
||||||
extern "C" { \
|
extern "C" { \
|
||||||
static node::node_module _module = \
|
static node::node_module _module = \
|
||||||
{ \
|
{ \
|
||||||
@ -369,24 +370,23 @@ extern "C" NODE_EXTERN void node_module_register(void* mod);
|
|||||||
__FILE__, \
|
__FILE__, \
|
||||||
NULL, \
|
NULL, \
|
||||||
(node::addon_context_register_func) (regfunc), \
|
(node::addon_context_register_func) (regfunc), \
|
||||||
modstr, \
|
NODE_STRINGIFY(modname), \
|
||||||
priv, \
|
priv, \
|
||||||
NULL \
|
NULL \
|
||||||
}; \
|
}; \
|
||||||
NODE_C_CTOR(_register) { \
|
NODE_C_CTOR(_register_ ## modname) { \
|
||||||
node_module_register(&_module); \
|
node_module_register(&_module); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NODE_MODULE(modname, regfunc) \
|
#define NODE_MODULE(modname, regfunc) \
|
||||||
NODE_MODULE_X(NODE_STRINGIFY(modname), regfunc, NULL, 0)
|
NODE_MODULE_X(modname, regfunc, NULL, 0)
|
||||||
|
|
||||||
#define NODE_MODULE_CONTEXT_AWARE(modname, regfunc) \
|
#define NODE_MODULE_CONTEXT_AWARE(modname, regfunc) \
|
||||||
NODE_MODULE_CONTEXT_AWARE_X(NODE_STRINGIFY(modname), regfunc, NULL, 0)
|
NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, NULL, 0)
|
||||||
|
|
||||||
#define NODE_MODULE_CONTEXT_AWARE_BUILTIN(modname, regfunc) \
|
#define NODE_MODULE_CONTEXT_AWARE_BUILTIN(modname, regfunc) \
|
||||||
NODE_MODULE_CONTEXT_AWARE_X(NODE_STRINGIFY(modname), \
|
NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, NULL, NM_F_BUILTIN) \
|
||||||
regfunc, NULL, NM_F_BUILTIN)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For backward compatibility in add-on modules.
|
* For backward compatibility in add-on modules.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user