koffi 2.1.0-beta.3 → 2.1.0

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 (250) hide show
  1. package/ChangeLog.md +2 -1
  2. package/build/qemu/2.1.0/koffi_darwin_arm64.tar.gz +0 -0
  3. package/build/qemu/2.1.0/koffi_darwin_x64.tar.gz +0 -0
  4. package/build/qemu/2.1.0/koffi_freebsd_arm64.tar.gz +0 -0
  5. package/build/qemu/2.1.0/koffi_freebsd_ia32.tar.gz +0 -0
  6. package/build/qemu/2.1.0/koffi_freebsd_x64.tar.gz +0 -0
  7. package/build/qemu/2.1.0/koffi_linux_arm32hf.tar.gz +0 -0
  8. package/build/qemu/2.1.0/koffi_linux_arm64.tar.gz +0 -0
  9. package/build/qemu/2.1.0/koffi_linux_ia32.tar.gz +0 -0
  10. package/build/qemu/2.1.0/koffi_linux_riscv64hf64.tar.gz +0 -0
  11. package/build/qemu/2.1.0/koffi_linux_x64.tar.gz +0 -0
  12. package/build/qemu/2.1.0/koffi_openbsd_ia32.tar.gz +0 -0
  13. package/build/qemu/2.1.0/koffi_openbsd_x64.tar.gz +0 -0
  14. package/build/qemu/2.1.0/koffi_win32_arm64.tar.gz +0 -0
  15. package/build/qemu/2.1.0/koffi_win32_ia32.tar.gz +0 -0
  16. package/build/qemu/2.1.0/koffi_win32_x64.tar.gz +0 -0
  17. package/doc/benchmarks.md +14 -14
  18. package/doc/benchmarks.xlsx +0 -0
  19. package/doc/index.rst +2 -2
  20. package/doc/static/perf_linux_20220812.png +0 -0
  21. package/doc/static/perf_windows_20220812.png +0 -0
  22. package/doc/types.md +10 -12
  23. package/package.json +2 -2
  24. package/qemu/registry/machines.json +2 -2
  25. package/qemu/registry/sha256sum.txt +2 -2
  26. package/src/abi_arm32.cc +23 -55
  27. package/src/abi_arm64.cc +22 -54
  28. package/src/abi_riscv64.cc +20 -52
  29. package/src/abi_x64_sysv.cc +20 -52
  30. package/src/abi_x64_win.cc +20 -52
  31. package/src/abi_x86.cc +24 -56
  32. package/src/call.cc +117 -143
  33. package/src/call.hh +4 -4
  34. package/src/ffi.cc +16 -4
  35. package/src/util.hh +0 -20
  36. package/test/callbacks.js +3 -3
  37. package/test/misc.c +2 -2
  38. package/test/sync.js +2 -2
  39. package/vendor/libcc/libcc.cc +75 -55
  40. package/vendor/libcc/libcc.hh +306 -255
  41. package/vendor/raylib/projects/VS2019-Android/raylib_android/raylib_android.NativeActivity/raylib_android.NativeActivity.vcxproj +226 -0
  42. package/vendor/raylib/projects/VS2019-Android/raylib_android/raylib_android.NativeActivity/raylib_android.NativeActivity.vcxproj.filters +10 -0
  43. package/vendor/raylib/projects/VS2019-Android/raylib_android/raylib_android.NativeActivity/raylib_android.NativeActivity.vcxproj.user +4 -0
  44. package/vendor/raylib/projects/VS2019-Android/raylib_android.sln +75 -0
  45. package/vendor/raylib/projects/VS2022/examples/audio_module_playing.vcxproj +390 -0
  46. package/vendor/raylib/projects/VS2022/examples/audio_multichannel_sound.vcxproj +390 -0
  47. package/vendor/raylib/projects/VS2022/examples/audio_music_stream.vcxproj +390 -0
  48. package/vendor/raylib/projects/VS2022/examples/audio_raw_stream.vcxproj +390 -0
  49. package/vendor/raylib/projects/VS2022/examples/audio_sound_loading.vcxproj +390 -0
  50. package/vendor/raylib/projects/VS2022/examples/audio_stream_effects.vcxproj +390 -0
  51. package/vendor/raylib/projects/VS2022/examples/core_2d_camera.vcxproj +390 -0
  52. package/vendor/raylib/projects/VS2022/examples/core_2d_camera_mouse_zoom.vcxproj +390 -0
  53. package/vendor/raylib/projects/VS2022/examples/core_2d_camera_platformer.vcxproj +390 -0
  54. package/vendor/raylib/projects/VS2022/examples/core_3d_camera_first_person.vcxproj +390 -0
  55. package/vendor/raylib/projects/VS2022/examples/core_3d_camera_free.vcxproj +390 -0
  56. package/vendor/raylib/projects/VS2022/examples/core_3d_camera_mode.vcxproj +390 -0
  57. package/vendor/raylib/projects/VS2022/examples/core_3d_picking.vcxproj +390 -0
  58. package/vendor/raylib/projects/VS2022/examples/core_basic_screen_manager.vcxproj +390 -0
  59. package/vendor/raylib/projects/VS2022/examples/core_basic_window.vcxproj +390 -0
  60. package/vendor/raylib/projects/VS2022/examples/core_custom_frame_control.vcxproj +390 -0
  61. package/vendor/raylib/projects/VS2022/examples/core_custom_logging.vcxproj +390 -0
  62. package/vendor/raylib/projects/VS2022/examples/core_drop_files.vcxproj +390 -0
  63. package/vendor/raylib/projects/VS2022/examples/core_input_gamepad.vcxproj +387 -0
  64. package/vendor/raylib/projects/VS2022/examples/core_input_gestures.vcxproj +387 -0
  65. package/vendor/raylib/projects/VS2022/examples/core_input_keys.vcxproj +387 -0
  66. package/vendor/raylib/projects/VS2022/examples/core_input_mouse.vcxproj +387 -0
  67. package/vendor/raylib/projects/VS2022/examples/core_input_mouse_wheel.vcxproj +387 -0
  68. package/vendor/raylib/projects/VS2022/examples/core_input_multitouch.vcxproj +387 -0
  69. package/vendor/raylib/projects/VS2022/examples/core_loading_thread.vcxproj +387 -0
  70. package/vendor/raylib/projects/VS2022/examples/core_random_values.vcxproj +387 -0
  71. package/vendor/raylib/projects/VS2022/examples/core_scissor_test.vcxproj +387 -0
  72. package/vendor/raylib/projects/VS2022/examples/core_split_screen.vcxproj +387 -0
  73. package/vendor/raylib/projects/VS2022/examples/core_storage_values.vcxproj +387 -0
  74. package/vendor/raylib/projects/VS2022/examples/core_vr_simulator.vcxproj +387 -0
  75. package/vendor/raylib/projects/VS2022/examples/core_window_flags.vcxproj +387 -0
  76. package/vendor/raylib/projects/VS2022/examples/core_window_letterbox.vcxproj +387 -0
  77. package/vendor/raylib/projects/VS2022/examples/core_window_should_close.vcxproj +390 -0
  78. package/vendor/raylib/projects/VS2022/examples/core_world_screen.vcxproj +387 -0
  79. package/vendor/raylib/projects/VS2022/examples/easings_testbed.vcxproj +387 -0
  80. package/vendor/raylib/projects/VS2022/examples/embedded_files_loading.vcxproj +387 -0
  81. package/vendor/raylib/projects/VS2022/examples/models_animation.vcxproj +387 -0
  82. package/vendor/raylib/projects/VS2022/examples/models_billboard.vcxproj +387 -0
  83. package/vendor/raylib/projects/VS2022/examples/models_box_collisions.vcxproj +387 -0
  84. package/vendor/raylib/projects/VS2022/examples/models_cubicmap.vcxproj +387 -0
  85. package/vendor/raylib/projects/VS2022/examples/models_first_person_maze.vcxproj +387 -0
  86. package/vendor/raylib/projects/VS2022/examples/models_geometric_shapes.vcxproj +387 -0
  87. package/vendor/raylib/projects/VS2022/examples/models_heightmap.vcxproj +387 -0
  88. package/vendor/raylib/projects/VS2022/examples/models_loading.vcxproj +387 -0
  89. package/vendor/raylib/projects/VS2022/examples/models_loading_gltf.vcxproj +387 -0
  90. package/vendor/raylib/projects/VS2022/examples/models_loading_vox.vcxproj +387 -0
  91. package/vendor/raylib/projects/VS2022/examples/models_mesh_generation.vcxproj +387 -0
  92. package/vendor/raylib/projects/VS2022/examples/models_mesh_picking.vcxproj +387 -0
  93. package/vendor/raylib/projects/VS2022/examples/models_orthographic_projection.vcxproj +387 -0
  94. package/vendor/raylib/projects/VS2022/examples/models_rlgl_solar_system.vcxproj +387 -0
  95. package/vendor/raylib/projects/VS2022/examples/models_skybox.vcxproj +387 -0
  96. package/vendor/raylib/projects/VS2022/examples/models_waving_cubes.vcxproj +387 -0
  97. package/vendor/raylib/projects/VS2022/examples/models_yaw_pitch_roll.vcxproj +387 -0
  98. package/vendor/raylib/projects/VS2022/examples/rlgl_compute_shaders.vcxproj +391 -0
  99. package/vendor/raylib/projects/VS2022/examples/rlgl_standalone.vcxproj +391 -0
  100. package/vendor/raylib/projects/VS2022/examples/shaders_basic_lighting.vcxproj +387 -0
  101. package/vendor/raylib/projects/VS2022/examples/shaders_custom_uniform.vcxproj +387 -0
  102. package/vendor/raylib/projects/VS2022/examples/shaders_eratosthenes.vcxproj +387 -0
  103. package/vendor/raylib/projects/VS2022/examples/shaders_fog.vcxproj +387 -0
  104. package/vendor/raylib/projects/VS2022/examples/shaders_hot_reloading.vcxproj +387 -0
  105. package/vendor/raylib/projects/VS2022/examples/shaders_julia_set.vcxproj +387 -0
  106. package/vendor/raylib/projects/VS2022/examples/shaders_mesh_instancing.vcxproj +387 -0
  107. package/vendor/raylib/projects/VS2022/examples/shaders_model_shader.vcxproj +387 -0
  108. package/vendor/raylib/projects/VS2022/examples/shaders_multi_sample2d.vcxproj +387 -0
  109. package/vendor/raylib/projects/VS2022/examples/shaders_palette_switch.vcxproj +387 -0
  110. package/vendor/raylib/projects/VS2022/examples/shaders_postprocessing.vcxproj +387 -0
  111. package/vendor/raylib/projects/VS2022/examples/shaders_raymarching.vcxproj +387 -0
  112. package/vendor/raylib/projects/VS2022/examples/shaders_shapes_textures.vcxproj +387 -0
  113. package/vendor/raylib/projects/VS2022/examples/shaders_simple_mask.vcxproj +387 -0
  114. package/vendor/raylib/projects/VS2022/examples/shaders_spotlight.vcxproj +387 -0
  115. package/vendor/raylib/projects/VS2022/examples/shaders_texture_drawing.vcxproj +387 -0
  116. package/vendor/raylib/projects/VS2022/examples/shaders_texture_waves.vcxproj +387 -0
  117. package/vendor/raylib/projects/VS2022/examples/shapes_basic_shapes.vcxproj +387 -0
  118. package/vendor/raylib/projects/VS2022/examples/shapes_bouncing_ball.vcxproj +387 -0
  119. package/vendor/raylib/projects/VS2022/examples/shapes_collision_area.vcxproj +387 -0
  120. package/vendor/raylib/projects/VS2022/examples/shapes_colors_palette.vcxproj +387 -0
  121. package/vendor/raylib/projects/VS2022/examples/shapes_draw_circle_sector.vcxproj +387 -0
  122. package/vendor/raylib/projects/VS2022/examples/shapes_draw_rectangle_rounded.vcxproj +387 -0
  123. package/vendor/raylib/projects/VS2022/examples/shapes_draw_ring.vcxproj +387 -0
  124. package/vendor/raylib/projects/VS2022/examples/shapes_easings_ball_anim.vcxproj +387 -0
  125. package/vendor/raylib/projects/VS2022/examples/shapes_easings_box_anim.vcxproj +387 -0
  126. package/vendor/raylib/projects/VS2022/examples/shapes_easings_rectangle_array.vcxproj +387 -0
  127. package/vendor/raylib/projects/VS2022/examples/shapes_following_eyes.vcxproj +387 -0
  128. package/vendor/raylib/projects/VS2022/examples/shapes_lines_bezier.vcxproj +387 -0
  129. package/vendor/raylib/projects/VS2022/examples/shapes_logo_raylib.vcxproj +387 -0
  130. package/vendor/raylib/projects/VS2022/examples/shapes_logo_raylib_anim.vcxproj +387 -0
  131. package/vendor/raylib/projects/VS2022/examples/shapes_rectangle_scaling.vcxproj +387 -0
  132. package/vendor/raylib/projects/VS2022/examples/text_codepoints_loading.vcxproj +387 -0
  133. package/vendor/raylib/projects/VS2022/examples/text_draw_3d.vcxproj +387 -0
  134. package/vendor/raylib/projects/VS2022/examples/text_font_filters.vcxproj +387 -0
  135. package/vendor/raylib/projects/VS2022/examples/text_font_loading.vcxproj +387 -0
  136. package/vendor/raylib/projects/VS2022/examples/text_font_sdf.vcxproj +387 -0
  137. package/vendor/raylib/projects/VS2022/examples/text_font_spritefont.vcxproj +387 -0
  138. package/vendor/raylib/projects/VS2022/examples/text_format_text.vcxproj +387 -0
  139. package/vendor/raylib/projects/VS2022/examples/text_input_box.vcxproj +387 -0
  140. package/vendor/raylib/projects/VS2022/examples/text_raylib_fonts.vcxproj +387 -0
  141. package/vendor/raylib/projects/VS2022/examples/text_rectangle_bounds.vcxproj +387 -0
  142. package/vendor/raylib/projects/VS2022/examples/text_unicode.vcxproj +387 -0
  143. package/vendor/raylib/projects/VS2022/examples/text_writing_anim.vcxproj +387 -0
  144. package/vendor/raylib/projects/VS2022/examples/textures_background_scrolling.vcxproj +387 -0
  145. package/vendor/raylib/projects/VS2022/examples/textures_blend_modes.vcxproj +387 -0
  146. package/vendor/raylib/projects/VS2022/examples/textures_bunnymark.vcxproj +387 -0
  147. package/vendor/raylib/projects/VS2022/examples/textures_draw_tiled.vcxproj +387 -0
  148. package/vendor/raylib/projects/VS2022/examples/textures_fog_of_war.vcxproj +387 -0
  149. package/vendor/raylib/projects/VS2022/examples/textures_gif_player.vcxproj +387 -0
  150. package/vendor/raylib/projects/VS2022/examples/textures_image_drawing.vcxproj +387 -0
  151. package/vendor/raylib/projects/VS2022/examples/textures_image_generation.vcxproj +387 -0
  152. package/vendor/raylib/projects/VS2022/examples/textures_image_loading.vcxproj +387 -0
  153. package/vendor/raylib/projects/VS2022/examples/textures_image_processing.vcxproj +387 -0
  154. package/vendor/raylib/projects/VS2022/examples/textures_image_text.vcxproj +387 -0
  155. package/vendor/raylib/projects/VS2022/examples/textures_logo_raylib.vcxproj +387 -0
  156. package/vendor/raylib/projects/VS2022/examples/textures_mouse_painting.vcxproj +387 -0
  157. package/vendor/raylib/projects/VS2022/examples/textures_npatch_drawing.vcxproj +387 -0
  158. package/vendor/raylib/projects/VS2022/examples/textures_particles_blending.vcxproj +387 -0
  159. package/vendor/raylib/projects/VS2022/examples/textures_polygon.vcxproj +387 -0
  160. package/vendor/raylib/projects/VS2022/examples/textures_raw_data.vcxproj +387 -0
  161. package/vendor/raylib/projects/VS2022/examples/textures_sprite_anim.vcxproj +387 -0
  162. package/vendor/raylib/projects/VS2022/examples/textures_sprite_button.vcxproj +387 -0
  163. package/vendor/raylib/projects/VS2022/examples/textures_sprite_explosion.vcxproj +387 -0
  164. package/vendor/raylib/projects/VS2022/examples/textures_srcrec_dstrec.vcxproj +387 -0
  165. package/vendor/raylib/projects/VS2022/examples/textures_to_image.vcxproj +387 -0
  166. package/vendor/raylib/projects/VS2022/raylib/raylib.vcxproj +340 -0
  167. package/vendor/raylib/projects/VS2022/raylib.sln +2347 -0
  168. package/build/qemu/2.1.0-beta.3/koffi_darwin_arm64.tar.gz +0 -0
  169. package/build/qemu/2.1.0-beta.3/koffi_darwin_x64.tar.gz +0 -0
  170. package/build/qemu/2.1.0-beta.3/koffi_freebsd_arm64.tar.gz +0 -0
  171. package/build/qemu/2.1.0-beta.3/koffi_freebsd_ia32.tar.gz +0 -0
  172. package/build/qemu/2.1.0-beta.3/koffi_freebsd_x64.tar.gz +0 -0
  173. package/build/qemu/2.1.0-beta.3/koffi_linux_arm32hf.tar.gz +0 -0
  174. package/build/qemu/2.1.0-beta.3/koffi_linux_arm64.tar.gz +0 -0
  175. package/build/qemu/2.1.0-beta.3/koffi_linux_ia32.tar.gz +0 -0
  176. package/build/qemu/2.1.0-beta.3/koffi_linux_riscv64hf64.tar.gz +0 -0
  177. package/build/qemu/2.1.0-beta.3/koffi_linux_x64.tar.gz +0 -0
  178. package/build/qemu/2.1.0-beta.3/koffi_openbsd_ia32.tar.gz +0 -0
  179. package/build/qemu/2.1.0-beta.3/koffi_openbsd_x64.tar.gz +0 -0
  180. package/build/qemu/2.1.0-beta.3/koffi_win32_arm64.tar.gz +0 -0
  181. package/build/qemu/2.1.0-beta.3/koffi_win32_ia32.tar.gz +0 -0
  182. package/build/qemu/2.1.0-beta.3/koffi_win32_x64.tar.gz +0 -0
  183. package/doc/dist/doctrees/benchmarks.doctree +0 -0
  184. package/doc/dist/doctrees/changes.doctree +0 -0
  185. package/doc/dist/doctrees/contribute.doctree +0 -0
  186. package/doc/dist/doctrees/environment.pickle +0 -0
  187. package/doc/dist/doctrees/functions.doctree +0 -0
  188. package/doc/dist/doctrees/index.doctree +0 -0
  189. package/doc/dist/doctrees/memory.doctree +0 -0
  190. package/doc/dist/doctrees/platforms.doctree +0 -0
  191. package/doc/dist/doctrees/start.doctree +0 -0
  192. package/doc/dist/doctrees/types.doctree +0 -0
  193. package/doc/dist/html/.buildinfo +0 -4
  194. package/doc/dist/html/_sources/benchmarks.md.txt +0 -137
  195. package/doc/dist/html/_sources/changes.md.txt +0 -161
  196. package/doc/dist/html/_sources/contribute.md.txt +0 -127
  197. package/doc/dist/html/_sources/functions.md.txt +0 -421
  198. package/doc/dist/html/_sources/index.rst.txt +0 -39
  199. package/doc/dist/html/_sources/memory.md.txt +0 -32
  200. package/doc/dist/html/_sources/platforms.md.txt +0 -31
  201. package/doc/dist/html/_sources/start.md.txt +0 -100
  202. package/doc/dist/html/_sources/types.md.txt +0 -541
  203. package/doc/dist/html/_static/_sphinx_javascript_frameworks_compat.js +0 -134
  204. package/doc/dist/html/_static/basic.css +0 -932
  205. package/doc/dist/html/_static/bench_linux.png +0 -0
  206. package/doc/dist/html/_static/bench_windows.png +0 -0
  207. package/doc/dist/html/_static/custom.css +0 -22
  208. package/doc/dist/html/_static/debug.css +0 -69
  209. package/doc/dist/html/_static/doctools.js +0 -264
  210. package/doc/dist/html/_static/documentation_options.js +0 -14
  211. package/doc/dist/html/_static/file.png +0 -0
  212. package/doc/dist/html/_static/jquery-3.6.0.js +0 -10881
  213. package/doc/dist/html/_static/jquery.js +0 -2
  214. package/doc/dist/html/_static/language_data.js +0 -199
  215. package/doc/dist/html/_static/minus.png +0 -0
  216. package/doc/dist/html/_static/perf_linux_20220623.png +0 -0
  217. package/doc/dist/html/_static/perf_linux_20220623_2.png +0 -0
  218. package/doc/dist/html/_static/perf_linux_20220627.png +0 -0
  219. package/doc/dist/html/_static/perf_linux_20220628.png +0 -0
  220. package/doc/dist/html/_static/perf_windows_20220623.png +0 -0
  221. package/doc/dist/html/_static/perf_windows_20220623_2.png +0 -0
  222. package/doc/dist/html/_static/perf_windows_20220627.png +0 -0
  223. package/doc/dist/html/_static/perf_windows_20220628.png +0 -0
  224. package/doc/dist/html/_static/plus.png +0 -0
  225. package/doc/dist/html/_static/pygments.css +0 -252
  226. package/doc/dist/html/_static/scripts/furo-extensions.js +0 -0
  227. package/doc/dist/html/_static/scripts/furo.js +0 -3
  228. package/doc/dist/html/_static/scripts/furo.js.LICENSE.txt +0 -7
  229. package/doc/dist/html/_static/scripts/furo.js.map +0 -1
  230. package/doc/dist/html/_static/searchtools.js +0 -531
  231. package/doc/dist/html/_static/skeleton.css +0 -296
  232. package/doc/dist/html/_static/styles/furo-extensions.css +0 -2
  233. package/doc/dist/html/_static/styles/furo-extensions.css.map +0 -1
  234. package/doc/dist/html/_static/styles/furo.css +0 -2
  235. package/doc/dist/html/_static/styles/furo.css.map +0 -1
  236. package/doc/dist/html/_static/underscore-1.13.1.js +0 -2042
  237. package/doc/dist/html/_static/underscore.js +0 -6
  238. package/doc/dist/html/benchmarks.html +0 -571
  239. package/doc/dist/html/changes.html +0 -686
  240. package/doc/dist/html/contribute.html +0 -403
  241. package/doc/dist/html/functions.html +0 -718
  242. package/doc/dist/html/genindex.html +0 -253
  243. package/doc/dist/html/index.html +0 -359
  244. package/doc/dist/html/memory.html +0 -346
  245. package/doc/dist/html/objects.inv +0 -0
  246. package/doc/dist/html/platforms.html +0 -371
  247. package/doc/dist/html/search.html +0 -261
  248. package/doc/dist/html/searchindex.js +0 -1
  249. package/doc/dist/html/start.html +0 -384
  250. package/doc/dist/html/types.html +0 -1061
package/src/call.cc CHANGED
@@ -48,78 +48,82 @@ CallData::~CallData()
48
48
  }
49
49
  }
50
50
 
51
- const char *CallData::PushString(Napi::Value value)
51
+ bool CallData::PushString(Napi::Value value, const char **out_str)
52
52
  {
53
- RG_ASSERT(value.IsString());
53
+ if (value.IsString()) {
54
+ Span<char> buf;
55
+ size_t len = 0;
56
+ napi_status status;
54
57
 
55
- Napi::Env env = value.Env();
58
+ buf.ptr = (char *)mem->heap.ptr;
59
+ buf.len = std::max((Size)0, mem->heap.len - Kibibytes(32));
56
60
 
57
- Span<char> buf;
58
- size_t len = 0;
59
- napi_status status;
60
-
61
- buf.ptr = (char *)mem->heap.ptr;
62
- buf.len = std::max((Size)0, mem->heap.len - Kibibytes(32));
63
-
64
- status = napi_get_value_string_utf8(env, value, buf.ptr, (size_t)buf.len, &len);
65
- RG_ASSERT(status == napi_ok);
66
-
67
- len++;
68
-
69
- if (RG_LIKELY(len < (size_t)buf.len)) {
70
- mem->heap.ptr += (Size)len;
71
- mem->heap.len -= (Size)len;
72
- } else {
73
- status = napi_get_value_string_utf8(env, value, nullptr, 0, &len);
61
+ status = napi_get_value_string_utf8(env, value, buf.ptr, (size_t)buf.len, &len);
74
62
  RG_ASSERT(status == napi_ok);
75
63
 
76
64
  len++;
77
65
 
78
- buf.ptr = (char *)Allocator::Allocate(&call_alloc, (Size)len);
79
- buf.len = (Size)len;
66
+ if (RG_LIKELY(len < (size_t)buf.len)) {
67
+ mem->heap.ptr += (Size)len;
68
+ mem->heap.len -= (Size)len;
69
+ } else {
70
+ status = napi_get_value_string_utf8(env, value, nullptr, 0, &len);
71
+ RG_ASSERT(status == napi_ok);
80
72
 
81
- status = napi_get_value_string_utf8(env, value, buf.ptr, (size_t)buf.len, &len);
82
- RG_ASSERT(status == napi_ok);
83
- }
73
+ buf = AllocateMemory<char>(&call_alloc, (Size)len + 1);
74
+
75
+ status = napi_get_value_string_utf8(env, value, buf.ptr, (size_t)buf.len, &len);
76
+ RG_ASSERT(status == napi_ok);
77
+ }
84
78
 
85
- return buf.ptr;
79
+ *out_str = buf.ptr;
80
+ return true;
81
+ } else if (IsNullOrUndefined(value)) {
82
+ *out_str = nullptr;
83
+ return true;
84
+ } else {
85
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected string", GetValueType(instance, value));
86
+ return false;
87
+ }
86
88
  }
87
89
 
88
- const char16_t *CallData::PushString16(Napi::Value value)
90
+ bool CallData::PushString16(Napi::Value value, const char16_t **out_str16)
89
91
  {
90
- RG_ASSERT(value.IsString());
91
-
92
- Napi::Env env = value.Env();
92
+ if (value.IsString()) {
93
+ Span<char16_t> buf;
94
+ size_t len = 0;
95
+ napi_status status;
93
96
 
94
- Span<char16_t> buf;
95
- size_t len = 0;
96
- napi_status status;
97
+ buf.ptr = (char16_t *)mem->heap.ptr;
98
+ buf.len = std::max((Size)0, mem->heap.len - Kibibytes(32)) / 2;
97
99
 
98
- buf.ptr = (char16_t *)mem->heap.ptr;
99
- buf.len = std::max((Size)0, mem->heap.len - Kibibytes(32)) / 2;
100
-
101
- status = napi_get_value_string_utf16(env, value, buf.ptr, (size_t)buf.len, &len);
102
- RG_ASSERT(status == napi_ok);
103
-
104
- len++;
105
-
106
- if (RG_LIKELY(len < (size_t)buf.len)) {
107
- mem->heap.ptr += (Size)len * 2;
108
- mem->heap.len -= (Size)len * 2;
109
- } else {
110
- status = napi_get_value_string_utf16(env, value, nullptr, 0, &len);
100
+ status = napi_get_value_string_utf16(env, value, buf.ptr, (size_t)buf.len, &len);
111
101
  RG_ASSERT(status == napi_ok);
112
102
 
113
103
  len++;
114
104
 
115
- buf.ptr = (char16_t *)Allocator::Allocate(&call_alloc, (Size)len * 2);
116
- buf.len = (Size)len;
105
+ if (RG_LIKELY(len < (size_t)buf.len)) {
106
+ mem->heap.ptr += (Size)len * 2;
107
+ mem->heap.len -= (Size)len * 2;
108
+ } else {
109
+ status = napi_get_value_string_utf16(env, value, nullptr, 0, &len);
110
+ RG_ASSERT(status == napi_ok);
117
111
 
118
- status = napi_get_value_string_utf16(env, value, buf.ptr, (size_t)buf.len, &len);
119
- RG_ASSERT(status == napi_ok);
120
- }
112
+ buf = AllocateMemory<char16_t>(&call_alloc, ((Size)len + 1) * 2);
121
113
 
122
- return buf.ptr;
114
+ status = napi_get_value_string_utf16(env, value, buf.ptr, (size_t)buf.len, &len);
115
+ RG_ASSERT(status == napi_ok);
116
+ }
117
+
118
+ *out_str16 = buf.ptr;
119
+ return true;
120
+ } else if (IsNullOrUndefined(value)) {
121
+ *out_str16 = nullptr;
122
+ return true;
123
+ } else {
124
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected string", GetValueType(instance, value));
125
+ return false;
126
+ }
123
127
  }
124
128
 
125
129
  bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origin, int16_t realign)
@@ -144,7 +148,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
144
148
 
145
149
  case PrimitiveKind::Bool: {
146
150
  if (RG_UNLIKELY(!value.IsBoolean())) {
147
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected boolean", GetValueType(instance, value), member.name);
151
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected boolean", GetValueType(instance, value));
148
152
  return false;
149
153
  }
150
154
 
@@ -153,7 +157,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
153
157
  } break;
154
158
  case PrimitiveKind::Int8: {
155
159
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
156
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
160
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
157
161
  return false;
158
162
  }
159
163
 
@@ -162,7 +166,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
162
166
  } break;
163
167
  case PrimitiveKind::UInt8: {
164
168
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
165
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
169
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
166
170
  return false;
167
171
  }
168
172
 
@@ -171,7 +175,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
171
175
  } break;
172
176
  case PrimitiveKind::Int16: {
173
177
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
174
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
178
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
175
179
  return false;
176
180
  }
177
181
 
@@ -180,7 +184,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
180
184
  } break;
181
185
  case PrimitiveKind::Int16S: {
182
186
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
183
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
187
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
184
188
  return false;
185
189
  }
186
190
 
@@ -189,7 +193,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
189
193
  } break;
190
194
  case PrimitiveKind::UInt16: {
191
195
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
192
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
196
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
193
197
  return false;
194
198
  }
195
199
 
@@ -198,7 +202,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
198
202
  } break;
199
203
  case PrimitiveKind::UInt16S: {
200
204
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
201
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
205
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
202
206
  return false;
203
207
  }
204
208
 
@@ -207,7 +211,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
207
211
  } break;
208
212
  case PrimitiveKind::Int32: {
209
213
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
210
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
214
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
211
215
  return false;
212
216
  }
213
217
 
@@ -216,7 +220,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
216
220
  } break;
217
221
  case PrimitiveKind::Int32S: {
218
222
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
219
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
223
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
220
224
  return false;
221
225
  }
222
226
 
@@ -225,7 +229,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
225
229
  } break;
226
230
  case PrimitiveKind::UInt32: {
227
231
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
228
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
232
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
229
233
  return false;
230
234
  }
231
235
 
@@ -234,7 +238,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
234
238
  } break;
235
239
  case PrimitiveKind::UInt32S: {
236
240
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
237
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
241
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
238
242
  return false;
239
243
  }
240
244
 
@@ -243,7 +247,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
243
247
  } break;
244
248
  case PrimitiveKind::Int64: {
245
249
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
246
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
250
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
247
251
  return false;
248
252
  }
249
253
 
@@ -252,7 +256,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
252
256
  } break;
253
257
  case PrimitiveKind::Int64S: {
254
258
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
255
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
259
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
256
260
  return false;
257
261
  }
258
262
 
@@ -261,7 +265,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
261
265
  } break;
262
266
  case PrimitiveKind::UInt64: {
263
267
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
264
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
268
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
265
269
  return false;
266
270
  }
267
271
 
@@ -270,7 +274,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
270
274
  } break;
271
275
  case PrimitiveKind::UInt64S: {
272
276
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
273
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
277
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
274
278
  return false;
275
279
  }
276
280
 
@@ -279,49 +283,28 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
279
283
  } break;
280
284
  case PrimitiveKind::String: {
281
285
  const char *str;
282
- if (RG_LIKELY(value.IsString())) {
283
- str = PushString(value);
284
- if (RG_UNLIKELY(!str))
285
- return false;
286
- } else if (IsNullOrUndefined(value)) {
287
- str = nullptr;
288
- } else {
289
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected string", GetValueType(instance, value), member.name);
286
+ if (RG_UNLIKELY(!PushString(value, &str)))
290
287
  return false;
291
- }
292
288
 
293
289
  *(const char **)dest = str;
294
290
  } break;
295
291
  case PrimitiveKind::String16: {
296
292
  const char16_t *str16;
297
- if (RG_LIKELY(value.IsString())) {
298
- str16 = PushString16(value);
299
- if (RG_UNLIKELY(!str16))
300
- return false;
301
- } else if (IsNullOrUndefined(value)) {
302
- str16 = nullptr;
303
- } else {
304
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected string", GetValueType(instance, value), member.name);
293
+ if (RG_UNLIKELY(!PushString16(value, &str16)))
305
294
  return false;
306
- }
307
295
 
308
296
  *(const char16_t **)dest = str16;
309
297
  } break;
310
298
  case PrimitiveKind::Pointer: {
311
- if (CheckValueTag(instance, value, member.type->ref.marker)) {
312
- Napi::External<void> external = value.As<Napi::External<void>>();
313
- void *ptr = external.Data();
314
- *(void **)dest = ptr;
315
- } else if (IsNullOrUndefined(value)) {
316
- *(void **)dest = nullptr;
317
- } else {
318
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected %3", GetValueType(instance, value), member.name, member.type->name);
299
+ void *ptr;
300
+ if (RG_UNLIKELY(!PushPointer(value, member.type, 1, &ptr)))
319
301
  return false;
320
- }
302
+
303
+ *(void **)dest = ptr;
321
304
  } break;
322
305
  case PrimitiveKind::Record: {
323
306
  if (RG_UNLIKELY(!IsObject(value))) {
324
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected object", GetValueType(instance, value), member.name);
307
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
325
308
  return false;
326
309
  }
327
310
 
@@ -346,13 +329,13 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
346
329
  if (!PushStringArray(value, member.type, dest))
347
330
  return false;
348
331
  } else {
349
- ThrowError<Napi::TypeError>(env, "Unexpected value %1 for member '%2', expected array", GetValueType(instance, value), member.name);
332
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected array", GetValueType(instance, value));
350
333
  return false;
351
334
  }
352
335
  } break;
353
336
  case PrimitiveKind::Float32: {
354
337
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
355
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
338
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
356
339
  return false;
357
340
  }
358
341
 
@@ -361,7 +344,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
361
344
  } break;
362
345
  case PrimitiveKind::Float64: {
363
346
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
364
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected number", GetValueType(instance, value), member.name);
347
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
365
348
  return false;
366
349
  }
367
350
 
@@ -383,7 +366,7 @@ bool CallData::PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origi
383
366
  } else if (IsNullOrUndefined(value)) {
384
367
  ptr = nullptr;
385
368
  } else {
386
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for member '%2', expected %3", GetValueType(instance, value), member.name, member.type->name);
369
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), member.type->name);
387
370
  return false;
388
371
  }
389
372
 
@@ -401,7 +384,7 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *ref,
401
384
  {
402
385
  RG_ASSERT(array.IsArray());
403
386
 
404
- if (RG_UNLIKELY(array.Length() != len)) {
387
+ if (RG_UNLIKELY(array.Length() != (size_t)len)) {
405
388
  ThrowError<Napi::Error>(env, "Expected array of length %1, got %2", len, array.Length());
406
389
  return false;
407
390
  }
@@ -410,8 +393,8 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *ref,
410
393
 
411
394
  #define PUSH_ARRAY(Check, Expected, GetCode) \
412
395
  do { \
413
- for (uint32_t i = 0; i < len; i++) { \
414
- Napi::Value value = array[i]; \
396
+ for (Size i = 0; i < len; i++) { \
397
+ Napi::Value value = array[(uint32_t)i]; \
415
398
  \
416
399
  int16_t align = std::max(ref->align, realign); \
417
400
  \
@@ -419,7 +402,7 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *ref,
419
402
  uint8_t *dest = origin + offset; \
420
403
  \
421
404
  if (RG_UNLIKELY(!(Check))) { \
422
- ThrowError<Napi::TypeError>(env, "Unexpected value %1 in array, expected %2", GetValueType(instance, value), (Expected)); \
405
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), (Expected)); \
423
406
  return false; \
424
407
  } \
425
408
  \
@@ -523,37 +506,30 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *ref,
523
506
  });
524
507
  } break;
525
508
  case PrimitiveKind::String: {
526
- PUSH_ARRAY(value.IsString() || IsNullOrUndefined(value), "string", {
527
- if (!IsNullOrUndefined(value)) {
528
- const char *str = PushString(value);
529
- if (RG_UNLIKELY(!str))
530
- return false;
531
- *(const char **)dest = str;
532
- } else {
533
- *(const char **)dest = nullptr;
534
- }
509
+ PUSH_ARRAY(true, "string", {
510
+ const char *str;
511
+ if (RG_UNLIKELY(!PushString(value, &str)))
512
+ return false;
513
+
514
+ *(const char **)dest = str;
535
515
  });
536
516
  } break;
537
517
  case PrimitiveKind::String16: {
538
- PUSH_ARRAY(value.IsString() || IsNullOrUndefined(value), "string", {
539
- if (!IsNullOrUndefined(value)) {
540
- const char16_t *str16 = PushString16(value);
541
- if (RG_UNLIKELY(!str16))
542
- return false;
543
- *(const char16_t **)dest = str16;
544
- } else {
545
- *(const char16_t **)dest = nullptr;
546
- }
518
+ PUSH_ARRAY(true, "string", {
519
+ const char16_t *str16;
520
+ if (RG_UNLIKELY(!PushString16(value, &str16)))
521
+ return false;
522
+
523
+ *(const char16_t **)dest = str16;
547
524
  });
548
525
  } break;
549
526
  case PrimitiveKind::Pointer: {
550
- PUSH_ARRAY(CheckValueTag(instance, value, ref->ref.marker) || IsNullOrUndefined(value), ref->name, {
551
- if (!IsNullOrUndefined(value)) {
552
- Napi::External<void> external = value.As<Napi::External<void>>();
553
- *(void **)dest = external.Data();
554
- } else {
555
- *(void **)dest = nullptr;
556
- }
527
+ PUSH_ARRAY(true, ref->name, {
528
+ void *ptr;
529
+ if (RG_UNLIKELY(!PushPointer(value, ref, 1, &ptr)))
530
+ return false;
531
+
532
+ *(const void **)dest = ptr;
557
533
  });
558
534
  } break;
559
535
  case PrimitiveKind::Record: {
@@ -564,8 +540,8 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *ref,
564
540
  });
565
541
  } break;
566
542
  case PrimitiveKind::Array: {
567
- for (uint32_t i = 0; i < len; i++) {
568
- Napi::Value value = array[i];
543
+ for (Size i = 0; i < len; i++) {
544
+ Napi::Value value = array[(uint32_t)i];
569
545
 
570
546
  int16_t align = std::max(ref->align, realign);
571
547
  offset = AlignLen(offset, align);
@@ -588,7 +564,7 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *ref,
588
564
  if (!PushStringArray(value, ref, dest))
589
565
  return false;
590
566
  } else {
591
- ThrowError<Napi::TypeError>(env, "Unexpected value %1 in array, expected array", GetValueType(instance, value));
567
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected array", GetValueType(instance, value));
592
568
  return false;
593
569
  }
594
570
 
@@ -608,8 +584,8 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *ref,
608
584
  });
609
585
  } break;
610
586
  case PrimitiveKind::Callback: {
611
- for (uint32_t i = 0; i < len; i++) {
612
- Napi::Value value = array[i];
587
+ for (Size i = 0; i < len; i++) {
588
+ Napi::Value value = array[(uint32_t)i];
613
589
 
614
590
  int16_t align = std::max(ref->align, realign);
615
591
  offset = AlignLen(offset, align);
@@ -630,7 +606,7 @@ bool CallData::PushNormalArray(Napi::Array array, Size len, const TypeInfo *ref,
630
606
  } else if (IsNullOrUndefined(value)) {
631
607
  ptr = nullptr;
632
608
  } else {
633
- ThrowError<Napi::TypeError>(env, "Unexpected value %1 in array, expected %2", GetValueType(instance, value), ref->name);
609
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), ref->name);
634
610
  return false;
635
611
  }
636
612
 
@@ -669,7 +645,7 @@ bool CallData::PushTypedArray(Napi::TypedArray array, Size len, const TypeInfo *
669
645
  Size offset = 0;
670
646
  Size size = (Size)array.ElementSize();
671
647
 
672
- for (uint32_t i = 0; i < len; i++) {
648
+ for (Size i = 0; i < len; i++) {
673
649
  offset = AlignLen(offset, realign);
674
650
 
675
651
  uint8_t *dest = origin + offset;
@@ -715,10 +691,8 @@ bool CallData::PushStringArray(Napi::Value obj, const TypeInfo *type, uint8_t *o
715
691
  return true;
716
692
  }
717
693
 
718
- bool CallData::PushPointer(Napi::Value value, const ParameterInfo &param, void **out_ptr)
694
+ bool CallData::PushPointer(Napi::Value value, const TypeInfo *type, int directions, void **out_ptr)
719
695
  {
720
- const TypeInfo *type = param.type;
721
-
722
696
  if (CheckValueTag(instance, value, &CastMarker)) {
723
697
  Napi::External<ValueCast> external = value.As<Napi::External<ValueCast>>();
724
698
  ValueCast *cast = external.Data();
@@ -757,7 +731,7 @@ bool CallData::PushPointer(Napi::Value value, const ParameterInfo &param, void *
757
731
 
758
732
  ptr = AllocHeap(size, 16);
759
733
 
760
- if (param.directions & 1) {
734
+ if (directions & 1) {
761
735
  if (!PushNormalArray(array, len, type->ref.type, ptr))
762
736
  return false;
763
737
  } else {
@@ -771,7 +745,7 @@ bool CallData::PushPointer(Napi::Value value, const ParameterInfo &param, void *
771
745
 
772
746
  ptr = AllocHeap(size, 16);
773
747
 
774
- if (param.directions & 1) {
748
+ if (directions & 1) {
775
749
  if (!PushTypedArray(array, len, type->ref.type, ptr))
776
750
  return false;
777
751
  } else {
@@ -789,7 +763,7 @@ bool CallData::PushPointer(Napi::Value value, const ParameterInfo &param, void *
789
763
 
790
764
  ptr = AllocHeap(type->ref.type->size, 16);
791
765
 
792
- if (param.directions & 1) {
766
+ if (directions & 1) {
793
767
  if (!PushObject(obj, type->ref.type, ptr))
794
768
  return false;
795
769
  } else {
@@ -799,7 +773,7 @@ bool CallData::PushPointer(Napi::Value value, const ParameterInfo &param, void *
799
773
  goto unexpected;
800
774
  }
801
775
 
802
- if (param.directions & 2) {
776
+ if (directions & 2) {
803
777
  OutArgument *out = out_arguments.AppendDefault();
804
778
 
805
779
  napi_status status = napi_create_reference(env, value, 1, &out->ref);
@@ -817,7 +791,7 @@ bool CallData::PushPointer(Napi::Value value, const ParameterInfo &param, void *
817
791
  }
818
792
 
819
793
  unexpected:
820
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected %3", GetValueType(instance, value), param.offset + 1, type->name);
794
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), type->name);
821
795
  return false;
822
796
  }
823
797
 
package/src/call.hh CHANGED
@@ -97,13 +97,13 @@ private:
97
97
  template <typename T = uint8_t>
98
98
  T *AllocHeap(Size size, Size align);
99
99
 
100
- const char *PushString(Napi::Value value);
101
- const char16_t *PushString16(Napi::Value value);
100
+ bool PushString(Napi::Value value, const char **out_str);
101
+ bool PushString16(Napi::Value value, const char16_t **out_str16);
102
102
  bool PushObject(Napi::Object obj, const TypeInfo *type, uint8_t *origin, int16_t realign = 0);
103
103
  bool PushNormalArray(Napi::Array array, Size len, const TypeInfo *ref, uint8_t *origin, int16_t realign = 0);
104
104
  bool PushTypedArray(Napi::TypedArray array, Size len, const TypeInfo *ref, uint8_t *origin, int16_t realign = 0);
105
105
  bool PushStringArray(Napi::Value value, const TypeInfo *type, uint8_t *origin);
106
- bool PushPointer(Napi::Value value, const ParameterInfo &param, void **out_ptr);
106
+ bool PushPointer(Napi::Value value, const TypeInfo *type, int directions, void **out_ptr);
107
107
 
108
108
  void PopObject(Napi::Object obj, const uint8_t *origin, const TypeInfo *type, int16_t realign = 0);
109
109
  Napi::Object PopObject(const uint8_t *origin, const TypeInfo *type, int16_t realign = 0);
@@ -161,7 +161,7 @@ inline T *CallData::AllocHeap(Size size, Size align)
161
161
  int flags = 0;
162
162
  #endif
163
163
 
164
- ptr = (uint8_t *)Allocator::Allocate(&call_alloc, size + align, flags);
164
+ ptr = AllocateMemory<uint8_t>(&call_alloc, size + align, flags).ptr;
165
165
  ptr = AlignUp(ptr, align);
166
166
 
167
167
  return ptr;
package/src/ffi.cc CHANGED
@@ -170,6 +170,12 @@ static Napi::Value GetSetConfig(const Napi::CallbackInfo &info)
170
170
  return obj;
171
171
  }
172
172
 
173
+ static inline bool CheckAlignment(int64_t align)
174
+ {
175
+ bool valid = (align > 0) && (align <= 8 && !(align & (align - 1)));
176
+ return valid;
177
+ }
178
+
173
179
  static Napi::Value CreateStructType(const Napi::CallbackInfo &info, bool pad)
174
180
  {
175
181
  Napi::Env env = info.Env();
@@ -224,8 +230,8 @@ static Napi::Value CreateStructType(const Napi::CallbackInfo &info, bool pad)
224
230
 
225
231
  int64_t align64 = ((Napi::Value)array[0u]).As<Napi::Number>().Int64Value();
226
232
 
227
- if (align64 < 1 || align64 > 64) {
228
- ThrowError<Napi::Error>(env, "Alignment value must be between 1 and 64");
233
+ if (!CheckAlignment(align64)) {
234
+ ThrowError<Napi::Error>(env, "Alignment of member '%1' must be 1, 2, 4 or 8", member.name);
229
235
  return env.Null();
230
236
  }
231
237
 
@@ -1460,14 +1466,20 @@ static inline PrimitiveKind GetSignPrimitive(Size len, bool sign)
1460
1466
 
1461
1467
  static inline PrimitiveKind GetLittleEndianPrimitive(PrimitiveKind kind)
1462
1468
  {
1463
- // Sensitive to endianness
1469
+ #ifdef RG_BIG_ENDIAN
1470
+ return (PrimitiveKind)((int)kind + 1);
1471
+ #else
1464
1472
  return kind;
1473
+ #endif
1465
1474
  }
1466
1475
 
1467
1476
  static inline PrimitiveKind GetBigEndianPrimitive(PrimitiveKind kind)
1468
1477
  {
1469
- // Sensitive to endianness
1478
+ #ifdef RG_BIG_ENDIAN
1479
+ return kind;
1480
+ #else
1470
1481
  return (PrimitiveKind)((int)kind + 1);
1482
+ #endif
1471
1483
  }
1472
1484
 
1473
1485
  static Napi::Object InitBaseTypes(Napi::Env env)
package/src/util.hh CHANGED
@@ -33,26 +33,6 @@ void ThrowError(Napi::Env env, const char *msg, Args... args)
33
33
  err.ThrowAsJavaScriptException();
34
34
  }
35
35
 
36
- static inline Size AlignLen(Size len, Size align)
37
- {
38
- Size aligned = (len + align - 1) / align * align;
39
- return aligned;
40
- }
41
-
42
- template <typename T>
43
- static inline T *AlignUp(T *ptr, Size align)
44
- {
45
- uint8_t *aligned = (uint8_t *)(((uintptr_t)ptr + align - 1) / align * align);
46
- return (T *)aligned;
47
- }
48
-
49
- template <typename T>
50
- static inline T *AlignDown(T *ptr, Size align)
51
- {
52
- uint8_t *aligned = (uint8_t *)((uintptr_t)ptr / align * align);
53
- return (T *)aligned;
54
- }
55
-
56
36
  static inline bool IsInteger(const TypeInfo *type)
57
37
  {
58
38
  bool integer = ((int)type->primitive >= (int)PrimitiveKind::Int8 &&
package/test/callbacks.js CHANGED
@@ -18,10 +18,10 @@ const assert = require('assert');
18
18
 
19
19
  const BFG = koffi.struct('BFG', {
20
20
  a: 'int8_t',
21
- b: [16, 'int64_t'],
21
+ e: [8, 'short'],
22
+ b: 'int64_t',
22
23
  c: 'char',
23
- d: 'str',
24
- e: 'short',
24
+ d: 'const char *',
25
25
  inner: koffi.struct({
26
26
  f: 'float',
27
27
  g: 'double'