koffi 1.1.0 → 1.1.3

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 (43) hide show
  1. package/CMakeLists.txt +10 -7
  2. package/README.md +29 -28
  3. package/build/qemu/1.1.3/koffi_darwin_x64.tar.gz +0 -0
  4. package/build/qemu/1.1.3/koffi_freebsd_arm64.tar.gz +0 -0
  5. package/build/qemu/1.1.3/koffi_freebsd_ia32.tar.gz +0 -0
  6. package/build/qemu/1.1.3/koffi_freebsd_x64.tar.gz +0 -0
  7. package/build/qemu/1.1.3/koffi_linux_arm.tar.gz +0 -0
  8. package/build/qemu/1.1.3/koffi_linux_arm64.tar.gz +0 -0
  9. package/build/qemu/1.1.3/koffi_linux_ia32.tar.gz +0 -0
  10. package/build/qemu/1.1.3/koffi_linux_x64.tar.gz +0 -0
  11. package/build/qemu/1.1.3/koffi_openbsd_x64.tar.gz +0 -0
  12. package/build/qemu/1.1.3/koffi_win32_ia32.tar.gz +0 -0
  13. package/build/qemu/1.1.3/koffi_win32_x64.tar.gz +0 -0
  14. package/package.json +2 -2
  15. package/qemu/qemu.js +1 -1
  16. package/qemu/registry/machines.json +47 -3
  17. package/qemu/registry/sha256sum.txt +16 -12
  18. package/src/abi_arm32.cc +43 -4
  19. package/src/abi_arm64.cc +22 -5
  20. package/src/abi_x64_sysv.cc +1 -1
  21. package/src/abi_x64_win.cc +1 -1
  22. package/src/abi_x86.cc +10 -4
  23. package/src/call.cc +213 -44
  24. package/src/call.hh +2 -2
  25. package/src/ffi.cc +63 -36
  26. package/src/ffi.hh +10 -4
  27. package/src/parser.cc +46 -24
  28. package/src/parser.hh +3 -1
  29. package/src/util.hh +1 -1
  30. package/test/CMakeLists.txt +3 -0
  31. package/test/misc.c +17 -0
  32. package/vendor/libcc/libcc.cc +7 -7
  33. package/vendor/libcc/libcc.hh +4 -1
  34. package/build/qemu/1.1.0/koffi_darwin_x64.tar.gz +0 -0
  35. package/build/qemu/1.1.0/koffi_freebsd_arm64.tar.gz +0 -0
  36. package/build/qemu/1.1.0/koffi_freebsd_ia32.tar.gz +0 -0
  37. package/build/qemu/1.1.0/koffi_freebsd_x64.tar.gz +0 -0
  38. package/build/qemu/1.1.0/koffi_linux_arm.tar.gz +0 -0
  39. package/build/qemu/1.1.0/koffi_linux_arm64.tar.gz +0 -0
  40. package/build/qemu/1.1.0/koffi_linux_ia32.tar.gz +0 -0
  41. package/build/qemu/1.1.0/koffi_linux_x64.tar.gz +0 -0
  42. package/build/qemu/1.1.0/koffi_win32_ia32.tar.gz +0 -0
  43. package/build/qemu/1.1.0/koffi_win32_x64.tar.gz +0 -0
package/src/parser.cc CHANGED
@@ -19,34 +19,29 @@
19
19
 
20
20
  namespace RG {
21
21
 
22
- bool PrototypeParser::Parse(Napi::String proto, FunctionInfo *func)
22
+ bool PrototypeParser::Parse(const char *str, FunctionInfo *out_func)
23
23
  {
24
- if (!proto.IsString()) {
25
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for prototype, expected string", GetValueType(instance, proto));
26
- return false;
27
- }
28
-
29
- std::string hold = proto;
30
-
31
24
  tokens.Clear();
32
25
  offset = 0;
33
26
  valid = true;
34
27
 
35
- Tokenize(hold.c_str());
28
+ Tokenize(str);
36
29
 
37
- func->ret.type = ParseType();
38
- if (func->ret.type->primitive == PrimitiveKind::Array) {
30
+ out_func->ret.type = ParseType();
31
+ if (out_func->ret.type->primitive == PrimitiveKind::Array) {
39
32
  MarkError("You are not allowed to directly return C arrays");
40
33
  return false;
41
34
  }
42
35
  if (Match("__cdecl")) {
43
- func->convention = CallConvention::Cdecl;
36
+ out_func->convention = CallConvention::Cdecl;
44
37
  } else if (Match("__stdcall")) {
45
- func->convention = CallConvention::Stdcall;
38
+ out_func->convention = CallConvention::Stdcall;
46
39
  } else if (Match("__fastcall")) {
47
- func->convention = CallConvention::Fastcall;
40
+ out_func->convention = CallConvention::Fastcall;
41
+ } else if (Match("__thiscall")) {
42
+ out_func->convention = CallConvention::Thiscall;
48
43
  }
49
- func->name = ParseIdentifier();
44
+ out_func->name = ParseIdentifier();
50
45
 
51
46
  Consume("(");
52
47
  if (offset < tokens.len && tokens[offset] != ")") {
@@ -54,7 +49,7 @@ bool PrototypeParser::Parse(Napi::String proto, FunctionInfo *func)
54
49
  ParameterInfo param = {};
55
50
 
56
51
  if (Match("...")) {
57
- func->variadic = true;
52
+ out_func->variadic = true;
58
53
  break;
59
54
  }
60
55
 
@@ -83,18 +78,18 @@ bool PrototypeParser::Parse(Napi::String proto, FunctionInfo *func)
83
78
 
84
79
  offset += (offset < tokens.len && IsIdentifier(tokens[offset]));
85
80
 
86
- if (func->parameters.len >= MaxParameters) {
81
+ if (out_func->parameters.len >= MaxParameters) {
87
82
  MarkError("Functions cannot have more than %1 parameters", MaxParameters);
88
83
  return false;
89
84
  }
90
- if ((param.directions & 2) && ++func->out_parameters >= MaxOutParameters) {
85
+ if ((param.directions & 2) && ++out_func->out_parameters >= MaxOutParameters) {
91
86
  MarkError("Functions cannot have more than out %1 parameters", MaxOutParameters);
92
87
  return false;
93
88
  }
94
89
 
95
- param.offset = func->parameters.len;
90
+ param.offset = out_func->parameters.len;
96
91
 
97
- func->parameters.Append(param);
92
+ out_func->parameters.Append(param);
98
93
 
99
94
  if (offset >= tokens.len || tokens[offset] != ",")
100
95
  break;
@@ -125,6 +120,17 @@ void PrototypeParser::Tokenize(const char *str)
125
120
  Span<const char> tok = MakeSpan(str + i, j - i);
126
121
  tokens.Append(tok);
127
122
 
123
+ i = j - 1;
124
+ } else if (IsAsciiDigit(c)) {
125
+ Size j = i;
126
+ while (str[++j] && IsAsciiDigit(str[j]));
127
+ if (str[j] == '.') {
128
+ while (str[++j] && IsAsciiDigit(str[j]));
129
+ }
130
+
131
+ Span<const char> tok = MakeSpan(str + i, j - i);
132
+ tokens.Append(tok);
133
+
128
134
  i = j - 1;
129
135
  } else if (c == '.' && str[i + 1] == '.' && str[i + 2] == '.') {
130
136
  tokens.Append("...");
@@ -165,11 +171,21 @@ const TypeInfo *PrototypeParser::ParseType()
165
171
  }
166
172
  buf.ptr[--buf.len] = 0;
167
173
 
168
- if (TestStr(buf, "char") && indirect) {
169
- buf.RemoveFrom(0);
170
- Fmt(&buf, "string");
174
+ if (indirect) {
175
+ const TypeInfo *type = instance->types_map.FindValue(buf.ptr, nullptr);
176
+ PrimitiveKind primitive = type ? type->primitive : PrimitiveKind::Void;
177
+
178
+ if (primitive == PrimitiveKind::Int8 || primitive == PrimitiveKind::UInt8) {
179
+ buf.RemoveFrom(0);
180
+ Fmt(&buf, "string");
181
+
182
+ indirect--;
183
+ } else if (primitive == PrimitiveKind::Int16 || primitive == PrimitiveKind::UInt16) {
184
+ buf.RemoveFrom(0);
185
+ Fmt(&buf, "string16");
171
186
 
172
- indirect--;
187
+ indirect--;
188
+ }
173
189
  }
174
190
 
175
191
  while (buf.len) {
@@ -250,4 +266,10 @@ bool PrototypeParser::IsIdentifier(Span<const char> tok) const
250
266
  return IsAsciiAlpha(tok[0]) || tok[0] == '_';
251
267
  }
252
268
 
269
+ bool ParsePrototype(Napi::Env env, const char *str, FunctionInfo *out_func)
270
+ {
271
+ PrototypeParser parser(env);
272
+ return parser.Parse(str, out_func);
273
+ }
274
+
253
275
  }
package/src/parser.hh CHANGED
@@ -36,7 +36,7 @@ class PrototypeParser {
36
36
  public:
37
37
  PrototypeParser(Napi::Env env) : env(env), instance(env.GetInstanceData<InstanceData>()) {}
38
38
 
39
- bool Parse(Napi::String proto, FunctionInfo *func);
39
+ bool Parse(const char *str, FunctionInfo *out_func);
40
40
 
41
41
  private:
42
42
  void Tokenize(const char *str);
@@ -60,4 +60,6 @@ private:
60
60
  }
61
61
  };
62
62
 
63
+ bool ParsePrototype(Napi::Env env, const char *str, FunctionInfo *out_func);
64
+
63
65
  }
package/src/util.hh CHANGED
@@ -78,7 +78,7 @@ T CopyNumber(const Napi::Value &value)
78
78
  RG_ASSERT(value.IsNumber() || value.IsBigInt());
79
79
 
80
80
  if (RG_LIKELY(value.IsNumber())) {
81
- return (T)value.As<Napi::Number>();
81
+ return (T)value.As<Napi::Number>().DoubleValue();
82
82
  } else if (value.IsBigInt()) {
83
83
  Napi::BigInt bigint = value.As<Napi::BigInt>();
84
84
 
@@ -42,6 +42,9 @@ else()
42
42
  -Wno-unused-function -Wno-missing-field-initializers
43
43
  -Wno-unused-value -Wno-implicit-fallthrough -Wno-stringop-overflow
44
44
  -Wno-unused-result)
45
+ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
46
+ target_compile_options(raylib PRIVATE -Wno-unknown-warning-option)
47
+ endif()
45
48
  endif()
46
49
 
47
50
  if(WIN32)
package/test/misc.c CHANGED
@@ -104,6 +104,13 @@ typedef struct PackedBFG {
104
104
  } PackedBFG;
105
105
  #pragma pack(pop)
106
106
 
107
+ typedef struct FixedString {
108
+ char buf[64];
109
+ } FixedString;
110
+ typedef struct FixedWide {
111
+ int16_t buf[64];
112
+ } FixedWide;
113
+
107
114
  EXPORT void FillPack1(int a, Pack1 *p)
108
115
  {
109
116
  p->a = a;
@@ -359,3 +366,13 @@ EXPORT const char16_t *Concat16(const char16_t *str1, const char16_t *str2)
359
366
 
360
367
  return buf;
361
368
  }
369
+
370
+ EXPORT FixedString ReturnFixedStr(FixedString str)
371
+ {
372
+ return str;
373
+ }
374
+
375
+ EXPORT FixedWide ReturnFixedWide(FixedWide str)
376
+ {
377
+ return str;
378
+ }
@@ -3745,7 +3745,7 @@ static std::atomic_bool flag_interrupt = false;
3745
3745
  static std::atomic_bool explicit_interrupt = false;
3746
3746
  static int interrupt_pfd[2] = {-1, -1};
3747
3747
 
3748
- static void SetSignalHandler(int signal, struct sigaction *prev, void (*func)(int))
3748
+ void SetSignalHandler(int signal, void (*func)(int), struct sigaction *prev)
3749
3749
  {
3750
3750
  struct sigaction action = {};
3751
3751
 
@@ -3786,10 +3786,10 @@ RG_INIT(SetupDefaultHandlers)
3786
3786
  int ret = setpgid(0, 0);
3787
3787
  RG_ASSERT(!ret);
3788
3788
 
3789
- SetSignalHandler(SIGINT, nullptr, DefaultSignalHandler);
3790
- SetSignalHandler(SIGTERM, nullptr, DefaultSignalHandler);
3791
- SetSignalHandler(SIGHUP, nullptr, DefaultSignalHandler);
3792
- SetSignalHandler(SIGPIPE, nullptr, [](int) {});
3789
+ SetSignalHandler(SIGINT, DefaultSignalHandler);
3790
+ SetSignalHandler(SIGTERM, DefaultSignalHandler);
3791
+ SetSignalHandler(SIGHUP, DefaultSignalHandler);
3792
+ SetSignalHandler(SIGPIPE, [](int) {});
3793
3793
  }
3794
3794
 
3795
3795
  RG_EXIT(TerminateChildren)
@@ -3797,7 +3797,7 @@ RG_EXIT(TerminateChildren)
3797
3797
  pid_t pid = getpid();
3798
3798
  RG_ASSERT(pid > 1);
3799
3799
 
3800
- SetSignalHandler(SIGTERM, nullptr, [](int) {});
3800
+ SetSignalHandler(SIGTERM, [](int) {});
3801
3801
  kill(-pid, SIGTERM);
3802
3802
  }
3803
3803
 
@@ -4168,7 +4168,7 @@ WaitForResult WaitForInterrupt(int64_t timeout)
4168
4168
  static std::atomic_bool message = false;
4169
4169
 
4170
4170
  flag_interrupt = true;
4171
- SetSignalHandler(SIGUSR1, nullptr, [](int) { message = true; });
4171
+ SetSignalHandler(SIGUSR1, [](int) { message = true; });
4172
4172
 
4173
4173
  if (timeout >= 0) {
4174
4174
  struct timespec ts;
@@ -35,7 +35,7 @@
35
35
  #include <utility>
36
36
  #if defined(_WIN32)
37
37
  #include <intrin.h>
38
- #elif !defined(__APPLE__) && (!defined(__linux__) || defined(__GLIBC__))
38
+ #elif !defined(__APPLE__) && (!defined(__linux__) || defined(__GLIBC__)) && __has_include(<ucontext.h>)
39
39
  #define RG_FIBER_USE_UCONTEXT
40
40
  #include <ucontext.h>
41
41
  #else
@@ -54,6 +54,7 @@
54
54
  #pragma intrinsic(__rdtsc)
55
55
  #endif
56
56
 
57
+ struct sigaction;
57
58
  struct BrotliEncoderStateStruct;
58
59
 
59
60
  namespace RG {
@@ -3929,6 +3930,8 @@ enum class PipeMode {
3929
3930
  bool CreateOverlappedPipe(bool overlap0, bool overlap1, PipeMode mode, void *out_handles[2]); // HANDLE
3930
3931
  void CloseHandleSafe(void **handle_ptr); // HANDLE
3931
3932
  #else
3933
+ void SetSignalHandler(int signal, void (*func)(int), struct sigaction *prev = nullptr);
3934
+
3932
3935
  bool CreatePipe(int pfd[2]);
3933
3936
  void CloseDescriptorSafe(int *fd_ptr);
3934
3937
  #endif