koffi 2.8.7 → 2.8.9

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,14 @@
4
4
 
5
5
  ### Koffi 2.8
6
6
 
7
+ #### Koffi 2.8.9 (2024-05-17)
8
+
9
+ - Fix ABI issue regarding bool return values on x86_64 (and possibly other platforms)
10
+
11
+ #### Koffi 2.8.8 (2024-04-26)
12
+
13
+ - Support use of buffers with mismatched size (truncation or zero-filling)
14
+
7
15
  #### Koffi 2.8.7 (2024-04-23)
8
16
 
9
17
  - Improve compatibility with SEHOP on Windows ([@longhun12346](https://github.com/longhun12346))
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.8.7",
382
- stable: "2.8.7",
381
+ version: "2.8.9",
382
+ stable: "2.8.9",
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.8.7",
382
- stable: "2.8.7",
381
+ version: "2.8.9",
382
+ stable: "2.8.9",
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.8.7",
4
- "stable": "2.8.7",
3
+ "version": "2.8.9",
4
+ "stable": "2.8.9",
5
5
  "description": "Fast and simple C FFI (foreign function interface) for Node.js",
6
6
  "keywords": [
7
7
  "foreign",
@@ -518,7 +518,7 @@ Napi::Value CallData::Complete(const FunctionInfo *func)
518
518
 
519
519
  switch (func->ret.type->primitive) {
520
520
  case PrimitiveKind::Void: return env.Undefined();
521
- case PrimitiveKind::Bool: return Napi::Boolean::New(env, result.u32);
521
+ case PrimitiveKind::Bool: return Napi::Boolean::New(env, result.u8 & 0x1);
522
522
  case PrimitiveKind::Int8: return Napi::Number::New(env, (double)result.i8);
523
523
  case PrimitiveKind::UInt8: return Napi::Number::New(env, (double)result.u8);
524
524
  case PrimitiveKind::Int16: return Napi::Number::New(env, (double)result.i16);
@@ -654,7 +654,7 @@ Napi::Value CallData::Complete(const FunctionInfo *func)
654
654
 
655
655
  switch (func->ret.type->primitive) {
656
656
  case PrimitiveKind::Void: return env.Undefined();
657
- case PrimitiveKind::Bool: return Napi::Boolean::New(env, result.u32);
657
+ case PrimitiveKind::Bool: return Napi::Boolean::New(env, result.u8 & 0x1);
658
658
  case PrimitiveKind::Int8: return Napi::Number::New(env, (double)result.i8);
659
659
  case PrimitiveKind::UInt8: return Napi::Number::New(env, (double)result.u8);
660
660
  case PrimitiveKind::Int16: return Napi::Number::New(env, (double)result.i16);
@@ -455,7 +455,7 @@ Napi::Value CallData::Complete(const FunctionInfo *func)
455
455
 
456
456
  switch (func->ret.type->primitive) {
457
457
  case PrimitiveKind::Void: return env.Undefined();
458
- case PrimitiveKind::Bool: return Napi::Boolean::New(env, result.u32);
458
+ case PrimitiveKind::Bool: return Napi::Boolean::New(env, result.u8 & 0x1);
459
459
  case PrimitiveKind::Int8: return Napi::Number::New(env, (double)result.i8);
460
460
  case PrimitiveKind::UInt8: return Napi::Number::New(env, (double)result.u8);
461
461
  case PrimitiveKind::Int16: return Napi::Number::New(env, (double)result.i16);
@@ -495,7 +495,7 @@ Napi::Value CallData::Complete(const FunctionInfo *func)
495
495
 
496
496
  switch (func->ret.type->primitive) {
497
497
  case PrimitiveKind::Void: return env.Undefined();
498
- case PrimitiveKind::Bool: return Napi::Boolean::New(env, result.u32);
498
+ case PrimitiveKind::Bool: return Napi::Boolean::New(env, result.u8 & 0x1);
499
499
  case PrimitiveKind::Int8: return Napi::Number::New(env, (double)result.i8);
500
500
  case PrimitiveKind::UInt8: return Napi::Number::New(env, (double)result.u8);
501
501
  case PrimitiveKind::Int16: return Napi::Number::New(env, (double)result.i16);
@@ -307,7 +307,7 @@ Napi::Value CallData::Complete(const FunctionInfo *func)
307
307
 
308
308
  switch (func->ret.type->primitive) {
309
309
  case PrimitiveKind::Void: return env.Undefined();
310
- case PrimitiveKind::Bool: return Napi::Boolean::New(env, result.u32);
310
+ case PrimitiveKind::Bool: return Napi::Boolean::New(env, result.u8 & 0x1);
311
311
  case PrimitiveKind::Int8: return Napi::Number::New(env, (double)result.i8);
312
312
  case PrimitiveKind::UInt8: return Napi::Number::New(env, (double)result.u8);
313
313
  case PrimitiveKind::Int16: return Napi::Number::New(env, (double)result.i16);
@@ -421,7 +421,7 @@ Napi::Value CallData::Complete(const FunctionInfo *func)
421
421
 
422
422
  switch (func->ret.type->primitive) {
423
423
  case PrimitiveKind::Void: return env.Undefined();
424
- case PrimitiveKind::Bool: return Napi::Boolean::New(env, result.u32);
424
+ case PrimitiveKind::Bool: return Napi::Boolean::New(env, result.u8 & 0x1);
425
425
  case PrimitiveKind::Int8: return Napi::Number::New(env, (double)result.i8);
426
426
  case PrimitiveKind::UInt8: return Napi::Number::New(env, (double)result.u8);
427
427
  case PrimitiveKind::Int16: return Napi::Number::New(env, (double)result.i16);
@@ -593,9 +593,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
593
593
  return false;
594
594
  } else if (IsRawBuffer(value)) {
595
595
  Span<const uint8_t> buffer = GetRawBuffer(value);
596
-
597
- if (!PushBuffer(buffer, member.type->size, member.type, dest))
598
- return false;
596
+ PushBuffer(buffer, member.type->size, member.type, dest);
599
597
  } else if (value.IsString()) {
600
598
  if (!PushStringArray(value, member.type, dest))
601
599
  return false;
@@ -830,9 +828,7 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *type
830
828
  return false;
831
829
  } else if (IsRawBuffer(value)) {
832
830
  Span<const uint8_t> buffer = GetRawBuffer(value);
833
-
834
- if (!PushBuffer(buffer, ref->size, ref, dest))
835
- return false;
831
+ PushBuffer(buffer, ref->size, ref, dest);
836
832
  } else if (value.IsString()) {
837
833
  if (!PushStringArray(value, ref, dest))
838
834
  return false;
@@ -896,15 +892,13 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *type
896
892
  return true;
897
893
  }
898
894
 
899
- bool CallData::PushBuffer(Span<const uint8_t> buffer, Size size, const TypeInfo *type, uint8_t *origin)
895
+ void CallData::PushBuffer(Span<const uint8_t> buffer, Size size, const TypeInfo *type, uint8_t *origin)
900
896
  {
901
- if (buffer.len != size) [[unlikely]] {
902
- ThrowError<Napi::Error>(env, "Expected array or buffer of size %1, got %2", size, buffer.len);
903
- return false;
904
- }
897
+ buffer.len = std::min(buffer.len, size);
905
898
 
906
- // Go fast yeaaaah :)
899
+ // Go fast brrrrrrr :)
907
900
  memcpy_safe(origin, buffer.ptr, (size_t)buffer.len);
901
+ memset_safe(origin + buffer.len, 0, (size_t)(size - buffer.len));
908
902
 
909
903
  #define SWAP(CType) \
910
904
  do { \
@@ -929,8 +923,6 @@ bool CallData::PushBuffer(Span<const uint8_t> buffer, Size size, const TypeInfo
929
923
  }
930
924
 
931
925
  #undef SWAP
932
-
933
- return true;
934
926
  }
935
927
 
936
928
  bool CallData::PushStringArray(Napi::Value obj, const TypeInfo *type, uint8_t *origin)
@@ -119,7 +119,7 @@ public:
119
119
  Size PushString16Value(Napi::Value value, const char16_t **out_str16);
120
120
  bool PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origin);
121
121
  bool PushNormalArray(Napi::Array array, Size len, const TypeInfo *type, uint8_t *origin);
122
- bool PushBuffer(Span<const uint8_t> buffer, Size size, const TypeInfo *type, uint8_t *origin);
122
+ void PushBuffer(Span<const uint8_t> buffer, Size size, const TypeInfo *type, uint8_t *origin);
123
123
  bool PushStringArray(Napi::Value value, const TypeInfo *type, uint8_t *origin);
124
124
  bool PushPointer(Napi::Value value, const TypeInfo *type, int directions, void **out_ptr);
125
125
  Size PushIndirectString(Napi::Array array, const TypeInfo *ref, uint8_t **out_ptr);
@@ -1446,9 +1446,7 @@ bool Encode(Napi::Env env, uint8_t *origin, Napi::Value value, const TypeInfo *t
1446
1446
  return false;
1447
1447
  } else if (IsRawBuffer(value)) {
1448
1448
  Span<const uint8_t> buffer = GetRawBuffer(value);
1449
-
1450
- if (!call.PushBuffer(buffer, type->size, type, origin))
1451
- return false;
1449
+ call.PushBuffer(buffer, type->size, type, origin);
1452
1450
  } else if (value.IsString()) {
1453
1451
  if (!call.PushStringArray(value, type, origin))
1454
1452
  return false;