Skip to content

Commit 2368d67

Browse files
committed
node-api: declare type napi_cleanup_hook
Declare type `napi_cleanup_hook` so that the function signature can be shared across the codebase.
1 parent 01e673c commit 2368d67

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

doc/api/n-api.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,24 @@ typedef void (*napi_threadsafe_function_call_js)(napi_env env,
897897
Unless for reasons discussed in [Object Lifetime Management][], creating a
898898
handle and/or callback scope inside the function body is not necessary.
899899

900+
#### `napi_cleanup_hook`
901+
902+
<!-- YAML
903+
added: v10.2.0
904+
napiVersion: 3
905+
-->
906+
907+
Function pointer used with [`napi_add_env_cleanup_hook`][]. It will be called
908+
when the environment is being torn down.
909+
910+
Callback functions must satisfy the following signature:
911+
912+
```c
913+
typedef void (*napi_cleanup_hook)(void* data);
914+
```
915+
916+
* `[in] data`: The data that was passed to [`napi_add_env_cleanup_hook`][].
917+
900918
#### `napi_async_cleanup_hook`
901919

902920
<!-- YAML
@@ -1798,7 +1816,7 @@ napiVersion: 3
17981816

17991817
```c
18001818
NODE_EXTERN napi_status napi_add_env_cleanup_hook(napi_env env,
1801-
void (*fun)(void* arg),
1819+
napi_cleanup_hook fun,
18021820
void* arg);
18031821
```
18041822

src/node_api.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ void NAPI_CDECL napi_module_register(napi_module* mod) {
672672
}
673673

674674
napi_status NAPI_CDECL napi_add_env_cleanup_hook(
675-
napi_env env, void(NAPI_CDECL* fun)(void* arg), void* arg) {
675+
napi_env env, napi_cleanup_hook fun, void* arg) {
676676
CHECK_ENV(env);
677677
CHECK_ARG(env, fun);
678678

@@ -682,7 +682,7 @@ napi_status NAPI_CDECL napi_add_env_cleanup_hook(
682682
}
683683

684684
napi_status NAPI_CDECL napi_remove_env_cleanup_hook(
685-
napi_env env, void(NAPI_CDECL* fun)(void* arg), void* arg) {
685+
napi_env env, napi_cleanup_hook fun, void* arg) {
686686
CHECK_ENV(env);
687687
CHECK_ARG(env, fun);
688688

src/node_api.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_fatal_exception(napi_env env,
207207
napi_value err);
208208

209209
NAPI_EXTERN napi_status NAPI_CDECL napi_add_env_cleanup_hook(
210-
napi_env env, void(NAPI_CDECL* fun)(void* arg), void* arg);
210+
napi_env env, napi_cleanup_hook fun, void* arg);
211211

212212
NAPI_EXTERN napi_status NAPI_CDECL napi_remove_env_cleanup_hook(
213-
napi_env env, void(NAPI_CDECL* fun)(void* arg), void* arg);
213+
napi_env env, napi_cleanup_hook fun, void* arg);
214214

215215
NAPI_EXTERN napi_status NAPI_CDECL
216216
napi_open_callback_scope(napi_env env,

src/node_api_types.h

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
typedef struct napi_callback_scope__* napi_callback_scope;
77
typedef struct napi_async_context__* napi_async_context;
88
typedef struct napi_async_work__* napi_async_work;
9+
10+
#if NAPI_VERSION >= 3
11+
typedef void(NAPI_CDECL* napi_cleanup_hook)(void* arg);
12+
#endif // NAPI_VERSION >= 3
13+
914
#if NAPI_VERSION >= 4
1015
typedef struct napi_threadsafe_function__* napi_threadsafe_function;
1116
#endif // NAPI_VERSION >= 4

0 commit comments

Comments
 (0)