File tree Expand file tree Collapse file tree 3 files changed +62
-0
lines changed
test/node-api/test_null_init Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ {
2+ 'targets' : [
3+ {
4+ 'target_name' : 'test_null_init' ,
5+ 'sources' : [ 'test_null_init.c' ]
6+ }
7+ ]
8+ }
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ const common = require ( '../../common' ) ;
3+ const assert = require ( 'assert' ) ;
4+
5+ assert . throws (
6+ ( ) => require ( `./build/${ common . buildType } /test_null_init` ) ,
7+ / M o d u l e h a s n o d e c l a r e d e n t r y p o i n t [ . ] / ) ;
Original file line number Diff line number Diff line change 1+ #include <node_api.h>
2+
3+ #if defined(_MSC_VER )
4+ #if defined(__cplusplus )
5+ #define NAPI_C_CTOR (fn ) \
6+ static void NAPI_CDECL fn(void); \
7+ namespace { \
8+ struct fn##_ { \
9+ fn##_() { fn(); } \
10+ } fn##_v_; \
11+ } \
12+ static void NAPI_CDECL fn(void)
13+ #else // !defined(__cplusplus)
14+ #pragma section(".CRT$XCU", read)
15+ // The NAPI_C_CTOR macro defines a function fn that is called during CRT
16+ // initialization.
17+ // C does not support dynamic initialization of static variables and this code
18+ // simulates C++ behavior. Exporting the function pointer prevents it from being
19+ // optimized. See for details:
20+ // https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-initialization?view=msvc-170
21+ #define NAPI_C_CTOR (fn ) \
22+ static void NAPI_CDECL fn(void); \
23+ __declspec(dllexport, allocate(".CRT$XCU")) void(NAPI_CDECL * fn##_)(void) = \
24+ fn; \
25+ static void NAPI_CDECL fn(void)
26+ #endif // defined(__cplusplus)
27+ #else
28+ #define NAPI_C_CTOR (fn ) \
29+ static void fn(void) __attribute__((constructor)); \
30+ static void fn(void)
31+ #endif
32+
33+ #define NAPI_MODULE_TEST (modname , regfunc ) \
34+ EXTERN_C_START \
35+ static napi_module _module = { \
36+ NAPI_MODULE_VERSION, \
37+ 0, \
38+ __FILE__, \
39+ regfunc, \
40+ #modname, \
41+ NULL, \
42+ {0}, \
43+ }; \
44+ NAPI_C_CTOR(_register_##modname) { napi_module_register(&_module); } \
45+ EXTERN_C_END
46+
47+ NAPI_MODULE_TEST (NODE_GYP_MODULE_NAME , NULL )
You can’t perform that action at this time.
0 commit comments