koffi 2.7.4-beta.1 → 2.7.4

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,13 @@
4
4
 
5
5
  ### Koffi 2.7
6
6
 
7
+ #### Koffi 2.7.4 (2024-02-04)
8
+
9
+ - Support callbacks happening on main thread but outside JS call (such as during event loop)
10
+ - Improve stability after `koffi.reset()`
11
+ - Expose internal Node/NAPI `env` pointer
12
+ - Name main Koffi API functions
13
+
7
14
  #### Koffi 2.7.3 (2024-01-26)
8
15
 
9
16
  - Support decoding NULL terminated arrays
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/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.7.4-beta.1",
382
- stable: "2.7.3",
381
+ version: "2.7.4",
382
+ stable: "2.7.4",
383
383
  description: "Fast and simple C FFI (foreign function interface) for Node.js",
384
384
  keywords: [
385
385
  "foreign",
package/indirect.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.7.4-beta.1",
382
- stable: "2.7.3",
381
+ version: "2.7.4",
382
+ stable: "2.7.4",
383
383
  description: "Fast and simple C FFI (foreign function interface) for Node.js",
384
384
  keywords: [
385
385
  "foreign",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koffi",
3
- "version": "2.7.4-beta.1",
4
- "stable": "2.7.3",
3
+ "version": "2.7.4",
4
+ "stable": "2.7.4",
5
5
  "description": "Fast and simple C FFI (foreign function interface) for Node.js",
6
6
  "keywords": [
7
7
  "foreign",
@@ -30,12 +30,16 @@ function(add_node_addon)
30
30
  cmake_parse_arguments(ARG "" "NAME" "SOURCES" ${ARGN})
31
31
 
32
32
  add_library(${ARG_NAME} SHARED ${ARG_SOURCES} ${NODE_JS_SOURCES})
33
+ target_link_node(${ARG_NAME})
33
34
  set_target_properties(${ARG_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
34
- target_include_directories(${ARG_NAME} PRIVATE ${NODE_JS_INCLUDE_DIRS})
35
- target_link_libraries(${ARG_NAME} PRIVATE ${NODE_JS_LIBRARIES})
36
- target_compile_options(${ARG_NAME} PRIVATE ${NODE_JS_COMPILE_FLAGS})
35
+ endfunction()
36
+
37
+ function(target_link_node TARGET)
38
+ target_include_directories(${TARGET} PRIVATE ${NODE_JS_INCLUDE_DIRS})
39
+ target_link_libraries(${TARGET} PRIVATE ${NODE_JS_LIBRARIES})
40
+ target_compile_options(${TARGET} PRIVATE ${NODE_JS_COMPILE_FLAGS})
37
41
  if (NODE_JS_LINK_FLAGS)
38
- target_link_options(${ARG_NAME} PRIVATE ${NODE_JS_LINK_FLAGS})
42
+ target_link_options(${TARGET} PRIVATE ${NODE_JS_LINK_FLAGS})
39
43
  endif()
40
44
  endfunction()
41
45
 
@@ -3142,10 +3142,10 @@ static inline void Log(LogLevel level, const char *ctx, const char *fmt, Args...
3142
3142
  #ifdef RG_DEBUG
3143
3143
  const char *DebugLogContext(const char *filename, int line);
3144
3144
 
3145
- #define LogDebug(...) Log(LogLevel::Debug, DebugLogContext(__FILE__, __LINE__) __VA_OPT__(,) __VA_ARGS__)
3146
- #define LogInfo(...) Log(LogLevel::Info, nullptr __VA_OPT__(,) __VA_ARGS__)
3147
- #define LogWarning(...) Log(LogLevel::Warning, DebugLogContext(__FILE__, __LINE__) __VA_OPT__(,) __VA_ARGS__)
3148
- #define LogError(...) Log(LogLevel::Error, DebugLogContext(__FILE__, __LINE__) __VA_OPT__(,) __VA_ARGS__)
3145
+ #define LogDebug(...) Log(LogLevel::Debug, DebugLogContext(__FILE__, __LINE__), __VA_ARGS__)
3146
+ #define LogInfo(...) Log(LogLevel::Info, nullptr, __VA_ARGS__)
3147
+ #define LogWarning(...) Log(LogLevel::Warning, DebugLogContext(__FILE__, __LINE__), __VA_ARGS__)
3148
+ #define LogError(...) Log(LogLevel::Error, DebugLogContext(__FILE__, __LINE__), __VA_ARGS__)
3149
3149
  #else
3150
3150
  template <typename... Args>
3151
3151
  static inline void LogDebug(Args...) {}
@@ -21,13 +21,12 @@
21
21
 
22
22
  cmake_minimum_required(VERSION 3.6)
23
23
  cmake_policy(SET CMP0091 NEW)
24
-
25
24
  project(koffi C CXX ASM)
26
25
 
27
- include(CheckCXXCompilerFlag)
28
-
29
26
  find_package(CNoke)
30
27
 
28
+ include(CheckCXXCompilerFlag)
29
+
31
30
  set(CMAKE_CXX_STANDARD 20)
32
31
  if(MSVC)
33
32
  set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
@@ -1997,6 +1997,40 @@ static Napi::Value EncodeValue(const Napi::CallbackInfo &info)
1997
1997
  return env.Undefined();
1998
1998
  }
1999
1999
 
2000
+ static Napi::Value ResetKoffi(const Napi::CallbackInfo &info)
2001
+ {
2002
+ Napi::Env env = info.Env();
2003
+ InstanceData *instance = env.GetInstanceData<InstanceData>();
2004
+
2005
+ if (instance->broker) {
2006
+ napi_release_threadsafe_function(instance->broker, napi_tsfn_abort);
2007
+ instance->broker = nullptr;
2008
+ }
2009
+
2010
+ instance->types.RemoveFrom(instance->base_types_len);
2011
+
2012
+ {
2013
+ HashSet<const void *> base_types;
2014
+ HashMap<const char *, const TypeInfo *> new_map;
2015
+
2016
+ for (const TypeInfo &type: instance->types) {
2017
+ base_types.Set(&type);
2018
+ }
2019
+
2020
+ for (const auto &bucket: instance->types_map.table) {
2021
+ if (base_types.Find(bucket.value)) {
2022
+ new_map.Set(bucket.key, bucket.value);
2023
+ }
2024
+ }
2025
+
2026
+ std::swap(instance->types_map, new_map);
2027
+ }
2028
+
2029
+ instance->callbacks.Clear();
2030
+
2031
+ return env.Undefined();
2032
+ }
2033
+
2000
2034
  void LibraryHolder::Unload()
2001
2035
  {
2002
2036
  #ifdef _WIN32
@@ -2153,83 +2187,6 @@ static inline PrimitiveKind GetBigEndianPrimitive(PrimitiveKind kind)
2153
2187
  #endif
2154
2188
  }
2155
2189
 
2156
- static Napi::Object InitBaseTypes(Napi::Env env)
2157
- {
2158
- InstanceData *instance = env.GetInstanceData<InstanceData>();
2159
-
2160
- Napi::Object types = Napi::Object::New(env);
2161
-
2162
- RegisterPrimitiveType(env, types, {"void"}, PrimitiveKind::Void, 0, 0);
2163
- RegisterPrimitiveType(env, types, {"bool"}, PrimitiveKind::Bool, RG_SIZE(bool), alignof(bool));
2164
- RegisterPrimitiveType(env, types, {"int8_t", "int8"}, PrimitiveKind::Int8, 1, 1);
2165
- RegisterPrimitiveType(env, types, {"uint8_t", "uint8"}, PrimitiveKind::UInt8, 1, 1);
2166
- RegisterPrimitiveType(env, types, {"char"}, PrimitiveKind::Int8, 1, 1);
2167
- RegisterPrimitiveType(env, types, {"unsigned char", "uchar"}, PrimitiveKind::UInt8, 1, 1);
2168
- RegisterPrimitiveType(env, types, {"char16_t", "char16"}, PrimitiveKind::Int16, 2, 2);
2169
- RegisterPrimitiveType(env, types, {"int16_t", "int16"}, PrimitiveKind::Int16, 2, 2);
2170
- RegisterPrimitiveType(env, types, {"int16_le_t", "int16_le"}, GetLittleEndianPrimitive(PrimitiveKind::Int16), 2, 2);
2171
- RegisterPrimitiveType(env, types, {"int16_be_t", "int16_be"}, GetBigEndianPrimitive(PrimitiveKind::Int16), 2, 2);
2172
- RegisterPrimitiveType(env, types, {"uint16_t", "uint16"}, PrimitiveKind::UInt16, 2, 2);
2173
- RegisterPrimitiveType(env, types, {"uint16_le_t", "uint16_le"}, GetLittleEndianPrimitive(PrimitiveKind::UInt16), 2, 2);
2174
- RegisterPrimitiveType(env, types, {"uint16_be_t", "uint16_be"}, GetBigEndianPrimitive(PrimitiveKind::UInt16), 2, 2);
2175
- RegisterPrimitiveType(env, types, {"short"}, PrimitiveKind::Int16, 2, 2);
2176
- RegisterPrimitiveType(env, types, {"unsigned short", "ushort"}, PrimitiveKind::UInt16, 2, 2);
2177
- RegisterPrimitiveType(env, types, {"int32_t", "int32"}, PrimitiveKind::Int32, 4, 4);
2178
- RegisterPrimitiveType(env, types, {"int32_le_t", "int32_le"}, GetLittleEndianPrimitive(PrimitiveKind::Int32), 4, 4);
2179
- RegisterPrimitiveType(env, types, {"int32_be_t", "int32_be"}, GetBigEndianPrimitive(PrimitiveKind::Int32), 4, 4);
2180
- RegisterPrimitiveType(env, types, {"uint32_t", "uint32"}, PrimitiveKind::UInt32, 4, 4);
2181
- RegisterPrimitiveType(env, types, {"uint32_le_t", "uint32_le"}, GetLittleEndianPrimitive(PrimitiveKind::UInt32), 4, 4);
2182
- RegisterPrimitiveType(env, types, {"uint32_be_t", "uint32_be"}, GetBigEndianPrimitive(PrimitiveKind::UInt32), 4, 4);
2183
- RegisterPrimitiveType(env, types, {"int"}, PrimitiveKind::Int32, 4, 4);
2184
- RegisterPrimitiveType(env, types, {"unsigned int", "uint"}, PrimitiveKind::UInt32, 4, 4);
2185
- RegisterPrimitiveType(env, types, {"int64_t", "int64"}, PrimitiveKind::Int64, 8, alignof(int64_t));
2186
- RegisterPrimitiveType(env, types, {"int64_le_t", "int64_le"}, GetLittleEndianPrimitive(PrimitiveKind::Int64), 8, alignof(int64_t));
2187
- RegisterPrimitiveType(env, types, {"int64_be_t", "int64_be"}, GetBigEndianPrimitive(PrimitiveKind::Int64), 8, alignof(int64_t));
2188
- RegisterPrimitiveType(env, types, {"uint64_t", "uint64"}, PrimitiveKind::UInt64, 8, alignof(int64_t));
2189
- RegisterPrimitiveType(env, types, {"uint64_le_t", "uint64_le"}, GetLittleEndianPrimitive(PrimitiveKind::UInt64), 8, alignof(int64_t));
2190
- RegisterPrimitiveType(env, types, {"uint64_be_t", "uint64_be"}, GetBigEndianPrimitive(PrimitiveKind::UInt64), 8, alignof(int64_t));
2191
- RegisterPrimitiveType(env, types, {"intptr_t", "intptr"}, GetSignPrimitive(RG_SIZE(intptr_t), true), RG_SIZE(intptr_t), alignof(intptr_t));
2192
- RegisterPrimitiveType(env, types, {"uintptr_t", "uintptr"}, GetSignPrimitive(RG_SIZE(intptr_t), false), RG_SIZE(intptr_t), alignof(intptr_t));
2193
- RegisterPrimitiveType(env, types, {"size_t"}, GetSignPrimitive(RG_SIZE(size_t), false), RG_SIZE(size_t), alignof(size_t));
2194
- RegisterPrimitiveType(env, types, {"long"}, GetSignPrimitive(RG_SIZE(long), true), RG_SIZE(long), alignof(long));
2195
- RegisterPrimitiveType(env, types, {"unsigned long", "ulong"}, GetSignPrimitive(RG_SIZE(long), false), RG_SIZE(long), alignof(long));
2196
- RegisterPrimitiveType(env, types, {"long long", "longlong"}, PrimitiveKind::Int64, RG_SIZE(int64_t), alignof(int64_t));
2197
- RegisterPrimitiveType(env, types, {"unsigned long long", "ulonglong"}, PrimitiveKind::UInt64, RG_SIZE(uint64_t), alignof(uint64_t));
2198
- RegisterPrimitiveType(env, types, {"float", "float32"}, PrimitiveKind::Float32, 4, alignof(float));
2199
- RegisterPrimitiveType(env, types, {"double", "float64"}, PrimitiveKind::Float64, 8, alignof(double));
2200
- RegisterPrimitiveType(env, types, {"char *", "str", "string"}, PrimitiveKind::String, RG_SIZE(void *), alignof(void *), "char");
2201
- RegisterPrimitiveType(env, types, {"char16_t *", "char16 *", "str16", "string16"}, PrimitiveKind::String16, RG_SIZE(void *), alignof(void *), "char16_t");
2202
-
2203
- instance->void_type = instance->types_map.FindValue("void", nullptr);
2204
- instance->char_type = instance->types_map.FindValue("char", nullptr);
2205
- instance->char16_type = instance->types_map.FindValue("char16", nullptr);
2206
-
2207
- instance->active_symbol = Napi::Symbol::New(env, "active");
2208
-
2209
- types.Freeze();
2210
-
2211
- return types;
2212
- }
2213
-
2214
- static Napi::Value ResetKoffi(const Napi::CallbackInfo &info)
2215
- {
2216
- Napi::Env env = info.Env();
2217
- InstanceData *instance = env.GetInstanceData<InstanceData>();
2218
-
2219
- if (instance->broker) {
2220
- napi_release_threadsafe_function(instance->broker, napi_tsfn_abort);
2221
- instance->broker = nullptr;
2222
- }
2223
-
2224
- instance->types.Clear();
2225
- instance->types_map.Clear();
2226
- instance->callbacks.Clear();
2227
-
2228
- InitBaseTypes(env);
2229
-
2230
- return env.Undefined();
2231
- }
2232
-
2233
2190
  static InstanceData *CreateInstance()
2234
2191
  {
2235
2192
  InstanceData *instance = new InstanceData();
@@ -2258,52 +2215,52 @@ static Napi::Object InitModule(Napi::Env env, Napi::Object exports)
2258
2215
 
2259
2216
  env.SetInstanceData(instance);
2260
2217
 
2261
- exports.Set("config", Napi::Function::New(env, GetSetConfig));
2262
- exports.Set("stats", Napi::Function::New(env, GetStats));
2263
-
2264
- exports.Set("struct", Napi::Function::New(env, CreatePaddedStructType));
2265
- exports.Set("pack", Napi::Function::New(env, CreatePackedStructType));
2266
- exports.Set("union", Napi::Function::New(env, CreateUnionType));
2267
- exports.Set("Union", Napi::Function::New(env, InstantiateUnion));
2268
- exports.Set("opaque", Napi::Function::New(env, CreateOpaqueType));
2269
- exports.Set("pointer", Napi::Function::New(env, CreatePointerType));
2270
- exports.Set("array", Napi::Function::New(env, CreateArrayType));
2271
- exports.Set("proto", Napi::Function::New(env, CreateFunctionType));
2272
- exports.Set("alias", Napi::Function::New(env, CreateTypeAlias));
2218
+ exports.Set("config", Napi::Function::New(env, GetSetConfig, "config"));
2219
+ exports.Set("stats", Napi::Function::New(env, GetStats, "stats"));
2273
2220
 
2274
- exports.Set("sizeof", Napi::Function::New(env, GetTypeSize));
2275
- exports.Set("alignof", Napi::Function::New(env, GetTypeAlign));
2276
- exports.Set("offsetof", Napi::Function::New(env, GetMemberOffset));
2277
- exports.Set("resolve", Napi::Function::New(env, GetResolvedType));
2278
- exports.Set("introspect", Napi::Function::New(env, GetTypeDefinition));
2221
+ exports.Set("struct", Napi::Function::New(env, CreatePaddedStructType, "struct"));
2222
+ exports.Set("pack", Napi::Function::New(env, CreatePackedStructType, "pack"));
2223
+ exports.Set("union", Napi::Function::New(env, CreateUnionType, "union"));
2224
+ exports.Set("Union", Napi::Function::New(env, InstantiateUnion, "Union"));
2225
+ exports.Set("opaque", Napi::Function::New(env, CreateOpaqueType, "opaque"));
2226
+ exports.Set("pointer", Napi::Function::New(env, CreatePointerType, "pointer"));
2227
+ exports.Set("array", Napi::Function::New(env, CreateArrayType, "array"));
2228
+ exports.Set("proto", Napi::Function::New(env, CreateFunctionType, "proto"));
2229
+ exports.Set("alias", Napi::Function::New(env, CreateTypeAlias, "alias"));
2279
2230
 
2280
- exports.Set("load", Napi::Function::New(env, LoadSharedLibrary));
2231
+ exports.Set("sizeof", Napi::Function::New(env, GetTypeSize, "sizeof"));
2232
+ exports.Set("alignof", Napi::Function::New(env, GetTypeAlign, "alignof"));
2233
+ exports.Set("offsetof", Napi::Function::New(env, GetMemberOffset, "offsetof"));
2234
+ exports.Set("resolve", Napi::Function::New(env, GetResolvedType, "resolve"));
2235
+ exports.Set("introspect", Napi::Function::New(env, GetTypeDefinition, "introspect"));
2281
2236
 
2282
- exports.Set("in", Napi::Function::New(env, MarkIn));
2283
- exports.Set("out", Napi::Function::New(env, MarkOut));
2284
- exports.Set("inout", Napi::Function::New(env, MarkInOut));
2237
+ exports.Set("load", Napi::Function::New(env, LoadSharedLibrary, "load"));
2285
2238
 
2286
- exports.Set("disposable", Napi::Function::New(env, CreateDisposableType));
2287
- exports.Set("free", Napi::Function::New(env, CallFree));
2239
+ exports.Set("in", Napi::Function::New(env, MarkIn, "in"));
2240
+ exports.Set("out", Napi::Function::New(env, MarkOut, "out"));
2241
+ exports.Set("inout", Napi::Function::New(env, MarkInOut, "inout"));
2288
2242
 
2289
- exports.Set("register", Napi::Function::New(env, RegisterCallback));
2290
- exports.Set("unregister", Napi::Function::New(env, UnregisterCallback));
2243
+ exports.Set("disposable", Napi::Function::New(env, CreateDisposableType, "disposable"));
2244
+ exports.Set("free", Napi::Function::New(env, CallFree, "free"));
2291
2245
 
2292
- exports.Set("as", Napi::Function::New(env, CastValue));
2293
- exports.Set("decode", Napi::Function::New(env, DecodeValue));
2294
- exports.Set("address", Napi::Function::New(env, GetPointerAddress));
2295
- exports.Set("call", Napi::Function::New(env, CallPointerSync));
2296
- exports.Set("encode", Napi::Function::New(env, EncodeValue));
2246
+ exports.Set("register", Napi::Function::New(env, RegisterCallback, "register"));
2247
+ exports.Set("unregister", Napi::Function::New(env, UnregisterCallback, "unregister"));
2297
2248
 
2298
- exports.Set("reset", Napi::Function::New(env, ResetKoffi));
2249
+ exports.Set("as", Napi::Function::New(env, CastValue, "as"));
2250
+ exports.Set("decode", Napi::Function::New(env, DecodeValue, "decode"));
2251
+ exports.Set("address", Napi::Function::New(env, GetPointerAddress, "address"));
2252
+ exports.Set("call", Napi::Function::New(env, CallPointerSync, "call"));
2253
+ exports.Set("encode", Napi::Function::New(env, EncodeValue, "encode"));
2299
2254
 
2300
- exports.Set("errno", Napi::Function::New(env, GetOrSetErrNo));
2255
+ exports.Set("reset", Napi::Function::New(env, ResetKoffi, "reset"));
2301
2256
 
2302
- Napi::Object os = Napi::Object::New(env);
2303
- exports.Set("os", os);
2257
+ exports.Set("errno", Napi::Function::New(env, GetOrSetErrNo, "errno"));
2304
2258
 
2305
- // Init constants mapping
2259
+ // Export useful OS info
2306
2260
  {
2261
+ Napi::Object os = Napi::Object::New(env);
2262
+ exports.Set("os", os);
2263
+
2307
2264
  Napi::Object codes = Napi::Object::New(env);
2308
2265
 
2309
2266
  for (const ErrnoCodeInfo &info: ErrnoCodes) {
@@ -2321,8 +2278,71 @@ static Napi::Object InitModule(Napi::Env env, Napi::Object exports)
2321
2278
  exports.Set("extension", Napi::String::New(env, ".so"));
2322
2279
  #endif
2323
2280
 
2324
- Napi::Object types = InitBaseTypes(env);
2325
- exports.Set("types", types);
2281
+ // Init base types
2282
+ {
2283
+ Napi::Object types = Napi::Object::New(env);
2284
+ exports.Set("types", types);
2285
+
2286
+ RegisterPrimitiveType(env, types, {"void"}, PrimitiveKind::Void, 0, 0);
2287
+ RegisterPrimitiveType(env, types, {"bool"}, PrimitiveKind::Bool, RG_SIZE(bool), alignof(bool));
2288
+ RegisterPrimitiveType(env, types, {"int8_t", "int8"}, PrimitiveKind::Int8, 1, 1);
2289
+ RegisterPrimitiveType(env, types, {"uint8_t", "uint8"}, PrimitiveKind::UInt8, 1, 1);
2290
+ RegisterPrimitiveType(env, types, {"char"}, PrimitiveKind::Int8, 1, 1);
2291
+ RegisterPrimitiveType(env, types, {"unsigned char", "uchar"}, PrimitiveKind::UInt8, 1, 1);
2292
+ RegisterPrimitiveType(env, types, {"char16_t", "char16"}, PrimitiveKind::Int16, 2, 2);
2293
+ RegisterPrimitiveType(env, types, {"int16_t", "int16"}, PrimitiveKind::Int16, 2, 2);
2294
+ RegisterPrimitiveType(env, types, {"int16_le_t", "int16_le"}, GetLittleEndianPrimitive(PrimitiveKind::Int16), 2, 2);
2295
+ RegisterPrimitiveType(env, types, {"int16_be_t", "int16_be"}, GetBigEndianPrimitive(PrimitiveKind::Int16), 2, 2);
2296
+ RegisterPrimitiveType(env, types, {"uint16_t", "uint16"}, PrimitiveKind::UInt16, 2, 2);
2297
+ RegisterPrimitiveType(env, types, {"uint16_le_t", "uint16_le"}, GetLittleEndianPrimitive(PrimitiveKind::UInt16), 2, 2);
2298
+ RegisterPrimitiveType(env, types, {"uint16_be_t", "uint16_be"}, GetBigEndianPrimitive(PrimitiveKind::UInt16), 2, 2);
2299
+ RegisterPrimitiveType(env, types, {"short"}, PrimitiveKind::Int16, 2, 2);
2300
+ RegisterPrimitiveType(env, types, {"unsigned short", "ushort"}, PrimitiveKind::UInt16, 2, 2);
2301
+ RegisterPrimitiveType(env, types, {"int32_t", "int32"}, PrimitiveKind::Int32, 4, 4);
2302
+ RegisterPrimitiveType(env, types, {"int32_le_t", "int32_le"}, GetLittleEndianPrimitive(PrimitiveKind::Int32), 4, 4);
2303
+ RegisterPrimitiveType(env, types, {"int32_be_t", "int32_be"}, GetBigEndianPrimitive(PrimitiveKind::Int32), 4, 4);
2304
+ RegisterPrimitiveType(env, types, {"uint32_t", "uint32"}, PrimitiveKind::UInt32, 4, 4);
2305
+ RegisterPrimitiveType(env, types, {"uint32_le_t", "uint32_le"}, GetLittleEndianPrimitive(PrimitiveKind::UInt32), 4, 4);
2306
+ RegisterPrimitiveType(env, types, {"uint32_be_t", "uint32_be"}, GetBigEndianPrimitive(PrimitiveKind::UInt32), 4, 4);
2307
+ RegisterPrimitiveType(env, types, {"int"}, PrimitiveKind::Int32, 4, 4);
2308
+ RegisterPrimitiveType(env, types, {"unsigned int", "uint"}, PrimitiveKind::UInt32, 4, 4);
2309
+ RegisterPrimitiveType(env, types, {"int64_t", "int64"}, PrimitiveKind::Int64, 8, alignof(int64_t));
2310
+ RegisterPrimitiveType(env, types, {"int64_le_t", "int64_le"}, GetLittleEndianPrimitive(PrimitiveKind::Int64), 8, alignof(int64_t));
2311
+ RegisterPrimitiveType(env, types, {"int64_be_t", "int64_be"}, GetBigEndianPrimitive(PrimitiveKind::Int64), 8, alignof(int64_t));
2312
+ RegisterPrimitiveType(env, types, {"uint64_t", "uint64"}, PrimitiveKind::UInt64, 8, alignof(int64_t));
2313
+ RegisterPrimitiveType(env, types, {"uint64_le_t", "uint64_le"}, GetLittleEndianPrimitive(PrimitiveKind::UInt64), 8, alignof(int64_t));
2314
+ RegisterPrimitiveType(env, types, {"uint64_be_t", "uint64_be"}, GetBigEndianPrimitive(PrimitiveKind::UInt64), 8, alignof(int64_t));
2315
+ RegisterPrimitiveType(env, types, {"intptr_t", "intptr"}, GetSignPrimitive(RG_SIZE(intptr_t), true), RG_SIZE(intptr_t), alignof(intptr_t));
2316
+ RegisterPrimitiveType(env, types, {"uintptr_t", "uintptr"}, GetSignPrimitive(RG_SIZE(intptr_t), false), RG_SIZE(intptr_t), alignof(intptr_t));
2317
+ RegisterPrimitiveType(env, types, {"size_t"}, GetSignPrimitive(RG_SIZE(size_t), false), RG_SIZE(size_t), alignof(size_t));
2318
+ RegisterPrimitiveType(env, types, {"long"}, GetSignPrimitive(RG_SIZE(long), true), RG_SIZE(long), alignof(long));
2319
+ RegisterPrimitiveType(env, types, {"unsigned long", "ulong"}, GetSignPrimitive(RG_SIZE(long), false), RG_SIZE(long), alignof(long));
2320
+ RegisterPrimitiveType(env, types, {"long long", "longlong"}, PrimitiveKind::Int64, RG_SIZE(int64_t), alignof(int64_t));
2321
+ RegisterPrimitiveType(env, types, {"unsigned long long", "ulonglong"}, PrimitiveKind::UInt64, RG_SIZE(uint64_t), alignof(uint64_t));
2322
+ RegisterPrimitiveType(env, types, {"float", "float32"}, PrimitiveKind::Float32, 4, alignof(float));
2323
+ RegisterPrimitiveType(env, types, {"double", "float64"}, PrimitiveKind::Float64, 8, alignof(double));
2324
+ RegisterPrimitiveType(env, types, {"char *", "str", "string"}, PrimitiveKind::String, RG_SIZE(void *), alignof(void *), "char");
2325
+ RegisterPrimitiveType(env, types, {"char16_t *", "char16 *", "str16", "string16"}, PrimitiveKind::String16, RG_SIZE(void *), alignof(void *), "char16_t");
2326
+
2327
+ instance->void_type = instance->types_map.FindValue("void", nullptr);
2328
+ instance->char_type = instance->types_map.FindValue("char", nullptr);
2329
+ instance->char16_type = instance->types_map.FindValue("char16", nullptr);
2330
+
2331
+ instance->active_symbol = Napi::Symbol::New(env, "active");
2332
+
2333
+ instance->base_types_len = instance->types.len;
2334
+ }
2335
+
2336
+ // Expose internal Node stuff
2337
+ {
2338
+ Napi::Object node = Napi::Object::New(env);
2339
+ exports.Set("node", node);
2340
+
2341
+ Napi::External<void> external = Napi::External<void>::New(env, (napi_env)env);
2342
+ SetValueTag(instance, external, instance->void_type);
2343
+
2344
+ node.Set("env", external);
2345
+ }
2326
2346
 
2327
2347
  exports.Set("version", Napi::String::New(env, RG_STRINGIFY(VERSION)));
2328
2348
 
@@ -269,6 +269,7 @@ struct InstanceData {
269
269
  BucketArray<TypeInfo> types;
270
270
  HashMap<const char *, const TypeInfo *> types_map;
271
271
  BucketArray<FunctionInfo> callbacks;
272
+ Size base_types_len;
272
273
 
273
274
  bool debug;
274
275
  uint64_t tag_lower;