Skip to content

Commit c043f2c

Browse files
committed
restore original change + NAPI_MODULE_X
1 parent 12ba8a0 commit c043f2c

File tree

1 file changed

+10
-57
lines changed

1 file changed

+10
-57
lines changed

src/node_api.h

+10-57
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct uv_loop_s; // Forward declaration.
3131
typedef napi_value(NAPI_CDECL* napi_addon_register_func)(napi_env env,
3232
napi_value exports);
3333

34+
// Used by deprecated registration method napi_module_register.
3435
typedef struct napi_module {
3536
int nm_version;
3637
unsigned int nm_flags;
@@ -43,67 +44,15 @@ typedef struct napi_module {
4344

4445
#define NAPI_MODULE_VERSION 1
4546

46-
#if defined(_MSC_VER)
47-
#if defined(__cplusplus)
48-
#define NAPI_C_CTOR(fn) \
49-
static void NAPI_CDECL fn(void); \
50-
namespace { \
51-
struct fn##_ { \
52-
fn##_() { fn(); } \
53-
} fn##_v_; \
54-
} \
55-
static void NAPI_CDECL fn(void)
56-
#else // !defined(__cplusplus)
57-
#pragma section(".CRT$XCU", read)
58-
// The NAPI_C_CTOR macro defines a function fn that is called during CRT
59-
// initialization.
60-
// C does not support dynamic initialization of static variables and this code
61-
// simulates C++ behavior. Exporting the function pointer prevents it from being
62-
// optimized. See for details:
63-
// https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-initialization?view=msvc-170
64-
#define NAPI_C_CTOR(fn) \
65-
static void NAPI_CDECL fn(void); \
66-
__declspec(dllexport, allocate(".CRT$XCU")) void(NAPI_CDECL * fn##_)(void) = \
67-
fn; \
68-
static void NAPI_CDECL fn(void)
69-
#endif // defined(__cplusplus)
70-
#else
71-
#define NAPI_C_CTOR(fn) \
72-
static void fn(void) __attribute__((constructor)); \
73-
static void fn(void)
74-
#endif
75-
76-
#define NAPI_MODULE_X(modname, regfunc, priv, flags) \
77-
EXTERN_C_START \
78-
static napi_module _module = { \
79-
NAPI_MODULE_VERSION, \
80-
flags, \
81-
__FILE__, \
82-
regfunc, \
83-
#modname, \
84-
priv, \
85-
{0}, \
86-
}; \
87-
NAPI_C_CTOR(_register_##modname) { napi_module_register(&_module); } \
88-
EXTERN_C_END
89-
9047
#define NAPI_MODULE_INITIALIZER_X(base, version) \
9148
NAPI_MODULE_INITIALIZER_X_HELPER(base, version)
9249
#define NAPI_MODULE_INITIALIZER_X_HELPER(base, version) base##version
9350

9451
#ifdef __wasm32__
95-
#define NAPI_WASM_INITIALIZER \
96-
NAPI_MODULE_INITIALIZER_X(napi_register_wasm_v, NAPI_MODULE_VERSION)
97-
#define NAPI_MODULE(modname, regfunc) \
98-
EXTERN_C_START \
99-
NAPI_MODULE_EXPORT napi_value NAPI_WASM_INITIALIZER(napi_env env, \
100-
napi_value exports) { \
101-
return regfunc(env, exports); \
102-
} \
103-
EXTERN_C_END
104-
#endif
105-
52+
#define NAPI_MODULE_INITIALIZER_BASE napi_register_wasm_v
53+
#else
10654
#define NAPI_MODULE_INITIALIZER_BASE napi_register_module_v
55+
#endif
10756

10857
#define NAPI_MODULE_INITIALIZER \
10958
NAPI_MODULE_INITIALIZER_X(NAPI_MODULE_INITIALIZER_BASE, NAPI_MODULE_VERSION)
@@ -115,13 +64,17 @@ typedef struct napi_module {
11564
EXTERN_C_END \
11665
napi_value NAPI_MODULE_INITIALIZER(napi_env env, napi_value exports)
11766

118-
#ifndef __wasm32__
11967
#define NAPI_MODULE(modname, regfunc) \
12068
NAPI_MODULE_INIT() { return regfunc(env, exports); }
121-
#endif
69+
70+
// Deprecated. Use NAPI_MODULE.
71+
#define NAPI_MODULE_X(modname, regfunc, priv, flags) \
72+
NAPI_MODULE(modname, regfunc)
12273

12374
EXTERN_C_START
12475

76+
// Deprecated. Replaced by symbol-based registration defined by NAPI_MODULE
77+
// and NAPI_MODULE_INIT macros.
12578
NAPI_EXTERN void NAPI_CDECL napi_module_register(napi_module* mod);
12679

12780
NAPI_EXTERN NAPI_NO_RETURN void NAPI_CDECL

0 commit comments

Comments
 (0)