@shd101wyy/yo 0.1.24 → 0.1.26

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 (104) hide show
  1. package/.github/skills/yo-async-effects/async-effects-recipes.md +6 -6
  2. package/.github/skills/yo-core-patterns/core-patterns-cheatsheet.md +34 -0
  3. package/.github/skills/yo-syntax/syntax-cheatsheet.md +441 -2
  4. package/out/cjs/index.cjs +563 -567
  5. package/out/cjs/yo-cli.cjs +656 -651
  6. package/out/cjs/yo-lsp.cjs +614 -618
  7. package/out/esm/index.mjs +582 -586
  8. package/out/types/src/codegen/codegen-c.d.ts +2 -2
  9. package/out/types/src/codegen/functions/collection.d.ts +2 -2
  10. package/out/types/src/codegen/functions/context.d.ts +3 -2
  11. package/out/types/src/codegen/types/collection.d.ts +2 -2
  12. package/out/types/src/codegen/utils/index.d.ts +4 -1
  13. package/out/types/src/doc/builder.d.ts +2 -2
  14. package/out/types/src/evaluator/calls/closure-type.d.ts +2 -2
  15. package/out/types/src/evaluator/calls/record-type.d.ts +11 -0
  16. package/out/types/src/evaluator/context.d.ts +8 -9
  17. package/out/types/src/evaluator/index.d.ts +3 -3
  18. package/out/types/src/evaluator/types/record.d.ts +14 -0
  19. package/out/types/src/evaluator/types/validation.d.ts +2 -2
  20. package/out/types/src/evaluator/values/anonymous-module.d.ts +5 -5
  21. package/out/types/src/evaluator/values/impl.d.ts +1 -1
  22. package/out/types/src/expr.d.ts +2 -4
  23. package/out/types/src/function-value.d.ts +1 -1
  24. package/out/types/src/lsp/document-manager.d.ts +1 -1
  25. package/out/types/src/module-manager.d.ts +3 -3
  26. package/out/types/src/test-runner.d.ts +1 -0
  27. package/out/types/src/types/creators.d.ts +3 -4
  28. package/out/types/src/types/definitions.d.ts +8 -19
  29. package/out/types/src/types/guards.d.ts +3 -3
  30. package/out/types/src/types/tags.d.ts +0 -1
  31. package/out/types/src/types/utils.d.ts +1 -1
  32. package/out/types/src/value-tag.d.ts +0 -1
  33. package/out/types/src/value.d.ts +6 -13
  34. package/out/types/tsconfig.tsbuildinfo +1 -1
  35. package/package.json +1 -1
  36. package/std/error.yo +6 -6
  37. package/std/prelude.yo +1 -7
  38. package/vendor/mimalloc/.github/workflows/release.yaml +55 -0
  39. package/vendor/mimalloc/.github/workflows/stale.yaml +27 -0
  40. package/vendor/mimalloc/.github/workflows/test.yaml +163 -0
  41. package/vendor/mimalloc/CMakeLists.txt +52 -33
  42. package/vendor/mimalloc/azure-pipelines.yml +4 -3
  43. package/vendor/mimalloc/bin/bundle.bat +74 -0
  44. package/vendor/mimalloc/bin/bundle.sh +232 -0
  45. package/vendor/mimalloc/cmake/mimalloc-config-version.cmake +2 -2
  46. package/vendor/mimalloc/contrib/docker/alpine/Dockerfile +1 -1
  47. package/vendor/mimalloc/contrib/docker/alpine-arm32v7/Dockerfile +2 -2
  48. package/vendor/mimalloc/contrib/docker/alpine-x86/Dockerfile +1 -1
  49. package/vendor/mimalloc/contrib/docker/manylinux-x64/Dockerfile +1 -1
  50. package/vendor/mimalloc/contrib/vcpkg/portfile.cmake +4 -3
  51. package/vendor/mimalloc/contrib/vcpkg/vcpkg.json +1 -1
  52. package/vendor/mimalloc/doc/mimalloc-doc.h +42 -4
  53. package/vendor/mimalloc/doc/release-notes.md +15 -0
  54. package/vendor/mimalloc/ide/vs2022/mimalloc-lib.vcxproj +3 -3
  55. package/vendor/mimalloc/ide/vs2022/mimalloc-override-static-lib.vcxproj +511 -0
  56. package/vendor/mimalloc/ide/vs2022/mimalloc-override-static-lib.vcxproj.filters +117 -0
  57. package/vendor/mimalloc/ide/vs2022/mimalloc-test-dep.vcxproj +360 -0
  58. package/vendor/mimalloc/ide/vs2022/mimalloc-test-override-static.vcxproj +310 -0
  59. package/vendor/mimalloc/ide/vs2022/mimalloc.sln +92 -35
  60. package/vendor/mimalloc/include/mimalloc/atomic.h +178 -182
  61. package/vendor/mimalloc/include/mimalloc/bits.h +8 -10
  62. package/vendor/mimalloc/include/mimalloc/internal.h +76 -32
  63. package/vendor/mimalloc/include/mimalloc/prim.h +25 -18
  64. package/vendor/mimalloc/include/mimalloc/track.h +7 -2
  65. package/vendor/mimalloc/include/mimalloc/types.h +57 -29
  66. package/vendor/mimalloc/include/mimalloc-override.h +10 -10
  67. package/vendor/mimalloc/include/mimalloc-stats.h +18 -6
  68. package/vendor/mimalloc/include/mimalloc.h +22 -12
  69. package/vendor/mimalloc/readme.md +42 -17
  70. package/vendor/mimalloc/src/alloc-aligned.c +13 -11
  71. package/vendor/mimalloc/src/alloc-override.c +97 -17
  72. package/vendor/mimalloc/src/alloc-posix.c +44 -27
  73. package/vendor/mimalloc/src/alloc.c +73 -23
  74. package/vendor/mimalloc/src/arena-meta.c +3 -3
  75. package/vendor/mimalloc/src/arena.c +380 -192
  76. package/vendor/mimalloc/src/bitmap.c +68 -18
  77. package/vendor/mimalloc/src/bitmap.h +8 -4
  78. package/vendor/mimalloc/src/free.c +83 -47
  79. package/vendor/mimalloc/src/heap.c +94 -40
  80. package/vendor/mimalloc/src/init.c +273 -102
  81. package/vendor/mimalloc/src/libc.c +53 -8
  82. package/vendor/mimalloc/src/options.c +43 -40
  83. package/vendor/mimalloc/src/os.c +110 -45
  84. package/vendor/mimalloc/src/page-map.c +14 -8
  85. package/vendor/mimalloc/src/page-queue.c +9 -6
  86. package/vendor/mimalloc/src/page.c +26 -16
  87. package/vendor/mimalloc/src/prim/emscripten/prim.c +10 -1
  88. package/vendor/mimalloc/src/prim/osx/alloc-override-zone.c +35 -16
  89. package/vendor/mimalloc/src/prim/unix/prim.c +26 -22
  90. package/vendor/mimalloc/src/prim/wasi/prim.c +7 -4
  91. package/vendor/mimalloc/src/prim/windows/prim.c +247 -44
  92. package/vendor/mimalloc/src/random.c +8 -3
  93. package/vendor/mimalloc/src/stats.c +59 -48
  94. package/vendor/mimalloc/src/theap.c +85 -44
  95. package/vendor/mimalloc/src/threadlocal.c +102 -41
  96. package/vendor/mimalloc/test/main-override-static.c +31 -2
  97. package/vendor/mimalloc/test/main-override.c +27 -14
  98. package/vendor/mimalloc/test/main-static-dep.cpp +46 -0
  99. package/vendor/mimalloc/test/main-static-dep.h +11 -0
  100. package/vendor/mimalloc/test/test-api-fill.c +2 -2
  101. package/vendor/mimalloc/test/test-stress.c +3 -3
  102. package/vendor/mimalloc/test/test-wrong.c +11 -7
  103. package/out/types/src/evaluator/calls/module-type.d.ts +0 -11
  104. package/out/types/src/evaluator/types/module.d.ts +0 -19
@@ -9,9 +9,10 @@ terms of the MIT license. A copy of the license can be found in the file
9
9
  #define MIMALLOC_STATS_H
10
10
 
11
11
  #include <mimalloc.h>
12
- #include <stdint.h>
12
+ #include <string.h> // memset
13
+ #include <stdint.h> // int64_t
13
14
 
14
- #define MI_STAT_VERSION 4 // increased on every backward incompatible change
15
+ #define MI_STAT_VERSION 5 // increased on every backward incompatible change
15
16
 
16
17
  // alignment for atomic fields
17
18
  #if defined(_MSC_VER)
@@ -44,7 +45,7 @@ typedef struct mi_stat_counter_s {
44
45
  MI_STAT_COUNTER(reset) /* reset bytes */ \
45
46
  MI_STAT_COUNTER(purged) /* purged bytes */ \
46
47
  MI_STAT_COUNT(page_committed) /* committed memory inside pages */ \
47
- MI_STAT_COUNT(pages_abandoned) /* abandonded pages count */ \
48
+ MI_STAT_COUNT(pages_abandoned) /* abandoned pages count */ \
48
49
  MI_STAT_COUNT(threads) /* number of threads */ \
49
50
  MI_STAT_COUNT(malloc_normal) /* allocated bytes <= MI_LARGE_OBJ_SIZE_MAX */ \
50
51
  MI_STAT_COUNT(malloc_huge) /* allocated bytes in huge pages */ \
@@ -73,10 +74,12 @@ typedef struct mi_stat_counter_s {
73
74
  MI_STAT_COUNT(_segments_reserved) \
74
75
  /* only on v3 */ \
75
76
  MI_STAT_COUNT(heaps) \
77
+ MI_STAT_COUNT(theaps) \
76
78
  MI_STAT_COUNTER(pages_reclaim_on_alloc) \
77
79
  MI_STAT_COUNTER(pages_reclaim_on_free) \
78
80
  MI_STAT_COUNTER(pages_reabandon_full) \
79
- MI_STAT_COUNTER(pages_unabandon_busy_wait)
81
+ MI_STAT_COUNTER(pages_unabandon_busy_wait) \
82
+ MI_STAT_COUNTER(heaps_delete_wait)
80
83
 
81
84
  // Size bins for chunks
82
85
  typedef enum mi_chunkbin_e {
@@ -115,8 +118,17 @@ typedef struct mi_stats_s
115
118
  #undef MI_STAT_COUNT
116
119
  #undef MI_STAT_COUNTER
117
120
 
118
- // helper
119
- #define mi_stats_t_decl(name) mi_stats_t name = { 0 }; name.size = sizeof(mi_stats_t); name.version = MI_STAT_VERSION;
121
+ // Initialization
122
+ static inline void mi_stats_header_init(mi_stats_t* stats) {
123
+ stats->size = sizeof(*stats);
124
+ stats->version = MI_STAT_VERSION;
125
+ }
126
+ static inline void mi_stats_init(mi_stats_t* stats) {
127
+ memset(stats,0,sizeof(*stats));
128
+ mi_stats_header_init(stats);
129
+ }
130
+
131
+ #define mi_stats_t_decl(name) mi_stats_t name; mi_stats_init(&name);
120
132
 
121
133
  // Exported definitions
122
134
  #ifdef __cplusplus
@@ -8,7 +8,7 @@ terms of the MIT license. A copy of the license can be found in the file
8
8
  #ifndef MIMALLOC_H
9
9
  #define MIMALLOC_H
10
10
 
11
- #define MI_MALLOC_VERSION 3208 // major + minor + 2 digits patch
11
+ #define MI_MALLOC_VERSION 30302 // major + 2 digits minor + 2 digits patch
12
12
 
13
13
  // ------------------------------------------------------
14
14
  // Compiler specific attributes
@@ -114,7 +114,7 @@ mi_decl_export void* mi_expand(void* p, size_t newsize)
114
114
  mi_decl_export void mi_free(void* p) mi_attr_noexcept;
115
115
  mi_decl_nodiscard mi_decl_export mi_decl_restrict char* mi_strdup(const char* s) mi_attr_noexcept mi_attr_malloc;
116
116
  mi_decl_nodiscard mi_decl_export mi_decl_restrict char* mi_strndup(const char* s, size_t n) mi_attr_noexcept mi_attr_malloc;
117
- mi_decl_nodiscard mi_decl_export mi_decl_restrict char* mi_realpath(const char* fname, char* resolved_name) mi_attr_noexcept mi_attr_malloc;
117
+ mi_decl_nodiscard mi_decl_export mi_decl_restrict char* mi_realpath(const char* fname, char* resolved_name) mi_attr_noexcept;
118
118
 
119
119
  // ------------------------------------------------------
120
120
  // Extended allocation functions
@@ -133,6 +133,9 @@ mi_decl_nodiscard mi_decl_export void* mi_reallocf(void* p, size_t newsize)
133
133
  mi_decl_nodiscard mi_decl_export size_t mi_usable_size(const void* p) mi_attr_noexcept;
134
134
  mi_decl_nodiscard mi_decl_export size_t mi_good_size(size_t size) mi_attr_noexcept;
135
135
 
136
+ // `mi_free_small` is for special applications like language runtimes.
137
+ // it should only be used to free objects from `mi_(heap_)(m|z)alloc_small` and is potentially a tiny bit faster than `mi_free`
138
+ mi_decl_export void mi_free_small(void* p) mi_attr_noexcept;
136
139
 
137
140
  // -------------------------------------------------------------------------------------
138
141
  // Aligned allocation
@@ -242,7 +245,8 @@ mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_heap_malloc(mi_heap_t
242
245
  mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_heap_zalloc(mi_heap_t* heap, size_t size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size(2);
243
246
  mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_heap_calloc(mi_heap_t* heap, size_t count, size_t size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size2(2, 3);
244
247
  mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_heap_mallocn(mi_heap_t* heap, size_t count, size_t size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size2(2, 3);
245
- mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_heap_malloc_small(mi_heap_t* theap, size_t size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size(2);
248
+ mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_heap_malloc_small(mi_heap_t* heap, size_t size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size(2);
249
+ mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_heap_zalloc_small(mi_heap_t* heap, size_t size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size(2);
246
250
 
247
251
  mi_decl_nodiscard mi_decl_export void* mi_heap_realloc(mi_heap_t* heap, void* p, size_t newsize) mi_attr_noexcept mi_attr_alloc_size(3);
248
252
  mi_decl_nodiscard mi_decl_export void* mi_heap_reallocn(mi_heap_t* heap, void* p, size_t count, size_t size) mi_attr_noexcept mi_attr_alloc_size2(3, 4);
@@ -250,7 +254,7 @@ mi_decl_nodiscard mi_decl_export void* mi_heap_reallocf(mi_heap_t* theap, void*
250
254
 
251
255
  mi_decl_nodiscard mi_decl_export mi_decl_restrict char* mi_heap_strdup(mi_heap_t* heap, const char* s) mi_attr_noexcept mi_attr_malloc;
252
256
  mi_decl_nodiscard mi_decl_export mi_decl_restrict char* mi_heap_strndup(mi_heap_t* heap, const char* s, size_t n) mi_attr_noexcept mi_attr_malloc;
253
- mi_decl_nodiscard mi_decl_export mi_decl_restrict char* mi_heap_realpath(mi_heap_t* heap, const char* fname, char* resolved_name) mi_attr_noexcept mi_attr_malloc;
257
+ mi_decl_nodiscard mi_decl_export mi_decl_restrict char* mi_heap_realpath(mi_heap_t* heap, const char* fname, char* resolved_name) mi_attr_noexcept;
254
258
 
255
259
  mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_heap_malloc_aligned(mi_heap_t* heap, size_t size, size_t alignment) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size(2) mi_attr_alloc_align(3);
256
260
  mi_decl_nodiscard mi_decl_export 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 mi_attr_malloc mi_attr_alloc_size(2);
@@ -324,6 +328,7 @@ mi_decl_export bool mi_manage_os_memory(void* start, size_t size, bool is_comm
324
328
  mi_decl_export void mi_debug_show_arenas(void) mi_attr_noexcept;
325
329
  mi_decl_export void mi_arenas_print(void) mi_attr_noexcept;
326
330
  mi_decl_export size_t mi_arena_min_alignment(void);
331
+ mi_decl_export size_t mi_arena_min_size(void);
327
332
 
328
333
  typedef void* mi_arena_id_t;
329
334
  mi_decl_export void* mi_arena_area(mi_arena_id_t arena_id, size_t* size);
@@ -342,7 +347,7 @@ mi_decl_nodiscard mi_decl_export mi_heap_t* mi_heap_new_in_arena(mi_arena_id_t a
342
347
  // Used for example for separate interpreters in one process.
343
348
  // ------------------------------------------------------
344
349
 
345
- typedef void* mi_subproc_id_t;
350
+ typedef struct { void* _mi_subproc_id; } mi_subproc_id_t; // abstract type
346
351
  mi_decl_export mi_subproc_id_t mi_subproc_main(void);
347
352
  mi_decl_export mi_subproc_id_t mi_subproc_current(void);
348
353
  mi_decl_export mi_subproc_id_t mi_subproc_new(void);
@@ -375,6 +380,7 @@ mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_theap_malloc(mi_theap
375
380
  mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_theap_zalloc(mi_theap_t* theap, size_t size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size(2);
376
381
  mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_theap_calloc(mi_theap_t* theap, size_t count, size_t size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size2(2, 3);
377
382
  mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_theap_malloc_small(mi_theap_t* theap, size_t size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size(2);
383
+ mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_theap_zalloc_small(mi_theap_t* theap, size_t size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size(2);
378
384
  mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_theap_malloc_aligned(mi_theap_t* theap, size_t size, size_t alignment) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size(2) mi_attr_alloc_align(3);
379
385
  mi_decl_nodiscard mi_decl_export void* mi_theap_realloc(mi_theap_t* theap, void* p, size_t newsize) mi_attr_noexcept mi_attr_alloc_size(3);
380
386
 
@@ -401,6 +407,8 @@ mi_decl_export bool mi_manage_memory(void* start, size_t size, bool is_committe
401
407
  //mi_decl_export bool mi_theap_reload(mi_theap_t* theap, mi_arena_id_t arena);
402
408
  //mi_decl_export void mi_theap_unload(mi_theap_t* theap);
403
409
 
410
+ // unsafe: assumes the page belonging to `p` is only accessed by the calling thread.
411
+ mi_decl_export bool mi_unsafe_heap_page_is_under_utilized(mi_heap_t* heap, void* p, size_t perc_threshold) mi_attr_noexcept;
404
412
 
405
413
  // ------------------------------------------------------
406
414
  // Deprecated
@@ -422,7 +430,6 @@ mi_decl_export void mi_stats_print(void* out) mi_attr_noexcept; // backward com
422
430
  mi_decl_export void mi_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept; // not deprecated but declared in `mimalloc-stats.h` now.
423
431
 
424
432
 
425
-
426
433
  // ------------------------------------------------------
427
434
  // Options
428
435
  // ------------------------------------------------------
@@ -476,6 +483,7 @@ typedef enum mi_option_e {
476
483
  mi_option_allow_thp, // allow transparent huge pages? (=1) (on Android =0 by default). Set to 0 to disable THP for the process.
477
484
  mi_option_minimal_purge_size, // set minimal purge size (in KiB) (=0). By default set to either 64 or 2048 if THP is enabled.
478
485
  mi_option_arena_max_object_size, // set maximal object size that can be allocated in an arena (in KiB) (=2GiB on 64-bit).
486
+ mi_option_arena_is_numa_local, // experimental
479
487
  _mi_option_last,
480
488
  // legacy option names
481
489
  mi_option_large_os_pages = mi_option_allow_large_os_pages,
@@ -518,18 +526,20 @@ mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_pvalloc(size_t size)
518
526
  mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_aligned_alloc(size_t alignment, size_t size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size(2) mi_attr_alloc_align(1);
519
527
 
520
528
  mi_decl_nodiscard mi_decl_export void* mi_reallocarray(void* p, size_t count, size_t size) mi_attr_noexcept mi_attr_alloc_size2(2,3);
521
- mi_decl_nodiscard mi_decl_export int mi_reallocarr(void* p, size_t count, size_t size) mi_attr_noexcept;
529
+ mi_decl_nodiscard mi_decl_export int mi_reallocarr(void* ptrp, size_t count, size_t size) mi_attr_noexcept;
522
530
  mi_decl_nodiscard mi_decl_export void* mi_aligned_recalloc(void* p, size_t newcount, size_t size, size_t alignment) mi_attr_noexcept;
523
531
  mi_decl_nodiscard mi_decl_export void* mi_aligned_offset_recalloc(void* p, size_t newcount, size_t size, size_t alignment, size_t offset) mi_attr_noexcept;
524
532
 
525
- mi_decl_nodiscard mi_decl_export mi_decl_restrict unsigned short* mi_wcsdup(const unsigned short* s) mi_attr_noexcept mi_attr_malloc;
526
- mi_decl_nodiscard mi_decl_export mi_decl_restrict unsigned char* mi_mbsdup(const unsigned char* s) mi_attr_noexcept mi_attr_malloc;
527
- mi_decl_export int mi_dupenv_s(char** buf, size_t* size, const char* name) mi_attr_noexcept;
528
- mi_decl_export int mi_wdupenv_s(unsigned short** buf, size_t* size, const unsigned short* name) mi_attr_noexcept;
529
-
530
533
  mi_decl_export void mi_free_size(void* p, size_t size) mi_attr_noexcept;
531
534
  mi_decl_export void mi_free_size_aligned(void* p, size_t size, size_t alignment) mi_attr_noexcept;
532
535
  mi_decl_export void mi_free_aligned(void* p, size_t alignment) mi_attr_noexcept;
536
+ mi_decl_export int mi_dupenv_s(char** buf, size_t* size, const char* name) mi_attr_noexcept;
537
+
538
+ // wide characters
539
+ #include <wchar.h> // wchar_t
540
+ mi_decl_export int mi_wdupenv_s(wchar_t** buf, size_t* size, const wchar_t* name) mi_attr_noexcept;
541
+ mi_decl_nodiscard mi_decl_export mi_decl_restrict wchar_t* mi_wcsdup(const wchar_t* s) mi_attr_noexcept mi_attr_malloc;
542
+ mi_decl_nodiscard mi_decl_export mi_decl_restrict unsigned char* mi_mbsdup(const unsigned char* s) mi_attr_noexcept mi_attr_malloc;
533
543
 
534
544
  // The `mi_new` wrappers implement C++ semantics on out-of-memory instead of directly returning `NULL`.
535
545
  // (and call `std::get_new_handler` and potentially raise a `std::bad_alloc` exception).
@@ -1,7 +1,10 @@
1
-
2
1
  <img align="left" width="100" height="100" src="doc/mimalloc-logo.png"/>
3
-
4
- [<img align="right" src="https://dev.azure.com/Daan0324/mimalloc/_apis/build/status/microsoft.mimalloc?branchName=dev3"/>](https://dev.azure.com/Daan0324/mimalloc/_build?definitionId=1&_a=summary)
2
+ <div align="right">
3
+ <sup> v3:</sup><a href="https://github.com/microsoft/mimalloc/actions/workflows/test.yaml"><img src="https://github.com/microsoft/mimalloc/actions/workflows/test.yaml/badge.svg?branch=dev3"/></a>
4
+ <sup> v2:</sup><a href="https://github.com/microsoft/mimalloc/actions/workflows/test.yaml"><img src="https://github.com/microsoft/mimalloc/actions/workflows/test.yaml/badge.svg?branch=dev2"/></a>
5
+ <sup> v1:</sup><a href="https://github.com/microsoft/mimalloc/actions/workflows/test.yaml"><img src="https://github.com/microsoft/mimalloc/actions/workflows/test.yaml/badge.svg?branch=dev"/></a>
6
+ &nbsp;&nbsp;&nbsp;<sup>v3:</sup><a href="https://dev.azure.com/Daan0324/mimalloc/_build?definitionId=1&_a=summary"><img src="https://dev.azure.com/Daan0324/mimalloc/_apis/build/status/microsoft.mimalloc?branchName=dev3"/></a>
7
+ </div>
5
8
 
6
9
  # mimalloc
7
10
 
@@ -12,9 +15,9 @@ is a general purpose allocator with excellent [performance](#performance) charac
12
15
  Initially developed by Daan Leijen for the runtime systems of the
13
16
  [Koka](https://koka-lang.github.io) and [Lean](https://github.com/leanprover/lean) languages.
14
17
 
15
- Latest release : `v3.2.8` (2026-02-03) release candidate 3, please report any issues.
16
- Latest v2 release: `v2.2.7` (2026-01-15).
17
- Latest v1 release: `v1.9.7` (2026-01-15).
18
+ Latest release : `v3.3.2` (2026-04-29) recommended.
19
+ Latest v2 release: `v2.3.2` (2026-04-29) stable.
20
+ Latest v1 release: `v1.9.10` (2026-04-29) legacy.
18
21
 
19
22
  mimalloc is a drop-in replacement for `malloc` and can be used in other programs
20
23
  without code changes, for example, on dynamically linked ELF-based systems (Linux, BSD, etc.) you can use it as:
@@ -76,16 +79,32 @@ Enjoy!
76
79
  There are three maintained versions of mimalloc. These are mostly equal except for how the OS memory is handled.
77
80
  New development is mostly on v3, while v1 and v2 are maintained with security and bug fixes.
78
81
 
79
- - __v1__: initial design of mimalloc (release tags: `v1.9.x`, development branch `dev`). Send PR's against this version if possible.
80
- - __v2__: main mimalloc version. Uses thread-local segments to reduce fragmentation. (release tags: `v2.2.x`, development branch `dev2` and `main`)
81
- - __v3__: simplifies the lock-free design of previous versions and improves sharing of
82
+ - __v3__: recommended: simplifies the lock-free design of previous versions and improves sharing of
82
83
  memory between threads. On certain large workloads this version may use
83
84
  (much) less memory. Also supports true first-class heaps (that can allocate from any thread)
84
85
  and has more efficient heap-walking (for the CPython GC for example).
85
- (release tags: `v3.2.x`, development branch `dev3`).
86
+ (release tags: `v3.x`, development branch `dev3`).
87
+ - __v2__: stable mimalloc version. Uses thread-local segments to reduce fragmentation. (release tags: `v2.x`, development branch `dev2` and `main`)
88
+ - __v1__: legacy version: initial design of mimalloc (release tags: `v1.9.x`, development branch `dev`). Send PR's against this version if possible.
86
89
 
87
90
  ### Releases
88
-
91
+ * 2026-04-29, `v1.9.10`, `v2.3.2`, `v3.3.2`: various bug and security fixes through LLM audit (by @Zoxc).
92
+ Only increase minimal purge size automatically if allow_thp is set to 2. Enable large OS alignment
93
+ on all platforms (fixing OS large pages on Windows). Fix accounting of committed memory on Linux/macOS.
94
+ Update MSVC atomics implementation when using C mode. Upstream Emscripten fixes. Proper atomic do-once
95
+ implementation.
96
+ * 2026-04-20, `v1.9.9`, `v2.3.1`, `v3.3.1`: various bug and security fixes. Special thanks to
97
+ @jinpzhanAMD, @res2k, and @GoldJohnKing for their help in improving Windows finalization, and
98
+ @Zoxc for his help in finding various issues.
99
+ * 2026-04-15, `v1.9.8`, `v2.3.0`, `v3.3.0`: initial support for github (binary) releases,
100
+ fix visiting of full pages during collection (performance),
101
+ fix THP alignment (performance), fix arm64 cross-compilation on Windows, enable guard pages in debug mode,
102
+ always use uncommitted areas between arenas (security), enable static overloading of `malloc` etc. on Windows with the
103
+ static CRT (by @Noxybot), fix TLS slot leak on Windows (v3), enable clean DLL load/unload with statically linked
104
+ mimalloc (v3), fix race in `mi_heap_destroy` (v3), by default put page meta info separate from allocated
105
+ objects (v3,security), fix C++ overrides for emscripten. Various bugs found by DeepTest include:
106
+ fix offset for `mi_heap_realloc_aligned`, fix `mi_(w)dupenv_s` buffer size, fix potential overflow in size options,
107
+ and error codes for `mi_reallocarr(ay)`.
89
108
  * 2026-02-03, `v3.2.8` (rc3): Fix thread reinitialize issue on macOS. Fix SIMD codegen bug on older
90
109
  GCC versions. Extend Windows TLS slot limit from 64 to 1088. Report commit statistics more precise.
91
110
  Fixes issue in free-page search in arenas.
@@ -144,7 +163,7 @@ mimalloc is used in various large scale low-latency services and programs, for e
144
163
  <a href="https://azure.microsoft.com/"><img height="50" align="left" src="https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg"></a>
145
164
  <a href="https://deathstrandingpc.505games.com"><img height="100" src="doc/ds-logo.png"></a>
146
165
  <a href="https://docs.unrealengine.com/4.26/en-US/WhatsNew/Builds/ReleaseNotes/4_25/"><img height="100" src="doc/unreal-logo.svg"></a>
147
- <a href="https://cab.spbu.ru/software/spades/"><img height="100" src="doc/spades-logo.png"></a>
166
+ <a href="https://ablab.github.io/software/spades/"><img height="100" src="doc/spades-logo.png"></a>
148
167
 
149
168
 
150
169
  # Building
@@ -353,7 +372,7 @@ Further options for large workloads and services:
353
372
 
354
373
  - `MIMALLOC_ALLOW_THP=1`: By default always allow transparent huge pages (THP) on Linux systems. On Android only this is
355
374
  by default off. When set to `0`, THP is disabled for the process that mimalloc runs in. If enabled, mimalloc also sets
356
- the `MIMALLOC_MINIMAL_PURGE_SIZE` in v3 to 2MiB to avoid potentially breaking up transparent huge pages.
375
+ the `MIMALLOC_MINIMAL_PURGE_SIZE` in v3 to 2MiB to avoid potentially breaking up transparent huge pages when purging memory.
357
376
  - `MIMALLOC_USE_NUMA_NODES=N`: pretend there are at most `N` NUMA nodes. If not set, the actual NUMA nodes are detected
358
377
  at runtime. Setting `N` to 1 may avoid problems in some virtual environments. Also, setting it to a lower number than
359
378
  the actual NUMA nodes is fine and will only cause threads to potentially allocate more memory across actual NUMA
@@ -388,8 +407,7 @@ OS will copy the entire 1GiB huge page (or 2MiB large page) which can cause the
388
407
  _mimalloc_ can be build in secure mode by using the `-DMI_SECURE=ON` flags in `cmake`. This build enables various mitigations
389
408
  to make mimalloc more robust against exploits. In particular:
390
409
 
391
- - All internal mimalloc pages are surrounded by guard pages and the heap metadata is behind a guard page as well (so a buffer overflow
392
- exploit cannot reach into the metadata).
410
+ - All internal mimalloc page meta-data is surrounded by guard pages (so a buffer overflow exploit cannot reach into the metadata).
393
411
  - All free list pointers are
394
412
  [encoded](https://github.com/microsoft/mimalloc/blob/783e3377f79ee82af43a0793910a9f2d01ac7863/include/mimalloc-internal.h#L396)
395
413
  with per-page keys which is used both to prevent overwrites with a known pointer, as well as to detect heap corruption.
@@ -397,6 +415,9 @@ to make mimalloc more robust against exploits. In particular:
397
415
  - The free lists are initialized in a random order and allocation randomly chooses between extension and reuse within a page to
398
416
  mitigate against attacks that rely on a predicable allocation order. Similarly, the larger heap blocks allocated by mimalloc
399
417
  from the OS are also address randomized.
418
+ - If enabling `-DMI_SECURE_FULL=ON` there will also be guard pages at the end of each (64KiB) mimalloc page (thus interleaving
419
+ valid block data with inaccessible gaps). This setting is not recommended in general as it is more expensive and can lead to
420
+ reaching the maximum VMA limit on Linux systems if the heap gets too large.
400
421
 
401
422
  As always, evaluate with care as part of an overall security strategy as all of the above are mitigations but not guarantees.
402
423
 
@@ -413,13 +434,14 @@ various checks are done at runtime to catch development errors.
413
434
  ## Guarded Mode
414
435
 
415
436
  <span id="guarded">_mimalloc_ can be build in guarded mode using the `-DMI_GUARDED=ON` flags in `cmake`.</span>
416
- This enables placing OS guard pages behind certain object allocations to catch buffer overflows as they occur.
437
+ This is `ON` by default when building a debug version of mimalloc.
438
+ Guarded mode enables placing OS guard pages behind certain object allocations to catch buffer overflows as they occur.
417
439
  This can be invaluable to catch buffer-overflow bugs in large programs. However, it also means that any object
418
440
  allocated with a guard page takes at least 8 KiB memory for the guard page and its alignment. As such, allocating
419
441
  a guard page for every allocation may be too expensive both in terms of memory, and in terms of performance with
420
442
  many system calls. Therefore, there are various environment variables (and options) to tune this:
421
443
 
422
- - `MIMALLOC_GUARDED_SAMPLE_RATE=N`: Set the sample rate to `N` (by default 4000). This mode places a guard page
444
+ - `MIMALLOC_GUARDED_SAMPLE_RATE=N`: Set the sample rate to `N` (by default 0). This mode places a guard page
423
445
  behind every `N` suitable object allocations (per thread). Since the performance in guarded mode without placing
424
446
  guard pages is close to release mode, this can be used to enable guard pages even in production to catch latent
425
447
  buffer overflow bugs. Set the sample rate to `1` to guard every object, and to `0` to place no guard pages at all.
@@ -538,6 +560,9 @@ This is provided by [`mimalloc-override.h`](include/mimalloc-override.h). This o
538
560
  reliably though if all sources are
539
561
  under your control or otherwise mixing of pointers from different heaps may occur!
540
562
 
563
+ Note: recently we also enabled static overloading on Windows. In that case you need
564
+ to link with the static CRT _release_ runtime (`/MT`) and link with the static
565
+ `mimalloc(-debug).obj` (to take precendence over the definitions in the CRT library).
541
566
 
542
567
  # Tools
543
568
 
@@ -34,9 +34,14 @@ static mi_decl_restrict void* mi_theap_malloc_guarded_aligned(mi_theap_t* theap,
34
34
  if mi_unlikely(theap==NULL) { theap = _mi_theap_empty_get(); }
35
35
  #endif
36
36
  mi_assert_internal(alignment > 0 && alignment < MI_PAGE_MAX_OVERALLOC_ALIGN);
37
+ if mi_unlikely(alignment >= MI_PAGE_MAX_OVERALLOC_ALIGN || size > (MI_MAX_ALLOC_SIZE - MI_PADDING_SIZE - alignment)) {
38
+ _mi_error_message(EOVERFLOW, "(guarded) aligned allocation request is too large (size %zu, alignment %zu)\n", size, alignment);
39
+ return NULL;
40
+ }
37
41
  const size_t oversize = size + alignment - 1;
38
- void* base = _mi_theap_malloc_guarded(theap, oversize, zero);
39
- void* p = _mi_align_up_ptr(base, alignment);
42
+ void* const base = _mi_theap_malloc_guarded(theap, oversize, zero);
43
+ if (base==NULL) return NULL;
44
+ void* const p = _mi_align_up_ptr(base, alignment);
40
45
  mi_track_align(base, p, (uint8_t*)p - (uint8_t*)base, size);
41
46
  mi_assert_internal(mi_usable_size(p) >= size);
42
47
  mi_assert_internal(_mi_is_aligned(p, alignment));
@@ -74,9 +79,7 @@ static mi_decl_noinline void* mi_theap_malloc_zero_aligned_at_overalloc(mi_theap
74
79
  // in the first (and single) page such that the page info is `MI_PAGE_ALIGN` bytes before it (and can be found in the _mi_page_map).
75
80
  if mi_unlikely(offset != 0) {
76
81
  // todo: cannot support offset alignment for very large alignments yet
77
- #if MI_DEBUG > 0
78
82
  _mi_error_message(EOVERFLOW, "aligned allocation with a large alignment cannot be used with an alignment offset (size %zu, alignment %zu, offset %zu)\n", size, alignment, offset);
79
- #endif
80
83
  return NULL;
81
84
  }
82
85
  oversize = (size <= MI_SMALL_SIZE_MAX ? MI_SMALL_SIZE_MAX + 1 /* ensure we use generic malloc path */ : size);
@@ -86,7 +89,9 @@ static mi_decl_noinline void* mi_theap_malloc_zero_aligned_at_overalloc(mi_theap
86
89
  }
87
90
  else {
88
91
  // otherwise over-allocate
89
- 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.
92
+ mi_assert_internal(size <= (MI_MAX_ALLOC_SIZE - MI_PADDING_SIZE) && alignment <= MI_PAGE_MAX_OVERALLOC_ALIGN);
93
+ mi_assert_internal(size < SIZE_MAX - alignment); // `oversize` cannot overflow
94
+ oversize = (size < MI_MAX_ALIGN_SIZE ? MI_MAX_ALIGN_SIZE : size) + alignment - 1; // adjust for size <= 16; with size 0 and alignment 64k, we would allocate a 64k block and pointing just beyond that.
90
95
  p = mi_theap_malloc_zero_no_guarded(theap, oversize, zero, usable);
91
96
  if (p == NULL) return NULL;
92
97
  }
@@ -150,9 +155,7 @@ static mi_decl_noinline void* mi_theap_malloc_zero_aligned_at_generic(mi_theap_t
150
155
  mi_assert_internal(alignment != 0 && _mi_is_power_of_two(alignment));
151
156
  // we don't allocate more than MI_MAX_ALLOC_SIZE (see <https://sourceware.org/ml/libc-announce/2019/msg00001.html>)
152
157
  if mi_unlikely(size > (MI_MAX_ALLOC_SIZE - MI_PADDING_SIZE)) {
153
- #if MI_DEBUG > 0
154
158
  _mi_error_message(EOVERFLOW, "aligned allocation request is too large (size %zu, alignment %zu)\n", size, alignment);
155
- #endif
156
159
  return NULL;
157
160
  }
158
161
 
@@ -328,12 +331,12 @@ mi_decl_nodiscard mi_decl_restrict void* mi_heap_calloc_aligned(mi_heap_t* heap,
328
331
 
329
332
  static void* mi_theap_realloc_zero_aligned_at(mi_theap_t* theap, void* p, size_t newsize, size_t alignment, size_t offset, bool zero) mi_attr_noexcept {
330
333
  mi_assert(alignment > 0);
331
- if (alignment <= sizeof(uintptr_t)) return _mi_theap_realloc_zero(theap,p,newsize,zero,NULL,NULL);
334
+ if (alignment <= sizeof(uintptr_t) && offset==0) return _mi_theap_realloc_zero(theap,p,newsize,zero,NULL,NULL);
332
335
  if (p == NULL) return mi_theap_malloc_zero_aligned_at(theap,newsize,alignment,offset,zero,NULL);
333
336
  size_t size = mi_usable_size(p);
334
337
  if (newsize <= size && newsize >= (size - (size / 2))
335
338
  && (((uintptr_t)p + offset) % alignment) == 0) {
336
- return p; // reallocation still fits, is aligned and not more than 50% waste
339
+ return p; // reallocation still fits, is aligned and not more than 25% waste
337
340
  }
338
341
  else {
339
342
  // note: we don't zero allocate upfront so we only zero initialize the expanded part
@@ -354,8 +357,7 @@ static void* mi_theap_realloc_zero_aligned_at(mi_theap_t* theap, void* p, size_t
354
357
  static void* mi_theap_realloc_zero_aligned(mi_theap_t* theap, void* p, size_t newsize, size_t alignment, bool zero) mi_attr_noexcept {
355
358
  mi_assert(alignment > 0);
356
359
  if (alignment <= sizeof(uintptr_t)) return _mi_theap_realloc_zero(theap,p,newsize,zero,NULL,NULL);
357
- size_t offset = ((uintptr_t)p % alignment); // use offset of previous allocation (p can be NULL)
358
- return mi_theap_realloc_zero_aligned_at(theap,p,newsize,alignment,offset,zero);
360
+ return mi_theap_realloc_zero_aligned_at(theap,p,newsize,alignment,0,zero);
359
361
  }
360
362
 
361
363
  static void* mi_theap_realloc_aligned_at(mi_theap_t* theap, void* p, size_t newsize, size_t alignment, size_t offset) mi_attr_noexcept {
@@ -1,5 +1,5 @@
1
1
  /* ----------------------------------------------------------------------------
2
- Copyright (c) 2018-2021, Microsoft Research, Daan Leijen
2
+ Copyright (c) 2018-2026, Microsoft Research, Daan Leijen
3
3
  This is free software; you can redistribute it and/or modify it under the
4
4
  terms of the MIT license. A copy of the license can be found in the file
5
5
  "LICENSE" at the root of this distribution.
@@ -9,11 +9,8 @@ terms of the MIT license. A copy of the license can be found in the file
9
9
  #error "this file should be included from 'alloc.c' (so aliases can work)"
10
10
  #endif
11
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
12
 
16
- #if defined(MI_MALLOC_OVERRIDE) && !(defined(_WIN32))
13
+ #if defined(MI_MALLOC_OVERRIDE) && !defined(_DLL)
17
14
 
18
15
  #if defined(__APPLE__)
19
16
  #include <AvailabilityMacros.h>
@@ -51,7 +48,6 @@ typedef void* mi_nothrow_t;
51
48
  #define MI_FORWARD02(fun,x,y) { fun(x,y); }
52
49
  #endif
53
50
 
54
-
55
51
  #if defined(__APPLE__) && defined(MI_SHARED_LIB_EXPORT) && defined(MI_OSX_INTERPOSE)
56
52
  // define MI_OSX_IS_INTERPOSED as we should not provide forwarding definitions for
57
53
  // functions that are interposed (or the interposing does not work)
@@ -95,12 +91,12 @@ typedef void* mi_nothrow_t;
95
91
  MI_INTERPOSE_FUN(vfree,mi_cfree),
96
92
  #endif
97
93
  };
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
- };
94
+ #if defined(MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
95
+ MI_INTERPOSE_DECLS(_mi_interposes_10_7) = { MI_INTERPOSE_MI(strndup) };
96
+ #endif
97
+ #if defined(MAC_OS_X_VERSION_10_15) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_15)
98
+ MI_INTERPOSE_DECLS(_mi_interposes_10_15) = { MI_INTERPOSE_MI(aligned_alloc) };
99
+ #endif
104
100
 
105
101
  #ifdef __cplusplus
106
102
  extern "C" {
@@ -129,8 +125,90 @@ typedef void* mi_nothrow_t;
129
125
  };
130
126
 
131
127
  #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.
128
+ _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Size) _ACRTIMP _CRTALLOCATOR _CRT_HYBRIDPATCHABLE
129
+ void* __cdecl _expand(_Pre_notnull_ void* _Block, _In_ _CRT_GUARDOVERFLOW size_t _Size) {
130
+ return mi_expand(_Block, _Size);
131
+ }
132
+ _Check_return_ _ACRTIMP
133
+ size_t __cdecl _msize_base(_Pre_notnull_ void* _Block) _CRT_NOEXCEPT {
134
+ return mi_malloc_size(_Block);
135
+ }
136
+ _Check_return_ _ACRTIMP _CRT_HYBRIDPATCHABLE
137
+ size_t __cdecl _msize(_Pre_notnull_ void* _Block) {
138
+ return mi_malloc_size(_Block);
139
+ }
140
+ _ACRTIMP
141
+ void __cdecl _free_base(_Pre_maybenull_ _Post_invalid_ void* _Block) {
142
+ mi_free(_Block);
143
+ }
144
+ _ACRTIMP _CRT_HYBRIDPATCHABLE
145
+ void __cdecl free(_Pre_maybenull_ _Post_invalid_ void* _Block) {
146
+ mi_free(_Block);
147
+ }
148
+ _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Size) _ACRTIMP _CRTALLOCATOR _CRT_JIT_INTRINSIC _CRTRESTRICT _CRT_HYBRIDPATCHABLE
149
+ void* __cdecl malloc(_In_ _CRT_GUARDOVERFLOW size_t _Size) {
150
+ return mi_malloc(_Size);
151
+ }
152
+ _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Size) _ACRTIMP _CRTALLOCATOR _CRTRESTRICT
153
+ void* __cdecl _malloc_base(_In_ size_t _Size) {
154
+ return mi_malloc(_Size);
155
+ }
156
+ _Success_(return != 0) _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Size) _ACRTIMP _CRTALLOCATOR _CRTRESTRICT
157
+ void* __cdecl _realloc_base(_Pre_maybenull_ _Post_invalid_ void* _Block, _In_ size_t _Size) {
158
+ return mi_realloc(_Block, _Size);
159
+ }
160
+ _Success_(return != 0) _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Size) _ACRTIMP _CRTALLOCATOR _CRTRESTRICT _CRT_HYBRIDPATCHABLE
161
+ void* __cdecl realloc(_Pre_maybenull_ _Post_invalid_ void* _Block, _In_ _CRT_GUARDOVERFLOW size_t _Size) {
162
+ return mi_realloc(_Block, _Size);
163
+ }
164
+ _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Count * _Size) _ACRTIMP _CRTALLOCATOR _CRTRESTRICT
165
+ void* __cdecl _calloc_base(_In_ size_t _Count, _In_ size_t _Size) {
166
+ return mi_calloc(_Count, _Size);
167
+ }
168
+ _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Count * _Size) _ACRTIMP _CRT_JIT_INTRINSIC _CRTALLOCATOR _CRTRESTRICT
169
+ void* __cdecl calloc(_In_ _CRT_GUARDOVERFLOW size_t _Count, _In_ _CRT_GUARDOVERFLOW size_t _Size) {
170
+ return mi_calloc(_Count, _Size);
171
+ }
172
+ _Success_(return != 0) _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Count * _Size) _ACRTIMP _CRTALLOCATOR _CRTRESTRICT
173
+ void* __cdecl _recalloc_base(_Pre_maybenull_ _Post_invalid_ void* _Block, _In_ size_t _Count, _In_ size_t _Size) {
174
+ return mi_recalloc(_Block, _Count, _Size);
175
+ }
176
+ _Success_(return != 0) _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Count * _Size) _ACRTIMP _CRTALLOCATOR _CRTRESTRICT
177
+ void* __cdecl _recalloc(_Pre_maybenull_ _Post_invalid_ void* _Block, _In_ _CRT_GUARDOVERFLOW size_t _Count, _In_ _CRT_GUARDOVERFLOW size_t _Size) {
178
+ return mi_recalloc(_Block, _Count, _Size);
179
+ }
180
+ _ACRTIMP
181
+ void __cdecl _aligned_free(_Pre_maybenull_ _Post_invalid_ void* _Block) {
182
+ mi_free(_Block);
183
+ }
184
+ _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Size) _ACRTIMP _CRTALLOCATOR _CRTRESTRICT
185
+ void* __cdecl _aligned_malloc(_In_ _CRT_GUARDOVERFLOW size_t _Size, _In_ size_t _Alignment) {
186
+ return mi_malloc_aligned(_Size, _Alignment);
187
+ }
188
+ _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Size) _ACRTIMP _CRTALLOCATOR _CRTRESTRICT
189
+ void* __cdecl _aligned_offset_malloc(_In_ _CRT_GUARDOVERFLOW size_t _Size, _In_ size_t _Alignment, _In_ size_t _Offset) {
190
+ return mi_malloc_aligned_at(_Size, _Alignment, _Offset);
191
+ }
192
+ _Check_return_ _ACRTIMP
193
+ size_t __cdecl _aligned_msize(_Pre_notnull_ void* _Block, _In_ size_t _Alignment, _In_ size_t _Offset) {
194
+ MI_UNUSED(_Alignment); MI_UNUSED(_Offset); return mi_malloc_size(_Block);
195
+ }
196
+ _Success_(return != 0) _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Size) _ACRTIMP _CRTALLOCATOR _CRTRESTRICT
197
+ void* __cdecl _aligned_offset_realloc(_Pre_maybenull_ _Post_invalid_ void* _Block, _In_ _CRT_GUARDOVERFLOW size_t _Size, _In_ size_t _Alignment, _In_ size_t _Offset) {
198
+ return mi_realloc_aligned_at(_Block, _Size, _Alignment, _Offset);
199
+ }
200
+ _Success_(return != 0) _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Count * _Size) _ACRTIMP _CRTALLOCATOR _CRTRESTRICT
201
+ void* __cdecl _aligned_offset_recalloc(_Pre_maybenull_ _Post_invalid_ void* _Block, _In_ _CRT_GUARDOVERFLOW size_t _Count, _In_ _CRT_GUARDOVERFLOW size_t _Size, _In_ size_t _Alignment, _In_ size_t _Offset) {
202
+ return mi_recalloc_aligned_at(_Block, _Count, _Size, _Alignment, _Offset);
203
+ }
204
+ _Success_(return != 0) _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Size) _ACRTIMP _CRTALLOCATOR _CRTRESTRICT
205
+ void* __cdecl _aligned_realloc(_Pre_maybenull_ _Post_invalid_ void* _Block, _In_ _CRT_GUARDOVERFLOW size_t _Size, _In_ size_t _Alignment) {
206
+ return mi_realloc_aligned(_Block, _Size, _Alignment);
207
+ }
208
+ _Success_(return != 0) _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Count * _Size) _ACRTIMP _CRTALLOCATOR _CRTRESTRICT
209
+ void* __cdecl _aligned_recalloc(_Pre_maybenull_ _Post_invalid_ void* _Block, _In_ _CRT_GUARDOVERFLOW size_t _Count, _In_ _CRT_GUARDOVERFLOW size_t _Size, _In_ size_t _Alignment) {
210
+ return mi_recalloc_aligned(_Block, _Count, _Size, _Alignment);
211
+ }
134
212
  #else
135
213
  // On all other systems forward allocation primitives to our API
136
214
  mi_decl_export void* malloc(size_t size) MI_FORWARD1(mi_malloc, size)
@@ -215,7 +293,7 @@ typedef void* mi_nothrow_t;
215
293
  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
294
  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
295
 
218
- #if (MI_INTPTR_SIZE==8)
296
+ #if (MI_INTPTR_SIZE==8) || (MI_INTPTR_SIZE==4 && defined(__EMSCRIPTEN__)) // pr #1257
219
297
  void* _Znwm(size_t n) MI_FORWARD1(mi_new,n) // new 64-bit
220
298
  void* _Znam(size_t n) MI_FORWARD1(mi_new,n) // new[] 64-bit
221
299
  void* _ZnwmRKSt9nothrow_t(size_t n, mi_nothrow_t tag) { MI_UNUSED(tag); return mi_new_nothrow(n); }
@@ -278,7 +356,9 @@ extern "C" {
278
356
  void cfree(void* p) { mi_free(p); }
279
357
  void* pvalloc(size_t size) { return mi_pvalloc(size); }
280
358
  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); }
359
+ #if !defined(_WIN32)
360
+ void* _aligned_malloc(size_t size, size_t alignment) { return mi_malloc_aligned(size,alignment); }
361
+ #endif
282
362
  void* reallocarray(void* p, size_t count, size_t size) { return mi_reallocarray(p, count, size); }
283
363
  // some systems define reallocarr so mark it as a weak symbol (#751)
284
364
  mi_decl_weak int reallocarr(void* p, size_t count, size_t size) { return mi_reallocarr(p, count, size); }
@@ -313,4 +393,4 @@ mi_decl_weak int reallocarr(void* p, size_t count, size_t size) { return mi_r
313
393
  #pragma GCC visibility pop
314
394
  #endif
315
395
 
316
- #endif // MI_MALLOC_OVERRIDE && !_WIN32
396
+ #endif // MI_MALLOC_OVERRIDE