Skip to content

Commit a742f4a

Browse files
committed
restore test_null_init test
1 parent fbe67a9 commit a742f4a

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'test_null_init',
5+
'sources': [ 'test_null_init.c' ]
6+
}
7+
]
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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+
/Module has no declared entry point[.]/);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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)

0 commit comments

Comments
 (0)