@shd101wyy/yo 0.0.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.
Files changed (339) hide show
  1. package/LICENSE.md +17 -0
  2. package/README.md +80 -0
  3. package/out/cjs/index.cjs +51 -0
  4. package/out/cjs/yo-cli.cjs +2158 -0
  5. package/out/esm/index.mjs +51 -0
  6. package/out/types/src/codegen/async/runtime.d.ts +2 -0
  7. package/out/types/src/codegen/async/state-code-gen.d.ts +10 -0
  8. package/out/types/src/codegen/async/state-machine.d.ts +13 -0
  9. package/out/types/src/codegen/c/collection.d.ts +3 -0
  10. package/out/types/src/codegen/codegen-c.d.ts +12 -0
  11. package/out/types/src/codegen/constants.d.ts +3 -0
  12. package/out/types/src/codegen/expressions/array.d.ts +4 -0
  13. package/out/types/src/codegen/expressions/generation.d.ts +11 -0
  14. package/out/types/src/codegen/expressions/index.d.ts +2 -0
  15. package/out/types/src/codegen/functions/collection.d.ts +5 -0
  16. package/out/types/src/codegen/functions/context.d.ts +57 -0
  17. package/out/types/src/codegen/functions/generation.d.ts +25 -0
  18. package/out/types/src/codegen/functions/index.d.ts +2 -0
  19. package/out/types/src/codegen/index.d.ts +20 -0
  20. package/out/types/src/codegen/parallelism/runtime.d.ts +2 -0
  21. package/out/types/src/codegen/types/collection.d.ts +8 -0
  22. package/out/types/src/codegen/types/generation.d.ts +13 -0
  23. package/out/types/src/codegen/types/index.d.ts +2 -0
  24. package/out/types/src/codegen/utils/fixup.d.ts +2 -0
  25. package/out/types/src/codegen/utils/index.d.ts +77 -0
  26. package/out/types/src/codegen/values/index.d.ts +1 -0
  27. package/out/types/src/emitter.d.ts +11 -0
  28. package/out/types/src/env.d.ts +85 -0
  29. package/out/types/src/error.d.ts +45 -0
  30. package/out/types/src/evaluator/async/await-analysis-types.d.ts +23 -0
  31. package/out/types/src/evaluator/async/await-analysis.d.ts +5 -0
  32. package/out/types/src/evaluator/builtins/alignof.d.ts +8 -0
  33. package/out/types/src/evaluator/builtins/and_or.d.ts +8 -0
  34. package/out/types/src/evaluator/builtins/arc_fns.d.ts +58 -0
  35. package/out/types/src/evaluator/builtins/array_fns.d.ts +0 -0
  36. package/out/types/src/evaluator/builtins/as.d.ts +8 -0
  37. package/out/types/src/evaluator/builtins/async_fns.d.ts +8 -0
  38. package/out/types/src/evaluator/builtins/compt_assert.d.ts +8 -0
  39. package/out/types/src/evaluator/builtins/compt_boolean_fns.d.ts +8 -0
  40. package/out/types/src/evaluator/builtins/compt_expect_error.d.ts +8 -0
  41. package/out/types/src/evaluator/builtins/compt_list_fns.d.ts +33 -0
  42. package/out/types/src/evaluator/builtins/compt_print.d.ts +8 -0
  43. package/out/types/src/evaluator/builtins/compt_string_fns.d.ts +8 -0
  44. package/out/types/src/evaluator/builtins/consume.d.ts +8 -0
  45. package/out/types/src/evaluator/builtins/drop.d.ts +8 -0
  46. package/out/types/src/evaluator/builtins/dup.d.ts +8 -0
  47. package/out/types/src/evaluator/builtins/expr_fns.d.ts +33 -0
  48. package/out/types/src/evaluator/builtins/future_fns.d.ts +8 -0
  49. package/out/types/src/evaluator/builtins/gc.d.ts +8 -0
  50. package/out/types/src/evaluator/builtins/gensym.d.ts +8 -0
  51. package/out/types/src/evaluator/builtins/impl_constraint.d.ts +8 -0
  52. package/out/types/src/evaluator/builtins/macro_expand.d.ts +8 -0
  53. package/out/types/src/evaluator/builtins/numeric_fns.d.ts +8 -0
  54. package/out/types/src/evaluator/builtins/panic.d.ts +8 -0
  55. package/out/types/src/evaluator/builtins/ptr_fns.d.ts +8 -0
  56. package/out/types/src/evaluator/builtins/quote.d.ts +13 -0
  57. package/out/types/src/evaluator/builtins/rc.d.ts +8 -0
  58. package/out/types/src/evaluator/builtins/sizeof.d.ts +8 -0
  59. package/out/types/src/evaluator/builtins/the.d.ts +8 -0
  60. package/out/types/src/evaluator/builtins/type_fns.d.ts +28 -0
  61. package/out/types/src/evaluator/builtins/va_start.d.ts +8 -0
  62. package/out/types/src/evaluator/builtins/var_fns.d.ts +18 -0
  63. package/out/types/src/evaluator/calls/array.d.ts +13 -0
  64. package/out/types/src/evaluator/calls/array_type.d.ts +11 -0
  65. package/out/types/src/evaluator/calls/closure_type.d.ts +11 -0
  66. package/out/types/src/evaluator/calls/compt_function.d.ts +19 -0
  67. package/out/types/src/evaluator/calls/compt_list_type.d.ts +11 -0
  68. package/out/types/src/evaluator/calls/function.d.ts +16 -0
  69. package/out/types/src/evaluator/calls/function_type.d.ts +15 -0
  70. package/out/types/src/evaluator/calls/helper.d.ts +42 -0
  71. package/out/types/src/evaluator/calls/iso.d.ts +15 -0
  72. package/out/types/src/evaluator/calls/module_type.d.ts +11 -0
  73. package/out/types/src/evaluator/calls/numeric_type.d.ts +15 -0
  74. package/out/types/src/evaluator/calls/pointer.d.ts +8 -0
  75. package/out/types/src/evaluator/calls/pointer_type.d.ts +14 -0
  76. package/out/types/src/evaluator/calls/type.d.ts +12 -0
  77. package/out/types/src/evaluator/context.d.ts +169 -0
  78. package/out/types/src/evaluator/exprs/_expr.d.ts +8 -0
  79. package/out/types/src/evaluator/exprs/assignment.d.ts +9 -0
  80. package/out/types/src/evaluator/exprs/begin.d.ts +10 -0
  81. package/out/types/src/evaluator/exprs/binding.d.ts +12 -0
  82. package/out/types/src/evaluator/exprs/c_include.d.ts +8 -0
  83. package/out/types/src/evaluator/exprs/cond.d.ts +8 -0
  84. package/out/types/src/evaluator/exprs/destructuring_assignment.d.ts +33 -0
  85. package/out/types/src/evaluator/exprs/exists.d.ts +0 -0
  86. package/out/types/src/evaluator/exprs/expr.d.ts +9 -0
  87. package/out/types/src/evaluator/exprs/extern.d.ts +8 -0
  88. package/out/types/src/evaluator/exprs/identifer_and_operator.d.ts +9 -0
  89. package/out/types/src/evaluator/exprs/import.d.ts +9 -0
  90. package/out/types/src/evaluator/exprs/initialization_assignment.d.ts +8 -0
  91. package/out/types/src/evaluator/exprs/match.d.ts +8 -0
  92. package/out/types/src/evaluator/exprs/open.d.ts +8 -0
  93. package/out/types/src/evaluator/exprs/property_access.d.ts +8 -0
  94. package/out/types/src/evaluator/exprs/recur.d.ts +8 -0
  95. package/out/types/src/evaluator/exprs/subtype_of.d.ts +21 -0
  96. package/out/types/src/evaluator/exprs/test.d.ts +8 -0
  97. package/out/types/src/evaluator/exprs/typeof.d.ts +8 -0
  98. package/out/types/src/evaluator/exprs/while.d.ts +8 -0
  99. package/out/types/src/evaluator/index.d.ts +26 -0
  100. package/out/types/src/evaluator/types/array.d.ts +8 -0
  101. package/out/types/src/evaluator/types/closure.d.ts +8 -0
  102. package/out/types/src/evaluator/types/compt_list.d.ts +8 -0
  103. package/out/types/src/evaluator/types/concrete_module.d.ts +8 -0
  104. package/out/types/src/evaluator/types/dyn.d.ts +8 -0
  105. package/out/types/src/evaluator/types/enum.d.ts +8 -0
  106. package/out/types/src/evaluator/types/expr_synthesizer.d.ts +14 -0
  107. package/out/types/src/evaluator/types/field.d.ts +14 -0
  108. package/out/types/src/evaluator/types/fn_module.d.ts +8 -0
  109. package/out/types/src/evaluator/types/function.d.ts +58 -0
  110. package/out/types/src/evaluator/types/future_module.d.ts +8 -0
  111. package/out/types/src/evaluator/types/module.d.ts +19 -0
  112. package/out/types/src/evaluator/types/newtype.d.ts +8 -0
  113. package/out/types/src/evaluator/types/object.d.ts +8 -0
  114. package/out/types/src/evaluator/types/proofs.d.ts +0 -0
  115. package/out/types/src/evaluator/types/slice.d.ts +8 -0
  116. package/out/types/src/evaluator/types/struct.d.ts +8 -0
  117. package/out/types/src/evaluator/types/synthesizer.d.ts +16 -0
  118. package/out/types/src/evaluator/types/tuple.d.ts +18 -0
  119. package/out/types/src/evaluator/types/union.d.ts +8 -0
  120. package/out/types/src/evaluator/types/utils.d.ts +71 -0
  121. package/out/types/src/evaluator/types/validation.d.ts +3 -0
  122. package/out/types/src/evaluator/utils/array-utils.d.ts +15 -0
  123. package/out/types/src/evaluator/utils/closure.d.ts +35 -0
  124. package/out/types/src/evaluator/utils.d.ts +4 -0
  125. package/out/types/src/evaluator/values/anonymous_function.d.ts +8 -0
  126. package/out/types/src/evaluator/values/anonymous_module.d.ts +17 -0
  127. package/out/types/src/evaluator/values/anonymous_struct.d.ts +8 -0
  128. package/out/types/src/evaluator/values/array.d.ts +8 -0
  129. package/out/types/src/evaluator/values/boolean.d.ts +3 -0
  130. package/out/types/src/evaluator/values/char.d.ts +3 -0
  131. package/out/types/src/evaluator/values/compt_list.d.ts +8 -0
  132. package/out/types/src/evaluator/values/dyn.d.ts +8 -0
  133. package/out/types/src/evaluator/values/float.d.ts +4 -0
  134. package/out/types/src/evaluator/values/integer.d.ts +4 -0
  135. package/out/types/src/evaluator/values/module.d.ts +58 -0
  136. package/out/types/src/evaluator/values/string.d.ts +3 -0
  137. package/out/types/src/evaluator/values/tuple.d.ts +32 -0
  138. package/out/types/src/expr.d.ts +456 -0
  139. package/out/types/src/function-value.d.ts +42 -0
  140. package/out/types/src/index.d.ts +4 -0
  141. package/out/types/src/lexer.d.ts +2 -0
  142. package/out/types/src/logger.d.ts +1 -0
  143. package/out/types/src/module-manager.d.ts +30 -0
  144. package/out/types/src/naming-checker.d.ts +4 -0
  145. package/out/types/src/parser.d.ts +33 -0
  146. package/out/types/src/test-runner.d.ts +30 -0
  147. package/out/types/src/tests/codegen.test.d.ts +1 -0
  148. package/out/types/src/tests/fixme.test.d.ts +1 -0
  149. package/out/types/src/tests/module-manager.test.d.ts +1 -0
  150. package/out/types/src/tests/parser.test.d.ts +1 -0
  151. package/out/types/src/tests/sample.test.d.ts +0 -0
  152. package/out/types/src/tests/std.test.d.ts +1 -0
  153. package/out/types/src/token.d.ts +40 -0
  154. package/out/types/src/type-value.d.ts +7 -0
  155. package/out/types/src/types/compatibility.d.ts +16 -0
  156. package/out/types/src/types/creators.d.ts +73 -0
  157. package/out/types/src/types/definitions.d.ts +218 -0
  158. package/out/types/src/types/guards.d.ts +70 -0
  159. package/out/types/src/types/hierarchy.d.ts +4 -0
  160. package/out/types/src/types/index.d.ts +7 -0
  161. package/out/types/src/types/module_field.d.ts +2 -0
  162. package/out/types/src/types/tags.d.ts +45 -0
  163. package/out/types/src/types/utils.d.ts +50 -0
  164. package/out/types/src/unit-value.d.ts +7 -0
  165. package/out/types/src/utils.d.ts +6 -0
  166. package/out/types/src/value-tag.d.ts +29 -0
  167. package/out/types/src/value.d.ts +110 -0
  168. package/out/types/src/yo-cli.d.ts +1 -0
  169. package/out/types/tsconfig.tsbuildinfo +1 -0
  170. package/package.json +57 -0
  171. package/scripts/check-liburing.js +76 -0
  172. package/std/alg/hash.yo +50 -0
  173. package/std/allocator.yo +113 -0
  174. package/std/allocators/c_allocator.yo +118 -0
  175. package/std/async.yo +13 -0
  176. package/std/collections/array_list.yo +415 -0
  177. package/std/collections/hash_map.yo +482 -0
  178. package/std/collections/hash_set.yo +706 -0
  179. package/std/collections/index.yo +11 -0
  180. package/std/collections/linked_list.yo +439 -0
  181. package/std/error.yo +0 -0
  182. package/std/gc.yo +10 -0
  183. package/std/index.yo +12 -0
  184. package/std/io/file.yo +191 -0
  185. package/std/io/index.yo +5 -0
  186. package/std/libc/assert.yo +39 -0
  187. package/std/libc/ctype.yo +57 -0
  188. package/std/libc/errno.yo +182 -0
  189. package/std/libc/float.yo +87 -0
  190. package/std/libc/index.yo +29 -0
  191. package/std/libc/limits.yo +65 -0
  192. package/std/libc/math.yo +679 -0
  193. package/std/libc/signal.yo +101 -0
  194. package/std/libc/stdatomic.yo +213 -0
  195. package/std/libc/stdint.yo +214 -0
  196. package/std/libc/stdio.yo +225 -0
  197. package/std/libc/stdlib.yo +204 -0
  198. package/std/libc/string.yo +151 -0
  199. package/std/libc/time.yo +92 -0
  200. package/std/libc/unistd.yo +130 -0
  201. package/std/monad.yo +152 -0
  202. package/std/prelude.yo +3094 -0
  203. package/std/string/index.yo +8 -0
  204. package/std/string/rune.yo +82 -0
  205. package/std/string/string.yo +288 -0
  206. package/std/sync.yo +95 -0
  207. package/std/thread.yo +36 -0
  208. package/std/time.yo +13 -0
  209. package/std/worker.yo +36 -0
  210. package/vendor/mimalloc/.gitattributes +12 -0
  211. package/vendor/mimalloc/CMakeLists.txt +763 -0
  212. package/vendor/mimalloc/LICENSE +21 -0
  213. package/vendor/mimalloc/SECURITY.md +41 -0
  214. package/vendor/mimalloc/azure-pipelines.yml +251 -0
  215. package/vendor/mimalloc/bin/mimalloc-redirect-arm64.dll +0 -0
  216. package/vendor/mimalloc/bin/mimalloc-redirect-arm64.lib +0 -0
  217. package/vendor/mimalloc/bin/mimalloc-redirect-arm64ec.dll +0 -0
  218. package/vendor/mimalloc/bin/mimalloc-redirect-arm64ec.lib +0 -0
  219. package/vendor/mimalloc/bin/mimalloc-redirect.dll +0 -0
  220. package/vendor/mimalloc/bin/mimalloc-redirect.lib +0 -0
  221. package/vendor/mimalloc/bin/mimalloc-redirect32.dll +0 -0
  222. package/vendor/mimalloc/bin/mimalloc-redirect32.lib +0 -0
  223. package/vendor/mimalloc/bin/minject-arm64.exe +0 -0
  224. package/vendor/mimalloc/bin/minject.exe +0 -0
  225. package/vendor/mimalloc/bin/minject32.exe +0 -0
  226. package/vendor/mimalloc/bin/readme.md +118 -0
  227. package/vendor/mimalloc/cmake/JoinPaths.cmake +23 -0
  228. package/vendor/mimalloc/cmake/mimalloc-config-version.cmake +19 -0
  229. package/vendor/mimalloc/cmake/mimalloc-config.cmake +14 -0
  230. package/vendor/mimalloc/contrib/docker/alpine/Dockerfile +23 -0
  231. package/vendor/mimalloc/contrib/docker/alpine-arm32v7/Dockerfile +28 -0
  232. package/vendor/mimalloc/contrib/docker/alpine-x86/Dockerfile +28 -0
  233. package/vendor/mimalloc/contrib/docker/manylinux-x64/Dockerfile +23 -0
  234. package/vendor/mimalloc/contrib/docker/readme.md +10 -0
  235. package/vendor/mimalloc/contrib/vcpkg/portfile.cmake +64 -0
  236. package/vendor/mimalloc/contrib/vcpkg/readme.md +40 -0
  237. package/vendor/mimalloc/contrib/vcpkg/usage +20 -0
  238. package/vendor/mimalloc/contrib/vcpkg/vcpkg-cmake-wrapper.cmake +20 -0
  239. package/vendor/mimalloc/contrib/vcpkg/vcpkg.json +48 -0
  240. package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-a.svg +887 -0
  241. package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-b.svg +1185 -0
  242. package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-rss-a.svg +757 -0
  243. package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-rss-b.svg +1028 -0
  244. package/vendor/mimalloc/doc/bench-2020/bench-r5a-1.svg +769 -0
  245. package/vendor/mimalloc/doc/bench-2020/bench-r5a-12xlarge-2020-01-16-a.svg +868 -0
  246. package/vendor/mimalloc/doc/bench-2020/bench-r5a-12xlarge-2020-01-16-b.svg +1157 -0
  247. package/vendor/mimalloc/doc/bench-2020/bench-r5a-2.svg +983 -0
  248. package/vendor/mimalloc/doc/bench-2020/bench-r5a-rss-1.svg +683 -0
  249. package/vendor/mimalloc/doc/bench-2020/bench-r5a-rss-2.svg +854 -0
  250. package/vendor/mimalloc/doc/bench-2020/bench-spec-rss.svg +713 -0
  251. package/vendor/mimalloc/doc/bench-2020/bench-spec.svg +713 -0
  252. package/vendor/mimalloc/doc/bench-2020/bench-z4-1.svg +890 -0
  253. package/vendor/mimalloc/doc/bench-2020/bench-z4-2.svg +1146 -0
  254. package/vendor/mimalloc/doc/bench-2020/bench-z4-rss-1.svg +796 -0
  255. package/vendor/mimalloc/doc/bench-2020/bench-z4-rss-2.svg +974 -0
  256. package/vendor/mimalloc/doc/bench-2021/bench-amd5950x-2021-01-30-a.svg +952 -0
  257. package/vendor/mimalloc/doc/bench-2021/bench-amd5950x-2021-01-30-b.svg +1255 -0
  258. package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-a.svg +955 -0
  259. package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-b.svg +1269 -0
  260. package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-rss-a.svg +836 -0
  261. package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-rss-b.svg +1131 -0
  262. package/vendor/mimalloc/doc/bench-2021/bench-macmini-2021-01-30.svg +766 -0
  263. package/vendor/mimalloc/doc/doxyfile +2895 -0
  264. package/vendor/mimalloc/doc/ds-logo.jpg +0 -0
  265. package/vendor/mimalloc/doc/ds-logo.png +0 -0
  266. package/vendor/mimalloc/doc/mimalloc-doc.h +1452 -0
  267. package/vendor/mimalloc/doc/mimalloc-doxygen.css +60 -0
  268. package/vendor/mimalloc/doc/mimalloc-logo-100.png +0 -0
  269. package/vendor/mimalloc/doc/mimalloc-logo.png +0 -0
  270. package/vendor/mimalloc/doc/mimalloc-logo.svg +161 -0
  271. package/vendor/mimalloc/doc/spades-logo.png +0 -0
  272. package/vendor/mimalloc/doc/unreal-logo.svg +43 -0
  273. package/vendor/mimalloc/ide/vs2022/mimalloc-lib.vcxproj +500 -0
  274. package/vendor/mimalloc/ide/vs2022/mimalloc-lib.vcxproj.filters +108 -0
  275. package/vendor/mimalloc/ide/vs2022/mimalloc-override-dll.vcxproj +508 -0
  276. package/vendor/mimalloc/ide/vs2022/mimalloc-override-dll.vcxproj.filters +111 -0
  277. package/vendor/mimalloc/ide/vs2022/mimalloc-override-test-dep.vcxproj +355 -0
  278. package/vendor/mimalloc/ide/vs2022/mimalloc-override-test.vcxproj +360 -0
  279. package/vendor/mimalloc/ide/vs2022/mimalloc-test-api.vcxproj +295 -0
  280. package/vendor/mimalloc/ide/vs2022/mimalloc-test-stress.vcxproj +292 -0
  281. package/vendor/mimalloc/ide/vs2022/mimalloc-test.vcxproj +289 -0
  282. package/vendor/mimalloc/ide/vs2022/mimalloc.sln +151 -0
  283. package/vendor/mimalloc/include/mimalloc/atomic.h +557 -0
  284. package/vendor/mimalloc/include/mimalloc/internal.h +1153 -0
  285. package/vendor/mimalloc/include/mimalloc/prim.h +421 -0
  286. package/vendor/mimalloc/include/mimalloc/track.h +145 -0
  287. package/vendor/mimalloc/include/mimalloc/types.h +685 -0
  288. package/vendor/mimalloc/include/mimalloc-new-delete.h +66 -0
  289. package/vendor/mimalloc/include/mimalloc-override.h +68 -0
  290. package/vendor/mimalloc/include/mimalloc-stats.h +103 -0
  291. package/vendor/mimalloc/include/mimalloc.h +612 -0
  292. package/vendor/mimalloc/mimalloc.pc.in +11 -0
  293. package/vendor/mimalloc/readme.md +946 -0
  294. package/vendor/mimalloc/src/alloc-aligned.c +360 -0
  295. package/vendor/mimalloc/src/alloc-override.c +316 -0
  296. package/vendor/mimalloc/src/alloc-posix.c +185 -0
  297. package/vendor/mimalloc/src/alloc.c +692 -0
  298. package/vendor/mimalloc/src/arena-abandon.c +346 -0
  299. package/vendor/mimalloc/src/arena.c +1043 -0
  300. package/vendor/mimalloc/src/bitmap.c +441 -0
  301. package/vendor/mimalloc/src/bitmap.h +119 -0
  302. package/vendor/mimalloc/src/free.c +572 -0
  303. package/vendor/mimalloc/src/heap.c +733 -0
  304. package/vendor/mimalloc/src/init.c +714 -0
  305. package/vendor/mimalloc/src/libc.c +334 -0
  306. package/vendor/mimalloc/src/options.c +663 -0
  307. package/vendor/mimalloc/src/os.c +770 -0
  308. package/vendor/mimalloc/src/page-queue.c +390 -0
  309. package/vendor/mimalloc/src/page.c +1049 -0
  310. package/vendor/mimalloc/src/prim/emscripten/prim.c +249 -0
  311. package/vendor/mimalloc/src/prim/osx/alloc-override-zone.c +461 -0
  312. package/vendor/mimalloc/src/prim/osx/prim.c +9 -0
  313. package/vendor/mimalloc/src/prim/prim.c +76 -0
  314. package/vendor/mimalloc/src/prim/readme.md +9 -0
  315. package/vendor/mimalloc/src/prim/unix/prim.c +934 -0
  316. package/vendor/mimalloc/src/prim/wasi/prim.c +284 -0
  317. package/vendor/mimalloc/src/prim/windows/etw-mimalloc.wprp +61 -0
  318. package/vendor/mimalloc/src/prim/windows/etw.h +905 -0
  319. package/vendor/mimalloc/src/prim/windows/etw.man +0 -0
  320. package/vendor/mimalloc/src/prim/windows/prim.c +878 -0
  321. package/vendor/mimalloc/src/prim/windows/readme.md +17 -0
  322. package/vendor/mimalloc/src/random.c +258 -0
  323. package/vendor/mimalloc/src/segment-map.c +142 -0
  324. package/vendor/mimalloc/src/segment.c +1702 -0
  325. package/vendor/mimalloc/src/static.c +41 -0
  326. package/vendor/mimalloc/src/stats.c +635 -0
  327. package/vendor/mimalloc/test/CMakeLists.txt +56 -0
  328. package/vendor/mimalloc/test/main-override-dep.cpp +51 -0
  329. package/vendor/mimalloc/test/main-override-dep.h +11 -0
  330. package/vendor/mimalloc/test/main-override-static.c +539 -0
  331. package/vendor/mimalloc/test/main-override.c +36 -0
  332. package/vendor/mimalloc/test/main-override.cpp +497 -0
  333. package/vendor/mimalloc/test/main.c +46 -0
  334. package/vendor/mimalloc/test/readme.md +16 -0
  335. package/vendor/mimalloc/test/test-api-fill.c +343 -0
  336. package/vendor/mimalloc/test/test-api.c +466 -0
  337. package/vendor/mimalloc/test/test-stress.c +428 -0
  338. package/vendor/mimalloc/test/test-wrong.c +92 -0
  339. package/vendor/mimalloc/test/testhelper.h +49 -0
@@ -0,0 +1,360 @@
1
+ /* ----------------------------------------------------------------------------
2
+ Copyright (c) 2018-2021, Microsoft Research, Daan Leijen
3
+ This is free software; you can redistribute it and/or modify it under the
4
+ terms of the MIT license. A copy of the license can be found in the file
5
+ "LICENSE" at the root of this distribution.
6
+ -----------------------------------------------------------------------------*/
7
+
8
+ #include "mimalloc.h"
9
+ #include "mimalloc/internal.h"
10
+ #include "mimalloc/prim.h" // mi_prim_get_default_heap
11
+
12
+ #include <string.h> // memset
13
+
14
+ // ------------------------------------------------------
15
+ // Aligned Allocation
16
+ // ------------------------------------------------------
17
+
18
+ static bool mi_malloc_is_naturally_aligned( size_t size, size_t alignment ) {
19
+ // objects up to `MI_MAX_ALIGN_GUARANTEE` are allocated aligned to their size (see `segment.c:_mi_segment_page_start`).
20
+ mi_assert_internal(_mi_is_power_of_two(alignment) && (alignment > 0));
21
+ if (alignment > size) return false;
22
+ if (alignment <= MI_MAX_ALIGN_SIZE) return true;
23
+ const size_t bsize = mi_good_size(size);
24
+ return (bsize <= MI_MAX_ALIGN_GUARANTEE && (bsize & (alignment-1)) == 0);
25
+ }
26
+
27
+ #if MI_GUARDED
28
+ static mi_decl_restrict void* mi_heap_malloc_guarded_aligned(mi_heap_t* heap, size_t size, size_t alignment, bool zero) mi_attr_noexcept {
29
+ // use over allocation for guarded blocksl
30
+ mi_assert_internal(alignment > 0 && alignment < MI_BLOCK_ALIGNMENT_MAX);
31
+ const size_t oversize = size + alignment - 1;
32
+ void* base = _mi_heap_malloc_guarded(heap, oversize, zero);
33
+ void* p = mi_align_up_ptr(base, alignment);
34
+ mi_track_align(base, p, (uint8_t*)p - (uint8_t*)base, size);
35
+ mi_assert_internal(mi_usable_size(p) >= size);
36
+ mi_assert_internal(_mi_is_aligned(p, alignment));
37
+ return p;
38
+ }
39
+
40
+ static void* mi_heap_malloc_zero_no_guarded(mi_heap_t* heap, size_t size, bool zero) {
41
+ const size_t rate = heap->guarded_sample_rate;
42
+ // only write if `rate!=0` so we don't write to the constant `_mi_heap_empty`
43
+ if (rate != 0) { heap->guarded_sample_rate = 0; }
44
+ void* p = _mi_heap_malloc_zero(heap, size, zero);
45
+ if (rate != 0) { heap->guarded_sample_rate = rate; }
46
+ return p;
47
+ }
48
+ #else
49
+ static void* mi_heap_malloc_zero_no_guarded(mi_heap_t* heap, size_t size, bool zero) {
50
+ return _mi_heap_malloc_zero(heap, size, zero);
51
+ }
52
+ #endif
53
+
54
+ // Fallback aligned allocation that over-allocates -- split out for better codegen
55
+ static mi_decl_noinline void* mi_heap_malloc_zero_aligned_at_overalloc(mi_heap_t* const heap, const size_t size, const size_t alignment, const size_t offset, const bool zero) mi_attr_noexcept
56
+ {
57
+ mi_assert_internal(size <= (MI_MAX_ALLOC_SIZE - MI_PADDING_SIZE));
58
+ mi_assert_internal(alignment != 0 && _mi_is_power_of_two(alignment));
59
+
60
+ void* p;
61
+ size_t oversize;
62
+ if mi_unlikely(alignment > MI_BLOCK_ALIGNMENT_MAX) {
63
+ // use OS allocation for very large alignment and allocate inside a huge page (dedicated segment with 1 page)
64
+ // This can support alignments >= MI_SEGMENT_SIZE by ensuring the object can be aligned at a point in the
65
+ // first (and single) page such that the segment info is `MI_SEGMENT_SIZE` bytes before it (so it can be found by aligning the pointer down)
66
+ if mi_unlikely(offset != 0) {
67
+ // todo: cannot support offset alignment for very large alignments yet
68
+ #if MI_DEBUG > 0
69
+ _mi_error_message(EOVERFLOW, "aligned allocation with a very large alignment cannot be used with an alignment offset (size %zu, alignment %zu, offset %zu)\n", size, alignment, offset);
70
+ #endif
71
+ return NULL;
72
+ }
73
+ oversize = (size <= MI_SMALL_SIZE_MAX ? MI_SMALL_SIZE_MAX + 1 /* ensure we use generic malloc path */ : size);
74
+ // note: no guarded as alignment > 0
75
+ p = _mi_heap_malloc_zero_ex(heap, oversize, false, alignment); // the page block size should be large enough to align in the single huge page block
76
+ // zero afterwards as only the area from the aligned_p may be committed!
77
+ if (p == NULL) return NULL;
78
+ }
79
+ else {
80
+ // otherwise over-allocate
81
+ oversize = (size < MI_MAX_ALIGN_SIZE ? MI_MAX_ALIGN_SIZE : size) + alignment - 1; // adjust for size <= 16; with size 0 and aligment 64k, we would allocate a 64k block and pointing just beyond that.
82
+ p = mi_heap_malloc_zero_no_guarded(heap, oversize, zero);
83
+ if (p == NULL) return NULL;
84
+ }
85
+ mi_page_t* page = _mi_ptr_page(p);
86
+
87
+ // .. and align within the allocation
88
+ const uintptr_t align_mask = alignment - 1; // for any x, `(x & align_mask) == (x % alignment)`
89
+ const uintptr_t poffset = ((uintptr_t)p + offset) & align_mask;
90
+ const uintptr_t adjust = (poffset == 0 ? 0 : alignment - poffset);
91
+ mi_assert_internal(adjust < alignment);
92
+ void* aligned_p = (void*)((uintptr_t)p + adjust);
93
+ if (aligned_p != p) {
94
+ mi_page_set_has_aligned(page, true);
95
+ #if MI_GUARDED
96
+ // set tag to aligned so mi_usable_size works with guard pages
97
+ if (adjust >= sizeof(mi_block_t)) {
98
+ mi_block_t* const block = (mi_block_t*)p;
99
+ block->next = MI_BLOCK_TAG_ALIGNED;
100
+ }
101
+ #endif
102
+ _mi_padding_shrink(page, (mi_block_t*)p, adjust + size);
103
+ }
104
+ // todo: expand padding if overallocated ?
105
+
106
+ mi_assert_internal(mi_page_usable_block_size(page) >= adjust + size);
107
+ mi_assert_internal(((uintptr_t)aligned_p + offset) % alignment == 0);
108
+ mi_assert_internal(mi_usable_size(aligned_p)>=size);
109
+ mi_assert_internal(mi_usable_size(p) == mi_usable_size(aligned_p)+adjust);
110
+ #if MI_DEBUG > 1
111
+ mi_page_t* const apage = _mi_ptr_page(aligned_p);
112
+ void* unalign_p = _mi_page_ptr_unalign(apage, aligned_p);
113
+ mi_assert_internal(p == unalign_p);
114
+ #endif
115
+
116
+ // now zero the block if needed
117
+ if (alignment > MI_BLOCK_ALIGNMENT_MAX) {
118
+ // for the tracker, on huge aligned allocations only the memory from the start of the large block is defined
119
+ mi_track_mem_undefined(aligned_p, size);
120
+ if (zero) {
121
+ _mi_memzero_aligned(aligned_p, mi_usable_size(aligned_p));
122
+ }
123
+ }
124
+
125
+ if (p != aligned_p) {
126
+ mi_track_align(p,aligned_p,adjust,mi_usable_size(aligned_p));
127
+ #if MI_GUARDED
128
+ mi_track_mem_defined(p, sizeof(mi_block_t));
129
+ #endif
130
+ }
131
+ return aligned_p;
132
+ }
133
+
134
+ // Generic primitive aligned allocation -- split out for better codegen
135
+ static mi_decl_noinline void* mi_heap_malloc_zero_aligned_at_generic(mi_heap_t* const heap, const size_t size, const size_t alignment, const size_t offset, const bool zero) mi_attr_noexcept
136
+ {
137
+ mi_assert_internal(alignment != 0 && _mi_is_power_of_two(alignment));
138
+ // we don't allocate more than MI_MAX_ALLOC_SIZE (see <https://sourceware.org/ml/libc-announce/2019/msg00001.html>)
139
+ if mi_unlikely(size > (MI_MAX_ALLOC_SIZE - MI_PADDING_SIZE)) {
140
+ #if MI_DEBUG > 0
141
+ _mi_error_message(EOVERFLOW, "aligned allocation request is too large (size %zu, alignment %zu)\n", size, alignment);
142
+ #endif
143
+ return NULL;
144
+ }
145
+
146
+ // use regular allocation if it is guaranteed to fit the alignment constraints.
147
+ // this is important to try as the fast path in `mi_heap_malloc_zero_aligned` only works when there exist
148
+ // a page with the right block size, and if we always use the over-alloc fallback that would never happen.
149
+ if (offset == 0 && mi_malloc_is_naturally_aligned(size,alignment)) {
150
+ void* p = mi_heap_malloc_zero_no_guarded(heap, size, zero);
151
+ mi_assert_internal(p == NULL || ((uintptr_t)p % alignment) == 0);
152
+ const bool is_aligned_or_null = (((uintptr_t)p) & (alignment-1))==0;
153
+ if mi_likely(is_aligned_or_null) {
154
+ return p;
155
+ }
156
+ else {
157
+ // this should never happen if the `mi_malloc_is_naturally_aligned` check is correct..
158
+ mi_assert(false);
159
+ mi_free(p);
160
+ }
161
+ }
162
+
163
+ // fall back to over-allocation
164
+ return mi_heap_malloc_zero_aligned_at_overalloc(heap,size,alignment,offset,zero);
165
+ }
166
+
167
+
168
+ // Primitive aligned allocation
169
+ static void* mi_heap_malloc_zero_aligned_at(mi_heap_t* const heap, const size_t size, const size_t alignment, const size_t offset, const bool zero) mi_attr_noexcept
170
+ {
171
+ // note: we don't require `size > offset`, we just guarantee that the address at offset is aligned regardless of the allocated size.
172
+ if mi_unlikely(alignment == 0 || !_mi_is_power_of_two(alignment)) { // require power-of-two (see <https://en.cppreference.com/w/c/memory/aligned_alloc>)
173
+ #if MI_DEBUG > 0
174
+ _mi_error_message(EOVERFLOW, "aligned allocation requires the alignment to be a power-of-two (size %zu, alignment %zu)\n", size, alignment);
175
+ #endif
176
+ return NULL;
177
+ }
178
+
179
+ #if MI_GUARDED
180
+ if (offset==0 && alignment < MI_BLOCK_ALIGNMENT_MAX && mi_heap_malloc_use_guarded(heap,size)) {
181
+ return mi_heap_malloc_guarded_aligned(heap, size, alignment, zero);
182
+ }
183
+ #endif
184
+
185
+ // try first if there happens to be a small block available with just the right alignment
186
+ if mi_likely(size <= MI_SMALL_SIZE_MAX && alignment <= size) {
187
+ const uintptr_t align_mask = alignment-1; // for any x, `(x & align_mask) == (x % alignment)`
188
+ const size_t padsize = size + MI_PADDING_SIZE;
189
+ mi_page_t* page = _mi_heap_get_free_small_page(heap, padsize);
190
+ if mi_likely(page->free != NULL) {
191
+ const bool is_aligned = (((uintptr_t)page->free + offset) & align_mask)==0;
192
+ if mi_likely(is_aligned)
193
+ {
194
+ void* p = (zero ? _mi_page_malloc_zeroed(heap,page,padsize) : _mi_page_malloc(heap,page,padsize)); // call specific page malloc for better codegen
195
+ mi_assert_internal(p != NULL);
196
+ mi_assert_internal(((uintptr_t)p + offset) % alignment == 0);
197
+ mi_track_malloc(p,size,zero);
198
+ return p;
199
+ }
200
+ }
201
+ }
202
+
203
+ // fallback to generic aligned allocation
204
+ return mi_heap_malloc_zero_aligned_at_generic(heap, size, alignment, offset, zero);
205
+ }
206
+
207
+
208
+ // ------------------------------------------------------
209
+ // Optimized mi_heap_malloc_aligned / mi_malloc_aligned
210
+ // ------------------------------------------------------
211
+
212
+ mi_decl_nodiscard mi_decl_restrict void* mi_heap_malloc_aligned_at(mi_heap_t* heap, size_t size, size_t alignment, size_t offset) mi_attr_noexcept {
213
+ return mi_heap_malloc_zero_aligned_at(heap, size, alignment, offset, false);
214
+ }
215
+
216
+ mi_decl_nodiscard mi_decl_restrict void* mi_heap_malloc_aligned(mi_heap_t* heap, size_t size, size_t alignment) mi_attr_noexcept {
217
+ return mi_heap_malloc_aligned_at(heap, size, alignment, 0);
218
+ }
219
+
220
+ // ensure a definition is emitted
221
+ #if defined(__cplusplus)
222
+ void* _mi_extern_heap_malloc_aligned = (void*)&mi_heap_malloc_aligned;
223
+ #endif
224
+
225
+ // ------------------------------------------------------
226
+ // Aligned Allocation
227
+ // ------------------------------------------------------
228
+
229
+ mi_decl_nodiscard mi_decl_restrict void* mi_heap_zalloc_aligned_at(mi_heap_t* heap, size_t size, size_t alignment, size_t offset) mi_attr_noexcept {
230
+ return mi_heap_malloc_zero_aligned_at(heap, size, alignment, offset, true);
231
+ }
232
+
233
+ mi_decl_nodiscard mi_decl_restrict void* mi_heap_zalloc_aligned(mi_heap_t* heap, size_t size, size_t alignment) mi_attr_noexcept {
234
+ return mi_heap_zalloc_aligned_at(heap, size, alignment, 0);
235
+ }
236
+
237
+ mi_decl_nodiscard mi_decl_restrict void* mi_heap_calloc_aligned_at(mi_heap_t* heap, size_t count, size_t size, size_t alignment, size_t offset) mi_attr_noexcept {
238
+ size_t total;
239
+ if (mi_count_size_overflow(count, size, &total)) return NULL;
240
+ return mi_heap_zalloc_aligned_at(heap, total, alignment, offset);
241
+ }
242
+
243
+ mi_decl_nodiscard mi_decl_restrict void* mi_heap_calloc_aligned(mi_heap_t* heap, size_t count, size_t size, size_t alignment) mi_attr_noexcept {
244
+ return mi_heap_calloc_aligned_at(heap,count,size,alignment,0);
245
+ }
246
+
247
+ mi_decl_nodiscard mi_decl_restrict void* mi_malloc_aligned_at(size_t size, size_t alignment, size_t offset) mi_attr_noexcept {
248
+ return mi_heap_malloc_aligned_at(mi_prim_get_default_heap(), size, alignment, offset);
249
+ }
250
+
251
+ mi_decl_nodiscard mi_decl_restrict void* mi_malloc_aligned(size_t size, size_t alignment) mi_attr_noexcept {
252
+ return mi_heap_malloc_aligned(mi_prim_get_default_heap(), size, alignment);
253
+ }
254
+
255
+ mi_decl_nodiscard mi_decl_restrict void* mi_zalloc_aligned_at(size_t size, size_t alignment, size_t offset) mi_attr_noexcept {
256
+ return mi_heap_zalloc_aligned_at(mi_prim_get_default_heap(), size, alignment, offset);
257
+ }
258
+
259
+ mi_decl_nodiscard mi_decl_restrict void* mi_zalloc_aligned(size_t size, size_t alignment) mi_attr_noexcept {
260
+ return mi_heap_zalloc_aligned(mi_prim_get_default_heap(), size, alignment);
261
+ }
262
+
263
+ mi_decl_nodiscard mi_decl_restrict void* mi_calloc_aligned_at(size_t count, size_t size, size_t alignment, size_t offset) mi_attr_noexcept {
264
+ return mi_heap_calloc_aligned_at(mi_prim_get_default_heap(), count, size, alignment, offset);
265
+ }
266
+
267
+ mi_decl_nodiscard mi_decl_restrict void* mi_calloc_aligned(size_t count, size_t size, size_t alignment) mi_attr_noexcept {
268
+ return mi_heap_calloc_aligned(mi_prim_get_default_heap(), count, size, alignment);
269
+ }
270
+
271
+
272
+ // ------------------------------------------------------
273
+ // Aligned re-allocation
274
+ // ------------------------------------------------------
275
+
276
+ static void* mi_heap_realloc_zero_aligned_at(mi_heap_t* heap, void* p, size_t newsize, size_t alignment, size_t offset, bool zero) mi_attr_noexcept {
277
+ mi_assert(alignment > 0);
278
+ if (alignment <= sizeof(uintptr_t)) return _mi_heap_realloc_zero(heap,p,newsize,zero);
279
+ if (p == NULL) return mi_heap_malloc_zero_aligned_at(heap,newsize,alignment,offset,zero);
280
+ size_t size = mi_usable_size(p);
281
+ if (newsize <= size && newsize >= (size - (size / 2))
282
+ && (((uintptr_t)p + offset) % alignment) == 0) {
283
+ return p; // reallocation still fits, is aligned and not more than 50% waste
284
+ }
285
+ else {
286
+ // note: we don't zero allocate upfront so we only zero initialize the expanded part
287
+ void* newp = mi_heap_malloc_aligned_at(heap,newsize,alignment,offset);
288
+ if (newp != NULL) {
289
+ if (zero && newsize > size) {
290
+ // also set last word in the previous allocation to zero to ensure any padding is zero-initialized
291
+ size_t start = (size >= sizeof(intptr_t) ? size - sizeof(intptr_t) : 0);
292
+ _mi_memzero((uint8_t*)newp + start, newsize - start);
293
+ }
294
+ _mi_memcpy_aligned(newp, p, (newsize > size ? size : newsize));
295
+ mi_free(p); // only free if successful
296
+ }
297
+ return newp;
298
+ }
299
+ }
300
+
301
+ static void* mi_heap_realloc_zero_aligned(mi_heap_t* heap, void* p, size_t newsize, size_t alignment, bool zero) mi_attr_noexcept {
302
+ mi_assert(alignment > 0);
303
+ if (alignment <= sizeof(uintptr_t)) return _mi_heap_realloc_zero(heap,p,newsize,zero);
304
+ size_t offset = ((uintptr_t)p % alignment); // use offset of previous allocation (p can be NULL)
305
+ return mi_heap_realloc_zero_aligned_at(heap,p,newsize,alignment,offset,zero);
306
+ }
307
+
308
+ mi_decl_nodiscard void* mi_heap_realloc_aligned_at(mi_heap_t* heap, void* p, size_t newsize, size_t alignment, size_t offset) mi_attr_noexcept {
309
+ return mi_heap_realloc_zero_aligned_at(heap,p,newsize,alignment,offset,false);
310
+ }
311
+
312
+ mi_decl_nodiscard void* mi_heap_realloc_aligned(mi_heap_t* heap, void* p, size_t newsize, size_t alignment) mi_attr_noexcept {
313
+ return mi_heap_realloc_zero_aligned(heap,p,newsize,alignment,false);
314
+ }
315
+
316
+ mi_decl_nodiscard void* mi_heap_rezalloc_aligned_at(mi_heap_t* heap, void* p, size_t newsize, size_t alignment, size_t offset) mi_attr_noexcept {
317
+ return mi_heap_realloc_zero_aligned_at(heap, p, newsize, alignment, offset, true);
318
+ }
319
+
320
+ mi_decl_nodiscard void* mi_heap_rezalloc_aligned(mi_heap_t* heap, void* p, size_t newsize, size_t alignment) mi_attr_noexcept {
321
+ return mi_heap_realloc_zero_aligned(heap, p, newsize, alignment, true);
322
+ }
323
+
324
+ mi_decl_nodiscard void* mi_heap_recalloc_aligned_at(mi_heap_t* heap, void* p, size_t newcount, size_t size, size_t alignment, size_t offset) mi_attr_noexcept {
325
+ size_t total;
326
+ if (mi_count_size_overflow(newcount, size, &total)) return NULL;
327
+ return mi_heap_rezalloc_aligned_at(heap, p, total, alignment, offset);
328
+ }
329
+
330
+ mi_decl_nodiscard void* mi_heap_recalloc_aligned(mi_heap_t* heap, void* p, size_t newcount, size_t size, size_t alignment) mi_attr_noexcept {
331
+ size_t total;
332
+ if (mi_count_size_overflow(newcount, size, &total)) return NULL;
333
+ return mi_heap_rezalloc_aligned(heap, p, total, alignment);
334
+ }
335
+
336
+ mi_decl_nodiscard void* mi_realloc_aligned_at(void* p, size_t newsize, size_t alignment, size_t offset) mi_attr_noexcept {
337
+ return mi_heap_realloc_aligned_at(mi_prim_get_default_heap(), p, newsize, alignment, offset);
338
+ }
339
+
340
+ mi_decl_nodiscard void* mi_realloc_aligned(void* p, size_t newsize, size_t alignment) mi_attr_noexcept {
341
+ return mi_heap_realloc_aligned(mi_prim_get_default_heap(), p, newsize, alignment);
342
+ }
343
+
344
+ mi_decl_nodiscard void* mi_rezalloc_aligned_at(void* p, size_t newsize, size_t alignment, size_t offset) mi_attr_noexcept {
345
+ return mi_heap_rezalloc_aligned_at(mi_prim_get_default_heap(), p, newsize, alignment, offset);
346
+ }
347
+
348
+ mi_decl_nodiscard void* mi_rezalloc_aligned(void* p, size_t newsize, size_t alignment) mi_attr_noexcept {
349
+ return mi_heap_rezalloc_aligned(mi_prim_get_default_heap(), p, newsize, alignment);
350
+ }
351
+
352
+ mi_decl_nodiscard void* mi_recalloc_aligned_at(void* p, size_t newcount, size_t size, size_t alignment, size_t offset) mi_attr_noexcept {
353
+ return mi_heap_recalloc_aligned_at(mi_prim_get_default_heap(), p, newcount, size, alignment, offset);
354
+ }
355
+
356
+ mi_decl_nodiscard void* mi_recalloc_aligned(void* p, size_t newcount, size_t size, size_t alignment) mi_attr_noexcept {
357
+ return mi_heap_recalloc_aligned(mi_prim_get_default_heap(), p, newcount, size, alignment);
358
+ }
359
+
360
+
@@ -0,0 +1,316 @@
1
+ /* ----------------------------------------------------------------------------
2
+ Copyright (c) 2018-2021, Microsoft Research, Daan Leijen
3
+ This is free software; you can redistribute it and/or modify it under the
4
+ terms of the MIT license. A copy of the license can be found in the file
5
+ "LICENSE" at the root of this distribution.
6
+ -----------------------------------------------------------------------------*/
7
+
8
+ #if !defined(MI_IN_ALLOC_C)
9
+ #error "this file should be included from 'alloc.c' (so aliases can work)"
10
+ #endif
11
+
12
+ #if defined(MI_MALLOC_OVERRIDE) && defined(_WIN32) && !(defined(MI_SHARED_LIB) && defined(_DLL))
13
+ #error "It is only possible to override "malloc" on Windows when building as a DLL (and linking the C runtime as a DLL)"
14
+ #endif
15
+
16
+ #if defined(MI_MALLOC_OVERRIDE) && !(defined(_WIN32))
17
+
18
+ #if defined(__APPLE__)
19
+ #include <AvailabilityMacros.h>
20
+ mi_decl_externc void vfree(void* p);
21
+ mi_decl_externc size_t malloc_size(const void* p);
22
+ mi_decl_externc size_t malloc_good_size(size_t size);
23
+ #endif
24
+
25
+ // helper definition for C override of C++ new
26
+ typedef void* mi_nothrow_t;
27
+
28
+ // ------------------------------------------------------
29
+ // Override system malloc
30
+ // ------------------------------------------------------
31
+
32
+ #if (defined(__GNUC__) || defined(__clang__)) && !defined(__APPLE__) && !MI_TRACK_ENABLED
33
+ // gcc, clang: use aliasing to alias the exported function to one of our `mi_` functions
34
+ #if (defined(__GNUC__) && __GNUC__ >= 9)
35
+ #pragma GCC diagnostic ignored "-Wattributes" // or we get warnings that nodiscard is ignored on a forward
36
+ #define MI_FORWARD(fun) __attribute__((alias(#fun), used, visibility("default"), copy(fun)));
37
+ #else
38
+ #define MI_FORWARD(fun) __attribute__((alias(#fun), used, visibility("default")));
39
+ #endif
40
+ #define MI_FORWARD1(fun,x) MI_FORWARD(fun)
41
+ #define MI_FORWARD2(fun,x,y) MI_FORWARD(fun)
42
+ #define MI_FORWARD3(fun,x,y,z) MI_FORWARD(fun)
43
+ #define MI_FORWARD0(fun,x) MI_FORWARD(fun)
44
+ #define MI_FORWARD02(fun,x,y) MI_FORWARD(fun)
45
+ #else
46
+ // otherwise use forwarding by calling our `mi_` function
47
+ #define MI_FORWARD1(fun,x) { return fun(x); }
48
+ #define MI_FORWARD2(fun,x,y) { return fun(x,y); }
49
+ #define MI_FORWARD3(fun,x,y,z) { return fun(x,y,z); }
50
+ #define MI_FORWARD0(fun,x) { fun(x); }
51
+ #define MI_FORWARD02(fun,x,y) { fun(x,y); }
52
+ #endif
53
+
54
+
55
+ #if defined(__APPLE__) && defined(MI_SHARED_LIB_EXPORT) && defined(MI_OSX_INTERPOSE)
56
+ // define MI_OSX_IS_INTERPOSED as we should not provide forwarding definitions for
57
+ // functions that are interposed (or the interposing does not work)
58
+ #define MI_OSX_IS_INTERPOSED
59
+
60
+ mi_decl_externc size_t mi_malloc_size_checked(void *p) {
61
+ if (!mi_is_in_heap_region(p)) return 0;
62
+ return mi_usable_size(p);
63
+ }
64
+
65
+ // use interposing so `DYLD_INSERT_LIBRARIES` works without `DYLD_FORCE_FLAT_NAMESPACE=1`
66
+ // See: <https://books.google.com/books?id=K8vUkpOXhN4C&pg=PA73>
67
+ struct mi_interpose_s {
68
+ const void* replacement;
69
+ const void* target;
70
+ };
71
+ #define MI_INTERPOSE_FUN(oldfun,newfun) { (const void*)&newfun, (const void*)&oldfun }
72
+ #define MI_INTERPOSE_MI(fun) MI_INTERPOSE_FUN(fun,mi_##fun)
73
+
74
+ #define MI_INTERPOSE_DECLS(name) __attribute__((used)) static struct mi_interpose_s name[] __attribute__((section("__DATA, __interpose")))
75
+
76
+ MI_INTERPOSE_DECLS(_mi_interposes) =
77
+ {
78
+ MI_INTERPOSE_MI(malloc),
79
+ MI_INTERPOSE_MI(calloc),
80
+ MI_INTERPOSE_MI(realloc),
81
+ MI_INTERPOSE_MI(strdup),
82
+ MI_INTERPOSE_MI(realpath),
83
+ MI_INTERPOSE_MI(posix_memalign),
84
+ MI_INTERPOSE_MI(reallocf),
85
+ MI_INTERPOSE_MI(valloc),
86
+ MI_INTERPOSE_FUN(malloc_size,mi_malloc_size_checked),
87
+ MI_INTERPOSE_MI(malloc_good_size),
88
+ #ifdef MI_OSX_ZONE
89
+ // we interpose malloc_default_zone in alloc-override-osx.c so we can use mi_free safely
90
+ MI_INTERPOSE_MI(free),
91
+ MI_INTERPOSE_FUN(vfree,mi_free),
92
+ #else
93
+ // sometimes code allocates from default zone but deallocates using plain free :-( (like NxHashResizeToCapacity <https://github.com/nneonneo/osx-10.9-opensource/blob/master/objc4-551.1/runtime/hashtable2.mm>)
94
+ MI_INTERPOSE_FUN(free,mi_cfree), // use safe free that checks if pointers are from us
95
+ MI_INTERPOSE_FUN(vfree,mi_cfree),
96
+ #endif
97
+ };
98
+ MI_INTERPOSE_DECLS(_mi_interposes_10_7) __OSX_AVAILABLE(10.7) = {
99
+ MI_INTERPOSE_MI(strndup),
100
+ };
101
+ MI_INTERPOSE_DECLS(_mi_interposes_10_15) __OSX_AVAILABLE(10.15) = {
102
+ MI_INTERPOSE_MI(aligned_alloc),
103
+ };
104
+
105
+ #ifdef __cplusplus
106
+ extern "C" {
107
+ #endif
108
+ void _ZdlPv(void* p); // delete
109
+ void _ZdaPv(void* p); // delete[]
110
+ void _ZdlPvm(void* p, size_t n); // delete
111
+ void _ZdaPvm(void* p, size_t n); // delete[]
112
+ void* _Znwm(size_t n); // new
113
+ void* _Znam(size_t n); // new[]
114
+ void* _ZnwmRKSt9nothrow_t(size_t n, mi_nothrow_t tag); // new nothrow
115
+ void* _ZnamRKSt9nothrow_t(size_t n, mi_nothrow_t tag); // new[] nothrow
116
+ #ifdef __cplusplus
117
+ }
118
+ #endif
119
+ __attribute__((used)) static struct mi_interpose_s _mi_cxx_interposes[] __attribute__((section("__DATA, __interpose"))) =
120
+ {
121
+ MI_INTERPOSE_FUN(_ZdlPv,mi_free),
122
+ MI_INTERPOSE_FUN(_ZdaPv,mi_free),
123
+ MI_INTERPOSE_FUN(_ZdlPvm,mi_free_size),
124
+ MI_INTERPOSE_FUN(_ZdaPvm,mi_free_size),
125
+ MI_INTERPOSE_FUN(_Znwm,mi_new),
126
+ MI_INTERPOSE_FUN(_Znam,mi_new),
127
+ MI_INTERPOSE_FUN(_ZnwmRKSt9nothrow_t,mi_new_nothrow),
128
+ MI_INTERPOSE_FUN(_ZnamRKSt9nothrow_t,mi_new_nothrow),
129
+ };
130
+
131
+ #elif defined(_MSC_VER)
132
+ // cannot override malloc unless using a dll.
133
+ // we just override new/delete which does work in a static library.
134
+ #else
135
+ // On all other systems forward allocation primitives to our API
136
+ mi_decl_export void* malloc(size_t size) MI_FORWARD1(mi_malloc, size)
137
+ mi_decl_export void* calloc(size_t size, size_t n) MI_FORWARD2(mi_calloc, size, n)
138
+ mi_decl_export void* realloc(void* p, size_t newsize) MI_FORWARD2(mi_realloc, p, newsize)
139
+ mi_decl_export void free(void* p) MI_FORWARD0(mi_free, p)
140
+ // In principle we do not need to forward `strdup`/`strndup` but on some systems these do not use `malloc` internally (but a more primitive call)
141
+ // We only override if `strdup` is not a macro (as on some older libc's, see issue #885)
142
+ #if !defined(strdup)
143
+ mi_decl_export char* strdup(const char* str) MI_FORWARD1(mi_strdup, str)
144
+ #endif
145
+ #if !defined(strndup) && (!defined(__APPLE__) || (defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7))
146
+ mi_decl_export char* strndup(const char* str, size_t n) MI_FORWARD2(mi_strndup, str, n)
147
+ #endif
148
+ #endif
149
+
150
+ #if (defined(__GNUC__) || defined(__clang__)) && !defined(__APPLE__)
151
+ #pragma GCC visibility push(default)
152
+ #endif
153
+
154
+ // ------------------------------------------------------
155
+ // Override new/delete
156
+ // This is not really necessary as they usually call
157
+ // malloc/free anyway, but it improves performance.
158
+ // ------------------------------------------------------
159
+ #ifdef __cplusplus
160
+ // ------------------------------------------------------
161
+ // With a C++ compiler we override the new/delete operators.
162
+ // see <https://en.cppreference.com/w/cpp/memory/new/operator_new>
163
+ // ------------------------------------------------------
164
+ #include <new>
165
+
166
+ #ifndef MI_OSX_IS_INTERPOSED
167
+ void operator delete(void* p) noexcept MI_FORWARD0(mi_free,p)
168
+ void operator delete[](void* p) noexcept MI_FORWARD0(mi_free,p)
169
+
170
+ void* operator new(std::size_t n) noexcept(false) MI_FORWARD1(mi_new,n)
171
+ void* operator new[](std::size_t n) noexcept(false) MI_FORWARD1(mi_new,n)
172
+
173
+ void* operator new (std::size_t n, const std::nothrow_t& tag) noexcept { MI_UNUSED(tag); return mi_new_nothrow(n); }
174
+ void* operator new[](std::size_t n, const std::nothrow_t& tag) noexcept { MI_UNUSED(tag); return mi_new_nothrow(n); }
175
+
176
+ #if (__cplusplus >= 201402L || _MSC_VER >= 1916)
177
+ void operator delete (void* p, std::size_t n) noexcept MI_FORWARD02(mi_free_size,p,n)
178
+ void operator delete[](void* p, std::size_t n) noexcept MI_FORWARD02(mi_free_size,p,n)
179
+ #endif
180
+ #endif
181
+
182
+ #if (__cplusplus > 201402L && defined(__cpp_aligned_new)) && (!defined(__GNUC__) || (__GNUC__ > 5))
183
+ void operator delete (void* p, std::align_val_t al) noexcept { mi_free_aligned(p, static_cast<size_t>(al)); }
184
+ void operator delete[](void* p, std::align_val_t al) noexcept { mi_free_aligned(p, static_cast<size_t>(al)); }
185
+ void operator delete (void* p, std::size_t n, std::align_val_t al) noexcept { mi_free_size_aligned(p, n, static_cast<size_t>(al)); };
186
+ void operator delete[](void* p, std::size_t n, std::align_val_t al) noexcept { mi_free_size_aligned(p, n, static_cast<size_t>(al)); };
187
+ void operator delete (void* p, std::align_val_t al, const std::nothrow_t&) noexcept { mi_free_aligned(p, static_cast<size_t>(al)); }
188
+ void operator delete[](void* p, std::align_val_t al, const std::nothrow_t&) noexcept { mi_free_aligned(p, static_cast<size_t>(al)); }
189
+
190
+ void* operator new( std::size_t n, std::align_val_t al) noexcept(false) { return mi_new_aligned(n, static_cast<size_t>(al)); }
191
+ void* operator new[]( std::size_t n, std::align_val_t al) noexcept(false) { return mi_new_aligned(n, static_cast<size_t>(al)); }
192
+ void* operator new (std::size_t n, std::align_val_t al, const std::nothrow_t&) noexcept { return mi_new_aligned_nothrow(n, static_cast<size_t>(al)); }
193
+ void* operator new[](std::size_t n, std::align_val_t al, const std::nothrow_t&) noexcept { return mi_new_aligned_nothrow(n, static_cast<size_t>(al)); }
194
+ #endif
195
+
196
+ #elif (defined(__GNUC__) || defined(__clang__))
197
+ // ------------------------------------------------------
198
+ // Override by defining the mangled C++ names of the operators (as
199
+ // used by GCC and CLang).
200
+ // See <https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling>
201
+ // ------------------------------------------------------
202
+
203
+ void _ZdlPv(void* p) MI_FORWARD0(mi_free,p) // delete
204
+ void _ZdaPv(void* p) MI_FORWARD0(mi_free,p) // delete[]
205
+ void _ZdlPvm(void* p, size_t n) MI_FORWARD02(mi_free_size,p,n)
206
+ void _ZdaPvm(void* p, size_t n) MI_FORWARD02(mi_free_size,p,n)
207
+
208
+ void _ZdlPvSt11align_val_t(void* p, size_t al) { mi_free_aligned(p,al); }
209
+ void _ZdaPvSt11align_val_t(void* p, size_t al) { mi_free_aligned(p,al); }
210
+ void _ZdlPvmSt11align_val_t(void* p, size_t n, size_t al) { mi_free_size_aligned(p,n,al); }
211
+ void _ZdaPvmSt11align_val_t(void* p, size_t n, size_t al) { mi_free_size_aligned(p,n,al); }
212
+
213
+ void _ZdlPvRKSt9nothrow_t(void* p, mi_nothrow_t tag) { MI_UNUSED(tag); mi_free(p); } // operator delete(void*, std::nothrow_t const&)
214
+ void _ZdaPvRKSt9nothrow_t(void* p, mi_nothrow_t tag) { MI_UNUSED(tag); mi_free(p); } // operator delete[](void*, std::nothrow_t const&)
215
+ void _ZdlPvSt11align_val_tRKSt9nothrow_t(void* p, size_t al, mi_nothrow_t tag) { MI_UNUSED(tag); mi_free_aligned(p,al); } // operator delete(void*, std::align_val_t, std::nothrow_t const&)
216
+ void _ZdaPvSt11align_val_tRKSt9nothrow_t(void* p, size_t al, mi_nothrow_t tag) { MI_UNUSED(tag); mi_free_aligned(p,al); } // operator delete[](void*, std::align_val_t, std::nothrow_t const&)
217
+
218
+ #if (MI_INTPTR_SIZE==8)
219
+ void* _Znwm(size_t n) MI_FORWARD1(mi_new,n) // new 64-bit
220
+ void* _Znam(size_t n) MI_FORWARD1(mi_new,n) // new[] 64-bit
221
+ void* _ZnwmRKSt9nothrow_t(size_t n, mi_nothrow_t tag) { MI_UNUSED(tag); return mi_new_nothrow(n); }
222
+ void* _ZnamRKSt9nothrow_t(size_t n, mi_nothrow_t tag) { MI_UNUSED(tag); return mi_new_nothrow(n); }
223
+ void* _ZnwmSt11align_val_t(size_t n, size_t al) MI_FORWARD2(mi_new_aligned, n, al)
224
+ void* _ZnamSt11align_val_t(size_t n, size_t al) MI_FORWARD2(mi_new_aligned, n, al)
225
+ void* _ZnwmSt11align_val_tRKSt9nothrow_t(size_t n, size_t al, mi_nothrow_t tag) { MI_UNUSED(tag); return mi_new_aligned_nothrow(n,al); }
226
+ void* _ZnamSt11align_val_tRKSt9nothrow_t(size_t n, size_t al, mi_nothrow_t tag) { MI_UNUSED(tag); return mi_new_aligned_nothrow(n,al); }
227
+ #elif (MI_INTPTR_SIZE==4)
228
+ void* _Znwj(size_t n) MI_FORWARD1(mi_new,n) // new 64-bit
229
+ void* _Znaj(size_t n) MI_FORWARD1(mi_new,n) // new[] 64-bit
230
+ void* _ZnwjRKSt9nothrow_t(size_t n, mi_nothrow_t tag) { MI_UNUSED(tag); return mi_new_nothrow(n); }
231
+ void* _ZnajRKSt9nothrow_t(size_t n, mi_nothrow_t tag) { MI_UNUSED(tag); return mi_new_nothrow(n); }
232
+ void* _ZnwjSt11align_val_t(size_t n, size_t al) MI_FORWARD2(mi_new_aligned, n, al)
233
+ void* _ZnajSt11align_val_t(size_t n, size_t al) MI_FORWARD2(mi_new_aligned, n, al)
234
+ void* _ZnwjSt11align_val_tRKSt9nothrow_t(size_t n, size_t al, mi_nothrow_t tag) { MI_UNUSED(tag); return mi_new_aligned_nothrow(n,al); }
235
+ void* _ZnajSt11align_val_tRKSt9nothrow_t(size_t n, size_t al, mi_nothrow_t tag) { MI_UNUSED(tag); return mi_new_aligned_nothrow(n,al); }
236
+ #else
237
+ #error "define overloads for new/delete for this platform (just for performance, can be skipped)"
238
+ #endif
239
+ #endif // __cplusplus
240
+
241
+ // ------------------------------------------------------
242
+ // Further Posix & Unix functions definitions
243
+ // ------------------------------------------------------
244
+
245
+ #ifdef __cplusplus
246
+ extern "C" {
247
+ #endif
248
+
249
+ #ifndef MI_OSX_IS_INTERPOSED
250
+ // Forward Posix/Unix calls as well
251
+ void* reallocf(void* p, size_t newsize) MI_FORWARD2(mi_reallocf,p,newsize)
252
+ size_t malloc_size(const void* p) MI_FORWARD1(mi_usable_size,p)
253
+ #if !defined(__ANDROID__) && !defined(__FreeBSD__) && !defined(__DragonFly__)
254
+ size_t malloc_usable_size(void *p) MI_FORWARD1(mi_usable_size,p)
255
+ #else
256
+ size_t malloc_usable_size(const void *p) MI_FORWARD1(mi_usable_size,p)
257
+ #endif
258
+
259
+ // No forwarding here due to aliasing/name mangling issues
260
+ void* valloc(size_t size) { return mi_valloc(size); }
261
+ void vfree(void* p) { mi_free(p); }
262
+ size_t malloc_good_size(size_t size) { return mi_malloc_good_size(size); }
263
+ int posix_memalign(void** p, size_t alignment, size_t size) { return mi_posix_memalign(p, alignment, size); }
264
+
265
+ // `aligned_alloc` is only available when __USE_ISOC11 is defined.
266
+ // Note: it seems __USE_ISOC11 is not defined in musl (and perhaps other libc's) so we only check
267
+ // for it if using glibc.
268
+ // Note: Conda has a custom glibc where `aligned_alloc` is declared `static inline` and we cannot
269
+ // override it, but both _ISOC11_SOURCE and __USE_ISOC11 are undefined in Conda GCC7 or GCC9.
270
+ // Fortunately, in the case where `aligned_alloc` is declared as `static inline` it
271
+ // uses internally `memalign`, `posix_memalign`, or `_aligned_malloc` so we can avoid overriding it ourselves.
272
+ #if !defined(__GLIBC__) || __USE_ISOC11
273
+ void* aligned_alloc(size_t alignment, size_t size) { return mi_aligned_alloc(alignment, size); }
274
+ #endif
275
+ #endif
276
+
277
+ // no forwarding here due to aliasing/name mangling issues
278
+ void cfree(void* p) { mi_free(p); }
279
+ void* pvalloc(size_t size) { return mi_pvalloc(size); }
280
+ void* memalign(size_t alignment, size_t size) { return mi_memalign(alignment, size); }
281
+ void* _aligned_malloc(size_t alignment, size_t size) { return mi_aligned_alloc(alignment, size); }
282
+ void* reallocarray(void* p, size_t count, size_t size) { return mi_reallocarray(p, count, size); }
283
+ // some systems define reallocarr so mark it as a weak symbol (#751)
284
+ mi_decl_weak int reallocarr(void* p, size_t count, size_t size) { return mi_reallocarr(p, count, size); }
285
+
286
+ #if defined(__wasi__)
287
+ // forward __libc interface (see PR #667)
288
+ void* __libc_malloc(size_t size) MI_FORWARD1(mi_malloc, size)
289
+ void* __libc_calloc(size_t count, size_t size) MI_FORWARD2(mi_calloc, count, size)
290
+ void* __libc_realloc(void* p, size_t size) MI_FORWARD2(mi_realloc, p, size)
291
+ void __libc_free(void* p) MI_FORWARD0(mi_free, p)
292
+ void* __libc_memalign(size_t alignment, size_t size) { return mi_memalign(alignment, size); }
293
+
294
+ #elif defined(__linux__)
295
+ // forward __libc interface (needed for glibc-based and musl-based Linux distributions)
296
+ void* __libc_malloc(size_t size) MI_FORWARD1(mi_malloc,size)
297
+ void* __libc_calloc(size_t count, size_t size) MI_FORWARD2(mi_calloc,count,size)
298
+ void* __libc_realloc(void* p, size_t size) MI_FORWARD2(mi_realloc,p,size)
299
+ void __libc_free(void* p) MI_FORWARD0(mi_free,p)
300
+ void __libc_cfree(void* p) MI_FORWARD0(mi_free,p)
301
+
302
+ void* __libc_valloc(size_t size) { return mi_valloc(size); }
303
+ void* __libc_pvalloc(size_t size) { return mi_pvalloc(size); }
304
+ void* __libc_memalign(size_t alignment, size_t size) { return mi_memalign(alignment,size); }
305
+ int __posix_memalign(void** p, size_t alignment, size_t size) { return mi_posix_memalign(p,alignment,size); }
306
+ #endif
307
+
308
+ #ifdef __cplusplus
309
+ }
310
+ #endif
311
+
312
+ #if (defined(__GNUC__) || defined(__clang__)) && !defined(__APPLE__)
313
+ #pragma GCC visibility pop
314
+ #endif
315
+
316
+ #endif // MI_MALLOC_OVERRIDE && !_WIN32