koffi 2.5.16 → 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,6 +4,10 @@
4
4
 
5
5
  ### Koffi 2.5
6
6
 
7
+ #### Koffi 2.5.17 (2023-08-27)
8
+
9
+ - Fix compatibility with Electron
10
+
7
11
  #### Koffi 2.5.16 (2023-08-25)
8
12
 
9
13
  - Run Koffi tests through usual index.js entry point
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.16",
4
- "stable": "2.5.16",
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",
@@ -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;
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.16",
382
- stable: "2.5.16",
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
  }