Skip to content

Commit 9578c63

Browse files
committed
Propagating __attribute__((noreturn)) from headers
1 parent 29614f9 commit 9578c63

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ export function generateHeader(functions: FunctionDecl[]) {
1818
// Generate the struct of function pointers
1919
"struct WeakNodeApiHost {",
2020
...functions.map(
21-
({ returnType, name, argumentTypes }) =>
22-
`${returnType} (*${name})(${argumentTypes.join(", ")});`
21+
({ returnType, noReturn, name, argumentTypes }) =>
22+
`${returnType} ${
23+
noReturn ? " __attribute__((noreturn))" : ""
24+
}(*${name})(${argumentTypes.join(", ")});`
2325
),
2426
"};",
2527
"typedef void(*InjectHostFunction)(const WeakNodeApiHost&);",
@@ -41,9 +43,11 @@ export function generateSource(functions: FunctionDecl[]) {
4143
"};",
4244
``,
4345
// Generate function calling into the host
44-
...functions.flatMap(({ returnType, name, argumentTypes }) => {
46+
...functions.flatMap(({ returnType, noReturn, name, argumentTypes }) => {
4547
return [
46-
`extern "C" ${returnType} ${name}(${argumentTypes
48+
`extern "C" ${returnType} ${
49+
noReturn ? " __attribute__((noreturn))" : ""
50+
}${name}(${argumentTypes
4751
.map((type, index) => `${type} arg${index}`)
4852
.join(", ")}) {`,
4953
`if (g_host.${name} == nullptr) {`,

packages/react-native-node-api-modules/scripts/node-api-functions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export type FunctionDecl = {
5959
name: string;
6060
kind: "engine" | "runtime";
6161
returnType: string;
62+
noReturn: boolean;
6263
argumentTypes: string[];
6364
libraryPath: string;
6465
fallbackReturnStatement: string;
@@ -108,6 +109,7 @@ export function getNodeApiFunctions(version: NodeApiVersion = "v8") {
108109
nodeApiFunctions.push({
109110
name,
110111
returnType,
112+
noReturn: node.type.qualType.includes("__attribute__((noreturn))"),
111113
kind: engineSymbols.has(name) ? "engine" : "runtime",
112114
argumentTypes: argumentTypes
113115
.split(",")

0 commit comments

Comments
 (0)