File: addon.c

package info (click to toggle)
nodejs 20.19.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 219,072 kB
  • sloc: cpp: 1,277,408; javascript: 565,332; ansic: 129,476; python: 58,536; sh: 3,841; makefile: 2,725; asm: 1,732; perl: 248; lisp: 222; xml: 42
file content (22 lines) | stat: -rw-r--r-- 611 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <stdio.h>
#include <stdlib.h>
#include <node_api.h>

static void addon_free(napi_env env, void* data, void* hint) {
  napi_ref* ref = data;
  napi_delete_reference(env, *ref);
  free(ref);
  fprintf(stderr, "addon_free");
}

napi_value addon_new(napi_env env, napi_value exports, bool ref_first) {
  napi_ref* ref = malloc(sizeof(*ref));
  if (ref_first) {
    napi_create_reference(env, exports, 1, ref);
    napi_set_instance_data(env, ref, addon_free, NULL);
  } else {
    napi_set_instance_data(env, ref, addon_free, NULL);
    napi_create_reference(env, exports, 1, ref);
  }
  return exports;
}