koffi 2.9.1 → 2.10.0

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.
Files changed (93) hide show
  1. package/CHANGELOG.md +61 -48
  2. package/build/koffi/darwin_arm64/koffi.node +0 -0
  3. package/build/koffi/darwin_x64/koffi.node +0 -0
  4. package/build/koffi/freebsd_arm64/koffi.node +0 -0
  5. package/build/koffi/freebsd_ia32/koffi.node +0 -0
  6. package/build/koffi/freebsd_x64/koffi.node +0 -0
  7. package/build/koffi/linux_arm32/koffi.node +0 -0
  8. package/build/koffi/linux_arm64/koffi.node +0 -0
  9. package/build/koffi/linux_ia32/koffi.node +0 -0
  10. package/build/koffi/linux_riscv64/koffi.node +0 -0
  11. package/build/koffi/linux_x64/koffi.node +0 -0
  12. package/build/koffi/musl_x64/koffi.node +0 -0
  13. package/build/koffi/openbsd_ia32/koffi.node +0 -0
  14. package/build/koffi/openbsd_x64/koffi.node +0 -0
  15. package/build/koffi/win32_arm64/koffi.node +0 -0
  16. package/build/koffi/win32_ia32/koffi.node +0 -0
  17. package/build/koffi/win32_x64/koffi.node +0 -0
  18. package/doc/README.md +27 -0
  19. package/doc/assets.ini +19 -0
  20. package/doc/develop.sh +14 -0
  21. package/doc/flaat/flaat.css +25 -0
  22. package/doc/flaat/flaat.js +150 -0
  23. package/doc/flaat/normal.css +335 -0
  24. package/doc/flaat/print.css +30 -0
  25. package/doc/flaat/small.css +101 -0
  26. package/doc/{benchmarks.md → pages/benchmarks.md} +14 -18
  27. package/doc/{callbacks.md → pages/callbacks.md} +27 -36
  28. package/doc/{contribute.md → pages/contribute.md} +10 -12
  29. package/doc/{functions.md → pages/functions.md} +29 -34
  30. package/doc/pages/index.md +20 -0
  31. package/doc/{input.md → pages/input.md} +28 -33
  32. package/doc/{migration.md → pages/migration.md} +7 -10
  33. package/doc/{misc.md → pages/misc.md} +54 -23
  34. package/doc/{output.md → pages/output.md} +17 -20
  35. package/doc/{packaging.md → pages/packaging.md} +19 -12
  36. package/doc/{platforms.md → pages/platforms.md} +25 -11
  37. package/doc/{pointers.md → pages/pointers.md} +13 -16
  38. package/doc/{start.md → pages/start.md} +12 -14
  39. package/doc/{unions.md → pages/unions.md} +5 -7
  40. package/doc/{variables.md → pages/variables.md} +7 -11
  41. package/doc/pages.ini +89 -0
  42. package/doc/static/koffi.css +21 -0
  43. package/doc/static/koffi.js +21 -0
  44. package/doc/static/koffi.png +0 -0
  45. package/doc/static/logo.webp +0 -0
  46. package/doc/static/print.css +22 -0
  47. package/doc/templates/page.html +48 -0
  48. package/index.js +2 -2
  49. package/indirect.js +2 -2
  50. package/package.json +2 -2
  51. package/src/koffi/CMakeLists.txt +6 -0
  52. package/src/koffi/examples/yao-pkg/README.md +17 -0
  53. package/src/koffi/examples/yao-pkg/index.js +2 -0
  54. package/src/koffi/examples/yao-pkg/package.json +22 -0
  55. package/src/koffi/src/call.cc +2 -0
  56. package/src/koffi/src/ffi.cc +40 -4
  57. package/src/koffi/src/util.cc +1 -1
  58. package/doc/Makefile +0 -20
  59. package/doc/benchmarks.xlsx +0 -0
  60. package/doc/changelog.md +0 -5
  61. package/doc/conf.py +0 -118
  62. package/doc/index.rst +0 -47
  63. package/doc/make.bat +0 -35
  64. package/doc/poetry.lock +0 -521
  65. package/doc/pyproject.toml +0 -19
  66. package/doc/static/bench_linux.png +0 -0
  67. package/doc/static/bench_windows.png +0 -0
  68. package/doc/static/custom.css +0 -70
  69. package/doc/static/node_c.webp +0 -0
  70. package/doc/static/opensans/LICENSE.txt +0 -202
  71. package/doc/static/opensans/OpenSans.css +0 -39
  72. package/doc/static/opensans/OpenSans_v17_Latin_Bold.woff +0 -0
  73. package/doc/static/opensans/OpenSans_v17_Latin_Bold.woff2 +0 -0
  74. package/doc/static/opensans/OpenSans_v17_Latin_BoldItalic.woff +0 -0
  75. package/doc/static/opensans/OpenSans_v17_Latin_BoldItalic.woff2 +0 -0
  76. package/doc/static/opensans/OpenSans_v17_Latin_Italic.woff +0 -0
  77. package/doc/static/opensans/OpenSans_v17_Latin_Italic.woff2 +0 -0
  78. package/doc/static/opensans/OpenSans_v17_Latin_Regular.woff +0 -0
  79. package/doc/static/opensans/OpenSans_v17_Latin_Regular.woff2 +0 -0
  80. package/doc/static/perf_linux_20220623.png +0 -0
  81. package/doc/static/perf_linux_20220623_2.png +0 -0
  82. package/doc/static/perf_linux_20220627.png +0 -0
  83. package/doc/static/perf_linux_20220628.png +0 -0
  84. package/doc/static/perf_linux_20220812.png +0 -0
  85. package/doc/static/perf_windows_20220623.png +0 -0
  86. package/doc/static/perf_windows_20220623_2.png +0 -0
  87. package/doc/static/perf_windows_20220627.png +0 -0
  88. package/doc/static/perf_windows_20220628.png +0 -0
  89. package/doc/static/perf_windows_20220812.png +0 -0
  90. package/doc/templates/badges.html +0 -7
  91. package/doc/templates/logo.html +0 -3
  92. /package/doc/static/{perf_linux_20231028.png → perf_linux.png} +0 -0
  93. /package/doc/static/{perf_windows_20231028.png → perf_windows.png} +0 -0
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "KoffiConfig",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "start": "node index.js",
8
+ "bundle": "pkg ."
9
+ },
10
+ "author": "",
11
+ "license": "ISC",
12
+ "dependencies": {
13
+ "koffi": "^2.5.18"
14
+ },
15
+ "devDependencies": {
16
+ "@yao-pkg/pkg": "^6.1.1"
17
+ },
18
+ "bin": "index.js",
19
+ "pkg": {
20
+ "outputPath": "dist"
21
+ }
22
+ }
@@ -321,6 +321,7 @@ Size CallData::PushString16Value(Napi::Value value, const char16_t **out_str16)
321
321
  size_t len = 0;
322
322
  napi_status status;
323
323
 
324
+ mem->heap.ptr = AlignUp(mem->heap.ptr, 2);
324
325
  buf.ptr = (char16_t *)mem->heap.ptr;
325
326
  buf.len = std::max((Size)0, mem->heap.len - Kibibytes(32)) / 2;
326
327
 
@@ -426,6 +427,7 @@ Size CallData::PushString32Value(Napi::Value value, const char32_t **out_str32)
426
427
  if (buf16.len < 0) [[unlikely]]
427
428
  return -1;
428
429
 
430
+ mem->heap.ptr = AlignUp(mem->heap.ptr, 4);
429
431
  buf.ptr = (char32_t *)mem->heap.ptr;
430
432
  buf.len = std::max((Size)0, mem->heap.len - Kibibytes(32)) / 4;
431
433
 
@@ -244,8 +244,9 @@ static Napi::Value CreateStructType(const Napi::CallbackInfo &info, bool pad)
244
244
  }
245
245
 
246
246
  bool named = info.Length() > 1;
247
+ bool redefine = named && CheckValueTag(instance, info[0], &TypeInfoMarker);
247
248
 
248
- if (named && !info[0].IsString()) {
249
+ if (named && !info[0].IsString() && !redefine) {
249
250
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value for name, expected string", GetValueType(instance, info[0]));
250
251
  return env.Null();
251
252
  }
@@ -274,8 +275,20 @@ static Napi::Value CreateStructType(const Napi::CallbackInfo &info, bool pad)
274
275
  };
275
276
 
276
277
  TypeInfo *type = instance->types.AppendDefault();
278
+ TypeInfo *replace = nullptr;
277
279
 
278
- if (named) {
280
+ if (redefine) {
281
+ Napi::External<TypeInfo> external = name.As<Napi::External<TypeInfo>>();
282
+ const TypeInfo *raw = external.Data();
283
+
284
+ replace = (TypeInfo *)AlignDown(raw, 4);
285
+ type->name = replace->name;
286
+
287
+ if (replace->primitive != PrimitiveKind::Void || replace == instance->void_type) {
288
+ ThrowError<Napi::TypeError>(env, "Cannot redefine non-opaque type %1", replace->name);
289
+ return env.Null();
290
+ }
291
+ } else if (named) {
279
292
  type->name = DuplicateString(name.Utf8Value().c_str(), &instance->str_alloc).ptr;
280
293
 
281
294
  if (!MapType(env, instance, type, type->name))
@@ -366,6 +379,11 @@ static Napi::Value CreateStructType(const Napi::CallbackInfo &info, bool pad)
366
379
  type->flags &= ~(int)TypeFlag::IsIncomplete;
367
380
  err_guard.Disable();
368
381
 
382
+ if (replace) {
383
+ std::swap(*type, *replace);
384
+ type = replace;
385
+ }
386
+
369
387
  return WrapType(env, instance, type);
370
388
  }
371
389
 
@@ -390,8 +408,9 @@ static Napi::Value CreateUnionType(const Napi::CallbackInfo &info)
390
408
  }
391
409
 
392
410
  bool named = info.Length() > 1;
411
+ bool redefine = named && CheckValueTag(instance, info[0], &TypeInfoMarker);
393
412
 
394
- if (named && !info[0].IsString()) {
413
+ if (named && !info[0].IsString() && !redefine) {
395
414
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value for name, expected string", GetValueType(instance, info[0]));
396
415
  return env.Null();
397
416
  }
@@ -420,8 +439,20 @@ static Napi::Value CreateUnionType(const Napi::CallbackInfo &info)
420
439
  };
421
440
 
422
441
  TypeInfo *type = instance->types.AppendDefault();
442
+ TypeInfo *replace = nullptr;
423
443
 
424
- if (named) {
444
+ if (redefine) {
445
+ Napi::External<TypeInfo> external = name.As<Napi::External<TypeInfo>>();
446
+ const TypeInfo *raw = external.Data();
447
+
448
+ replace = (TypeInfo *)AlignDown(raw, 4);
449
+ type->name = replace->name;
450
+
451
+ if (replace->primitive != PrimitiveKind::Void || replace == instance->void_type) {
452
+ ThrowError<Napi::TypeError>(env, "Cannot redefine non-opaque type %1", replace->name);
453
+ return env.Null();
454
+ }
455
+ } else if (named) {
425
456
  type->name = DuplicateString(name.Utf8Value().c_str(), &instance->str_alloc).ptr;
426
457
 
427
458
  if (!MapType(env, instance, type, type->name))
@@ -507,6 +538,11 @@ static Napi::Value CreateUnionType(const Napi::CallbackInfo &info)
507
538
  Napi::Function constructor = MagicUnion::InitClass(env, type);
508
539
  type->construct.Reset(constructor, 1);
509
540
 
541
+ if (replace) {
542
+ std::swap(*type, *replace);
543
+ type = replace;
544
+ }
545
+
510
546
  return WrapType(env, instance, type);
511
547
  }
512
548
 
@@ -146,8 +146,8 @@ const TypeInfo *ResolveType(Napi::Value value, int *out_directions)
146
146
  return type;
147
147
  } else if (CheckValueTag(instance, value, &TypeInfoMarker)) {
148
148
  Napi::External<TypeInfo> external = value.As<Napi::External<TypeInfo>>();
149
-
150
149
  const TypeInfo *raw = external.Data();
150
+
151
151
  const TypeInfo *type = AlignDown(raw, 4);
152
152
  RG_ASSERT(type);
153
153
 
package/doc/Makefile DELETED
@@ -1,20 +0,0 @@
1
- # Minimal makefile for Sphinx documentation
2
- #
3
-
4
- # You can set these variables from the command line, and also
5
- # from the environment for the first two.
6
- SPHINXOPTS ?=
7
- SPHINXBUILD ?= sphinx-build
8
- SOURCEDIR = .
9
- BUILDDIR = dist
10
-
11
- # Put it first so that "make" without argument is like "make help".
12
- help:
13
- @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14
-
15
- .PHONY: help Makefile
16
-
17
- # Catch-all target: route all unknown targets to Sphinx using the new
18
- # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19
- %: Makefile
20
- @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Binary file
package/doc/changelog.md DELETED
@@ -1,5 +0,0 @@
1
- ---
2
- tocdepth: 3
3
- ---
4
-
5
- {{ "```{include} " ~ root ~ "/CHANGELOG.md" ~ "\n```" }}
package/doc/conf.py DELETED
@@ -1,118 +0,0 @@
1
- import json
2
- import os
3
-
4
- # -- Project information -----------------------------------------------------
5
-
6
- project = 'Koffi'
7
- copyright = '2022, Niels Martignène'
8
- author = 'Niels Martignène'
9
-
10
- root = None
11
- version = None
12
- revision = None
13
- stable = None
14
-
15
- names = ['../../src/koffi/package.json', '../package.json']
16
-
17
- for name in names:
18
- filename = os.path.dirname(__file__) + '/' + name
19
-
20
- if not os.path.exists(filename):
21
- continue;
22
-
23
- with open(filename) as f:
24
- config = json.load(f)
25
-
26
- root = os.path.dirname(name)
27
- version = config['version']
28
- revision = config['version']
29
- stable = config['stable']
30
-
31
- break
32
-
33
- if root is None:
34
- raise FileNotFoundError('Cannot find Koffi package.json')
35
-
36
- # -- General configuration ---------------------------------------------------
37
-
38
- extensions = [
39
- 'myst_parser',
40
- 'sphinx.ext.autosectionlabel',
41
- 'sphinxext.rediraffe'
42
- ]
43
-
44
- # Add any paths that contain templates here, relative to this directory.
45
- templates_path = ['templates']
46
-
47
- exclude_patterns = []
48
-
49
- # -- Options for HTML output -------------------------------------------------
50
-
51
- html_title = project
52
-
53
- html_theme = 'furo'
54
-
55
- html_static_path = ['static']
56
-
57
- html_theme_options = {
58
- 'light_css_variables': {
59
- 'font-stack': 'Open Sans',
60
- 'color-content-foreground': '#383838',
61
- 'color-brand-primary': '#383838',
62
- 'color-brand-content': '#e97713'
63
- },
64
- 'dark_css_variables': {
65
- 'font-stack': 'Open Sans',
66
- 'color-content-foreground': '#ffffffdd',
67
- 'color-brand-primary': '#ffffffdd',
68
- 'color-brand-content': '#e97713'
69
- }
70
- }
71
-
72
- html_link_suffix = ''
73
-
74
- html_css_files = [
75
- 'opensans/OpenSans.css',
76
- 'custom.css'
77
- ]
78
-
79
- html_sidebars = {
80
- "**": [
81
- "logo.html",
82
- "sidebar/search.html",
83
- "sidebar/scroll-start.html",
84
- "sidebar/navigation.html",
85
- "sidebar/ethical-ads.html",
86
- "badges.html",
87
- "sidebar/scroll-end.html",
88
- "sidebar/variant-selector.html"
89
- ]
90
- }
91
-
92
- html_context = {
93
- "root": root,
94
- "stable": stable
95
- }
96
-
97
- # -- MyST parser options -------------------------------------------------
98
-
99
- myst_enable_extensions = [
100
- 'linkify',
101
- 'substitution'
102
- ]
103
-
104
- myst_substitutions = html_context
105
-
106
- myst_heading_anchors = 3
107
-
108
- myst_linkify_fuzzy_links = False
109
-
110
- myst_number_code_blocks = ['c', 'js', 'sh', 'batch']
111
-
112
- # -- Redirections -------------------------------------------------
113
-
114
- rediraffe_redirects = {
115
- "changes.md": "changelog.md",
116
- "bundling.md": "packaging.md",
117
- "parameters.md": "input.md"
118
- }
package/doc/index.rst DELETED
@@ -1,47 +0,0 @@
1
- Koffi
2
- =====
3
-
4
- Overview
5
- --------
6
-
7
- Koffi is a **fast and easy-to-use C FFI module for Node.js**, featuring:
8
-
9
- * Low-overhead and fast performance (see :ref:`benchmarks<Benchmarks>`)
10
- * Support for primitive and aggregate data types (structs and fixed-size arrays), both by reference (pointer) and by value
11
- * Javascript functions can be used as C callbacks (since 1.2.0)
12
- * Well-tested code base for :ref:`popular OS/architecture combinations<Supported platforms>`
13
-
14
- Koffi requires a recent `Node.js <https://nodejs.org/>`_ version with N-API version 8 support, see :ref:`this page<Node.js>` for more information.
15
-
16
- The source code is available here: https://github.com/Koromix/rygel/ (in the *src/koffi* subdirectory).
17
-
18
- New releases are frequent, look at the :ref:`changelog<changelog>` for more information.
19
-
20
- Table of contents
21
- -----------------
22
-
23
- .. toctree::
24
- :maxdepth: 3
25
-
26
- platforms
27
- start
28
- functions
29
- input
30
- pointers
31
- output
32
- unions
33
- variables
34
- callbacks
35
- misc
36
- packaging
37
- benchmarks
38
- contribute
39
- changelog
40
- migration
41
-
42
- License
43
- -------
44
-
45
- This program is free software: you can redistribute it and/or modify it under the terms of the **MIT License**.
46
-
47
- Find more information here: https://choosealicense.com/licenses/mit/
package/doc/make.bat DELETED
@@ -1,35 +0,0 @@
1
- @ECHO OFF
2
-
3
- pushd %~dp0
4
-
5
- REM Command file for Sphinx documentation
6
-
7
- if "%SPHINXBUILD%" == "" (
8
- set SPHINXBUILD=sphinx-build
9
- )
10
- set SOURCEDIR=.
11
- set BUILDDIR=dist
12
-
13
- %SPHINXBUILD% >NUL 2>NUL
14
- if errorlevel 9009 (
15
- echo.
16
- echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
17
- echo.installed, then set the SPHINXBUILD environment variable to point
18
- echo.to the full path of the 'sphinx-build' executable. Alternatively you
19
- echo.may add the Sphinx directory to PATH.
20
- echo.
21
- echo.If you don't have Sphinx installed, grab it from
22
- echo.https://www.sphinx-doc.org/
23
- exit /b 1
24
- )
25
-
26
- if "%1" == "" goto help
27
-
28
- %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29
- goto end
30
-
31
- :help
32
- %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33
-
34
- :end
35
- popd