koffi 2.5.15 → 2.5.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,15 +4,20 @@
4
4
 
5
5
  ### Koffi 2.5
6
6
 
7
- #### Koffi 2.5.15 (2023-08-24)
7
+ #### Koffi 2.5.17 (2023-08-27)
8
8
 
9
- - Run Koffi tests through usual index.js entry point
9
+ - Fix compatibility with Electron
10
10
 
11
- #### Koffi 2.5.14 (2023-08-23)
11
+ #### Koffi 2.5.16 (2023-08-25)
12
12
 
13
+ - Run Koffi tests through usual index.js entry point
13
14
  - Fix DLL error when using Koffi from NW.js on Windows
14
15
  - Simplify NW.js Koffi example
15
16
 
17
+ ```{warning}
18
+ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those versions.
19
+ ```
20
+
16
21
  #### Koffi 2.5.12 (2023-08-21)
17
22
 
18
23
  - Fix native module bundling for FreeBSD ARM64 and Linux RISC-V 64
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/doc/benchmarks.md CHANGED
@@ -23,10 +23,10 @@ The results presented below were measured on my x86_64 Linux machine (Intel® Co
23
23
 
24
24
  ### rand results
25
25
 
26
- This test is based around repeated calls to a simple standard C function atoi, and has three implementations:
26
+ This test is based around repeated calls to a simple standard C function `rand`, and has three implementations:
27
27
 
28
- - the first one is the reference, it calls atoi through an N-API module, and is close to the theoretical limit of a perfect (no overhead) Node.js > C FFI implementation (pre-compiled static glue code)
29
- - the second one calls atoi through Koffi
28
+ - the first one is the reference, it calls rand through an N-API module, and is close to the theoretical limit of a perfect (no overhead) Node.js > C FFI implementation (pre-compiled static glue code)
29
+ - the second one calls rand through Koffi
30
30
  - the third one uses the official Node.js FFI implementation, node-ffi-napi
31
31
 
32
32
  Benchmark | Iteration time | Relative performance | Overhead
@@ -39,7 +39,7 @@ Because rand is a pretty small function, the FFI overhead is clearly visible.
39
39
 
40
40
  ### atoi results
41
41
 
42
- This test is similar to the rand one, but it is based on atoi, which takes a string parameter. Javascript (V8) to C string conversion is relatively slow and heavy.
42
+ This test is similar to the rand one, but it is based on `atoi`, which takes a string parameter. Javascript (V8) to C string conversion is relatively slow and heavy.
43
43
 
44
44
  Benchmark | Iteration time | Relative performance | Overhead
45
45
  ------------- | -------------- | -------------------- | --------
@@ -51,7 +51,7 @@ Because atoi is a pretty small function, the FFI overhead is clearly visible.
51
51
 
52
52
  ### Raylib results
53
53
 
54
- This benchmark uses the CPU-based image drawing functions in Raylib. The calls are much heavier than in the atoi benchmark, thus the FFI overhead is reduced. In this implementation, Koffi is compared to:
54
+ This benchmark uses the CPU-based image drawing functions in Raylib. The calls are much heavier than in previous benchmarks, thus the FFI overhead is reduced. In this implementation, Koffi is compared to:
55
55
 
56
56
  - Baseline: Full C++ version of the code (no JS)
57
57
  - [node-raylib](https://github.com/RobLoach/node-raylib): This is a native wrapper implemented with N-API
@@ -69,10 +69,10 @@ The results presented below were measured on my x86_64 Windows machine (Intel®
69
69
 
70
70
  ### rand results
71
71
 
72
- This test is based around repeated calls to a simple standard C function atoi, and has three implementations:
72
+ This test is based around repeated calls to a simple standard C function `rand`, and has three implementations:
73
73
 
74
- - the first one is the reference, it calls atoi through an N-API module, and is close to the theoretical limit of a perfect (no overhead) Node.js > C FFI implementation (pre-compiled static glue code)
75
- - the second one calls atoi through Koffi
74
+ - the first one is the reference, it calls rand through an N-API module, and is close to the theoretical limit of a perfect (no overhead) Node.js > C FFI implementation (pre-compiled static glue code)
75
+ - the second one calls rand through Koffi
76
76
  - the third one uses the official Node.js FFI implementation, node-ffi-napi
77
77
 
78
78
  Benchmark | Iteration time | Relative performance | Overhead
@@ -85,7 +85,7 @@ Because rand is a pretty small function, the FFI overhead is clearly visible.
85
85
 
86
86
  ### atoi results
87
87
 
88
- This test is similar to the rand one, but it is based on atoi, which takes a string parameter. Javascript (V8) to C string conversion is relatively slow and heavy.
88
+ This test is similar to the rand one, but it is based on `atoi`, which takes a string parameter. Javascript (V8) to C string conversion is relatively slow and heavy.
89
89
 
90
90
  The results below were measured on my x86_64 Windows machine (Intel® Core™ i5-4460):
91
91
 
package/doc/start.md CHANGED
@@ -20,7 +20,7 @@ import koffi from 'koffi';
20
20
 
21
21
  ## Simple examples
22
22
 
23
- Below you can find three examples:
23
+ Below you can find two examples:
24
24
 
25
25
  * The first one runs on Linux. The functions are declared with the C-like prototype language.
26
26
  * The second one runs on Windows, and uses the node-ffi like syntax to declare functions.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koffi",
3
- "version": "2.5.15",
4
- "stable": "2.5.15",
3
+ "version": "2.5.17",
4
+ "stable": "2.5.17",
5
5
  "description": "Fast and simple C FFI (foreign function interface) for Node.js",
6
6
  "keywords": [
7
7
  "foreign",
@@ -25,7 +25,7 @@
25
25
  "main": "src/index.js",
26
26
  "types": "src/index.d.ts",
27
27
  "scripts": {
28
- "install": "node src/cnoke/cnoke.js --prebuild -d src/koffi"
28
+ "install": "node src/cnoke/cnoke.js -p . -d src/koffi --prebuild"
29
29
  },
30
30
  "license": "MIT",
31
31
  "cnoke": {
@@ -29,41 +29,24 @@
29
29
  #include <windows.h>
30
30
  #include <delayimp.h>
31
31
 
32
- static HMODULE node_dll;
33
- static HMODULE nw_dll;
34
-
35
32
  static FARPROC WINAPI self_exe_hook(unsigned int event, DelayLoadInfo *info)
36
33
  {
37
- if (event == dliStartProcessing) {
38
- node_dll = GetModuleHandleA("node.dll");
39
- nw_dll = GetModuleHandleA("nw.dll");
40
-
41
- return NULL;
42
- }
43
-
44
- if (event == dliNotePreGetProcAddress) {
45
- if (node_dll) {
46
- FARPROC ret = GetProcAddress(node_dll, info->dlp.szProcName);
47
- if (ret)
48
- return ret;
49
- }
50
-
51
- if (nw_dll) {
52
- FARPROC ret = GetProcAddress(nw_dll, info->dlp.szProcName);
53
- if (ret)
54
- return ret;
55
- }
56
- }
57
-
58
- if (event == dliNotePreLoadLibrary && _stricmp(info->szDll, "node.exe") != 0) {
59
- if (!node_dll) {
60
- node_dll = GetModuleHandleA(NULL);
34
+ static const wchar_t *const NodeLibraries[] = {
35
+ L"node.dll",
36
+ NULL
37
+ };
38
+
39
+ if (event == dliNotePreLoadLibrary && !stricmp(info->szDll, "node.exe")) {
40
+ for (int i = 0; i < sizeof(NodeLibraries) / sizeof(*NodeLibraries); i++) {
41
+ const wchar_t *name = NodeLibraries[i];
42
+ HMODULE h = GetModuleHandleW(name);
43
+
44
+ if (h)
45
+ return (FARPROC)h;
61
46
  }
62
- return (FARPROC)node_dll;
63
47
  }
64
48
 
65
49
  return NULL;
66
50
  }
67
51
 
68
52
  const PfnDliHook __pfnDliNotifyHook2 = self_exe_hook;
69
- const PfnDliHook __pfnDliFailureHook2 = self_exe_hook;
@@ -77,7 +77,12 @@ async function main() {
77
77
  throw new Error(`Missing value for ${arg}`);
78
78
 
79
79
  config.project_dir = fs.realpathSync(value);
80
- } else if (arg == '-o' || arg == '--output') {
80
+ } else if (arg == '-p' || arg == '--package') {
81
+ if (value == null)
82
+ throw new Error(`Missing value for ${arg}`);
83
+
84
+ config.package_dir = fs.realpathSync(value);
85
+ } else if (arg == '-O' || arg == '--out') {
81
86
  if (value == null)
82
87
  throw new Error(`Missing value for ${arg}`);
83
88
 
@@ -153,9 +158,12 @@ Commands:
153
158
  clean Clean build files
154
159
 
155
160
  Options:
156
- -d, --directory <DIR> Change project directory
161
+ -d, --directory <DIR> Change source directory
157
162
  (default: current working directory)
158
- -O, --output <DIR> Change explicit output directory
163
+ -p, --package <DIR> Change package directory
164
+ (default: current working directory)
165
+
166
+ -O, --out <DIR> Set explicit output directory
159
167
  (default: ./build)
160
168
 
161
169
  -B, --config <CONFIG> Change build type: RelWithDebInfo, Debug, Release
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cnoke",
3
- "version": "3.3.2",
3
+ "version": "4.0.1",
4
4
  "description": "Build native Node addons based on CMake, without extra dependency",
5
5
  "keywords": [
6
6
  "native",
@@ -36,6 +36,7 @@ function Builder(config = {}) {
36
36
 
37
37
  let app_dir = config.app_dir;
38
38
  let project_dir = config.project_dir;
39
+ let package_dir = config.package_dir;
39
40
 
40
41
  if (app_dir == null)
41
42
  app_dir = __dirname.replace(/\\/g, '/') + '/..';
@@ -43,6 +44,9 @@ function Builder(config = {}) {
43
44
  project_dir = process.cwd();
44
45
  app_dir = app_dir.replace(/\\/g, '/');
45
46
  project_dir = project_dir.replace(/\\/g, '/');
47
+ if (package_dir == null)
48
+ package_dir = project_dir;
49
+ package_dir = package_dir.replace(/\\/g, '/');
46
50
 
47
51
  let runtime_version = config.runtime_version;
48
52
  let arch = config.arch;
@@ -68,15 +72,14 @@ function Builder(config = {}) {
68
72
  let pkg = read_package_json();
69
73
 
70
74
  if (pkg.cnoke.output != null) {
71
- build_dir = pkg.cnoke.output;
75
+ build_dir = expand_path(pkg.cnoke.output);
72
76
 
73
77
  if (!tools.path_is_absolute(build_dir))
74
- build_dir = project_dir + '/' + build_dir;
78
+ build_dir = package_dir + '/' + build_dir;
75
79
  } else {
76
80
  build_dir = project_dir + '/build';
77
81
  }
78
82
  }
79
- build_dir = expand_path(build_dir);
80
83
  work_dir = build_dir + `/v${runtime_version}_${arch}`;
81
84
 
82
85
  let cmake_bin = null;
@@ -285,7 +288,7 @@ function Builder(config = {}) {
285
288
  archive_filename = url;
286
289
 
287
290
  if (!tools.path_is_absolute(archive_filename))
288
- archive_filename = path.join(project_dir, archive_filename);
291
+ archive_filename = path.join(package_dir, archive_filename);
289
292
 
290
293
  if (!fs.existsSync(archive_filename))
291
294
  throw new Error('Cannot find local prebuilt archive');
@@ -302,7 +305,7 @@ function Builder(config = {}) {
302
305
  let require_filename = expand_path(pkg.cnoke.require);
303
306
 
304
307
  if (!tools.path_is_absolute(require_filename))
305
- require_filename = path.join(project_dir, require_filename);
308
+ require_filename = path.join(package_dir, require_filename);
306
309
 
307
310
  if (fs.existsSync(require_filename)) {
308
311
  let proc = spawnSync(process.execPath, ['-e', 'require(process.argv[1])', require_filename]);
@@ -320,6 +323,21 @@ function Builder(config = {}) {
320
323
  tools.unlink_recursive(build_dir);
321
324
  };
322
325
 
326
+ function find_parent_directory(dirname, basename)
327
+ {
328
+ if (process.platform == 'win32')
329
+ dirname = dirname.replace(/\\/g, '/');
330
+
331
+ do {
332
+ if (fs.existsSync(dirname + '/' + basename))
333
+ return dirname;
334
+
335
+ dirname = path.dirname(dirname);
336
+ } while (!dirname.endsWith('/'));
337
+
338
+ return null;
339
+ }
340
+
323
341
  function get_cache_directory() {
324
342
  if (process.platform == 'win32') {
325
343
  let cache_dir = process.env['APPDATA'];
@@ -404,12 +422,14 @@ function Builder(config = {}) {
404
422
  function read_package_json() {
405
423
  let pkg = {};
406
424
 
407
- try {
408
- let json = fs.readFileSync(project_dir + '/package.json', { encoding: 'utf-8' });
409
- pkg = JSON.parse(json);
410
- } catch (err) {
411
- if (err.code != 'ENOENT')
412
- throw err;
425
+ if (package_dir != null) {
426
+ try {
427
+ let json = fs.readFileSync(package_dir + '/package.json', { encoding: 'utf-8' });
428
+ pkg = JSON.parse(json);
429
+ } catch (err) {
430
+ if (err.code != 'ENOENT')
431
+ throw err;
432
+ }
413
433
  }
414
434
 
415
435
  if (pkg.cnoke == null)
package/src/index.js CHANGED
@@ -378,8 +378,8 @@ var require_package = __commonJS({
378
378
  "build/dist/src/koffi/package.json"(exports2, module2) {
379
379
  module2.exports = {
380
380
  name: "koffi",
381
- version: "2.5.15",
382
- stable: "2.5.15",
381
+ version: "2.5.17",
382
+ stable: "2.5.17",
383
383
  description: "Fast and simple C FFI (foreign function interface) for Node.js",
384
384
  keywords: [
385
385
  "foreign",
@@ -16,6 +16,6 @@
16
16
  "esbuild": "^0.18.17"
17
17
  },
18
18
  "dependencies": {
19
- "koffi": "^2.5.9"
19
+ "koffi": "2.5.17"
20
20
  }
21
21
  }
@@ -32,6 +32,6 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "electron-squirrel-startup": "^1.0.0",
35
- "koffi": "^2.5.9"
35
+ "koffi": "^2.5.17"
36
36
  }
37
37
  }
@@ -11,6 +11,6 @@
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
13
  "esbuild": "^0.18.17",
14
- "koffi": "^2.5.9"
14
+ "koffi": "^2.5.17"
15
15
  }
16
16
  }
@@ -5,6 +5,6 @@
5
5
  "author": "Niels Martignène <niels.martignene@protonmail.com>",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
- "koffi": "^2.5.14"
8
+ "koffi": "^2.5.17"
9
9
  }
10
10
  }
package/koffi-2.5.15.tgz DELETED
Binary file