koffi 1.1.0-beta.1 → 1.1.0-beta.2
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/CMakeLists.txt +4 -0
- package/README.md +12 -11
- package/build/qemu/1.1.0-beta.2/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.2/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.2/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.2/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.2/koffi_linux_arm.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.2/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.2/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.2/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.2/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.2/koffi_win32_x64.tar.gz +0 -0
- package/package.json +1 -1
- package/qemu/qemu.js +1 -0
- package/src/abi_arm32.cc +27 -45
- package/src/abi_arm64.cc +58 -132
- package/src/abi_x64_sysv.cc +24 -7
- package/src/abi_x64_win.cc +3 -0
- package/src/abi_x86.cc +3 -0
- package/src/call.cc +540 -33
- package/src/call.hh +5 -3
- package/src/ffi.cc +66 -2
- package/src/ffi.hh +3 -1
- package/src/parser.cc +4 -0
- package/src/util.cc +72 -0
- package/src/util.hh +2 -0
- package/test/misc.c +14 -8
- package/vendor/node-addon-api/CODE_OF_CONDUCT.md +4 -0
- package/vendor/node-addon-api/CONTRIBUTING.md +93 -0
- package/vendor/node-addon-api/appveyor.yml +37 -0
- package/vendor/node-addon-api/benchmark/README.md +47 -0
- package/vendor/node-addon-api/benchmark/binding.gyp +25 -0
- package/vendor/node-addon-api/benchmark/function_args.cc +217 -0
- package/vendor/node-addon-api/benchmark/function_args.js +60 -0
- package/vendor/node-addon-api/benchmark/index.js +34 -0
- package/vendor/node-addon-api/benchmark/property_descriptor.cc +91 -0
- package/vendor/node-addon-api/benchmark/property_descriptor.js +37 -0
- package/vendor/node-addon-api/doc/addon.md +163 -0
- package/vendor/node-addon-api/doc/array.md +81 -0
- package/vendor/node-addon-api/doc/array_buffer.md +155 -0
- package/vendor/node-addon-api/doc/async_context.md +86 -0
- package/vendor/node-addon-api/doc/async_operations.md +31 -0
- package/vendor/node-addon-api/doc/async_worker.md +427 -0
- package/vendor/node-addon-api/doc/async_worker_variants.md +557 -0
- package/vendor/node-addon-api/doc/bigint.md +97 -0
- package/vendor/node-addon-api/doc/boolean.md +68 -0
- package/vendor/node-addon-api/doc/buffer.md +150 -0
- package/vendor/node-addon-api/doc/callback_scope.md +54 -0
- package/vendor/node-addon-api/doc/callbackinfo.md +97 -0
- package/vendor/node-addon-api/doc/checker-tool.md +32 -0
- package/vendor/node-addon-api/doc/class_property_descriptor.md +123 -0
- package/vendor/node-addon-api/doc/cmake-js.md +68 -0
- package/vendor/node-addon-api/doc/conversion-tool.md +28 -0
- package/vendor/node-addon-api/doc/creating_a_release.md +62 -0
- package/vendor/node-addon-api/doc/dataview.md +248 -0
- package/vendor/node-addon-api/doc/date.md +68 -0
- package/vendor/node-addon-api/doc/env.md +196 -0
- package/vendor/node-addon-api/doc/error.md +120 -0
- package/vendor/node-addon-api/doc/error_handling.md +254 -0
- package/vendor/node-addon-api/doc/escapable_handle_scope.md +80 -0
- package/vendor/node-addon-api/doc/external.md +63 -0
- package/vendor/node-addon-api/doc/function.md +402 -0
- package/vendor/node-addon-api/doc/function_reference.md +238 -0
- package/vendor/node-addon-api/doc/generator.md +13 -0
- package/vendor/node-addon-api/doc/handle_scope.md +63 -0
- package/vendor/node-addon-api/doc/hierarchy.md +91 -0
- package/vendor/node-addon-api/doc/instance_wrap.md +408 -0
- package/vendor/node-addon-api/doc/maybe.md +76 -0
- package/vendor/node-addon-api/doc/memory_management.md +27 -0
- package/vendor/node-addon-api/doc/name.md +29 -0
- package/vendor/node-addon-api/doc/node-gyp.md +82 -0
- package/vendor/node-addon-api/doc/number.md +163 -0
- package/vendor/node-addon-api/doc/object.md +411 -0
- package/vendor/node-addon-api/doc/object_lifetime_management.md +83 -0
- package/vendor/node-addon-api/doc/object_reference.md +117 -0
- package/vendor/node-addon-api/doc/object_wrap.md +588 -0
- package/vendor/node-addon-api/doc/prebuild_tools.md +16 -0
- package/vendor/node-addon-api/doc/promises.md +79 -0
- package/vendor/node-addon-api/doc/property_descriptor.md +286 -0
- package/vendor/node-addon-api/doc/propertylvalue.md +50 -0
- package/vendor/node-addon-api/doc/range_error.md +59 -0
- package/vendor/node-addon-api/doc/reference.md +113 -0
- package/vendor/node-addon-api/doc/setup.md +110 -0
- package/vendor/node-addon-api/doc/string.md +93 -0
- package/vendor/node-addon-api/doc/symbol.md +61 -0
- package/vendor/node-addon-api/doc/threadsafe.md +121 -0
- package/vendor/node-addon-api/doc/threadsafe_function.md +290 -0
- package/vendor/node-addon-api/doc/type_error.md +59 -0
- package/vendor/node-addon-api/doc/typed_array.md +78 -0
- package/vendor/node-addon-api/doc/typed_array_of.md +137 -0
- package/vendor/node-addon-api/doc/typed_threadsafe_function.md +306 -0
- package/vendor/node-addon-api/doc/value.md +340 -0
- package/vendor/node-addon-api/doc/version_management.md +43 -0
- package/vendor/node-addon-api/package.json +415 -0
- package/vendor/node-addon-api/test/README.md +91 -0
- package/vendor/node-addon-api/test/addon.cc +36 -0
- package/vendor/node-addon-api/test/addon.js +11 -0
- package/vendor/node-addon-api/test/addon_build/index.js +49 -0
- package/vendor/node-addon-api/test/addon_build/tpl/addon.cc +17 -0
- package/vendor/node-addon-api/test/addon_build/tpl/binding.gyp +62 -0
- package/vendor/node-addon-api/test/addon_build/tpl/index.js +9 -0
- package/vendor/node-addon-api/test/addon_build/tpl/package.json +11 -0
- package/vendor/node-addon-api/test/addon_data.cc +99 -0
- package/vendor/node-addon-api/test/addon_data.js +46 -0
- package/vendor/node-addon-api/test/array_buffer.cc +243 -0
- package/vendor/node-addon-api/test/array_buffer.js +69 -0
- package/vendor/node-addon-api/test/async_context.cc +36 -0
- package/vendor/node-addon-api/test/async_context.js +122 -0
- package/vendor/node-addon-api/test/async_progress_queue_worker.cc +83 -0
- package/vendor/node-addon-api/test/async_progress_queue_worker.js +46 -0
- package/vendor/node-addon-api/test/async_progress_worker.cc +134 -0
- package/vendor/node-addon-api/test/async_progress_worker.js +61 -0
- package/vendor/node-addon-api/test/async_worker.cc +106 -0
- package/vendor/node-addon-api/test/async_worker.js +179 -0
- package/vendor/node-addon-api/test/async_worker_nocallback.js +13 -0
- package/vendor/node-addon-api/test/async_worker_persistent.cc +63 -0
- package/vendor/node-addon-api/test/async_worker_persistent.js +24 -0
- package/vendor/node-addon-api/test/basic_types/array.cc +40 -0
- package/vendor/node-addon-api/test/basic_types/array.js +35 -0
- package/vendor/node-addon-api/test/basic_types/boolean.cc +38 -0
- package/vendor/node-addon-api/test/basic_types/boolean.js +35 -0
- package/vendor/node-addon-api/test/basic_types/number.cc +99 -0
- package/vendor/node-addon-api/test/basic_types/number.js +114 -0
- package/vendor/node-addon-api/test/basic_types/value.cc +120 -0
- package/vendor/node-addon-api/test/basic_types/value.js +133 -0
- package/vendor/node-addon-api/test/bigint.cc +91 -0
- package/vendor/node-addon-api/test/bigint.js +53 -0
- package/vendor/node-addon-api/test/binding-swallowexcept.cc +12 -0
- package/vendor/node-addon-api/test/binding.cc +173 -0
- package/vendor/node-addon-api/test/binding.gyp +124 -0
- package/vendor/node-addon-api/test/buffer.cc +183 -0
- package/vendor/node-addon-api/test/buffer.js +69 -0
- package/vendor/node-addon-api/test/callbackscope.cc +22 -0
- package/vendor/node-addon-api/test/callbackscope.js +49 -0
- package/vendor/node-addon-api/test/common/index.js +114 -0
- package/vendor/node-addon-api/test/common/test_helper.h +71 -0
- package/vendor/node-addon-api/test/dataview/dataview.cc +48 -0
- package/vendor/node-addon-api/test/dataview/dataview.js +35 -0
- package/vendor/node-addon-api/test/dataview/dataview_read_write.cc +115 -0
- package/vendor/node-addon-api/test/dataview/dataview_read_write.js +90 -0
- package/vendor/node-addon-api/test/date.cc +44 -0
- package/vendor/node-addon-api/test/date.js +18 -0
- package/vendor/node-addon-api/test/env_cleanup.cc +88 -0
- package/vendor/node-addon-api/test/env_cleanup.js +56 -0
- package/vendor/node-addon-api/test/error.cc +287 -0
- package/vendor/node-addon-api/test/error.js +81 -0
- package/vendor/node-addon-api/test/error_handling_for_primitives.cc +13 -0
- package/vendor/node-addon-api/test/error_handling_for_primitives.js +29 -0
- package/vendor/node-addon-api/test/error_terminating_environment.js +95 -0
- package/vendor/node-addon-api/test/external.cc +81 -0
- package/vendor/node-addon-api/test/external.js +88 -0
- package/vendor/node-addon-api/test/function.cc +324 -0
- package/vendor/node-addon-api/test/function.js +133 -0
- package/vendor/node-addon-api/test/function_reference.cc +202 -0
- package/vendor/node-addon-api/test/function_reference.js +157 -0
- package/vendor/node-addon-api/test/globalObject/global_object.cc +61 -0
- package/vendor/node-addon-api/test/globalObject/global_object_delete_property.cc +31 -0
- package/vendor/node-addon-api/test/globalObject/global_object_delete_property.js +61 -0
- package/vendor/node-addon-api/test/globalObject/global_object_get_property.cc +40 -0
- package/vendor/node-addon-api/test/globalObject/global_object_get_property.js +57 -0
- package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.cc +28 -0
- package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.js +48 -0
- package/vendor/node-addon-api/test/globalObject/global_object_set_property.cc +31 -0
- package/vendor/node-addon-api/test/globalObject/global_object_set_property.js +58 -0
- package/vendor/node-addon-api/test/handlescope.cc +60 -0
- package/vendor/node-addon-api/test/handlescope.js +14 -0
- package/vendor/node-addon-api/test/index.js +159 -0
- package/vendor/node-addon-api/test/maybe/check.cc +23 -0
- package/vendor/node-addon-api/test/maybe/index.js +38 -0
- package/vendor/node-addon-api/test/memory_management.cc +17 -0
- package/vendor/node-addon-api/test/memory_management.js +9 -0
- package/vendor/node-addon-api/test/movable_callbacks.cc +23 -0
- package/vendor/node-addon-api/test/movable_callbacks.js +21 -0
- package/vendor/node-addon-api/test/name.cc +108 -0
- package/vendor/node-addon-api/test/name.js +59 -0
- package/vendor/node-addon-api/test/napi_child.js +14 -0
- package/vendor/node-addon-api/test/object/delete_property.cc +38 -0
- package/vendor/node-addon-api/test/object/delete_property.js +41 -0
- package/vendor/node-addon-api/test/object/finalizer.cc +29 -0
- package/vendor/node-addon-api/test/object/finalizer.js +28 -0
- package/vendor/node-addon-api/test/object/get_property.cc +34 -0
- package/vendor/node-addon-api/test/object/get_property.js +40 -0
- package/vendor/node-addon-api/test/object/has_own_property.cc +34 -0
- package/vendor/node-addon-api/test/object/has_own_property.js +34 -0
- package/vendor/node-addon-api/test/object/has_property.cc +38 -0
- package/vendor/node-addon-api/test/object/has_property.js +37 -0
- package/vendor/node-addon-api/test/object/object.cc +350 -0
- package/vendor/node-addon-api/test/object/object.js +217 -0
- package/vendor/node-addon-api/test/object/object_deprecated.cc +66 -0
- package/vendor/node-addon-api/test/object/object_deprecated.js +47 -0
- package/vendor/node-addon-api/test/object/object_freeze_seal.cc +25 -0
- package/vendor/node-addon-api/test/object/object_freeze_seal.js +61 -0
- package/vendor/node-addon-api/test/object/set_property.cc +45 -0
- package/vendor/node-addon-api/test/object/set_property.js +30 -0
- package/vendor/node-addon-api/test/object/subscript_operator.cc +58 -0
- package/vendor/node-addon-api/test/object/subscript_operator.js +17 -0
- package/vendor/node-addon-api/test/object_reference.cc +219 -0
- package/vendor/node-addon-api/test/object_reference.js +259 -0
- package/vendor/node-addon-api/test/objectwrap.cc +268 -0
- package/vendor/node-addon-api/test/objectwrap.js +284 -0
- package/vendor/node-addon-api/test/objectwrap_constructor_exception.cc +26 -0
- package/vendor/node-addon-api/test/objectwrap_constructor_exception.js +18 -0
- package/vendor/node-addon-api/test/objectwrap_function.cc +45 -0
- package/vendor/node-addon-api/test/objectwrap_function.js +22 -0
- package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.cc +30 -0
- package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.js +13 -0
- package/vendor/node-addon-api/test/objectwrap_removewrap.cc +45 -0
- package/vendor/node-addon-api/test/objectwrap_removewrap.js +40 -0
- package/vendor/node-addon-api/test/objectwrap_worker_thread.js +19 -0
- package/vendor/node-addon-api/test/promise.cc +29 -0
- package/vendor/node-addon-api/test/promise.js +18 -0
- package/vendor/node-addon-api/test/reference.cc +24 -0
- package/vendor/node-addon-api/test/reference.js +14 -0
- package/vendor/node-addon-api/test/run_script.cc +56 -0
- package/vendor/node-addon-api/test/run_script.js +45 -0
- package/vendor/node-addon-api/test/symbol.cc +79 -0
- package/vendor/node-addon-api/test/symbol.js +73 -0
- package/vendor/node-addon-api/test/testUtil.js +54 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.cc +195 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.js +188 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.cc +63 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.js +12 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.cc +115 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.js +14 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.cc +26 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.js +7 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.cc +225 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.js +59 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.cc +42 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.js +53 -0
- package/vendor/node-addon-api/test/thunking_manual.cc +140 -0
- package/vendor/node-addon-api/test/thunking_manual.js +17 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.cc +215 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.js +188 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.cc +68 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.js +12 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.cc +127 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.js +14 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.cc +28 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.js +7 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.cc +237 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.js +59 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.cc +53 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.js +53 -0
- package/vendor/node-addon-api/test/typedarray-bigint.js +58 -0
- package/vendor/node-addon-api/test/typedarray.cc +216 -0
- package/vendor/node-addon-api/test/typedarray.js +69 -0
- package/vendor/node-addon-api/test/version_management.cc +27 -0
- package/vendor/node-addon-api/test/version_management.js +31 -0
- package/vendor/node-addon-api/unit-test/README.md +28 -0
- package/vendor/node-addon-api/unit-test/binding-file-template.js +39 -0
- package/vendor/node-addon-api/unit-test/binding.gyp +72 -0
- package/vendor/node-addon-api/unit-test/exceptions.js +32 -0
- package/vendor/node-addon-api/unit-test/generate-binding-cc.js +61 -0
- package/vendor/node-addon-api/unit-test/injectTestParams.js +101 -0
- package/vendor/node-addon-api/unit-test/listOfTestModules.js +88 -0
- package/vendor/node-addon-api/unit-test/matchModules.js +65 -0
- package/vendor/node-addon-api/unit-test/setup.js +13 -0
- package/vendor/node-addon-api/unit-test/spawnTask.js +26 -0
- package/vendor/node-addon-api/unit-test/test.js +30 -0
- package/build/qemu/1.1.0-beta.1/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.1/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.1/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.1/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.1/koffi_linux_arm.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.1/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.1/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.1/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.1/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.1/koffi_win32_x64.tar.gz +0 -0
package/src/call.hh
CHANGED
|
@@ -86,10 +86,12 @@ private:
|
|
|
86
86
|
|
|
87
87
|
const char *PushString(const Napi::Value &value);
|
|
88
88
|
const char16_t *PushString16(const Napi::Value &value);
|
|
89
|
-
bool PushObject(const Napi::Object &obj, const TypeInfo *type, uint8_t *dest);
|
|
89
|
+
bool PushObject(const Napi::Object &obj, const TypeInfo *type, uint8_t *dest, int16_t realign = 0);
|
|
90
|
+
bool PushArray(const Napi::Object &obj, const TypeInfo *type, uint8_t *dest, int16_t realign = 0);
|
|
90
91
|
|
|
91
|
-
void PopObject(Napi::Object obj, const uint8_t *
|
|
92
|
-
Napi::Object PopObject(const uint8_t *
|
|
92
|
+
void PopObject(Napi::Object obj, const uint8_t *src, const TypeInfo *type, int16_t realign = 0);
|
|
93
|
+
Napi::Object PopObject(const uint8_t *src, const TypeInfo *type, int16_t realign = 0);
|
|
94
|
+
Napi::Object PopArray(const uint8_t *src, const TypeInfo *type, int16_t realign = 0);
|
|
93
95
|
};
|
|
94
96
|
|
|
95
97
|
template <typename T>
|
package/src/ffi.cc
CHANGED
|
@@ -85,6 +85,10 @@ static Napi::Value CreateStructType(const Napi::CallbackInfo &info, bool pad)
|
|
|
85
85
|
member.type = ResolveType(instance, value);
|
|
86
86
|
if (!member.type)
|
|
87
87
|
return env.Null();
|
|
88
|
+
if (member.type->primitive == PrimitiveKind::Void) {
|
|
89
|
+
ThrowError<Napi::TypeError>(env, "Type Void cannot be used as a member");
|
|
90
|
+
return env.Null();
|
|
91
|
+
}
|
|
88
92
|
|
|
89
93
|
member.align = pad ? member.type->align : 1;
|
|
90
94
|
|
|
@@ -241,6 +245,57 @@ static Napi::Value MarkInOut(const Napi::CallbackInfo &info)
|
|
|
241
245
|
return EncodePointerDirection(info, 3);
|
|
242
246
|
}
|
|
243
247
|
|
|
248
|
+
static Napi::Value CreateArrayType(const Napi::CallbackInfo &info)
|
|
249
|
+
{
|
|
250
|
+
Napi::Env env = info.Env();
|
|
251
|
+
InstanceData *instance = env.GetInstanceData<InstanceData>();
|
|
252
|
+
|
|
253
|
+
if (info.Length() < 2) {
|
|
254
|
+
ThrowError<Napi::TypeError>(env, "Expected 2 arguments, got %1", info.Length());
|
|
255
|
+
return env.Null();
|
|
256
|
+
}
|
|
257
|
+
if (!info[1].IsNumber()) {
|
|
258
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for length, expected integer", GetValueType(instance, info[1]));
|
|
259
|
+
return env.Null();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const TypeInfo *ref = ResolveType(instance, info[0]);
|
|
263
|
+
int64_t len = (uint16_t)info[1].As<Napi::Number>().Int64Value();
|
|
264
|
+
|
|
265
|
+
if (!ref)
|
|
266
|
+
return env.Null();
|
|
267
|
+
if (len <= 0) {
|
|
268
|
+
ThrowError<Napi::TypeError>(env, "Array length must be non-zero positive");
|
|
269
|
+
return env.Null();
|
|
270
|
+
}
|
|
271
|
+
if (len > INT16_MAX / ref->size) {
|
|
272
|
+
ThrowError<Napi::TypeError>(env, "Array length is too high (max = %1)", INT16_MAX / ref->size);
|
|
273
|
+
return env.Null();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
TypeInfo *type = instance->types.AppendDefault();
|
|
277
|
+
RG_DEFER_N(err_guard) { instance->types.RemoveLast(1); };
|
|
278
|
+
|
|
279
|
+
type->name = Fmt(&instance->str_alloc, "%1[%2]", ref->name, len).ptr;
|
|
280
|
+
|
|
281
|
+
type->primitive = PrimitiveKind::Array;
|
|
282
|
+
type->align = ref->align;
|
|
283
|
+
type->size = (int16_t)(len * ref->size);
|
|
284
|
+
type->ref = ref;
|
|
285
|
+
|
|
286
|
+
// If the insert succeeds, we cannot fail anymore
|
|
287
|
+
if (!instance->types_map.TrySet(type).second) {
|
|
288
|
+
ThrowError<Napi::Error>(env, "Duplicate type name '%1'", type->name);
|
|
289
|
+
return env.Null();
|
|
290
|
+
}
|
|
291
|
+
err_guard.Disable();
|
|
292
|
+
|
|
293
|
+
Napi::External<TypeInfo> external = Napi::External<TypeInfo>::New(env, type);
|
|
294
|
+
SetValueTag(instance, external, &TypeInfoMarker);
|
|
295
|
+
|
|
296
|
+
return external;
|
|
297
|
+
}
|
|
298
|
+
|
|
244
299
|
static Span<uint8_t> AllocateAndAlign16(Allocator *alloc, Size size)
|
|
245
300
|
{
|
|
246
301
|
RG_ASSERT(AlignLen(size, 16) == size);
|
|
@@ -324,8 +379,9 @@ static Napi::Value TranslateVariadicCall(const Napi::CallbackInfo &info)
|
|
|
324
379
|
param.type = ResolveType(instance, info[i], ¶m.directions);
|
|
325
380
|
if (!param.type)
|
|
326
381
|
return env.Null();
|
|
327
|
-
if (param.type->primitive == PrimitiveKind::Void
|
|
328
|
-
|
|
382
|
+
if (param.type->primitive == PrimitiveKind::Void ||
|
|
383
|
+
param.type->primitive == PrimitiveKind::Array) {
|
|
384
|
+
ThrowError<Napi::TypeError>(env, "Type %1 cannot be used as a parameter", PrimitiveKindNames[(int)param.type->primitive]);
|
|
329
385
|
return env.Null();
|
|
330
386
|
}
|
|
331
387
|
|
|
@@ -456,6 +512,11 @@ static bool ParseClassicFunction(Napi::Env env, Napi::String name, Napi::Value r
|
|
|
456
512
|
func->ret.type = ResolveType(instance, ret);
|
|
457
513
|
if (!func->ret.type)
|
|
458
514
|
return false;
|
|
515
|
+
if (func->ret.type->primitive == PrimitiveKind::Array) {
|
|
516
|
+
ThrowError<Napi::Error>(env, "You are not allowed to directly return fixed-size arrays");
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
519
|
+
|
|
459
520
|
if (!parameters.IsArray()) {
|
|
460
521
|
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for parameters of '%2', expected an array", GetValueType(instance, parameters), func->name);
|
|
461
522
|
return false;
|
|
@@ -682,6 +743,8 @@ void LibraryHolder::Unref() const
|
|
|
682
743
|
static void RegisterPrimitiveType(InstanceData *instance, const char *name, PrimitiveKind primitive,
|
|
683
744
|
int16_t size, int16_t align)
|
|
684
745
|
{
|
|
746
|
+
RG_ASSERT(align <= size);
|
|
747
|
+
|
|
685
748
|
TypeInfo *type = instance->types.AppendDefault();
|
|
686
749
|
|
|
687
750
|
type->name = name;
|
|
@@ -805,6 +868,7 @@ static void SetExports(Napi::Env env, Func func)
|
|
|
805
868
|
func("pack", Napi::Function::New(env, CreatePackedStructType));
|
|
806
869
|
func("handle", Napi::Function::New(env, CreateHandleType));
|
|
807
870
|
func("pointer", Napi::Function::New(env, CreatePointerType));
|
|
871
|
+
func("array", Napi::Function::New(env, CreateArrayType));
|
|
808
872
|
func("load", Napi::Function::New(env, LoadSharedLibrary));
|
|
809
873
|
func("in", Napi::Function::New(env, MarkIn));
|
|
810
874
|
func("out", Napi::Function::New(env, MarkOut));
|
package/src/ffi.hh
CHANGED
|
@@ -39,6 +39,7 @@ enum class PrimitiveKind {
|
|
|
39
39
|
String16,
|
|
40
40
|
Pointer,
|
|
41
41
|
Record,
|
|
42
|
+
Array,
|
|
42
43
|
Float32,
|
|
43
44
|
Float64
|
|
44
45
|
};
|
|
@@ -57,6 +58,7 @@ static const char *const PrimitiveKindNames[] = {
|
|
|
57
58
|
"String16",
|
|
58
59
|
"Pointer",
|
|
59
60
|
"Record",
|
|
61
|
+
"Array",
|
|
60
62
|
"Float32",
|
|
61
63
|
"Float64"
|
|
62
64
|
};
|
|
@@ -73,7 +75,7 @@ struct TypeInfo {
|
|
|
73
75
|
int16_t align;
|
|
74
76
|
|
|
75
77
|
HeapArray<RecordMember> members; // Record only
|
|
76
|
-
const TypeInfo *ref; // Pointer
|
|
78
|
+
const TypeInfo *ref; // Pointer or array
|
|
77
79
|
|
|
78
80
|
RG_HASHTABLE_HANDLER(TypeInfo, name);
|
|
79
81
|
};
|
package/src/parser.cc
CHANGED
|
@@ -35,6 +35,10 @@ bool PrototypeParser::Parse(Napi::String proto, FunctionInfo *func)
|
|
|
35
35
|
Tokenize(hold.c_str());
|
|
36
36
|
|
|
37
37
|
func->ret.type = ParseType();
|
|
38
|
+
if (func->ret.type->primitive == PrimitiveKind::Array) {
|
|
39
|
+
MarkError("You are not allowed to directly return fixed-size arrays");
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
38
42
|
if (Match("__cdecl")) {
|
|
39
43
|
func->convention = CallConvention::Cdecl;
|
|
40
44
|
} else if (Match("__stdcall")) {
|
package/src/util.cc
CHANGED
|
@@ -126,4 +126,76 @@ bool CheckValueTag(const InstanceData *instance, Napi::Value value, const void *
|
|
|
126
126
|
return match;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
+
class HfaAnalyser {
|
|
130
|
+
uint32_t primitives;
|
|
131
|
+
Size count;
|
|
132
|
+
|
|
133
|
+
public:
|
|
134
|
+
bool Analyse(const TypeInfo *type, int min, int max);
|
|
135
|
+
|
|
136
|
+
private:
|
|
137
|
+
void AnalyseStruct(const TypeInfo *type);
|
|
138
|
+
void AnalyseArray(const TypeInfo *type);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
bool HfaAnalyser::Analyse(const TypeInfo *type, int min, int max)
|
|
142
|
+
{
|
|
143
|
+
primitives = 0;
|
|
144
|
+
count = 0;
|
|
145
|
+
|
|
146
|
+
if (type->primitive == PrimitiveKind::Record) {
|
|
147
|
+
AnalyseStruct(type);
|
|
148
|
+
} else if (type->primitive == PrimitiveKind::Array) {
|
|
149
|
+
AnalyseArray(type);
|
|
150
|
+
} else {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
bool hfa = (count >= min && count <= max && PopCount(primitives) == 1);
|
|
155
|
+
return hfa;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
void HfaAnalyser::AnalyseStruct(const TypeInfo *type)
|
|
159
|
+
{
|
|
160
|
+
RG_ASSERT(type->primitive == PrimitiveKind::Record);
|
|
161
|
+
|
|
162
|
+
for (const RecordMember &member: type->members) {
|
|
163
|
+
if (member.type->primitive == PrimitiveKind::Record) {
|
|
164
|
+
AnalyseStruct(member.type);
|
|
165
|
+
} else if (member.type->primitive == PrimitiveKind::Array) {
|
|
166
|
+
AnalyseArray(member.type);
|
|
167
|
+
} else if (member.type->primitive == PrimitiveKind::Float32 ||
|
|
168
|
+
member.type->primitive == PrimitiveKind::Float64) {
|
|
169
|
+
primitives |= 1u << (int)member.type->primitive;
|
|
170
|
+
count++;
|
|
171
|
+
} else {
|
|
172
|
+
primitives = UINT_MAX;
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
void HfaAnalyser::AnalyseArray(const TypeInfo *type)
|
|
179
|
+
{
|
|
180
|
+
RG_ASSERT(type->primitive == PrimitiveKind::Array);
|
|
181
|
+
|
|
182
|
+
if (type->ref->primitive == PrimitiveKind::Record) {
|
|
183
|
+
AnalyseStruct(type->ref);
|
|
184
|
+
} else if (type->ref->primitive == PrimitiveKind::Array) {
|
|
185
|
+
AnalyseArray(type->ref);
|
|
186
|
+
} else if (type->ref->primitive == PrimitiveKind::Float32 ||
|
|
187
|
+
type->ref->primitive == PrimitiveKind::Float64) {
|
|
188
|
+
primitives |= 1u << (int)type->ref->primitive;
|
|
189
|
+
count += type->size / type->ref->size;;
|
|
190
|
+
} else {
|
|
191
|
+
primitives = UINT_MAX;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
bool IsHFA(const TypeInfo *type, int min, int max)
|
|
196
|
+
{
|
|
197
|
+
HfaAnalyser analyser;
|
|
198
|
+
return analyser.Analyse(type, min, max);
|
|
199
|
+
}
|
|
200
|
+
|
|
129
201
|
}
|
package/src/util.hh
CHANGED
package/test/misc.c
CHANGED
|
@@ -60,8 +60,7 @@ typedef struct Float2 {
|
|
|
60
60
|
} Float2;
|
|
61
61
|
typedef struct Float3 {
|
|
62
62
|
float a;
|
|
63
|
-
float b;
|
|
64
|
-
float c;
|
|
63
|
+
float b[2];
|
|
65
64
|
} Float3;
|
|
66
65
|
|
|
67
66
|
typedef struct Double2 {
|
|
@@ -70,8 +69,10 @@ typedef struct Double2 {
|
|
|
70
69
|
} Double2;
|
|
71
70
|
typedef struct Double3 {
|
|
72
71
|
double a;
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
struct {
|
|
73
|
+
double b;
|
|
74
|
+
double c;
|
|
75
|
+
} s;
|
|
75
76
|
} Double3;
|
|
76
77
|
|
|
77
78
|
typedef struct IJK1 { int8_t i; int8_t j; int8_t k; } IJK1;
|
|
@@ -185,13 +186,18 @@ EXPORT Float3 PackFloat3(float a, float b, float c, Float3 *out)
|
|
|
185
186
|
Float3 ret;
|
|
186
187
|
|
|
187
188
|
ret.a = a;
|
|
188
|
-
ret.b = b;
|
|
189
|
-
ret.
|
|
189
|
+
ret.b[0] = b;
|
|
190
|
+
ret.b[1] = c;
|
|
190
191
|
*out = ret;
|
|
191
192
|
|
|
192
193
|
return ret;
|
|
193
194
|
}
|
|
194
195
|
|
|
196
|
+
EXPORT Float3 ThroughFloat3(Float3 f3)
|
|
197
|
+
{
|
|
198
|
+
return f3;
|
|
199
|
+
}
|
|
200
|
+
|
|
195
201
|
EXPORT Double2 PackDouble2(double a, double b, Double2 *out)
|
|
196
202
|
{
|
|
197
203
|
Double2 ret;
|
|
@@ -208,8 +214,8 @@ EXPORT Double3 PackDouble3(double a, double b, double c, Double3 *out)
|
|
|
208
214
|
Double3 ret;
|
|
209
215
|
|
|
210
216
|
ret.a = a;
|
|
211
|
-
ret.b = b;
|
|
212
|
-
ret.c = c;
|
|
217
|
+
ret.s.b = b;
|
|
218
|
+
ret.s.c = c;
|
|
213
219
|
*out = ret;
|
|
214
220
|
|
|
215
221
|
return ret;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
|
|
2
|
+
# Developer's Certificate of Origin 1.1
|
|
3
|
+
|
|
4
|
+
By making a contribution to this project, I certify that:
|
|
5
|
+
|
|
6
|
+
(a) The contribution was created in whole or in part by me and I
|
|
7
|
+
have the right to submit it under the open source license
|
|
8
|
+
indicated in the file; or
|
|
9
|
+
|
|
10
|
+
(b) The contribution is based upon previous work that, to the best
|
|
11
|
+
of my knowledge, is covered under an appropriate open source
|
|
12
|
+
license and I have the right under that license to submit that
|
|
13
|
+
work with modifications, whether created in whole or in part
|
|
14
|
+
by me, under the same open source license (unless I am
|
|
15
|
+
permitted to submit under a different license), as indicated
|
|
16
|
+
in the file; or
|
|
17
|
+
|
|
18
|
+
(c) The contribution was provided directly to me by some other
|
|
19
|
+
person who certified (a), (b) or (c) and I have not modified
|
|
20
|
+
it.
|
|
21
|
+
|
|
22
|
+
(d) I understand and agree that this project and the contribution
|
|
23
|
+
are public and that a record of the contribution (including all
|
|
24
|
+
personal information I submit with it, including my sign-off) is
|
|
25
|
+
maintained indefinitely and may be redistributed consistent with
|
|
26
|
+
this project or the open source license(s) involved.
|
|
27
|
+
|
|
28
|
+
# **node-addon-api** Contribution Philosophy
|
|
29
|
+
|
|
30
|
+
The **node-addon-api** team loves contributions. There are many ways in which you can
|
|
31
|
+
contribute to **node-addon-api**:
|
|
32
|
+
- Source code fixes
|
|
33
|
+
- Additional tests
|
|
34
|
+
- Documentation improvements
|
|
35
|
+
- Joining the Node-API working group and participating in meetings
|
|
36
|
+
|
|
37
|
+
## Source changes
|
|
38
|
+
|
|
39
|
+
**node-addon-api** is meant to be a thin convenience wrapper around Node-API. With this
|
|
40
|
+
in mind, contributions of any new APIs that wrap around a core Node-API API will
|
|
41
|
+
be considered for merge. However, changes that wrap existing **node-addon-api**
|
|
42
|
+
APIs are encouraged to instead be provided as an ecosystem module. The
|
|
43
|
+
**node-addon-api** team is happy to link to a curated set of modules that build on
|
|
44
|
+
top of **node-addon-api** if they have broad usefulness to the community and promote
|
|
45
|
+
a recommended idiom or pattern.
|
|
46
|
+
|
|
47
|
+
### Rationale
|
|
48
|
+
|
|
49
|
+
The Node-API team considered a couple different approaches with regards to changes
|
|
50
|
+
extending **node-addon-api**
|
|
51
|
+
- Larger core module - Incorporate these helpers and patterns into **node-addon-api**
|
|
52
|
+
- Extras package - Create a new package (strawman name '**node-addon-api**-extras')
|
|
53
|
+
that contain utility classes and methods that help promote good patterns and
|
|
54
|
+
idioms while writing native addons with **node-addon-api**.
|
|
55
|
+
- Ecosystem - Encourage creation of a module ecosystem around **node-addon-api**
|
|
56
|
+
where folks can build on top of it.
|
|
57
|
+
|
|
58
|
+
#### Larger Core
|
|
59
|
+
This is probably our simplest option in terms of immediate action needed. It
|
|
60
|
+
would involve landing any open PRs against **node-addon-api**, and continuing to
|
|
61
|
+
encourage folks to make PRs for utility helpers against the same repository.
|
|
62
|
+
|
|
63
|
+
The downside of the approach is the following:
|
|
64
|
+
- Less coherency for our API set
|
|
65
|
+
- More maintenance burden on the Node-API WG core team.
|
|
66
|
+
|
|
67
|
+
#### Extras Package
|
|
68
|
+
This involves us spinning up a new package which contains the utility classes
|
|
69
|
+
and methods. This has the benefit of having a separate module where helpers
|
|
70
|
+
which make it easier to implement certain patterns and idioms for native addons
|
|
71
|
+
easier.
|
|
72
|
+
|
|
73
|
+
The downside of this approach is the following:
|
|
74
|
+
- Potential for confusion - we'll need to provide clear documentation to help the
|
|
75
|
+
community understand where a particular contribution should be directed to (what
|
|
76
|
+
belongs in **node-addon-api** vs **node-addon-api-extras**)
|
|
77
|
+
- Need to define the level of support/API guarantees
|
|
78
|
+
- Unclear if the maintenance burden on the Node-API WG is reduced or not
|
|
79
|
+
|
|
80
|
+
#### Ecosystem
|
|
81
|
+
This doesn't require a ton of up-front work from the Node-API WG. Instead of
|
|
82
|
+
accepting utility PRs into **node-addon-api** or creating and maintaining a new
|
|
83
|
+
module, the WG will encourage the creation of an ecosystem of modules that
|
|
84
|
+
build on top of **node-addon-api**, and provide some level of advertising for these
|
|
85
|
+
modules (listing them out on the repository/wiki, using them in workshops/tutorials
|
|
86
|
+
etc).
|
|
87
|
+
|
|
88
|
+
The downside of this approach is the following:
|
|
89
|
+
- Potential for lack of visibility - evangelism and education is hard, and module
|
|
90
|
+
authors might not find right patterns and instead implement things themselves
|
|
91
|
+
- There might be greater friction for the Node-API WG in evolving APIs since the
|
|
92
|
+
ecosystem would have taken dependencies on the API shape of **node-addon-api**
|
|
93
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
environment:
|
|
2
|
+
# https://github.com/jasongin/nvs/blob/HEAD/doc/CI.md
|
|
3
|
+
NVS_VERSION: 1.4.2
|
|
4
|
+
matrix:
|
|
5
|
+
- NODEJS_VERSION: node/10
|
|
6
|
+
- NODEJS_VERSION: node/12
|
|
7
|
+
- NODEJS_VERSION: node/14
|
|
8
|
+
- NODEJS_VERSION: nightly
|
|
9
|
+
|
|
10
|
+
os: Visual Studio 2017
|
|
11
|
+
platform:
|
|
12
|
+
- x86
|
|
13
|
+
- x64
|
|
14
|
+
|
|
15
|
+
install:
|
|
16
|
+
# nvs
|
|
17
|
+
- git clone --branch v%NVS_VERSION% --depth 1 https://github.com/jasongin/nvs %LOCALAPPDATA%\nvs
|
|
18
|
+
- set PATH=%LOCALAPPDATA%\nvs;%PATH%
|
|
19
|
+
- nvs --version
|
|
20
|
+
# node.js
|
|
21
|
+
- nvs add %NODEJS_VERSION%/%PLATFORM%
|
|
22
|
+
- nvs use %NODEJS_VERSION%/%PLATFORM%
|
|
23
|
+
- node --version
|
|
24
|
+
- node -p process.arch
|
|
25
|
+
- npm --version
|
|
26
|
+
# app
|
|
27
|
+
- npm install
|
|
28
|
+
|
|
29
|
+
test_script:
|
|
30
|
+
- npm test
|
|
31
|
+
|
|
32
|
+
build: off
|
|
33
|
+
|
|
34
|
+
version: "{build}"
|
|
35
|
+
|
|
36
|
+
cache:
|
|
37
|
+
- node_modules
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Benchmarks
|
|
2
|
+
|
|
3
|
+
## Running the benchmarks
|
|
4
|
+
|
|
5
|
+
From the parent directory, run
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm run-script benchmark
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The above script supports the following arguments:
|
|
12
|
+
|
|
13
|
+
* `--benchmarks=...`: A semicolon-separated list of benchmark names. These names
|
|
14
|
+
will be mapped to file names in this directory by appending `.js`.
|
|
15
|
+
|
|
16
|
+
## Adding benchmarks
|
|
17
|
+
|
|
18
|
+
The steps below should be followed when adding new benchmarks.
|
|
19
|
+
|
|
20
|
+
0. Decide on a name for the benchmark. This name will be used in several places.
|
|
21
|
+
This example will use the name `new_benchmark`.
|
|
22
|
+
|
|
23
|
+
0. Create files `new_benchmark.cc` and `new_benchmark.js` in this directory.
|
|
24
|
+
|
|
25
|
+
0. Copy an existing benchmark in `binding.gyp` and change the target name prefix
|
|
26
|
+
and the source file name to `new_benchmark`. This should result in two new
|
|
27
|
+
targets which look like this:
|
|
28
|
+
|
|
29
|
+
```gyp
|
|
30
|
+
{
|
|
31
|
+
'target_name': 'new_benchmark',
|
|
32
|
+
'sources': [ 'new_benchmark.cc' ],
|
|
33
|
+
'includes': [ '../except.gypi' ],
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
'target_name': 'new_benchmark_noexcept',
|
|
37
|
+
'sources': [ 'new_benchmark.cc' ],
|
|
38
|
+
'includes': [ '../noexcept.gypi' ],
|
|
39
|
+
},
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
There should always be a pair of targets: one bearing the name of the
|
|
43
|
+
benchmark and configured with C++ exceptions enabled, and one bearing the
|
|
44
|
+
same name followed by the suffix `_noexcept` and configured with C++
|
|
45
|
+
exceptions disabled. This will ensure that the benchmark can be written to
|
|
46
|
+
cover both the case where C++ exceptions are enabled and the case where they
|
|
47
|
+
are disabled.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
'target_defaults': { 'includes': ['../common.gypi'] },
|
|
3
|
+
'targets': [
|
|
4
|
+
{
|
|
5
|
+
'target_name': 'function_args',
|
|
6
|
+
'sources': [ 'function_args.cc' ],
|
|
7
|
+
'includes': [ '../except.gypi' ],
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
'target_name': 'function_args_noexcept',
|
|
11
|
+
'sources': [ 'function_args.cc' ],
|
|
12
|
+
'includes': [ '../noexcept.gypi' ],
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
'target_name': 'property_descriptor',
|
|
16
|
+
'sources': [ 'property_descriptor.cc' ],
|
|
17
|
+
'includes': [ '../except.gypi' ],
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
'target_name': 'property_descriptor_noexcept',
|
|
21
|
+
'sources': [ 'property_descriptor.cc' ],
|
|
22
|
+
'includes': [ '../noexcept.gypi' ],
|
|
23
|
+
},
|
|
24
|
+
]
|
|
25
|
+
}
|