koffi 3.0.1 → 3.0.2

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.
@@ -12,6 +12,34 @@ namespace K {
12
12
  // #define EXTERNAL_POINTERS
13
13
  // #define EXTERNAL_TYPES
14
14
 
15
+ #if defined(_MSC_VER)
16
+ #define FORCE_INLINE __forceinline
17
+ #else
18
+ #define FORCE_INLINE __attribute__((always_inline)) inline
19
+ #endif
20
+ #if defined(UNITY_BUILD)
21
+ #define INLINE_UNITY FORCE_INLINE
22
+ #else
23
+ #define INLINE_UNITY
24
+ #endif
25
+
26
+ #if defined(__GNUC__) || defined(__clang__)
27
+ #if __has_attribute(musttail) && __has_attribute(preserve_none)
28
+ #define MUST_TAIL __attribute__((musttail))
29
+ #define PRESERVE_NONE __attribute__((preserve_none))
30
+ #elif __has_attribute(musttail) && !defined(__clang__)
31
+ // GCC regalloc seems better, so the generated code is not too bad even without preserve_none
32
+ #define MUST_TAIL __attribute__((musttail))
33
+ #define PRESERVE_NONE
34
+ #endif
35
+ #endif
36
+
37
+ #define NAPI_OK(Call) \
38
+ do { \
39
+ napi_status status = (Call); \
40
+ K_ASSERT(status == napi_ok); \
41
+ } while (false)
42
+
15
43
  static const Size DefaultSyncStackSize = Mebibytes(1);
16
44
  static const Size DefaultSyncHeapSize = Mebibytes(2);
17
45
  static const Size DefaultAsyncStackSize = Kibibytes(128);
@@ -50,11 +78,13 @@ enum class TypeFlag {
50
78
  enum class ArrayHint {
51
79
  Array,
52
80
  Typed,
81
+ Buffer,
53
82
  String
54
83
  };
55
84
  static const char *const ArrayHintNames[] = {
56
85
  "Array",
57
86
  "Typed",
87
+ "Buffer",
58
88
  "String"
59
89
  };
60
90
 
@@ -121,7 +151,7 @@ class LibraryHandle: public Napi::ObjectWrap<LibraryHandle> {
121
151
  LibraryHolder *lib = nullptr;
122
152
 
123
153
  public:
124
- static Napi::Function InitClass(Napi::Env env);
154
+ static Napi::Function InitClass(InstanceData *instance);
125
155
 
126
156
  LibraryHandle(const Napi::CallbackInfo &info);
127
157
 
@@ -389,6 +419,12 @@ struct SharedData {
389
419
  };
390
420
  static_assert(MaxTrampolines <= INT16_MAX);
391
421
 
422
+ extern const napi_type_tag LibraryHandleMarker;
423
+ extern const napi_type_tag TypeObjectMarker;
424
+ extern const napi_type_tag DirectionMarker;
425
+ extern const napi_type_tag UnionValueMarker;
426
+ extern const napi_type_tag CastMarker;
427
+
392
428
  extern SharedData shared;
393
429
 
394
430
  // Some Node-API functions are loaded dynamically to work around bugs or because they are recent
@@ -4,6 +4,8 @@
4
4
  #include "lib/native/base/base.hh"
5
5
  #include "ffi.hh"
6
6
  #include "parser.hh"
7
+ #include "type.hh"
8
+ #include "util.hh"
7
9
 
8
10
  #include <napi.h>
9
11
 
@@ -159,7 +161,7 @@ const TypeInfo *PrototypeParser::ParseType(int *out_directions)
159
161
 
160
162
  while (offset >= start) {
161
163
  Span<const char> str = MakeSpan(tokens[start].ptr, tokens[offset].end() - tokens[start].ptr);
162
- const TypeInfo *type = ResolveType(env, str);
164
+ const TypeInfo *type = ResolveType(instance, str);
163
165
 
164
166
  if (type) {
165
167
  offset++;
@@ -0,0 +1,122 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: 2026 Niels Martignène <niels.martignene@protonmail.com>
3
+
4
+ function loadStatic(pkg) {
5
+ let native = null;
6
+
7
+ if (pkg == 'linux-arm64') {
8
+ try {
9
+ native = require('@koromix/koffi-linux-arm64');
10
+ } catch (err) {
11
+ // Go on
12
+ }
13
+ }
14
+
15
+ if (pkg == 'linux-ia32') {
16
+ try {
17
+ native = require('@koromix/koffi-linux-ia32');
18
+ } catch (err) {
19
+ // Go on
20
+ }
21
+ }
22
+
23
+ if (pkg == 'linux-x64') {
24
+ try {
25
+ native = require('@koromix/koffi-linux-x64');
26
+ } catch (err) {
27
+ // Go on
28
+ }
29
+ }
30
+
31
+ if (pkg == 'linux-riscv64') {
32
+ try {
33
+ native = require('@koromix/koffi-linux-riscv64');
34
+ } catch (err) {
35
+ // Go on
36
+ }
37
+ }
38
+
39
+ if (pkg == 'freebsd-ia32') {
40
+ try {
41
+ native = require('@koromix/koffi-freebsd-ia32');
42
+ } catch (err) {
43
+ // Go on
44
+ }
45
+ }
46
+
47
+ if (pkg == 'freebsd-x64') {
48
+ try {
49
+ native = require('@koromix/koffi-freebsd-x64');
50
+ } catch (err) {
51
+ // Go on
52
+ }
53
+ }
54
+
55
+ if (pkg == 'freebsd-arm64') {
56
+ try {
57
+ native = require('@koromix/koffi-freebsd-arm64');
58
+ } catch (err) {
59
+ // Go on
60
+ }
61
+ }
62
+
63
+ if (pkg == 'openbsd-ia32') {
64
+ try {
65
+ native = require('@koromix/koffi-openbsd-ia32');
66
+ } catch (err) {
67
+ // Go on
68
+ }
69
+ }
70
+
71
+ if (pkg == 'openbsd-x64') {
72
+ try {
73
+ native = require('@koromix/koffi-openbsd-x64');
74
+ } catch (err) {
75
+ // Go on
76
+ }
77
+ }
78
+
79
+ if (pkg == 'win32-ia32') {
80
+ try {
81
+ native = require('@koromix/koffi-win32-ia32');
82
+ } catch (err) {
83
+ // Go on
84
+ }
85
+ }
86
+
87
+ if (pkg == 'win32-x64') {
88
+ try {
89
+ native = require('@koromix/koffi-win32-x64');
90
+ } catch (err) {
91
+ // Go on
92
+ }
93
+ }
94
+
95
+ if (pkg == 'darwin-x64') {
96
+ try {
97
+ native = require('@koromix/koffi-darwin-x64');
98
+ } catch (err) {
99
+ // Go on
100
+ }
101
+ }
102
+
103
+ if (pkg == 'darwin-arm64') {
104
+ try {
105
+ native = require('@koromix/koffi-darwin-arm64');
106
+ } catch (err) {
107
+ // Go on
108
+ }
109
+ }
110
+
111
+ if (pkg == 'linux-loong64') {
112
+ try {
113
+ native = require('@koromix/koffi-linux-loong64');
114
+ } catch (err) {
115
+ // Go on
116
+ }
117
+ }
118
+
119
+ return native;
120
+ }
121
+
122
+ module.exports = { loadStatic };
@@ -0,0 +1,122 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: 2026 Niels Martignène <niels.martignene@protonmail.com>
3
+
4
+ function loadStatic(pkg) {
5
+ let native = null;
6
+
7
+ if (pkg == 'linux-arm64') {
8
+ try {
9
+ native = require('@koromix/koffi-linux-arm64');
10
+ } catch (err) {
11
+ // Go on
12
+ }
13
+ }
14
+
15
+ if (pkg == 'linux-ia32') {
16
+ try {
17
+ native = require('@koromix/koffi-linux-ia32');
18
+ } catch (err) {
19
+ // Go on
20
+ }
21
+ }
22
+
23
+ if (pkg == 'linux-x64') {
24
+ try {
25
+ native = require('@koromix/koffi-linux-x64');
26
+ } catch (err) {
27
+ // Go on
28
+ }
29
+ }
30
+
31
+ if (pkg == 'linux-riscv64') {
32
+ try {
33
+ native = require('@koromix/koffi-linux-riscv64');
34
+ } catch (err) {
35
+ // Go on
36
+ }
37
+ }
38
+
39
+ if (pkg == 'freebsd-ia32') {
40
+ try {
41
+ native = require('@koromix/koffi-freebsd-ia32');
42
+ } catch (err) {
43
+ // Go on
44
+ }
45
+ }
46
+
47
+ if (pkg == 'freebsd-x64') {
48
+ try {
49
+ native = require('@koromix/koffi-freebsd-x64');
50
+ } catch (err) {
51
+ // Go on
52
+ }
53
+ }
54
+
55
+ if (pkg == 'freebsd-arm64') {
56
+ try {
57
+ native = require('@koromix/koffi-freebsd-arm64');
58
+ } catch (err) {
59
+ // Go on
60
+ }
61
+ }
62
+
63
+ if (pkg == 'openbsd-ia32') {
64
+ try {
65
+ native = require('@koromix/koffi-openbsd-ia32');
66
+ } catch (err) {
67
+ // Go on
68
+ }
69
+ }
70
+
71
+ if (pkg == 'openbsd-x64') {
72
+ try {
73
+ native = require('@koromix/koffi-openbsd-x64');
74
+ } catch (err) {
75
+ // Go on
76
+ }
77
+ }
78
+
79
+ if (pkg == 'win32-ia32') {
80
+ try {
81
+ native = require('@koromix/koffi-win32-ia32');
82
+ } catch (err) {
83
+ // Go on
84
+ }
85
+ }
86
+
87
+ if (pkg == 'win32-x64') {
88
+ try {
89
+ native = require('@koromix/koffi-win32-x64');
90
+ } catch (err) {
91
+ // Go on
92
+ }
93
+ }
94
+
95
+ if (pkg == 'darwin-x64') {
96
+ try {
97
+ native = require('@koromix/koffi-darwin-x64');
98
+ } catch (err) {
99
+ // Go on
100
+ }
101
+ }
102
+
103
+ if (pkg == 'darwin-arm64') {
104
+ try {
105
+ native = require('@koromix/koffi-darwin-arm64');
106
+ } catch (err) {
107
+ // Go on
108
+ }
109
+ }
110
+
111
+ if (pkg == 'linux-loong64') {
112
+ try {
113
+ native = require('@koromix/koffi-linux-loong64');
114
+ } catch (err) {
115
+ // Go on
116
+ }
117
+ }
118
+
119
+ return native;
120
+ }
121
+
122
+ export { loadStatic }