koffi 2.6.5 → 2.6.6

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,10 +4,14 @@
4
4
 
5
5
  ### Koffi 2.6
6
6
 
7
+ #### Koffi 2.6.6 (2023-10-28)
8
+
9
+ - Better handle errors while making struct or union types
10
+
7
11
  #### Koffi 2.6.5 (2023-10-28)
8
12
 
9
13
  - Allow self-referential structs and unions
10
- - Fix rare Node.js "FATAL ERROR" with some invalid types specifiers
14
+ - Fix rare Node.js "FATAL ERROR" with some invalid type specifiers
11
15
 
12
16
  #### Koffi 2.6.4 (2023-10-26)
13
17
 
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.6.5",
382
- stable: "2.6.5",
381
+ version: "2.6.6",
382
+ stable: "2.6.6",
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.6.5",
382
- stable: "2.6.5",
381
+ version: "2.6.6",
382
+ stable: "2.6.6",
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.6.5",
4
- "stable": "2.6.5",
3
+ "version": "2.6.6",
4
+ "stable": "2.6.6",
5
5
  "description": "Fast and simple C FFI (foreign function interface) for Node.js",
6
6
  "keywords": [
7
7
  "foreign",
@@ -225,10 +225,20 @@ static Napi::Value CreateStructType(const Napi::CallbackInfo &info, bool pad)
225
225
  return env.Null();
226
226
  }
227
227
 
228
+ Napi::String name = info[0].As<Napi::String>();
229
+ Napi::Object obj = info[named].As<Napi::Object>();
230
+ Napi::Array keys = obj.GetPropertyNames();
231
+
228
232
  RG_DEFER_NC(err_guard, len = instance->types.len) {
229
- for (Size i = len + 1; i < instance->types.len; i++) {
230
- const TypeInfo &type = instance->types[i];
231
- instance->types_map.Remove(type.name);
233
+ Size start = len + !named;
234
+
235
+ for (Size i = start; i < instance->types.len; i++) {
236
+ const TypeInfo *it = &instance->types[i];
237
+ const TypeInfo **ptr = instance->types_map.Find(it->name);
238
+
239
+ if (ptr && *ptr == it) {
240
+ instance->types_map.Remove(ptr);
241
+ }
232
242
  }
233
243
 
234
244
  instance->types.RemoveFrom(len);
@@ -236,10 +246,6 @@ static Napi::Value CreateStructType(const Napi::CallbackInfo &info, bool pad)
236
246
 
237
247
  TypeInfo *type = instance->types.AppendDefault();
238
248
 
239
- Napi::String name = info[0].As<Napi::String>();
240
- Napi::Object obj = info[named].As<Napi::Object>();
241
- Napi::Array keys = obj.GetPropertyNames();
242
-
243
249
  if (named) {
244
250
  type->name = DuplicateString(name.Utf8Value().c_str(), &instance->str_alloc).ptr;
245
251
 
@@ -365,10 +371,20 @@ static Napi::Value CreateUnionType(const Napi::CallbackInfo &info)
365
371
  return env.Null();
366
372
  }
367
373
 
374
+ Napi::String name = info[0].As<Napi::String>();
375
+ Napi::Object obj = info[named].As<Napi::Object>();
376
+ Napi::Array keys = obj.GetPropertyNames();
377
+
368
378
  RG_DEFER_NC(err_guard, len = instance->types.len) {
369
- for (Size i = len + 1; i < instance->types.len; i++) {
370
- const TypeInfo &type = instance->types[i];
371
- instance->types_map.Remove(type.name);
379
+ Size start = len + !named;
380
+
381
+ for (Size i = start; i < instance->types.len; i++) {
382
+ const TypeInfo *it = &instance->types[i];
383
+ const TypeInfo **ptr = instance->types_map.Find(it->name);
384
+
385
+ if (ptr && *ptr == it) {
386
+ instance->types_map.Remove(ptr);
387
+ }
372
388
  }
373
389
 
374
390
  instance->types.RemoveFrom(len);
@@ -376,10 +392,6 @@ static Napi::Value CreateUnionType(const Napi::CallbackInfo &info)
376
392
 
377
393
  TypeInfo *type = instance->types.AppendDefault();
378
394
 
379
- Napi::String name = info[0].As<Napi::String>();
380
- Napi::Object obj = info[named].As<Napi::Object>();
381
- Napi::Array keys = obj.GetPropertyNames();
382
-
383
395
  if (named) {
384
396
  type->name = DuplicateString(name.Utf8Value().c_str(), &instance->str_alloc).ptr;
385
397