@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.
- package/.github/skills/yo-async-effects/async-effects-recipes.md +6 -6
- package/.github/skills/yo-core-patterns/core-patterns-cheatsheet.md +34 -0
- package/.github/skills/yo-syntax/syntax-cheatsheet.md +441 -2
- package/out/cjs/index.cjs +563 -567
- package/out/cjs/yo-cli.cjs +656 -651
- package/out/cjs/yo-lsp.cjs +614 -618
- package/out/esm/index.mjs +582 -586
- package/out/types/src/codegen/codegen-c.d.ts +2 -2
- package/out/types/src/codegen/functions/collection.d.ts +2 -2
- package/out/types/src/codegen/functions/context.d.ts +3 -2
- package/out/types/src/codegen/types/collection.d.ts +2 -2
- package/out/types/src/codegen/utils/index.d.ts +4 -1
- package/out/types/src/doc/builder.d.ts +2 -2
- package/out/types/src/evaluator/calls/closure-type.d.ts +2 -2
- package/out/types/src/evaluator/calls/record-type.d.ts +11 -0
- package/out/types/src/evaluator/context.d.ts +8 -9
- package/out/types/src/evaluator/index.d.ts +3 -3
- package/out/types/src/evaluator/types/record.d.ts +14 -0
- package/out/types/src/evaluator/types/validation.d.ts +2 -2
- package/out/types/src/evaluator/values/anonymous-module.d.ts +5 -5
- package/out/types/src/evaluator/values/impl.d.ts +1 -1
- package/out/types/src/expr.d.ts +2 -4
- package/out/types/src/function-value.d.ts +1 -1
- package/out/types/src/lsp/document-manager.d.ts +1 -1
- package/out/types/src/module-manager.d.ts +3 -3
- package/out/types/src/test-runner.d.ts +1 -0
- package/out/types/src/types/creators.d.ts +3 -4
- package/out/types/src/types/definitions.d.ts +8 -19
- package/out/types/src/types/guards.d.ts +3 -3
- package/out/types/src/types/tags.d.ts +0 -1
- package/out/types/src/types/utils.d.ts +1 -1
- package/out/types/src/value-tag.d.ts +0 -1
- package/out/types/src/value.d.ts +6 -13
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/std/error.yo +6 -6
- package/std/prelude.yo +1 -7
- package/vendor/mimalloc/.github/workflows/release.yaml +55 -0
- package/vendor/mimalloc/.github/workflows/stale.yaml +27 -0
- package/vendor/mimalloc/.github/workflows/test.yaml +163 -0
- package/vendor/mimalloc/CMakeLists.txt +52 -33
- package/vendor/mimalloc/azure-pipelines.yml +4 -3
- package/vendor/mimalloc/bin/bundle.bat +74 -0
- package/vendor/mimalloc/bin/bundle.sh +232 -0
- package/vendor/mimalloc/cmake/mimalloc-config-version.cmake +2 -2
- package/vendor/mimalloc/contrib/docker/alpine/Dockerfile +1 -1
- package/vendor/mimalloc/contrib/docker/alpine-arm32v7/Dockerfile +2 -2
- package/vendor/mimalloc/contrib/docker/alpine-x86/Dockerfile +1 -1
- package/vendor/mimalloc/contrib/docker/manylinux-x64/Dockerfile +1 -1
- package/vendor/mimalloc/contrib/vcpkg/portfile.cmake +4 -3
- package/vendor/mimalloc/contrib/vcpkg/vcpkg.json +1 -1
- package/vendor/mimalloc/doc/mimalloc-doc.h +42 -4
- package/vendor/mimalloc/doc/release-notes.md +15 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-lib.vcxproj +3 -3
- package/vendor/mimalloc/ide/vs2022/mimalloc-override-static-lib.vcxproj +511 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-override-static-lib.vcxproj.filters +117 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-test-dep.vcxproj +360 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-test-override-static.vcxproj +310 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc.sln +92 -35
- package/vendor/mimalloc/include/mimalloc/atomic.h +178 -182
- package/vendor/mimalloc/include/mimalloc/bits.h +8 -10
- package/vendor/mimalloc/include/mimalloc/internal.h +76 -32
- package/vendor/mimalloc/include/mimalloc/prim.h +25 -18
- package/vendor/mimalloc/include/mimalloc/track.h +7 -2
- package/vendor/mimalloc/include/mimalloc/types.h +57 -29
- package/vendor/mimalloc/include/mimalloc-override.h +10 -10
- package/vendor/mimalloc/include/mimalloc-stats.h +18 -6
- package/vendor/mimalloc/include/mimalloc.h +22 -12
- package/vendor/mimalloc/readme.md +42 -17
- package/vendor/mimalloc/src/alloc-aligned.c +13 -11
- package/vendor/mimalloc/src/alloc-override.c +97 -17
- package/vendor/mimalloc/src/alloc-posix.c +44 -27
- package/vendor/mimalloc/src/alloc.c +73 -23
- package/vendor/mimalloc/src/arena-meta.c +3 -3
- package/vendor/mimalloc/src/arena.c +380 -192
- package/vendor/mimalloc/src/bitmap.c +68 -18
- package/vendor/mimalloc/src/bitmap.h +8 -4
- package/vendor/mimalloc/src/free.c +83 -47
- package/vendor/mimalloc/src/heap.c +94 -40
- package/vendor/mimalloc/src/init.c +273 -102
- package/vendor/mimalloc/src/libc.c +53 -8
- package/vendor/mimalloc/src/options.c +43 -40
- package/vendor/mimalloc/src/os.c +110 -45
- package/vendor/mimalloc/src/page-map.c +14 -8
- package/vendor/mimalloc/src/page-queue.c +9 -6
- package/vendor/mimalloc/src/page.c +26 -16
- package/vendor/mimalloc/src/prim/emscripten/prim.c +10 -1
- package/vendor/mimalloc/src/prim/osx/alloc-override-zone.c +35 -16
- package/vendor/mimalloc/src/prim/unix/prim.c +26 -22
- package/vendor/mimalloc/src/prim/wasi/prim.c +7 -4
- package/vendor/mimalloc/src/prim/windows/prim.c +247 -44
- package/vendor/mimalloc/src/random.c +8 -3
- package/vendor/mimalloc/src/stats.c +59 -48
- package/vendor/mimalloc/src/theap.c +85 -44
- package/vendor/mimalloc/src/threadlocal.c +102 -41
- package/vendor/mimalloc/test/main-override-static.c +31 -2
- package/vendor/mimalloc/test/main-override.c +27 -14
- package/vendor/mimalloc/test/main-static-dep.cpp +46 -0
- package/vendor/mimalloc/test/main-static-dep.h +11 -0
- package/vendor/mimalloc/test/test-api-fill.c +2 -2
- package/vendor/mimalloc/test/test-stress.c +3 -3
- package/vendor/mimalloc/test/test-wrong.c +11 -7
- package/out/types/src/evaluator/calls/module-type.d.ts +0 -11
- package/out/types/src/evaluator/types/module.d.ts +0 -19
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* ----------------------------------------------------------------------------
|
|
2
|
-
Copyright (c) 2019-
|
|
2
|
+
Copyright (c) 2019-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.
|
|
@@ -16,21 +16,60 @@ that can be allocated.
|
|
|
16
16
|
#include "mimalloc/prim.h"
|
|
17
17
|
|
|
18
18
|
/* -----------------------------------------------------------
|
|
19
|
-
Each thread can have (a dynamically expanding) array of
|
|
20
|
-
thread-local values.
|
|
19
|
+
Each thread can have (a dynamically expanding) array of
|
|
20
|
+
thread-local values. Each slot has a value and a version.
|
|
21
|
+
The version is used to safely reuse slots.
|
|
21
22
|
----------------------------------------------------------- */
|
|
23
|
+
typedef struct mi_tls_slot_s {
|
|
24
|
+
size_t version;
|
|
25
|
+
void* value;
|
|
26
|
+
} mi_tls_slot_t;
|
|
22
27
|
|
|
23
28
|
typedef struct mi_thread_locals_s {
|
|
24
|
-
size_t
|
|
25
|
-
|
|
29
|
+
size_t count;
|
|
30
|
+
mi_tls_slot_t slots[1];
|
|
26
31
|
} mi_thread_locals_t;
|
|
27
32
|
|
|
28
|
-
static mi_thread_locals_t mi_thread_locals_empty = { 0, {NULL} };
|
|
33
|
+
static mi_thread_locals_t mi_thread_locals_empty = { 0, {{0,NULL}} };
|
|
29
34
|
|
|
30
35
|
mi_decl_thread mi_thread_locals_t* mi_thread_locals = &mi_thread_locals_empty; // always point to a valid `mi_thread_locals_t`
|
|
31
36
|
|
|
37
|
+
|
|
38
|
+
/* -----------------------------------------------------------
|
|
39
|
+
Each key consists of the slot index in the lower bits,
|
|
40
|
+
and its version it the top bits. When we get a value
|
|
41
|
+
the version must match or we return NULL. When we set
|
|
42
|
+
a value, we also set the version of the key.
|
|
43
|
+
----------------------------------------------------------- */
|
|
44
|
+
|
|
45
|
+
#if MI_SIZE_BITS < 64
|
|
46
|
+
#define MI_TLS_IDX_BITS (MI_SIZE_BITS/2) // half for the index, half for the version
|
|
47
|
+
#else
|
|
48
|
+
#define MI_TLS_IDX_BITS (MI_SIZE_BITS/4) // 16 bits for the index, 48 bits for the version
|
|
49
|
+
#endif
|
|
50
|
+
#define MI_TLS_IDX_MASK ((MI_ZU(1)<<MI_TLS_IDX_BITS)-1)
|
|
51
|
+
#define MI_TLS_IDX_MAX MI_TLS_IDX_MASK
|
|
52
|
+
#define MI_TLS_VERSION_MAX ((MI_ZU(1)<<(MI_SIZE_BITS - MI_TLS_IDX_BITS))-1)
|
|
53
|
+
|
|
54
|
+
static size_t mi_key_index( size_t key ) {
|
|
55
|
+
return (key & MI_TLS_IDX_MASK);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static size_t mi_key_version( size_t key ) {
|
|
59
|
+
return (key >> MI_TLS_IDX_BITS);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static mi_thread_local_t mi_key_create( size_t index, size_t version ) {
|
|
63
|
+
mi_assert_internal(version != 0 && version <= MI_TLS_VERSION_MAX);
|
|
64
|
+
mi_assert_internal(index <= MI_TLS_IDX_MAX);
|
|
65
|
+
const mi_thread_local_t key = ((version << MI_TLS_IDX_BITS) | index);
|
|
66
|
+
mi_assert_internal(key != 0);
|
|
67
|
+
return key;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
32
71
|
// dynamically reallocate the thread local slots when needed
|
|
33
|
-
static mi_thread_locals_t* mi_thread_locals_expand(
|
|
72
|
+
static mi_thread_locals_t* mi_thread_locals_expand(size_t least_idx) {
|
|
34
73
|
mi_thread_locals_t* tls_old = mi_thread_locals;
|
|
35
74
|
const size_t count_old = tls_old->count;
|
|
36
75
|
size_t count;
|
|
@@ -44,10 +83,11 @@ static mi_thread_locals_t* mi_thread_locals_expand(mi_thread_local_t atleast) {
|
|
|
44
83
|
else {
|
|
45
84
|
count = 2*count_old; // and double initially
|
|
46
85
|
}
|
|
47
|
-
if (count <=
|
|
48
|
-
count =
|
|
86
|
+
if (count <= least_idx) {
|
|
87
|
+
count = least_idx + 1;
|
|
49
88
|
}
|
|
50
|
-
|
|
89
|
+
if (count > MI_TLS_IDX_MAX) { return NULL; } // too large
|
|
90
|
+
mi_thread_locals_t* tls = (mi_thread_locals_t*)mi_rezalloc(tls_old, sizeof(mi_thread_locals_t) + count*sizeof(mi_tls_slot_t));
|
|
51
91
|
if mi_unlikely(tls==NULL) return NULL;
|
|
52
92
|
tls->count = count;
|
|
53
93
|
mi_thread_locals = tls;
|
|
@@ -56,11 +96,13 @@ static mi_thread_locals_t* mi_thread_locals_expand(mi_thread_local_t atleast) {
|
|
|
56
96
|
|
|
57
97
|
static mi_decl_noinline bool mi_thread_local_set_expand( mi_thread_local_t key, void* val ) {
|
|
58
98
|
if (val==NULL) return true;
|
|
59
|
-
|
|
99
|
+
const size_t idx = mi_key_index(key);
|
|
100
|
+
mi_thread_locals_t* tls = mi_thread_locals_expand(idx);
|
|
60
101
|
if (tls==NULL) return false;
|
|
61
|
-
mi_assert_internal(key < tls->count);
|
|
62
102
|
mi_assert_internal(tls == mi_thread_locals);
|
|
63
|
-
tls->
|
|
103
|
+
mi_assert_internal(idx < tls->count);
|
|
104
|
+
tls->slots[idx].value = val;
|
|
105
|
+
tls->slots[idx].version = mi_key_version(key);
|
|
64
106
|
return true;
|
|
65
107
|
}
|
|
66
108
|
|
|
@@ -69,8 +111,11 @@ static mi_decl_noinline bool mi_thread_local_set_expand( mi_thread_local_t key,
|
|
|
69
111
|
bool _mi_thread_local_set( mi_thread_local_t key, void* val ) {
|
|
70
112
|
mi_thread_locals_t* tls = mi_thread_locals;
|
|
71
113
|
mi_assert_internal(tls!=NULL);
|
|
72
|
-
|
|
73
|
-
|
|
114
|
+
mi_assert_internal(key!=0);
|
|
115
|
+
const size_t idx = mi_key_index(key);
|
|
116
|
+
if mi_likely(idx < tls->count) {
|
|
117
|
+
tls->slots[idx].value = val;
|
|
118
|
+
tls->slots[idx].version = mi_key_version(key);
|
|
74
119
|
return true;
|
|
75
120
|
}
|
|
76
121
|
else {
|
|
@@ -82,11 +127,13 @@ bool _mi_thread_local_set( mi_thread_local_t key, void* val ) {
|
|
|
82
127
|
void* _mi_thread_local_get( mi_thread_local_t key ) {
|
|
83
128
|
const mi_thread_locals_t* const tls = mi_thread_locals;
|
|
84
129
|
mi_assert_internal(tls!=NULL);
|
|
85
|
-
|
|
86
|
-
|
|
130
|
+
mi_assert_internal(key!=0);
|
|
131
|
+
const size_t idx = mi_key_index(key);
|
|
132
|
+
if mi_likely(idx < tls->count && mi_key_version(key) == tls->slots[idx].version) {
|
|
133
|
+
return tls->slots[idx].value;
|
|
87
134
|
}
|
|
88
135
|
else {
|
|
89
|
-
return NULL;
|
|
136
|
+
return NULL;
|
|
90
137
|
}
|
|
91
138
|
}
|
|
92
139
|
|
|
@@ -105,6 +152,7 @@ Create and free fresh TLS key's
|
|
|
105
152
|
|
|
106
153
|
static mi_lock_t mi_thread_locals_lock; // we need a lock in order to re-allocate the slot bits
|
|
107
154
|
static mi_bitmap_t* mi_thread_locals_free; // reuse an arena bitmap to track which slots were assigned (1=free, 0=in-use)
|
|
155
|
+
static size_t mi_thread_locals_version; // version to be able to reuse slots safely
|
|
108
156
|
|
|
109
157
|
void _mi_thread_locals_init(void) {
|
|
110
158
|
mi_lock_init(&mi_thread_locals_lock);
|
|
@@ -119,43 +167,56 @@ void _mi_thread_locals_done(void) {
|
|
|
119
167
|
}
|
|
120
168
|
|
|
121
169
|
// strange signature but allows us to reuse the arena code for claiming free pages
|
|
122
|
-
static bool
|
|
170
|
+
static bool mi_thread_local_claim_fun(size_t _slice_index, mi_arena_t* _arena, bool* keep_set) {
|
|
123
171
|
MI_UNUSED(_slice_index); MI_UNUSED(_arena);
|
|
124
172
|
*keep_set = false;
|
|
125
173
|
return true;
|
|
126
174
|
}
|
|
127
175
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
176
|
+
// When we claim a free slot, we increase the global version counter
|
|
177
|
+
// (so if we reuse a slot it will be returning NULL initially when a thread tries to get it)
|
|
178
|
+
static mi_thread_local_t mi_thread_local_claim(void) {
|
|
179
|
+
size_t idx = 0;
|
|
180
|
+
if (mi_thread_locals_free != NULL && mi_bitmap_try_find_and_claim(mi_thread_locals_free,0,&idx,&mi_thread_local_claim_fun,NULL)) {
|
|
181
|
+
mi_thread_locals_version++;
|
|
182
|
+
if (mi_thread_locals_version >= MI_TLS_VERSION_MAX) { mi_thread_locals_version = 1; } /* wrap around the version */
|
|
183
|
+
return mi_key_create( idx, mi_thread_locals_version);
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
return 0;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
static bool mi_thread_local_create_expand(void) {
|
|
191
|
+
mi_bitmap_t* const slots = mi_thread_locals_free;
|
|
131
192
|
// 1024 bits at a time
|
|
132
193
|
const size_t oldcount = (slots==NULL ? 0 : mi_bitmap_max_bits(slots));
|
|
133
194
|
const size_t newcount = 1024 + oldcount;
|
|
195
|
+
if (newcount > MI_TLS_IDX_MAX) { return false; }
|
|
134
196
|
const size_t newsize = mi_bitmap_size( newcount, NULL );
|
|
135
|
-
|
|
136
|
-
if (
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if mi_likely(slots!=NULL && mi_bitmap_try_find_and_claim(slots,0,&idx,&mi_thread_local_claim,NULL)) {
|
|
142
|
-
key = idx+1;
|
|
143
|
-
}
|
|
197
|
+
mi_bitmap_t* newslots = (mi_bitmap_t*)mi_zalloc_aligned(newsize, MI_BCHUNK_SIZE);
|
|
198
|
+
if (newslots==NULL) { return false; }
|
|
199
|
+
if (slots!=NULL) {
|
|
200
|
+
// copy over the previous bitmap
|
|
201
|
+
_mi_memcpy_aligned(newslots, slots, mi_bitmap_size(oldcount, NULL));
|
|
202
|
+
mi_free(slots);
|
|
144
203
|
}
|
|
145
|
-
|
|
204
|
+
mi_bitmap_init(newslots, newcount, true /* pretend already zero'd so we do not zero out the copied old entries */);
|
|
205
|
+
mi_bitmap_unsafe_setN(newslots, oldcount, newcount - oldcount); /* set the new expanded slots as available */
|
|
206
|
+
mi_thread_locals_free = newslots;
|
|
207
|
+
return true;
|
|
146
208
|
}
|
|
147
209
|
|
|
210
|
+
|
|
148
211
|
// create a fresh key
|
|
149
212
|
mi_thread_local_t _mi_thread_local_create(void) {
|
|
150
213
|
mi_thread_local_t key = 0;
|
|
151
214
|
mi_lock(&mi_thread_locals_lock) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
else {
|
|
158
|
-
key = mi_thread_local_create_expand();
|
|
215
|
+
key = mi_thread_local_claim();
|
|
216
|
+
if (key==0) {
|
|
217
|
+
if (mi_thread_local_create_expand()) {
|
|
218
|
+
key = mi_thread_local_claim();
|
|
219
|
+
}
|
|
159
220
|
}
|
|
160
221
|
}
|
|
161
222
|
return key;
|
|
@@ -164,11 +225,11 @@ mi_thread_local_t _mi_thread_local_create(void) {
|
|
|
164
225
|
// free a key
|
|
165
226
|
void _mi_thread_local_free(mi_thread_local_t key) {
|
|
166
227
|
if (key==0) return;
|
|
167
|
-
const size_t idx = key
|
|
228
|
+
const size_t idx = mi_key_index(key);
|
|
168
229
|
mi_lock(&mi_thread_locals_lock) {
|
|
169
230
|
mi_bitmap_t* const slots = mi_thread_locals_free;
|
|
170
231
|
if (slots!=NULL && idx < mi_bitmap_max_bits(slots)) {
|
|
171
|
-
mi_bitmap_set(slots,
|
|
232
|
+
mi_bitmap_set(slots,idx);
|
|
172
233
|
}
|
|
173
234
|
}
|
|
174
235
|
}
|
|
@@ -28,11 +28,20 @@ static void test_canary_leak(void);
|
|
|
28
28
|
static void test_manage_os_memory(void);
|
|
29
29
|
// static void test_large_pages(void);
|
|
30
30
|
|
|
31
|
+
#if _WIN32
|
|
32
|
+
#include "main-static-dep.h"
|
|
33
|
+
static void test_dep(); // test static mimalloc in a separate DLL
|
|
34
|
+
#else
|
|
35
|
+
static void test_dep() {};
|
|
36
|
+
#endif
|
|
37
|
+
|
|
31
38
|
|
|
32
39
|
int main() {
|
|
33
40
|
mi_version();
|
|
34
41
|
mi_stats_reset();
|
|
35
42
|
|
|
43
|
+
test_dep();
|
|
44
|
+
|
|
36
45
|
// mi_bins();
|
|
37
46
|
|
|
38
47
|
// test_manage_os_memory();
|
|
@@ -190,10 +199,10 @@ static void test_process_info(void) {
|
|
|
190
199
|
}
|
|
191
200
|
|
|
192
201
|
static void test_reserved(void) {
|
|
193
|
-
#define KiB
|
|
202
|
+
#define KiB 1024UL
|
|
194
203
|
#define MiB (KiB*KiB)
|
|
195
204
|
#define GiB (MiB*KiB)
|
|
196
|
-
mi_reserve_os_memory(
|
|
205
|
+
mi_reserve_os_memory(3500*MiB, false, true);
|
|
197
206
|
void* p1 = malloc(100);
|
|
198
207
|
void* p2 = malloc(100000);
|
|
199
208
|
void* p3 = malloc(2*GiB);
|
|
@@ -276,6 +285,26 @@ static void test_manage_os_memory(void) {
|
|
|
276
285
|
}
|
|
277
286
|
#endif
|
|
278
287
|
|
|
288
|
+
#if _WIN32
|
|
289
|
+
|
|
290
|
+
static void call_library(void) {
|
|
291
|
+
HMODULE dll = LoadLibraryA("mimalloc-test-static-dep.dll");
|
|
292
|
+
if (dll != NULL) {
|
|
293
|
+
TestFun fun = (TestFun)GetProcAddress(dll, "Test");
|
|
294
|
+
if (fun != NULL) {
|
|
295
|
+
fun();
|
|
296
|
+
}
|
|
297
|
+
bool ok = FreeLibrary(dll);
|
|
298
|
+
if (!ok) printf("unable to free library: %i\n", ok);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
static void test_dep(void) {
|
|
303
|
+
call_library();
|
|
304
|
+
call_library();
|
|
305
|
+
}
|
|
306
|
+
#endif
|
|
307
|
+
|
|
279
308
|
// Experiment with huge OS pages
|
|
280
309
|
#if 0
|
|
281
310
|
|
|
@@ -2,35 +2,48 @@
|
|
|
2
2
|
#include <stdio.h>
|
|
3
3
|
#include <assert.h>
|
|
4
4
|
#include <string.h>
|
|
5
|
-
|
|
6
|
-
#include <mimalloc-override.h>
|
|
5
|
+
#include <mimalloc.h>
|
|
6
|
+
// #include <mimalloc-override.h>
|
|
7
7
|
|
|
8
8
|
int main() {
|
|
9
9
|
mi_version(); // ensure mimalloc library is linked
|
|
10
10
|
void* p1 = malloc(78);
|
|
11
|
+
_expand(p1, 100);
|
|
12
|
+
if (!mi_is_in_heap_region(p1)) {
|
|
13
|
+
printf("p1: malloc failed to allocate in heap region\n");
|
|
14
|
+
return 1;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
11
18
|
void* p2 = malloc(24);
|
|
19
|
+
if (!mi_is_in_heap_region(p2)) {
|
|
20
|
+
printf("p2: malloc failed to allocate in heap region\n");
|
|
21
|
+
return 1;
|
|
22
|
+
}
|
|
12
23
|
free(p1);
|
|
13
24
|
p1 = malloc(8);
|
|
14
|
-
|
|
25
|
+
char* s = strdup("hello\n");
|
|
15
26
|
free(p2);
|
|
16
27
|
p2 = malloc(16);
|
|
17
|
-
|
|
28
|
+
void* p3 = realloc(p1, 32); if (p3!=NULL) { p1 = p3; }
|
|
18
29
|
free(p1);
|
|
19
30
|
free(p2);
|
|
20
|
-
|
|
31
|
+
free(s);
|
|
21
32
|
//mi_collect(true);
|
|
22
33
|
|
|
23
34
|
/* now test if override worked by allocating/freeing across the api's*/
|
|
24
|
-
|
|
25
|
-
//free(p1);
|
|
26
|
-
//p2 = malloc(32);
|
|
27
|
-
//mi_free(p2);
|
|
28
|
-
p1 = malloc(24);
|
|
29
|
-
p2 = reallocarray(p1, 16, 16);
|
|
30
|
-
free(p2);
|
|
31
|
-
p1 = malloc(24);
|
|
32
|
-
assert(reallocarr(&p1, 16, 16) == 0);
|
|
35
|
+
p1 = mi_malloc(32);
|
|
33
36
|
free(p1);
|
|
37
|
+
p2 = malloc(32);
|
|
38
|
+
mi_free(p2);
|
|
39
|
+
|
|
40
|
+
//p1 = malloc(24);
|
|
41
|
+
//p2 = reallocarray(p1, 16, 16);
|
|
42
|
+
//free(p2);
|
|
43
|
+
//p1 = malloc(24);
|
|
44
|
+
//assert(reallocarr(&p1, 16, 16) == 0);
|
|
45
|
+
//free(p1);
|
|
46
|
+
|
|
34
47
|
mi_stats_print(NULL);
|
|
35
48
|
return 0;
|
|
36
49
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// test allocation in a DLL that is statically linked to mimalloc
|
|
2
|
+
#include <string>
|
|
3
|
+
#include <iostream>
|
|
4
|
+
#include "main-static-dep.h"
|
|
5
|
+
#include <mimalloc.h>
|
|
6
|
+
|
|
7
|
+
class Static {
|
|
8
|
+
private:
|
|
9
|
+
void* p;
|
|
10
|
+
public:
|
|
11
|
+
Static() {
|
|
12
|
+
printf("static-dep: static constructor\n");
|
|
13
|
+
p = mi_malloc(64);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
~Static() {
|
|
17
|
+
mi_free(p);
|
|
18
|
+
printf("static-dep: static destructor\n");
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
static Static s = Static();
|
|
24
|
+
|
|
25
|
+
void Test(void) {
|
|
26
|
+
char* s = mi_mallocn_tp(char, 128);
|
|
27
|
+
strcpy_s(s, 128, "hello world!");
|
|
28
|
+
printf("message from static dll: %s\n", s);
|
|
29
|
+
mi_free(s);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
#include <windows.h>
|
|
34
|
+
|
|
35
|
+
BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID reserved) {
|
|
36
|
+
(void)(reserved);
|
|
37
|
+
(void)(module);
|
|
38
|
+
if (reason==DLL_PROCESS_ATTACH) {
|
|
39
|
+
printf("static-dep: dll attach\n");
|
|
40
|
+
}
|
|
41
|
+
else if (reason==DLL_PROCESS_DETACH) {
|
|
42
|
+
mi_option_enable(mi_option_destroy_on_exit);
|
|
43
|
+
printf("static-dep: dll detach\n");
|
|
44
|
+
}
|
|
45
|
+
return TRUE;
|
|
46
|
+
}
|
|
@@ -310,7 +310,7 @@ bool check_zero_init(uint8_t* p, size_t size) {
|
|
|
310
310
|
|
|
311
311
|
#if MI_DEBUG >= 2
|
|
312
312
|
bool check_debug_fill_uninit(uint8_t* p, size_t size) {
|
|
313
|
-
#if MI_TRACK_VALGRIND || MI_TRACK_ASAN
|
|
313
|
+
#if MI_TRACK_VALGRIND || MI_TRACK_ASAN || MI_GUARDED
|
|
314
314
|
(void)p; (void)size;
|
|
315
315
|
return true; // when compiled with valgrind we don't init on purpose
|
|
316
316
|
#else
|
|
@@ -326,7 +326,7 @@ bool check_debug_fill_uninit(uint8_t* p, size_t size) {
|
|
|
326
326
|
}
|
|
327
327
|
|
|
328
328
|
bool check_debug_fill_freed(uint8_t* p, size_t size) {
|
|
329
|
-
#if MI_TRACK_VALGRIND
|
|
329
|
+
#if MI_TRACK_VALGRIND || MI_GUARDED
|
|
330
330
|
(void)p; (void)size;
|
|
331
331
|
return true; // when compiled with valgrind we don't fill on purpose
|
|
332
332
|
#else
|
|
@@ -360,8 +360,8 @@ int main(int argc, char** argv) {
|
|
|
360
360
|
mi_option_enable(mi_option_visit_abandoned);
|
|
361
361
|
#endif
|
|
362
362
|
#if !defined(NDEBUG) && !defined(USE_STD_MALLOC)
|
|
363
|
-
mi_option_set(mi_option_arena_reserve,
|
|
364
|
-
mi_option_set(mi_option_purge_delay,1);
|
|
363
|
+
mi_option_set(mi_option_arena_reserve, mi_arena_min_size()/1024 /* in KiB ! */);
|
|
364
|
+
mi_option_set(mi_option_purge_delay,1);
|
|
365
365
|
#endif
|
|
366
366
|
#if defined(NDEBUG) && !defined(USE_STD_MALLOC)
|
|
367
367
|
// mi_option_set(mi_option_purge_delay,-1);
|
|
@@ -422,7 +422,7 @@ int main(int argc, char** argv) {
|
|
|
422
422
|
// fputs(json,stderr);
|
|
423
423
|
// mi_free(json);
|
|
424
424
|
//}
|
|
425
|
-
#endif
|
|
425
|
+
#endif
|
|
426
426
|
mi_collect(true);
|
|
427
427
|
mi_stats_print(NULL);
|
|
428
428
|
#endif
|
|
@@ -53,8 +53,11 @@ terms of the MIT license. A copy of the license can be found in the file
|
|
|
53
53
|
#endif
|
|
54
54
|
|
|
55
55
|
int main(int argc, char** argv) {
|
|
56
|
+
(void)(argc);
|
|
57
|
+
(void)(argv);
|
|
56
58
|
int* p = (int*)mi(malloc)(3*sizeof(int));
|
|
57
|
-
|
|
59
|
+
p[0] = 1;
|
|
60
|
+
|
|
58
61
|
int* r = (int*)mi_malloc_aligned(8,16);
|
|
59
62
|
mi_free(r);
|
|
60
63
|
|
|
@@ -64,19 +67,20 @@ int main(int argc, char** argv) {
|
|
|
64
67
|
mi(free)(c);
|
|
65
68
|
|
|
66
69
|
// undefined access
|
|
67
|
-
|
|
68
|
-
printf("undefined: %
|
|
70
|
+
long* q = (long*)mi(malloc)(sizeof(long));
|
|
71
|
+
printf("undefined: %ld\n", *q);
|
|
69
72
|
|
|
70
73
|
// illegal int read
|
|
71
|
-
printf("invalid: over: %
|
|
74
|
+
printf("invalid: over: %ld, under: %ld\n", q[1], q[-1]);
|
|
72
75
|
|
|
73
76
|
*q = 42;
|
|
74
77
|
|
|
75
78
|
// buffer overflow
|
|
76
79
|
q[1] = 43;
|
|
80
|
+
q[2] = 44;
|
|
77
81
|
|
|
78
82
|
// buffer underflow
|
|
79
|
-
q[-1] =
|
|
83
|
+
q[-1] = 41;
|
|
80
84
|
|
|
81
85
|
mi(free)(q);
|
|
82
86
|
|
|
@@ -84,9 +88,9 @@ int main(int argc, char** argv) {
|
|
|
84
88
|
mi(free)(q);
|
|
85
89
|
|
|
86
90
|
// use after free
|
|
87
|
-
printf("use-after-free: %
|
|
91
|
+
printf("use-after-free: %ld\n", *q);
|
|
88
92
|
|
|
89
93
|
// leak p
|
|
90
94
|
// mi_free(p)
|
|
91
95
|
return 0;
|
|
92
|
-
}
|
|
96
|
+
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type Environment } from "../../env";
|
|
2
|
-
import { type Expr } from "../../expr";
|
|
3
|
-
import type { ModuleType } from "../../types/definitions";
|
|
4
|
-
import type { EvaluatorContext, ModuleTypeCallResult } from "../context";
|
|
5
|
-
export declare function tryToImplementModuleWithArgumentsByModuleType({ moduleExpr, moduleType, argExprs, callerEnv, context, }: {
|
|
6
|
-
moduleExpr: Expr;
|
|
7
|
-
moduleType: ModuleType;
|
|
8
|
-
argExprs: Expr[];
|
|
9
|
-
callerEnv: Environment;
|
|
10
|
-
context: EvaluatorContext;
|
|
11
|
-
}): ModuleTypeCallResult;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Environment } from "../../env";
|
|
2
|
-
import { type Expr, type FnCallExpr } from "../../expr";
|
|
3
|
-
import type { ModuleField } from "../../types/definitions";
|
|
4
|
-
import type { EvaluatorContext } from "../context";
|
|
5
|
-
export declare function evaluateModuleField({ expr, moduleFieldIndex, env, context, isForEvaluatingModuleType, }: {
|
|
6
|
-
expr: Expr;
|
|
7
|
-
moduleFieldIndex: number;
|
|
8
|
-
env: Environment;
|
|
9
|
-
context: EvaluatorContext;
|
|
10
|
-
isForEvaluatingModuleType: boolean;
|
|
11
|
-
}): {
|
|
12
|
-
field: ModuleField;
|
|
13
|
-
env: Environment;
|
|
14
|
-
};
|
|
15
|
-
export declare function evaluateModuleType({ expr, env, context, }: {
|
|
16
|
-
expr: FnCallExpr;
|
|
17
|
-
env: Environment;
|
|
18
|
-
context: EvaluatorContext;
|
|
19
|
-
}): FnCallExpr;
|