koffi 2.7.1 → 2.7.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.
- package/CHANGELOG.md +10 -0
- package/README.md +2 -2
- package/build/koffi/darwin_arm64/koffi.node +0 -0
- package/build/koffi/darwin_x64/koffi.node +0 -0
- package/build/koffi/freebsd_arm64/koffi.node +0 -0
- package/build/koffi/freebsd_ia32/koffi.node +0 -0
- package/build/koffi/freebsd_x64/koffi.node +0 -0
- package/build/koffi/linux_arm32hf/koffi.node +0 -0
- package/build/koffi/linux_arm64/koffi.node +0 -0
- package/build/koffi/linux_ia32/koffi.node +0 -0
- package/build/koffi/linux_riscv64hf64/koffi.node +0 -0
- package/build/koffi/linux_x64/koffi.node +0 -0
- package/build/koffi/openbsd_ia32/koffi.node +0 -0
- package/build/koffi/openbsd_x64/koffi.node +0 -0
- package/build/koffi/win32_arm64/koffi.node +0 -0
- package/build/koffi/win32_ia32/koffi.node +0 -0
- package/build/koffi/win32_x64/koffi.node +0 -0
- package/doc/misc.md +1 -1
- package/doc/unions.md +2 -2
- package/index.d.ts +2 -1
- package/index.js +23 -23
- package/indirect.js +23 -23
- package/package.json +2 -2
- package/src/core/libcc/brotli.cc +16 -24
- package/src/core/libcc/libcc.cc +63 -69
- package/src/core/libcc/libcc.hh +103 -110
- package/src/core/libcc/lz4.cc +18 -25
- package/src/core/libcc/miniz.cc +10 -18
- package/src/koffi/src/call.cc +1 -1
- package/src/koffi/src/util.cc +7 -13
- package/src/koffi/src/util.hh +9 -1
- package/vendor/node-addon-api/CHANGELOG.md +76 -0
- package/vendor/node-addon-api/LICENSE.md +2 -6
- package/vendor/node-addon-api/README.md +10 -9
- package/vendor/node-addon-api/benchmark/binding.gyp +4 -4
- package/vendor/node-addon-api/common.gypi +1 -2
- package/vendor/node-addon-api/doc/array.md +1 -1
- package/vendor/node-addon-api/doc/async_worker_variants.md +16 -16
- package/vendor/node-addon-api/doc/cmake-js.md +1 -1
- package/vendor/node-addon-api/doc/env.md +11 -0
- package/vendor/node-addon-api/doc/hierarchy.md +2 -0
- package/vendor/node-addon-api/doc/setup.md +53 -71
- package/vendor/node-addon-api/doc/syntax_error.md +66 -0
- package/vendor/node-addon-api/doc/value.md +2 -0
- package/vendor/node-addon-api/index.js +2 -1
- package/vendor/node-addon-api/napi-inl.h +68 -65
- package/vendor/node-addon-api/napi.h +15 -5
- package/vendor/node-addon-api/node_addon_api.gyp +32 -0
- package/vendor/node-addon-api/package.json +14 -3
- package/vendor/node-addon-api/test/addon.cc +7 -1
- package/vendor/node-addon-api/test/addon.js +5 -9
- package/vendor/node-addon-api/test/addon_data.cc +3 -3
- package/vendor/node-addon-api/test/addon_data.js +16 -38
- package/vendor/node-addon-api/test/bigint.cc +0 -1
- package/vendor/node-addon-api/test/binding.cc +12 -1
- package/vendor/node-addon-api/test/binding.gyp +10 -8
- package/vendor/node-addon-api/test/child_processes/addon.js +11 -0
- package/vendor/node-addon-api/test/child_processes/addon_data.js +24 -0
- package/vendor/node-addon-api/test/child_processes/objectwrap_function.js +22 -0
- package/vendor/node-addon-api/test/child_processes/threadsafe_function_exception.js +33 -0
- package/vendor/node-addon-api/test/child_processes/typed_threadsafe_function_exception.js +19 -0
- package/vendor/node-addon-api/test/common/index.js +57 -3
- package/vendor/node-addon-api/test/env_misc.cc +25 -0
- package/vendor/node-addon-api/test/env_misc.js +12 -0
- package/vendor/node-addon-api/test/error.cc +47 -0
- package/vendor/node-addon-api/test/error.js +16 -0
- package/vendor/node-addon-api/test/index.js +5 -0
- package/vendor/node-addon-api/test/objectwrap_function.cc +10 -12
- package/vendor/node-addon-api/test/objectwrap_function.js +4 -20
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_exception.cc +50 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_exception.js +20 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_exception.cc +39 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_exception.js +13 -0
package/src/core/libcc/libcc.hh
CHANGED
|
@@ -249,14 +249,6 @@ extern "C" void AssertMessage(const char *filename, int line, const char *cond);
|
|
|
249
249
|
#define RG_UNREACHABLE() __assume(0)
|
|
250
250
|
#endif
|
|
251
251
|
|
|
252
|
-
#if defined(__EMSCRIPTEN__)
|
|
253
|
-
#define RG_EXPORT EMSCRIPTEN_KEEPALIVE
|
|
254
|
-
#elif defined(_WIN32)
|
|
255
|
-
#define RG_EXPORT __declspec(dllexport)
|
|
256
|
-
#else
|
|
257
|
-
#define RG_EXPORT __attribute__((visibility("default")))
|
|
258
|
-
#endif
|
|
259
|
-
|
|
260
252
|
#define RG_DELETE_COPY(Cls) \
|
|
261
253
|
Cls(const Cls&) = delete; \
|
|
262
254
|
Cls &operator=(const Cls&) = delete;
|
|
@@ -1221,11 +1213,7 @@ public:
|
|
|
1221
1213
|
RG_ASSERT(len <= N - count);
|
|
1222
1214
|
|
|
1223
1215
|
T *first = data + len;
|
|
1224
|
-
#if __cplusplus >= 201703L
|
|
1225
1216
|
if constexpr(!std::is_trivial<T>::value) {
|
|
1226
|
-
#else
|
|
1227
|
-
if (true) {
|
|
1228
|
-
#endif
|
|
1229
1217
|
for (Size i = 0; i < count; i++) {
|
|
1230
1218
|
new (data + len) T();
|
|
1231
1219
|
len++;
|
|
@@ -1323,11 +1311,7 @@ public:
|
|
|
1323
1311
|
{
|
|
1324
1312
|
RemoveFrom(0);
|
|
1325
1313
|
Grow(other.capacity);
|
|
1326
|
-
#if __cplusplus >= 201703L
|
|
1327
1314
|
if constexpr(!std::is_trivial<T>::value) {
|
|
1328
|
-
#else
|
|
1329
|
-
if (true) {
|
|
1330
|
-
#endif
|
|
1331
1315
|
for (Size i = 0; i < other.len; i++) {
|
|
1332
1316
|
ptr[i] = other.ptr[i];
|
|
1333
1317
|
}
|
|
@@ -1432,11 +1416,7 @@ public:
|
|
|
1432
1416
|
Grow(count);
|
|
1433
1417
|
|
|
1434
1418
|
T *first = ptr + len;
|
|
1435
|
-
#if __cplusplus >= 201703L
|
|
1436
1419
|
if constexpr(!std::is_trivial<T>::value) {
|
|
1437
|
-
#else
|
|
1438
|
-
if (true) {
|
|
1439
|
-
#endif
|
|
1440
1420
|
for (Size i = 0; i < count; i++) {
|
|
1441
1421
|
new (ptr + len) T();
|
|
1442
1422
|
len++;
|
|
@@ -1454,11 +1434,7 @@ public:
|
|
|
1454
1434
|
Grow();
|
|
1455
1435
|
|
|
1456
1436
|
T *first = ptr + len;
|
|
1457
|
-
#if __cplusplus >= 201703L
|
|
1458
1437
|
if constexpr(!std::is_trivial<T>::value) {
|
|
1459
|
-
#else
|
|
1460
|
-
if (true) {
|
|
1461
|
-
#endif
|
|
1462
1438
|
new (ptr + len) T;
|
|
1463
1439
|
}
|
|
1464
1440
|
ptr[len++] = value;
|
|
@@ -1470,11 +1446,7 @@ public:
|
|
|
1470
1446
|
|
|
1471
1447
|
T *first = ptr + len;
|
|
1472
1448
|
for (const T &value: values) {
|
|
1473
|
-
#if __cplusplus >= 201703L
|
|
1474
1449
|
if constexpr(!std::is_trivial<T>::value) {
|
|
1475
|
-
#else
|
|
1476
|
-
if (true) {
|
|
1477
|
-
#endif
|
|
1478
1450
|
new (ptr + len) T;
|
|
1479
1451
|
}
|
|
1480
1452
|
ptr[len++] = value;
|
|
@@ -1486,11 +1458,7 @@ public:
|
|
|
1486
1458
|
{
|
|
1487
1459
|
RG_ASSERT(first >= 0 && first <= len);
|
|
1488
1460
|
|
|
1489
|
-
#if __cplusplus >= 201703L
|
|
1490
1461
|
if constexpr(!std::is_trivial<T>::value) {
|
|
1491
|
-
#else
|
|
1492
|
-
if (true) {
|
|
1493
|
-
#endif
|
|
1494
1462
|
for (Size i = first; i < len; i++) {
|
|
1495
1463
|
ptr[i].~T();
|
|
1496
1464
|
}
|
|
@@ -1796,11 +1764,7 @@ private:
|
|
|
1796
1764
|
void DeleteValues([[maybe_unused]] iterator_type begin,
|
|
1797
1765
|
[[maybe_unused]] iterator_type end)
|
|
1798
1766
|
{
|
|
1799
|
-
#if __cplusplus >= 201703L
|
|
1800
1767
|
if constexpr(!std::is_trivial<T>::value) {
|
|
1801
|
-
#else
|
|
1802
|
-
if (true) {
|
|
1803
|
-
#endif
|
|
1804
1768
|
for (iterator_type it = begin; it != end; ++it) {
|
|
1805
1769
|
it->~T();
|
|
1806
1770
|
}
|
|
@@ -2077,11 +2041,7 @@ public:
|
|
|
2077
2041
|
}
|
|
2078
2042
|
~HashTable()
|
|
2079
2043
|
{
|
|
2080
|
-
#if __cplusplus >= 201703L
|
|
2081
2044
|
if constexpr(std::is_trivial<ValueType>::value) {
|
|
2082
|
-
#else
|
|
2083
|
-
if (false) {
|
|
2084
|
-
#endif
|
|
2085
2045
|
count = 0;
|
|
2086
2046
|
Rehash(0);
|
|
2087
2047
|
} else {
|
|
@@ -2278,11 +2238,7 @@ private:
|
|
|
2278
2238
|
template <typename T = KeyType>
|
|
2279
2239
|
const ValueType *Find(Size *idx, const T &key) const
|
|
2280
2240
|
{
|
|
2281
|
-
#if __cplusplus >= 201703L
|
|
2282
2241
|
if constexpr(std::is_pointer<ValueType>::value) {
|
|
2283
|
-
#else
|
|
2284
|
-
if (false) {
|
|
2285
|
-
#endif
|
|
2286
2242
|
while (data[*idx]) {
|
|
2287
2243
|
const KeyType &it_key = Handler::GetKey(data[*idx]);
|
|
2288
2244
|
if (Handler::TestKeys(it_key, key))
|
|
@@ -3184,18 +3140,22 @@ static inline void Log(LogLevel level, const char *ctx, const char *fmt, Args...
|
|
|
3184
3140
|
|
|
3185
3141
|
// Shortcut log functions
|
|
3186
3142
|
#ifdef RG_DEBUG
|
|
3187
|
-
|
|
3188
|
-
|
|
3143
|
+
const char *DebugLogContext(const char *filename, int line);
|
|
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__)
|
|
3189
3149
|
#else
|
|
3190
|
-
template <typename... Args>
|
|
3191
|
-
static inline void LogDebug(Args...) {}
|
|
3150
|
+
template <typename... Args>
|
|
3151
|
+
static inline void LogDebug(Args...) {}
|
|
3152
|
+
template <typename... Args>
|
|
3153
|
+
static inline void LogInfo(Args... args) { Log(LogLevel::Info, nullptr, args...); }
|
|
3154
|
+
template <typename... Args>
|
|
3155
|
+
static inline void LogWarning(Args... args) { Log(LogLevel::Warning, "Warning: ", args...); }
|
|
3156
|
+
template <typename... Args>
|
|
3157
|
+
static inline void LogError(Args... args) { Log(LogLevel::Error, "Error: ", args...); }
|
|
3192
3158
|
#endif
|
|
3193
|
-
template <typename... Args>
|
|
3194
|
-
static inline void LogInfo(Args... args) { Log(LogLevel::Info, nullptr, args...); }
|
|
3195
|
-
template <typename... Args>
|
|
3196
|
-
static inline void LogWarning(Args... args) { Log(LogLevel::Warning, "Warning", args...); }
|
|
3197
|
-
template <typename... Args>
|
|
3198
|
-
static inline void LogError(Args... args) { Log(LogLevel::Error, "Error", args...); }
|
|
3199
3159
|
|
|
3200
3160
|
void SetLogHandler(const std::function<LogFunc> &func);
|
|
3201
3161
|
void DefaultLogHandler(LogLevel level, const char *ctx, const char *msg);
|
|
@@ -3301,7 +3261,7 @@ static inline bool TestStrI(Span<const char> str1, const char *str2)
|
|
|
3301
3261
|
return (i == str1.len) && !str2[i];
|
|
3302
3262
|
}
|
|
3303
3263
|
static inline bool TestStrI(const char *str1, Span<const char> str2)
|
|
3304
|
-
{ return
|
|
3264
|
+
{ return TestStrI(str2, str1); }
|
|
3305
3265
|
static inline bool TestStrI(const char *str1, const char *str2)
|
|
3306
3266
|
{
|
|
3307
3267
|
Size i = 0;
|
|
@@ -4344,8 +4304,8 @@ enum class CompressionSpeed {
|
|
|
4344
4304
|
Fast
|
|
4345
4305
|
};
|
|
4346
4306
|
|
|
4347
|
-
class
|
|
4348
|
-
class
|
|
4307
|
+
class StreamDecoder;
|
|
4308
|
+
class StreamEncoder;
|
|
4349
4309
|
|
|
4350
4310
|
class StreamReader {
|
|
4351
4311
|
RG_DELETE_COPY(StreamReader)
|
|
@@ -4383,8 +4343,7 @@ class StreamReader {
|
|
|
4383
4343
|
bool eof = false;
|
|
4384
4344
|
} source;
|
|
4385
4345
|
|
|
4386
|
-
|
|
4387
|
-
StreamDecompressor *decompressor = nullptr;
|
|
4346
|
+
StreamDecoder *decoder = nullptr;
|
|
4388
4347
|
|
|
4389
4348
|
int64_t raw_len = -1;
|
|
4390
4349
|
Size raw_read = 0;
|
|
@@ -4408,6 +4367,9 @@ public:
|
|
|
4408
4367
|
: StreamReader() { Open(func, filename, compression_type); }
|
|
4409
4368
|
~StreamReader() { Close(true); }
|
|
4410
4369
|
|
|
4370
|
+
// Call before Open!
|
|
4371
|
+
void SetDecoder(StreamDecoder *decoder);
|
|
4372
|
+
|
|
4411
4373
|
bool Open(Span<const uint8_t> buf, const char *filename = nullptr,
|
|
4412
4374
|
CompressionType compression_type = CompressionType::None);
|
|
4413
4375
|
bool Open(FILE *fp, const char *filename,
|
|
@@ -4421,7 +4383,6 @@ public:
|
|
|
4421
4383
|
bool Rewind();
|
|
4422
4384
|
|
|
4423
4385
|
const char *GetFileName() const { return filename; }
|
|
4424
|
-
CompressionType GetCompressionType() const { return compression_type; }
|
|
4425
4386
|
int64_t GetReadLimit() { return read_max; }
|
|
4426
4387
|
bool IsValid() const { return filename && !error; }
|
|
4427
4388
|
bool IsEOF() const { return eof; }
|
|
@@ -4449,62 +4410,38 @@ private:
|
|
|
4449
4410
|
|
|
4450
4411
|
Size ReadRaw(Size max_len, void *out_buf);
|
|
4451
4412
|
|
|
4452
|
-
friend class
|
|
4413
|
+
friend class StreamDecoder;
|
|
4453
4414
|
};
|
|
4454
4415
|
|
|
4455
|
-
static inline Size ReadFile(const char *filename, CompressionType compression_type, Span<uint8_t> out_buf)
|
|
4456
|
-
{
|
|
4457
|
-
StreamReader st(filename, compression_type);
|
|
4458
|
-
return st.Read(out_buf);
|
|
4459
|
-
}
|
|
4460
4416
|
static inline Size ReadFile(const char *filename, Span<uint8_t> out_buf)
|
|
4461
4417
|
{
|
|
4462
4418
|
StreamReader st(filename);
|
|
4463
4419
|
return st.Read(out_buf);
|
|
4464
4420
|
}
|
|
4465
|
-
static inline Size ReadFile(const char *filename, CompressionType compression_type, Span<char> out_buf)
|
|
4466
|
-
{
|
|
4467
|
-
StreamReader st(filename, compression_type);
|
|
4468
|
-
return st.Read(out_buf);
|
|
4469
|
-
}
|
|
4470
4421
|
static inline Size ReadFile(const char *filename, Span<char> out_buf)
|
|
4471
4422
|
{
|
|
4472
4423
|
StreamReader st(filename);
|
|
4473
4424
|
return st.Read(out_buf);
|
|
4474
4425
|
}
|
|
4475
|
-
|
|
4476
|
-
static inline Size ReadFile(const char *filename, Size max_len, CompressionType compression_type,
|
|
4477
|
-
HeapArray<uint8_t> *out_buf)
|
|
4478
|
-
{
|
|
4479
|
-
StreamReader st(filename, compression_type);
|
|
4480
|
-
return st.ReadAll(max_len, out_buf);
|
|
4481
|
-
}
|
|
4482
4426
|
static inline Size ReadFile(const char *filename, Size max_len, HeapArray<uint8_t> *out_buf)
|
|
4483
4427
|
{
|
|
4484
4428
|
StreamReader st(filename);
|
|
4485
4429
|
return st.ReadAll(max_len, out_buf);
|
|
4486
4430
|
}
|
|
4487
|
-
static inline Size ReadFile(const char *filename, Size max_len, CompressionType compression_type,
|
|
4488
|
-
HeapArray<char> *out_buf)
|
|
4489
|
-
{
|
|
4490
|
-
StreamReader st(filename, compression_type);
|
|
4491
|
-
return st.ReadAll(max_len, out_buf);
|
|
4492
|
-
}
|
|
4493
4431
|
static inline Size ReadFile(const char *filename, Size max_len, HeapArray<char> *out_buf)
|
|
4494
4432
|
{
|
|
4495
4433
|
StreamReader st(filename);
|
|
4496
4434
|
return st.ReadAll(max_len, out_buf);
|
|
4497
4435
|
}
|
|
4498
4436
|
|
|
4499
|
-
class
|
|
4437
|
+
class StreamDecoder {
|
|
4500
4438
|
protected:
|
|
4501
4439
|
StreamReader *reader;
|
|
4502
4440
|
|
|
4503
4441
|
public:
|
|
4504
|
-
|
|
4505
|
-
virtual ~
|
|
4442
|
+
StreamDecoder(StreamReader *reader) : reader(reader) {}
|
|
4443
|
+
virtual ~StreamDecoder() {}
|
|
4506
4444
|
|
|
4507
|
-
virtual bool Init(CompressionType type) = 0;
|
|
4508
4445
|
virtual Size Read(Size max_len, void *out_buf) = 0;
|
|
4509
4446
|
|
|
4510
4447
|
protected:
|
|
@@ -4517,7 +4454,7 @@ protected:
|
|
|
4517
4454
|
void SetEOF(bool eof) { reader->eof = eof; }
|
|
4518
4455
|
};
|
|
4519
4456
|
|
|
4520
|
-
typedef
|
|
4457
|
+
typedef StreamDecoder *CreateDecompressorFunc(StreamReader *reader, CompressionType type);
|
|
4521
4458
|
|
|
4522
4459
|
class StreamDecompressorHelper {
|
|
4523
4460
|
public:
|
|
@@ -4525,9 +4462,9 @@ public:
|
|
|
4525
4462
|
};
|
|
4526
4463
|
|
|
4527
4464
|
#define RG_REGISTER_DECOMPRESSOR(Type, Cls) \
|
|
4528
|
-
static
|
|
4465
|
+
static StreamDecoder *RG_UNIQUE_NAME(CreateDecompressor)(StreamReader *reader, CompressionType type) \
|
|
4529
4466
|
{ \
|
|
4530
|
-
|
|
4467
|
+
StreamDecoder *decompressor = new Cls(reader, type); \
|
|
4531
4468
|
return decompressor; \
|
|
4532
4469
|
} \
|
|
4533
4470
|
static StreamDecompressorHelper RG_UNIQUE_NAME(CreateDecompressorHelper)((Type), RG_UNIQUE_NAME(CreateDecompressor))
|
|
@@ -4601,9 +4538,7 @@ class StreamWriter {
|
|
|
4601
4538
|
bool vt100;
|
|
4602
4539
|
} dest;
|
|
4603
4540
|
|
|
4604
|
-
|
|
4605
|
-
CompressionSpeed compression_speed = CompressionSpeed::Default;
|
|
4606
|
-
StreamCompressor *compressor = nullptr;
|
|
4541
|
+
StreamEncoder *encoder = nullptr;
|
|
4607
4542
|
|
|
4608
4543
|
int64_t raw_written = 0;
|
|
4609
4544
|
|
|
@@ -4633,6 +4568,9 @@ public:
|
|
|
4633
4568
|
: StreamWriter() { Open(func, filename, compression_type, compression_speed); }
|
|
4634
4569
|
~StreamWriter() { Close(true); }
|
|
4635
4570
|
|
|
4571
|
+
// Call before Open!
|
|
4572
|
+
void SetEncoder(StreamEncoder *encoder);
|
|
4573
|
+
|
|
4636
4574
|
bool Open(HeapArray<uint8_t> *mem, const char *filename = nullptr,
|
|
4637
4575
|
CompressionType compression_type = CompressionType::None,
|
|
4638
4576
|
CompressionSpeed compression_speed = CompressionSpeed::Default);
|
|
@@ -4655,8 +4593,6 @@ public:
|
|
|
4655
4593
|
bool Flush();
|
|
4656
4594
|
|
|
4657
4595
|
const char *GetFileName() const { return filename; }
|
|
4658
|
-
CompressionType GetCompressionType() const { return compression_type; }
|
|
4659
|
-
CompressionSpeed GetCompressionSpeed() const { return compression_speed; }
|
|
4660
4596
|
bool IsVt100() const { return dest.vt100; }
|
|
4661
4597
|
bool IsValid() const { return filename && !error; }
|
|
4662
4598
|
|
|
@@ -4677,33 +4613,30 @@ private:
|
|
|
4677
4613
|
|
|
4678
4614
|
bool WriteRaw(Span<const uint8_t> buf);
|
|
4679
4615
|
|
|
4680
|
-
friend class
|
|
4616
|
+
friend class StreamEncoder;
|
|
4681
4617
|
};
|
|
4682
4618
|
|
|
4683
|
-
static inline bool WriteFile(Span<const uint8_t> buf, const char *filename, unsigned int flags = 0
|
|
4684
|
-
CompressionType compression_type = CompressionType::None)
|
|
4619
|
+
static inline bool WriteFile(Span<const uint8_t> buf, const char *filename, unsigned int flags = 0)
|
|
4685
4620
|
{
|
|
4686
|
-
StreamWriter st(filename, flags
|
|
4621
|
+
StreamWriter st(filename, flags);
|
|
4687
4622
|
st.Write(buf);
|
|
4688
4623
|
return st.Close();
|
|
4689
4624
|
}
|
|
4690
|
-
static inline bool WriteFile(Span<const char> buf, const char *filename, unsigned int flags = 0
|
|
4691
|
-
CompressionType compression_type = CompressionType::None)
|
|
4625
|
+
static inline bool WriteFile(Span<const char> buf, const char *filename, unsigned int flags = 0)
|
|
4692
4626
|
{
|
|
4693
|
-
StreamWriter st(filename, flags
|
|
4627
|
+
StreamWriter st(filename, flags);
|
|
4694
4628
|
st.Write(buf);
|
|
4695
4629
|
return st.Close();
|
|
4696
4630
|
}
|
|
4697
4631
|
|
|
4698
|
-
class
|
|
4632
|
+
class StreamEncoder {
|
|
4699
4633
|
protected:
|
|
4700
4634
|
StreamWriter *writer;
|
|
4701
4635
|
|
|
4702
4636
|
public:
|
|
4703
|
-
|
|
4704
|
-
virtual ~
|
|
4637
|
+
StreamEncoder(StreamWriter *writer) : writer(writer) {}
|
|
4638
|
+
virtual ~StreamEncoder() {}
|
|
4705
4639
|
|
|
4706
|
-
virtual bool Init(CompressionType type, CompressionSpeed speed) = 0;
|
|
4707
4640
|
virtual bool Write(Span<const uint8_t> buf) = 0;
|
|
4708
4641
|
virtual bool Finalize() = 0;
|
|
4709
4642
|
|
|
@@ -4714,7 +4647,7 @@ protected:
|
|
|
4714
4647
|
bool WriteRaw(Span<const uint8_t> buf) { return writer->WriteRaw(buf); }
|
|
4715
4648
|
};
|
|
4716
4649
|
|
|
4717
|
-
typedef
|
|
4650
|
+
typedef StreamEncoder *CreateCompressorFunc(StreamWriter *writer, CompressionType type, CompressionSpeed speed);
|
|
4718
4651
|
|
|
4719
4652
|
class StreamCompressorHelper {
|
|
4720
4653
|
public:
|
|
@@ -4722,9 +4655,9 @@ public:
|
|
|
4722
4655
|
};
|
|
4723
4656
|
|
|
4724
4657
|
#define RG_REGISTER_COMPRESSOR(Type, Cls) \
|
|
4725
|
-
static
|
|
4658
|
+
static StreamEncoder *RG_UNIQUE_NAME(CreateCompressor)(StreamWriter *writer, CompressionType type, CompressionSpeed speed) \
|
|
4726
4659
|
{ \
|
|
4727
|
-
|
|
4660
|
+
StreamEncoder *compressor = new Cls(writer, type, speed); \
|
|
4728
4661
|
return compressor; \
|
|
4729
4662
|
} \
|
|
4730
4663
|
static StreamCompressorHelper RG_UNIQUE_NAME(CreateCompressorHelper)((Type), RG_UNIQUE_NAME(CreateCompressor))
|
|
@@ -4934,6 +4867,36 @@ bool OptionToEnum(Span<const OptionDesc> options, Span<const char> str, T *out_v
|
|
|
4934
4867
|
return false;
|
|
4935
4868
|
}
|
|
4936
4869
|
|
|
4870
|
+
template <typename T>
|
|
4871
|
+
bool OptionToEnumI(Span<const char *const> options, Span<const char> str, T *out_value)
|
|
4872
|
+
{
|
|
4873
|
+
for (Size i = 0; i < options.len; i++) {
|
|
4874
|
+
const char *opt = options[i];
|
|
4875
|
+
|
|
4876
|
+
if (TestStrI(opt, str)) {
|
|
4877
|
+
*out_value = (T)i;
|
|
4878
|
+
return true;
|
|
4879
|
+
}
|
|
4880
|
+
}
|
|
4881
|
+
|
|
4882
|
+
return false;
|
|
4883
|
+
}
|
|
4884
|
+
|
|
4885
|
+
template <typename T>
|
|
4886
|
+
bool OptionToEnumI(Span<const OptionDesc> options, Span<const char> str, T *out_value)
|
|
4887
|
+
{
|
|
4888
|
+
for (Size i = 0; i < options.len; i++) {
|
|
4889
|
+
const OptionDesc &desc = options[i];
|
|
4890
|
+
|
|
4891
|
+
if (TestStrI(desc.name, str)) {
|
|
4892
|
+
*out_value = (T)i;
|
|
4893
|
+
return true;
|
|
4894
|
+
}
|
|
4895
|
+
}
|
|
4896
|
+
|
|
4897
|
+
return false;
|
|
4898
|
+
}
|
|
4899
|
+
|
|
4937
4900
|
template <typename T>
|
|
4938
4901
|
bool OptionToFlag(Span<const char *const> options, Span<const char> str, T *out_flags, bool enable = true)
|
|
4939
4902
|
{
|
|
@@ -4964,6 +4927,36 @@ bool OptionToFlag(Span<const OptionDesc> options, Span<const char> str, T *out_f
|
|
|
4964
4927
|
return false;
|
|
4965
4928
|
}
|
|
4966
4929
|
|
|
4930
|
+
template <typename T>
|
|
4931
|
+
bool OptionToFlagI(Span<const char *const> options, Span<const char> str, T *out_flags, bool enable = true)
|
|
4932
|
+
{
|
|
4933
|
+
for (Size i = 0; i < options.len; i++) {
|
|
4934
|
+
const char *opt = options[i];
|
|
4935
|
+
|
|
4936
|
+
if (TestStrI(opt, str)) {
|
|
4937
|
+
*out_flags = ApplyMask(*out_flags, 1u << i, enable);
|
|
4938
|
+
return true;
|
|
4939
|
+
}
|
|
4940
|
+
}
|
|
4941
|
+
|
|
4942
|
+
return false;
|
|
4943
|
+
}
|
|
4944
|
+
|
|
4945
|
+
template <typename T>
|
|
4946
|
+
bool OptionToFlagI(Span<const OptionDesc> options, Span<const char> str, T *out_flags, bool enable = true)
|
|
4947
|
+
{
|
|
4948
|
+
for (Size i = 0; i < options.len; i++) {
|
|
4949
|
+
const OptionDesc &desc = options[i];
|
|
4950
|
+
|
|
4951
|
+
if (TestStrI(desc.name, str)) {
|
|
4952
|
+
*out_flags = ApplyMask(*out_flags, 1u << i, enable);
|
|
4953
|
+
return true;
|
|
4954
|
+
}
|
|
4955
|
+
}
|
|
4956
|
+
|
|
4957
|
+
return false;
|
|
4958
|
+
}
|
|
4959
|
+
|
|
4967
4960
|
// ------------------------------------------------------------------------
|
|
4968
4961
|
// Console prompter (simplified readline)
|
|
4969
4962
|
// ------------------------------------------------------------------------
|
package/src/core/libcc/lz4.cc
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
|
|
28
28
|
namespace RG {
|
|
29
29
|
|
|
30
|
-
class LZ4Decompressor: public
|
|
30
|
+
class LZ4Decompressor: public StreamDecoder {
|
|
31
31
|
LZ4F_dctx *decoder = nullptr;
|
|
32
32
|
bool done = false;
|
|
33
33
|
|
|
@@ -39,25 +39,23 @@ class LZ4Decompressor: public StreamDecompressor {
|
|
|
39
39
|
Size out_len = 0;
|
|
40
40
|
|
|
41
41
|
public:
|
|
42
|
-
LZ4Decompressor(StreamReader *reader
|
|
42
|
+
LZ4Decompressor(StreamReader *reader, CompressionType type);
|
|
43
43
|
~LZ4Decompressor();
|
|
44
44
|
|
|
45
|
-
bool Init(CompressionType type) override;
|
|
46
45
|
Size Read(Size max_len, void *out_buf) override;
|
|
47
46
|
};
|
|
48
47
|
|
|
49
|
-
LZ4Decompressor
|
|
50
|
-
|
|
51
|
-
LZ4F_freeDecompressionContext(decoder);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
bool LZ4Decompressor::Init(CompressionType)
|
|
48
|
+
LZ4Decompressor::LZ4Decompressor(StreamReader *reader, CompressionType)
|
|
49
|
+
: StreamDecoder(reader)
|
|
55
50
|
{
|
|
56
51
|
LZ4F_errorCode_t err = LZ4F_createDecompressionContext(&decoder, LZ4F_VERSION);
|
|
57
52
|
if (LZ4F_isError(err))
|
|
58
53
|
throw std::bad_alloc();
|
|
54
|
+
}
|
|
59
55
|
|
|
60
|
-
|
|
56
|
+
LZ4Decompressor::~LZ4Decompressor()
|
|
57
|
+
{
|
|
58
|
+
LZ4F_freeDecompressionContext(decoder);
|
|
61
59
|
}
|
|
62
60
|
|
|
63
61
|
Size LZ4Decompressor::Read(Size max_len, void *user_buf)
|
|
@@ -106,27 +104,22 @@ Size LZ4Decompressor::Read(Size max_len, void *user_buf)
|
|
|
106
104
|
RG_UNREACHABLE();
|
|
107
105
|
}
|
|
108
106
|
|
|
109
|
-
class LZ4Compressor: public
|
|
107
|
+
class LZ4Compressor: public StreamEncoder {
|
|
110
108
|
LZ4F_cctx *encoder = nullptr;
|
|
111
109
|
LZ4F_preferences_t prefs = {};
|
|
112
110
|
|
|
113
111
|
HeapArray<uint8_t> dynamic_buf;
|
|
114
112
|
|
|
115
113
|
public:
|
|
116
|
-
LZ4Compressor(StreamWriter *writer
|
|
114
|
+
LZ4Compressor(StreamWriter *writer, CompressionType type, CompressionSpeed speed);
|
|
117
115
|
~LZ4Compressor();
|
|
118
116
|
|
|
119
|
-
bool Init(CompressionType type, CompressionSpeed speed) override;
|
|
120
117
|
bool Write(Span<const uint8_t> buf) override;
|
|
121
118
|
bool Finalize() override;
|
|
122
119
|
};
|
|
123
120
|
|
|
124
|
-
LZ4Compressor
|
|
125
|
-
|
|
126
|
-
LZ4F_freeCompressionContext(encoder);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
bool LZ4Compressor::Init(CompressionType, CompressionSpeed speed)
|
|
121
|
+
LZ4Compressor::LZ4Compressor(StreamWriter *writer, CompressionType, CompressionSpeed speed)
|
|
122
|
+
: StreamEncoder(writer)
|
|
130
123
|
{
|
|
131
124
|
LZ4F_errorCode_t err = LZ4F_createCompressionContext(&encoder, LZ4F_VERSION);
|
|
132
125
|
if (LZ4F_isError(err))
|
|
@@ -141,15 +134,15 @@ bool LZ4Compressor::Init(CompressionType, CompressionSpeed speed)
|
|
|
141
134
|
dynamic_buf.Grow(LZ4F_HEADER_SIZE_MAX);
|
|
142
135
|
|
|
143
136
|
size_t ret = LZ4F_compressBegin(encoder, dynamic_buf.end(), dynamic_buf.capacity - dynamic_buf.len, &prefs);
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
LogError("Failed to start LZ4 stream for '%1': %2", GetFileName(), LZ4F_getErrorName(ret));
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
137
|
+
if (LZ4F_isError(ret))
|
|
138
|
+
throw std::bad_alloc();
|
|
149
139
|
|
|
150
140
|
dynamic_buf.len += ret;
|
|
141
|
+
}
|
|
151
142
|
|
|
152
|
-
|
|
143
|
+
LZ4Compressor::~LZ4Compressor()
|
|
144
|
+
{
|
|
145
|
+
LZ4F_freeCompressionContext(encoder);
|
|
153
146
|
}
|
|
154
147
|
|
|
155
148
|
bool LZ4Compressor::Write(Span<const uint8_t> buf)
|
package/src/core/libcc/miniz.cc
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
|
|
27
27
|
namespace RG {
|
|
28
28
|
|
|
29
|
-
class MinizDecompressor: public
|
|
29
|
+
class MinizDecompressor: public StreamDecoder {
|
|
30
30
|
tinfl_decompressor inflator;
|
|
31
31
|
bool done = false;
|
|
32
32
|
|
|
@@ -45,21 +45,19 @@ class MinizDecompressor: public StreamDecompressor {
|
|
|
45
45
|
Size uncompressed_size = 0;
|
|
46
46
|
|
|
47
47
|
public:
|
|
48
|
-
MinizDecompressor(StreamReader *reader
|
|
48
|
+
MinizDecompressor(StreamReader *reader, CompressionType type);
|
|
49
49
|
~MinizDecompressor() {}
|
|
50
50
|
|
|
51
|
-
bool Init(CompressionType type) override;
|
|
52
51
|
Size Read(Size max_len, void *out_buf) override;
|
|
53
52
|
};
|
|
54
53
|
|
|
55
|
-
|
|
54
|
+
MinizDecompressor::MinizDecompressor(StreamReader *reader, CompressionType type)
|
|
55
|
+
: StreamDecoder(reader)
|
|
56
56
|
{
|
|
57
57
|
static_assert(RG_SIZE(out_buf) >= TINFL_LZ_DICT_SIZE);
|
|
58
58
|
|
|
59
59
|
tinfl_init(&inflator);
|
|
60
60
|
is_gzip = (type == CompressionType::Gzip);
|
|
61
|
-
|
|
62
|
-
return true;
|
|
63
61
|
}
|
|
64
62
|
|
|
65
63
|
Size MinizDecompressor::Read(Size max_len, void *user_buf)
|
|
@@ -217,7 +215,7 @@ truncated_error:
|
|
|
217
215
|
return -1;
|
|
218
216
|
}
|
|
219
217
|
|
|
220
|
-
class MinizCompressor: public
|
|
218
|
+
class MinizCompressor: public StreamEncoder {
|
|
221
219
|
tdefl_compressor deflator;
|
|
222
220
|
|
|
223
221
|
// Gzip support
|
|
@@ -229,10 +227,9 @@ class MinizCompressor: public StreamCompressor {
|
|
|
229
227
|
LocalArray<uint8_t, 1024> small_buf;
|
|
230
228
|
|
|
231
229
|
public:
|
|
232
|
-
MinizCompressor(StreamWriter *writer
|
|
230
|
+
MinizCompressor(StreamWriter *writer, CompressionType type, CompressionSpeed speed);
|
|
233
231
|
~MinizCompressor() {}
|
|
234
232
|
|
|
235
|
-
bool Init(CompressionType type, CompressionSpeed speed) override;
|
|
236
233
|
bool Write(Span<const uint8_t> buf) override;
|
|
237
234
|
bool Finalize() override;
|
|
238
235
|
|
|
@@ -240,7 +237,8 @@ private:
|
|
|
240
237
|
bool WriteDeflate(Span<const uint8_t> buf);
|
|
241
238
|
};
|
|
242
239
|
|
|
243
|
-
|
|
240
|
+
MinizCompressor::MinizCompressor(StreamWriter *writer, CompressionType type, CompressionSpeed speed)
|
|
241
|
+
: StreamEncoder(writer)
|
|
244
242
|
{
|
|
245
243
|
is_gzip = (type == CompressionType::Gzip);
|
|
246
244
|
|
|
@@ -256,10 +254,7 @@ bool MinizCompressor::Init(CompressionType type, CompressionSpeed speed)
|
|
|
256
254
|
MinizCompressor *compressor = (MinizCompressor *)udata;
|
|
257
255
|
return (int)compressor->WriteRaw(MakeSpan((uint8_t *)buf, len));
|
|
258
256
|
}, this, flags);
|
|
259
|
-
|
|
260
|
-
LogError("Failed to initialize Deflate compression for '%1'", GetFileName());
|
|
261
|
-
return false;
|
|
262
|
-
}
|
|
257
|
+
RG_ASSERT(status == TDEFL_STATUS_OKAY);
|
|
263
258
|
|
|
264
259
|
if (is_gzip) {
|
|
265
260
|
static uint8_t gzip_header[] = {
|
|
@@ -271,11 +266,8 @@ bool MinizCompressor::Init(CompressionType type, CompressionSpeed speed)
|
|
|
271
266
|
0 // OS
|
|
272
267
|
};
|
|
273
268
|
|
|
274
|
-
|
|
275
|
-
return false;
|
|
269
|
+
WriteRaw(gzip_header);
|
|
276
270
|
}
|
|
277
|
-
|
|
278
|
-
return true;
|
|
279
271
|
}
|
|
280
272
|
|
|
281
273
|
bool MinizCompressor::Write(Span<const uint8_t> buf)
|
package/src/koffi/src/call.cc
CHANGED
|
@@ -1269,7 +1269,7 @@ void CallData::PopOutArguments()
|
|
|
1269
1269
|
RG_ASSERT(array.IsArray());
|
|
1270
1270
|
RG_ASSERT(array.Length() == 1);
|
|
1271
1271
|
|
|
1272
|
-
Size len =
|
|
1272
|
+
Size len = NullTerminatedLength((const char16_t *)out.ptr, out.max_len);
|
|
1273
1273
|
Napi::String str = Napi::String::New(env, (const char16_t *)out.ptr, len);
|
|
1274
1274
|
|
|
1275
1275
|
array.Set(0u, str);
|
package/src/koffi/src/util.cc
CHANGED
|
@@ -779,17 +779,6 @@ void DecodeObject(Napi::Object obj, const uint8_t *origin, const TypeInfo *type)
|
|
|
779
779
|
}
|
|
780
780
|
}
|
|
781
781
|
|
|
782
|
-
Size WideStringLength(const char16_t *str16, Size max)
|
|
783
|
-
{
|
|
784
|
-
Size len = 0;
|
|
785
|
-
|
|
786
|
-
while (len < max && str16[len]) {
|
|
787
|
-
len++;
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
return len;
|
|
791
|
-
}
|
|
792
|
-
|
|
793
782
|
Napi::Value DecodeArray(Napi::Env env, const uint8_t *origin, const TypeInfo *type)
|
|
794
783
|
{
|
|
795
784
|
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
@@ -873,7 +862,7 @@ Napi::Value DecodeArray(Napi::Env env, const uint8_t *origin, const TypeInfo *ty
|
|
|
873
862
|
case PrimitiveKind::Int16: {
|
|
874
863
|
if (type->hint == ArrayHint::String) {
|
|
875
864
|
const char16_t *ptr = (const char16_t *)origin;
|
|
876
|
-
Size count =
|
|
865
|
+
Size count = NullTerminatedLength(ptr, len);
|
|
877
866
|
|
|
878
867
|
Napi::String str = Napi::String::New(env, ptr, count);
|
|
879
868
|
return str;
|
|
@@ -1186,7 +1175,12 @@ Napi::Value Decode(Napi::Env env, const uint8_t *ptr, const TypeInfo *type, cons
|
|
|
1186
1175
|
} break;
|
|
1187
1176
|
case PrimitiveKind::Int16:
|
|
1188
1177
|
case PrimitiveKind::UInt16: {
|
|
1189
|
-
Size count =
|
|
1178
|
+
Size count = NullTerminatedLength((const char16_t *)ptr, RG_SIZE_MAX);
|
|
1179
|
+
type = MakeArrayType(instance, type, count);
|
|
1180
|
+
} break;
|
|
1181
|
+
|
|
1182
|
+
case PrimitiveKind::Pointer: {
|
|
1183
|
+
Size count = NullTerminatedLength((const void **)ptr, RG_SIZE_MAX);
|
|
1190
1184
|
type = MakeArrayType(instance, type, count);
|
|
1191
1185
|
} break;
|
|
1192
1186
|
|