You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"node-gyp rebuild" on a C++ node addon that contains special chars within target_name in binding.gyp
(snip from binding.gyp)
"target_name": "my-addon", #this will fail
"target_name": "my_addon", #no errors
How often does it reproduce? Is there a required condition?
100% reproducible with conditions specified
What is the expected behavior?
successful node addon rebuild
What do you see instead?
(snip from build output)
: error: expected initializer before ‘-’ token
/home/dj/.cache/node-gyp/12.18.2/include/node/node_api.h:53:15: note: in definition of macro ‘NAPI_C_CTOR’
53 | static void fn(void) attribute((constructor));
| ^~
(snip)
: error: expected initializer before ‘-’ token
/home/dj/.cache/node-gyp/12.18.2/include/node/node_api.h:54:15: note: in definition of macro ‘NAPI_C_CTOR’
54 | static void fn(void)
| ^~
/home/dj/.cache/node-gyp/12.18.2/include/node/node_api.h:75:3: note: in expansion of macro ‘NAPI_MODULE_X’
75 | NAPI_MODULE_X(modname, regfunc, NULL, 0) // NOLINT (readability/null_usage)
| ^~~~~~~~~~~~~
Additional information
Problem exists within the definition of macro NAPI_MODULE_X within ~/.nvm/versions/node/v12.18.2/include/node/node_api.h
Root cause is that the module name is being used as a C++ symbol when it doesn't need to be.
To fix, change NAPI_MODULE_X at line 57 of ~/.nvm/versions/node/v12.18.2/include/node/node_api.h
from:
#define NAPI_MODULE_X(modname, regfunc, priv, flags)
EXTERN_C_START
static napi_module _module =
{
NAPI_MODULE_VERSION,
flags, FILE,
regfunc,
#modname,
priv,
{0},
};
NAPI_C_CTOR(register ## modname) {
napi_module_register(&_module);
}
EXTERN_C_END
This change will use regfunc instead of modname in the token pasting for the C ctor name.
The text was updated successfully, but these errors were encountered:
djulien
changed the title
node-gyp rebuild fails with node addon api if module name contains special chars
"node-gyp rebuild" fails with node addon api if module name contains special chars
Jan 13, 2021
Version: v12.18.2 (but I've had this problem with older versions as well)
Platform: Linux djfujnb 5.4.0-58-generic transform streams: unpipe or ignore future writes after .push(null) #64-Ubuntu SMP Wed Dec 9 08:16:25 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Subsystem: node-gyp + node addon api
What steps will reproduce the bug?
"node-gyp rebuild" on a C++ node addon that contains special chars within target_name in binding.gyp
(snip from binding.gyp)
"target_name": "my-addon", #this will fail
"target_name": "my_addon", #no errors
How often does it reproduce? Is there a required condition?
100% reproducible with conditions specified
What is the expected behavior?
successful node addon rebuild
What do you see instead?
(snip from build output)
: error: expected initializer before ‘-’ token
/home/dj/.cache/node-gyp/12.18.2/include/node/node_api.h:53:15: note: in definition of macro ‘NAPI_C_CTOR’
53 | static void fn(void) attribute((constructor));
| ^~
(snip)
: error: expected initializer before ‘-’ token
/home/dj/.cache/node-gyp/12.18.2/include/node/node_api.h:54:15: note: in definition of macro ‘NAPI_C_CTOR’
54 | static void fn(void)
| ^~
/home/dj/.cache/node-gyp/12.18.2/include/node/node_api.h:75:3: note: in expansion of macro ‘NAPI_MODULE_X’
75 | NAPI_MODULE_X(modname, regfunc, NULL, 0) // NOLINT (readability/null_usage)
| ^~~~~~~~~~~~~
Additional information
Problem exists within the definition of macro NAPI_MODULE_X within ~/.nvm/versions/node/v12.18.2/include/node/node_api.h
Root cause is that the module name is being used as a C++ symbol when it doesn't need to be.
To fix, change NAPI_MODULE_X at line 57 of ~/.nvm/versions/node/v12.18.2/include/node/node_api.h
from:
#define NAPI_MODULE_X(modname, regfunc, priv, flags)
EXTERN_C_START
static napi_module _module =
{
NAPI_MODULE_VERSION,
flags,
FILE,
regfunc,
#modname,
priv,
{0},
};
NAPI_C_CTOR(register ## modname) {
napi_module_register(&_module);
}
EXTERN_C_END
to (see "CHANGED HERE"):
#define NAPI_MODULE_X(modname, regfunc, priv, flags)
EXTERN_C_START
static napi_module _module =
{
NAPI_MODULE_VERSION,
flags,
FILE,
regfunc,
#modname,
priv,
{0},
};
NAPI_C_CTOR(register ## regfunc /*modname CHANGED HERE*/) {
napi_module_register(&_module);
}
EXTERN_C_END
This change will use regfunc instead of modname in the token pasting for the C ctor name.
The text was updated successfully, but these errors were encountered: