Skip to content

Commit 2cb0726

Browse files
committed
Rename inject_host to inject_weak_node_api_host, mark it extern "C" and move it out of namespace
1 parent e74a133 commit 2cb0726

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

packages/react-native-node-api-modules/scripts/generate-weak-node-api-injector.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,23 @@ export function generateSource(functions: FunctionDecl[]) {
2525
#endif
2626
2727
namespace callstack::nodeapihost {
28-
29-
using node_api::internal::InjectHostFunction;
30-
using node_api::internal::NodeApiHost;
3128
3229
void injectIntoWeakNodeApi() {
3330
void *module = dlopen(WEAK_NODE_API_LIBRARY_NAME, RTLD_NOW | RTLD_LOCAL);
34-
if (NULL == module) {
31+
if (nullptr == module) {
3532
log_debug("NapiHost: Failed to load weak-node-api: %s", dlerror());
3633
abort();
3734
}
3835
39-
auto inject_host = (InjectHostFunction)dlsym(
40-
module, "_ZN8node_api8internal11inject_hostERKNS0_11NodeApiHostE");
41-
if (NULL == inject_host) {
42-
log_debug("NapiHost: Failed to find 'inject_host' function: %s", dlerror());
36+
auto inject_weak_node_api_host = (InjectHostFunction)dlsym(
37+
module, "inject_weak_node_api_host");
38+
if (nullptr == inject_weak_node_api_host) {
39+
log_debug("NapiHost: Failed to find 'inject_weak_node_api_host' function: %s", dlerror());
4340
abort();
4441
}
4542
4643
log_debug("Injecting WeakNodeApiHost");
47-
inject_host(NodeApiHost {
44+
inject_weak_node_api_host(WeakNodeApiHost {
4845
${functions
4946
.filter(({ kind }) => kind === "engine")
5047
.flatMap(({ name }) => `.${name} = ${name},`)

packages/react-native-node-api-modules/scripts/generate-weak-node-api.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ export function generateHeader(functions: FunctionDecl[]) {
1515
"#include <node_api.h>", // Node-API
1616
"#include <stdio.h>", // fprintf()
1717
"#include <stdlib.h>", // abort()
18-
"namespace node_api::internal {",
1918
// Generate the struct of function pointers
20-
"struct NodeApiHost {",
19+
"struct WeakNodeApiHost {",
2120
...functions.map(
2221
({ returnType, name, argumentTypes }) =>
2322
`${returnType} (*${name})(${argumentTypes.join(", ")});`
2423
),
2524
"};",
26-
"typedef void(*InjectHostFunction)(const NodeApiHost&);",
25+
"typedef void(*InjectHostFunction)(const WeakNodeApiHost&);",
26+
`extern "C" void inject_weak_node_api_host(const WeakNodeApiHost& host);`,
2727
].join("\n");
2828
}
2929

@@ -34,14 +34,11 @@ export function generateSource(functions: FunctionDecl[]) {
3434
return [
3535
"// This file is generated by react-native-node-api-modules",
3636
`#include "weak_node_api.hpp"`, // Generated header
37-
"namespace node_api::internal {",
3837
// Generate the struct of function pointers
39-
"NodeApiHost g_host;",
40-
"void inject_host(const NodeApiHost& host) {",
38+
"WeakNodeApiHost g_host;",
39+
"void inject_weak_node_api_host(const WeakNodeApiHost& host) {",
4140
" g_host = host;",
4241
"};",
43-
"} // namespace node_api::internal",
44-
"using node_api::internal::g_host;",
4542
``,
4643
// Generate function calling into the host
4744
...functions.flatMap(({ returnType, name, argumentTypes }) => {

0 commit comments

Comments
 (0)