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/test/misc.c CHANGED
@@ -90,10 +90,10 @@ typedef struct IJK8 { int64_t i; int64_t j; int64_t k; } IJK8;
90
90
 
91
91
  typedef struct BFG {
92
92
  int8_t a;
93
- char _pad1[15]; int64_t b;
93
+ char _pad1[7]; short e;
94
+ int64_t b;
94
95
  signed char c;
95
96
  const char *d;
96
- short e;
97
97
  struct {
98
98
  float f;
99
99
  double g;
package/test/sync.js CHANGED
@@ -61,10 +61,10 @@ const IntFloat = koffi.struct('IntFloat', {
61
61
 
62
62
  const BFG = koffi.struct('BFG', {
63
63
  a: 'int8_t',
64
- b: [16, 'int64_t'],
64
+ e: [8, 'short'],
65
+ b: 'int64_t',
65
66
  c: 'char',
66
67
  d: 'const char *',
67
- e: 'short',
68
68
  inner: koffi.struct({
69
69
  f: 'float',
70
70
  g: 'double'
@@ -205,7 +205,7 @@ void LinkedAllocator::ReleaseAll()
205
205
  Node *head = list.next;
206
206
  while (head) {
207
207
  Node *next = head->next;
208
- Allocator::Release(allocator, head, -1);
208
+ ReleaseMemory(allocator, head, -1);
209
209
  head = next;
210
210
  }
211
211
  list = {};
@@ -213,7 +213,7 @@ void LinkedAllocator::ReleaseAll()
213
213
 
214
214
  void *LinkedAllocator::Allocate(Size size, unsigned int flags)
215
215
  {
216
- Bucket *bucket = (Bucket *)Allocator::Allocate(allocator, RG_SIZE(*bucket) + size, flags);
216
+ Bucket *bucket = AllocateMemory<Bucket>(allocator, RG_SIZE(*bucket) + size, flags).ptr;
217
217
 
218
218
  if (list.prev) {
219
219
  list.prev->next = &bucket->head;
@@ -227,7 +227,12 @@ void *LinkedAllocator::Allocate(Size size, unsigned int flags)
227
227
  bucket->head.next = nullptr;
228
228
  }
229
229
 
230
- return bucket->data;
230
+ uint8_t *data = bucket->data;
231
+ uint8_t *aligned = AlignUp(data, 16);
232
+
233
+ RG_ASSERT(aligned - data <= 8);
234
+
235
+ return (void *)aligned;
231
236
  }
232
237
 
233
238
  void LinkedAllocator::Resize(void **ptr, Size old_size, Size new_size, unsigned int flags)
@@ -239,8 +244,9 @@ void LinkedAllocator::Resize(void **ptr, Size old_size, Size new_size, unsigned
239
244
  *ptr = nullptr;
240
245
  } else {
241
246
  Bucket *bucket = PointerToBucket(*ptr);
242
- Allocator::Resize(allocator, (void **)&bucket, RG_SIZE(*bucket) + old_size,
243
- RG_SIZE(*bucket) + new_size, flags);
247
+
248
+ bucket = ResizeMemory(allocator, bucket, RG_SIZE(*bucket) + old_size,
249
+ RG_SIZE(*bucket) + new_size, flags).ptr;
244
250
 
245
251
  if (bucket->head.next) {
246
252
  bucket->head.next->prev = &bucket->head;
@@ -253,7 +259,12 @@ void LinkedAllocator::Resize(void **ptr, Size old_size, Size new_size, unsigned
253
259
  list.next = &bucket->head;
254
260
  }
255
261
 
256
- *ptr = bucket->data;
262
+ uint8_t *data = bucket->data;
263
+ uint8_t *aligned = AlignUp(data, 16);
264
+
265
+ RG_ASSERT(aligned - data <= 8);
266
+
267
+ *ptr = (void *)aligned;
257
268
  }
258
269
  }
259
270
 
@@ -273,7 +284,7 @@ void LinkedAllocator::Release(void *ptr, Size size)
273
284
  list.next = bucket->head.next;
274
285
  }
275
286
 
276
- Allocator::Release(allocator, bucket, size);
287
+ ReleaseMemory(allocator, bucket, size);
277
288
  }
278
289
  }
279
290
 
@@ -284,16 +295,18 @@ void *BlockAllocatorBase::Allocate(Size size, unsigned int flags)
284
295
  LinkedAllocator *alloc = GetAllocator();
285
296
 
286
297
  // Keep alignement requirements
287
- Size aligned_size = AlignSizeValue(size);
298
+ Size aligned_size = AlignLen(size, 8);
288
299
 
289
300
  if (AllocateSeparately(aligned_size)) {
290
- uint8_t *ptr = (uint8_t *)Allocator::Allocate(alloc, size, flags);
301
+ uint8_t *ptr = AllocateMemory<uint8_t>(alloc, size, flags).ptr;
291
302
  return ptr;
292
303
  } else {
293
304
  if (!current_bucket || (current_bucket->used + aligned_size) > block_size) {
294
- current_bucket = (Bucket *)Allocator::Allocate(alloc, RG_SIZE(Bucket) + block_size,
295
- flags & ~(int)Allocator::Flag::Zero);
296
- current_bucket->used = 0;
305
+ current_bucket = AllocateMemory<Bucket>(alloc, RG_SIZE(Bucket) + block_size,
306
+ flags & ~(int)Allocator::Flag::Zero).ptr;
307
+ current_bucket->used = AlignUp(current_bucket->data, 16) - current_bucket->data;
308
+
309
+ RG_ASSERT(current_bucket->used <= 8);
297
310
  }
298
311
 
299
312
  uint8_t *ptr = current_bucket->data + current_bucket->used;
@@ -320,12 +333,13 @@ void BlockAllocatorBase::Resize(void **ptr, Size old_size, Size new_size, unsign
320
333
  old_size = 0;
321
334
  }
322
335
 
323
- Size aligned_old_size = AlignSizeValue(old_size);
324
- Size aligned_new_size = AlignSizeValue(new_size);
336
+ Size aligned_old_size = AlignLen(old_size, 8);
337
+ Size aligned_new_size = AlignLen(new_size, 8);
325
338
  Size aligned_delta = aligned_new_size - aligned_old_size;
326
339
 
327
340
  // Try fast path
328
- if (*ptr && *ptr == last_alloc && (current_bucket->used + aligned_delta) <= block_size &&
341
+ if (*ptr && *ptr == last_alloc &&
342
+ (current_bucket->used + aligned_delta) <= block_size &&
329
343
  !AllocateSeparately(aligned_new_size)) {
330
344
  current_bucket->used += aligned_delta;
331
345
 
@@ -334,7 +348,7 @@ void BlockAllocatorBase::Resize(void **ptr, Size old_size, Size new_size, unsign
334
348
  }
335
349
  } else if (AllocateSeparately(aligned_old_size)) {
336
350
  LinkedAllocator *alloc = GetAllocator();
337
- Allocator::Resize(alloc, ptr, old_size, new_size, flags);
351
+ ptr = ResizeMemory(alloc, ptr, old_size, new_size, flags).ptr;
338
352
  } else {
339
353
  void *new_ptr = Allocate(new_size, flags & ~(int)Allocator::Flag::Zero);
340
354
  if (new_size > old_size) {
@@ -359,17 +373,17 @@ void BlockAllocatorBase::Release(void *ptr, Size size)
359
373
  if (ptr) {
360
374
  LinkedAllocator *alloc = GetAllocator();
361
375
 
362
- Size aligned_size = AlignSizeValue(size);
376
+ Size aligned_size = AlignLen(size, 8);
363
377
 
364
378
  if (ptr == last_alloc) {
365
379
  current_bucket->used -= aligned_size;
366
380
  if (!current_bucket->used) {
367
- Allocator::Release(alloc, current_bucket, RG_SIZE(Bucket) + block_size);
381
+ ReleaseMemory(alloc, current_bucket, RG_SIZE(Bucket) + block_size);
368
382
  current_bucket = nullptr;
369
383
  }
370
384
  last_alloc = nullptr;
371
385
  } else if (AllocateSeparately(aligned_size)) {
372
- Allocator::Release(alloc, ptr, size);
386
+ ReleaseMemory(alloc, ptr, size);
373
387
  }
374
388
  }
375
389
  }
@@ -419,10 +433,10 @@ void IndirectBlockAllocator::ReleaseAll()
419
433
  // ------------------------------------------------------------------------
420
434
 
421
435
  // XXX: Rewrite the ugly parsing part
422
- Date Date::Parse(Span<const char> date_str, unsigned int flags,
423
- Span<const char> *out_remaining)
436
+ LocalDate LocalDate::Parse(Span<const char> date_str, unsigned int flags,
437
+ Span<const char> *out_remaining)
424
438
  {
425
- Date date;
439
+ LocalDate date;
426
440
 
427
441
  int parts[3] = {};
428
442
  int lengths[3] = {};
@@ -488,14 +502,14 @@ malformed:
488
502
  return {};
489
503
  }
490
504
 
491
- Date Date::FromJulianDays(int days)
505
+ LocalDate LocalDate::FromJulianDays(int days)
492
506
  {
493
507
  RG_ASSERT(days >= 0);
494
508
 
495
509
  // Algorithm from Richards, copied from Wikipedia:
496
510
  // https://en.wikipedia.org/w/index.php?title=Julian_day&oldid=792497863
497
511
 
498
- Date date;
512
+ LocalDate date;
499
513
  {
500
514
  int f = days + 1401 + (((4 * days + 274277) / 146097) * 3) / 4 - 38;
501
515
  int e = 4 * f + 3;
@@ -509,7 +523,7 @@ Date Date::FromJulianDays(int days)
509
523
  return date;
510
524
  }
511
525
 
512
- int Date::ToJulianDays() const
526
+ int LocalDate::ToJulianDays() const
513
527
  {
514
528
  RG_ASSERT(IsValid());
515
529
 
@@ -529,7 +543,7 @@ int Date::ToJulianDays() const
529
543
  return julian_days;
530
544
  }
531
545
 
532
- int Date::GetWeekDay() const
546
+ int LocalDate::GetWeekDay() const
533
547
  {
534
548
  RG_ASSERT(IsValid());
535
549
 
@@ -554,7 +568,7 @@ int Date::GetWeekDay() const
554
568
  return week_day;
555
569
  }
556
570
 
557
- Date &Date::operator++()
571
+ LocalDate &LocalDate::operator++()
558
572
  {
559
573
  RG_ASSERT(IsValid());
560
574
 
@@ -572,7 +586,7 @@ Date &Date::operator++()
572
586
  return *this;
573
587
  }
574
588
 
575
- Date &Date::operator--()
589
+ LocalDate &LocalDate::operator--()
576
590
  {
577
591
  RG_ASSERT(IsValid());
578
592
 
@@ -748,7 +762,7 @@ bool CopyString(Span<const char> str, Span<char> buf)
748
762
 
749
763
  Span<char> DuplicateString(Span<const char> str, Allocator *alloc)
750
764
  {
751
- char *new_str = (char *)Allocator::Allocate(alloc, str.len + 1);
765
+ char *new_str = AllocateMemory<char>(alloc, str.len + 1).ptr;
752
766
  memcpy_safe(new_str, str.ptr, (size_t)str.len);
753
767
  new_str[str.len] = 0;
754
768
  return MakeSpan(new_str, str.len);
@@ -1342,7 +1356,7 @@ static inline void ProcessArg(const FmtArg &arg, AppendFunc append)
1342
1356
  } break;
1343
1357
  case FmtType::MemorySize:
1344
1358
  case FmtType::DiskSize: { arg2.u.i = *(const int64_t *)ptr; } break;
1345
- case FmtType::Date: { arg2.u.date = *(const Date *)ptr; } break;
1359
+ case FmtType::Date: { arg2.u.date = *(const LocalDate *)ptr; } break;
1346
1360
  case FmtType::TimeISO:
1347
1361
  case FmtType::TimeNice: { arg2.u.time = *(const TimeSpec *)ptr; } break;
1348
1362
  case FmtType::Random: { RG_UNREACHABLE(); } break;
@@ -2757,7 +2771,7 @@ const char *GetApplicationExecutable()
2757
2771
  RG_ASSERT(strlen(path) < RG_SIZE(executable_path));
2758
2772
 
2759
2773
  CopyString(path, executable_path);
2760
- Allocator::Release(nullptr, (void *)path, -1);
2774
+ ReleaseMemory(nullptr, (void *)path, -1);
2761
2775
  }
2762
2776
  }
2763
2777
 
@@ -3546,10 +3560,8 @@ bool ExecuteCommandLine(const char *cmd_line, FunctionRef<Span<const uint8_t>()>
3546
3560
  STARTUPINFOW si = {};
3547
3561
 
3548
3562
  // Convert command line
3549
- Span<wchar_t> cmd_line_w;
3550
- cmd_line_w.len = 4 * strlen(cmd_line) + 2;
3551
- cmd_line_w.ptr = (wchar_t *)Allocator::Allocate(nullptr, cmd_line_w.len);
3552
- RG_DEFER { Allocator::Release(nullptr, cmd_line_w.ptr, cmd_line_w.len); };
3563
+ Span<wchar_t> cmd_line_w = AllocateMemory<wchar_t>(nullptr, 4 * strlen(cmd_line) + 2);
3564
+ RG_DEFER { ReleaseMemory(nullptr, cmd_line_w.ptr, cmd_line_w.len); };
3553
3565
  if (ConvertUtf8ToWin32Wide(cmd_line, cmd_line_w) < 0)
3554
3566
  return false;
3555
3567
 
@@ -4679,14 +4691,24 @@ static RG_THREAD_LOCAL Size rnd_offset;
4679
4691
 
4680
4692
  static void InitChaCha20(uint32_t state[16], uint32_t key[8], uint32_t iv[2])
4681
4693
  {
4682
- static const char magic[] = "expand 32-byte k";
4683
-
4684
- // Sensitive to endianness
4685
- memcpy(state, magic, 16);
4686
- memcpy(state + 4, key, 32);
4694
+ static const uint32_t *const magic = (const uint32_t *)"expand 32-byte k";
4695
+
4696
+ state[0] = LittleEndian(magic[0]);
4697
+ state[1] = LittleEndian(magic[1]);
4698
+ state[2] = LittleEndian(magic[2]);
4699
+ state[3] = LittleEndian(magic[3]);
4700
+ state[4] = LittleEndian(key[0]);
4701
+ state[5] = LittleEndian(key[1]);
4702
+ state[6] = LittleEndian(key[2]);
4703
+ state[7] = LittleEndian(key[3]);
4704
+ state[8] = LittleEndian(key[4]);
4705
+ state[9] = LittleEndian(key[5]);
4706
+ state[10] = LittleEndian(key[6]);
4707
+ state[11] = LittleEndian(key[7]);
4687
4708
  state[12] = 0;
4688
4709
  state[13] = 0;
4689
- memcpy(state + 14, iv, 8);
4710
+ state[14] = LittleEndian(iv[0]);
4711
+ state[15] = LittleEndian(iv[1]);
4690
4712
  }
4691
4713
 
4692
4714
  static void RunChaCha20(uint32_t state[16], uint8_t out_buf[64])
@@ -5401,9 +5423,9 @@ Fiber::Fiber(const std::function<bool()> &f, Size stack_size)
5401
5423
  LogError("Failed to get fiber context: %1", strerror(errno));
5402
5424
  return;
5403
5425
  }
5404
- memcpy(&ucp, &fib_self, RG_SIZE(ucp));
5405
5426
 
5406
- ucp.uc_stack.ss_sp = Allocator::Allocate(nullptr, stack_size);
5427
+ memcpy(&ucp, &fib_self, RG_SIZE(ucp));
5428
+ ucp.uc_stack.ss_sp = GetDefaultAllocator()->Allocate(stack_size);
5407
5429
  ucp.uc_stack.ss_size = (size_t)stack_size;
5408
5430
  ucp.uc_link = nullptr;
5409
5431
 
@@ -5421,6 +5443,8 @@ Fiber::~Fiber()
5421
5443
  Finalize();
5422
5444
  fib_run = nullptr;
5423
5445
  }
5446
+
5447
+ ReleaseMemory(nullptr, ucp.uc_stack.ss_sp, (Size)ucp.uc_stack.ss_size);
5424
5448
  }
5425
5449
 
5426
5450
  void Fiber::SwitchTo()
@@ -5702,7 +5726,7 @@ bool StreamReader::Close(bool implicit)
5702
5726
  case CompressionType::Gzip:
5703
5727
  case CompressionType::Zlib: {
5704
5728
  #ifdef MZ_VERSION
5705
- Allocator::Release(nullptr, compression.u.miniz, RG_SIZE(*compression.u.miniz));
5729
+ ReleaseMemory(nullptr, compression.u.miniz, RG_SIZE(*compression.u.miniz));
5706
5730
  compression.u.miniz = nullptr;
5707
5731
  #else
5708
5732
  RG_UNREACHABLE();
@@ -5718,7 +5742,7 @@ bool StreamReader::Close(bool implicit)
5718
5742
  BrotliDecoderDestroyInstance(ctx->state);
5719
5743
  }
5720
5744
 
5721
- Allocator::Release(nullptr, ctx, RG_SIZE(*ctx));
5745
+ ReleaseMemory(nullptr, ctx, RG_SIZE(*ctx));
5722
5746
  compression.u.brotli = nullptr;
5723
5747
  }
5724
5748
  #else
@@ -5952,8 +5976,7 @@ bool StreamReader::InitDecompressor(CompressionType type)
5952
5976
  case CompressionType::Zlib: {
5953
5977
  #ifdef MZ_VERSION
5954
5978
  compression.u.miniz =
5955
- (MinizInflateContext *)Allocator::Allocate(nullptr, RG_SIZE(MinizInflateContext),
5956
- (int)Allocator::Flag::Zero);
5979
+ AllocateMemory<MinizInflateContext>(nullptr, RG_SIZE(MinizInflateContext), (int)Allocator::Flag::Zero).ptr;
5957
5980
  tinfl_init(&compression.u.miniz->inflator);
5958
5981
  compression.u.miniz->crc32 = MZ_CRC32_INIT;
5959
5982
  #else
@@ -5966,8 +5989,7 @@ bool StreamReader::InitDecompressor(CompressionType type)
5966
5989
  case CompressionType::Brotli: {
5967
5990
  #ifdef BROTLI_DEFAULT_MODE
5968
5991
  compression.u.brotli =
5969
- (BrotliDecompressContext *)Allocator::Allocate(nullptr, RG_SIZE(BrotliDecompressContext),
5970
- (int)Allocator::Flag::Zero);
5992
+ AllocateMemory<BrotliDecompressContext>(nullptr, RG_SIZE(BrotliDecompressContext), (int)Allocator::Flag::Zero).ptr;
5971
5993
  compression.u.brotli->state = BrotliDecoderCreateInstance(nullptr, nullptr, nullptr);
5972
5994
  #else
5973
5995
  LogError("Brotli decompression not available for '%1'", filename);
@@ -6505,7 +6527,7 @@ bool StreamWriter::Close(bool implicit)
6505
6527
  MinizDeflateContext *ctx = compression.u.miniz;
6506
6528
 
6507
6529
  RG_DEFER {
6508
- Allocator::Release(nullptr, ctx, RG_SIZE(*ctx));
6530
+ ReleaseMemory(nullptr, ctx, RG_SIZE(*ctx));
6509
6531
  compression.u.miniz = nullptr;
6510
6532
  };
6511
6533
 
@@ -6644,8 +6666,7 @@ bool StreamWriter::InitCompressor(CompressionType type, CompressionSpeed speed)
6644
6666
  case CompressionType::Zlib: {
6645
6667
  #ifdef MZ_VERSION
6646
6668
  compression.u.miniz =
6647
- (MinizDeflateContext *)Allocator::Allocate(nullptr, RG_SIZE(MinizDeflateContext),
6648
- (int)Allocator::Flag::Zero);
6669
+ AllocateMemory<MinizDeflateContext>(nullptr, RG_SIZE(MinizDeflateContext), (int)Allocator::Flag::Zero).ptr;
6649
6670
  compression.u.miniz->crc32 = MZ_CRC32_INIT;
6650
6671
 
6651
6672
  int flags = 0;
@@ -7012,9 +7033,8 @@ bool ReloadAssets()
7012
7033
  AssetInfo asset_copy;
7013
7034
 
7014
7035
  asset_copy.name = DuplicateString(asset.name, &assets_alloc).ptr;
7015
- uint8_t *data_ptr = (uint8_t *)Allocator::Allocate(&assets_alloc, asset.data.len);
7016
- memcpy_safe(data_ptr, asset.data.ptr, (size_t)asset.data.len);
7017
- asset_copy.data = {data_ptr, asset.data.len};
7036
+ asset_copy.data = AllocateMemory<uint8_t>(&assets_alloc, asset.data.len);
7037
+ memcpy_safe((void *)asset_copy.data.ptr, asset.data.ptr, (size_t)asset.data.len);
7018
7038
  asset_copy.compression_type = asset.compression_type;
7019
7039
  asset_copy.source_map = DuplicateString(asset.source_map, &assets_alloc).ptr;
7020
7040