Skip to content

Commit f83cdf5

Browse files
committed
Fix C++ function signatures in mimalloc
The C++ functions that take `std::nothrow_t` all take a reference. Without this change I'm seeing function signature mismatches because the final argument is not pointer-width. I'm guessing this simply went unnoticed because most platforms don't do signature checking in the linker and this just happens to work. e.g. `_ZnwjRKSt9nothrow_t` which demangles to `operator new(unsigned int, std::nothrow_t const&)`
1 parent 014afb6 commit f83cdf5

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

system/lib/mimalloc/src/alloc-override.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ typedef struct mi_nothrow_s { int _tag; } mi_nothrow_t;
108108
void _ZdaPvm(void* p, size_t n); // delete[]
109109
void* _Znwm(size_t n); // new
110110
void* _Znam(size_t n); // new[]
111-
void* _ZnwmRKSt9nothrow_t(size_t n, mi_nothrow_t tag); // new nothrow
112-
void* _ZnamRKSt9nothrow_t(size_t n, mi_nothrow_t tag); // new[] nothrow
111+
// XXX EMSCRIPTEN: Use pointer type for nothrow argument
112+
void* _ZnwmRKSt9nothrow_t(size_t n, mi_nothrow_t* tag); // new nothrow
113+
void* _ZnamRKSt9nothrow_t(size_t n, mi_nothrow_t* tag); // new[] nothrow
113114
#ifdef __cplusplus
114115
}
115116
#endif
@@ -201,21 +202,23 @@ typedef struct mi_nothrow_s { int _tag; } mi_nothrow_t;
201202
#if (MI_INTPTR_SIZE==8)
202203
void* _Znwm(size_t n) MI_FORWARD1(mi_new,n) // new 64-bit
203204
void* _Znam(size_t n) MI_FORWARD1(mi_new,n) // new[] 64-bit
204-
void* _ZnwmRKSt9nothrow_t(size_t n, mi_nothrow_t tag) { MI_UNUSED(tag); return mi_new_nothrow(n); }
205-
void* _ZnamRKSt9nothrow_t(size_t n, mi_nothrow_t tag) { MI_UNUSED(tag); return mi_new_nothrow(n); }
205+
// XXX EMSCRIPTEN: Use pointer type for nothrow argument
206+
void* _ZnwmRKSt9nothrow_t(size_t n, mi_nothrow_t* tag) { MI_UNUSED(tag); return mi_new_nothrow(n); }
207+
void* _ZnamRKSt9nothrow_t(size_t n, mi_nothrow_t* tag) { MI_UNUSED(tag); return mi_new_nothrow(n); }
206208
void* _ZnwmSt11align_val_t(size_t n, size_t al) MI_FORWARD2(mi_new_aligned, n, al)
207209
void* _ZnamSt11align_val_t(size_t n, size_t al) MI_FORWARD2(mi_new_aligned, n, al)
208-
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); }
209-
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); }
210+
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); }
211+
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); }
210212
#elif (MI_INTPTR_SIZE==4)
211213
void* _Znwj(size_t n) MI_FORWARD1(mi_new,n) // new 64-bit
212214
void* _Znaj(size_t n) MI_FORWARD1(mi_new,n) // new[] 64-bit
213-
void* _ZnwjRKSt9nothrow_t(size_t n, mi_nothrow_t tag) { MI_UNUSED(tag); return mi_new_nothrow(n); }
214-
void* _ZnajRKSt9nothrow_t(size_t n, mi_nothrow_t tag) { MI_UNUSED(tag); return mi_new_nothrow(n); }
215+
// XXX EMSCRIPTEN: Use pointer type for nothrow argument
216+
void* _ZnwjRKSt9nothrow_t(size_t n, mi_nothrow_t* tag) { MI_UNUSED(tag); return mi_new_nothrow(n); }
217+
void* _ZnajRKSt9nothrow_t(size_t n, mi_nothrow_t* tag) { MI_UNUSED(tag); return mi_new_nothrow(n); }
215218
void* _ZnwjSt11align_val_t(size_t n, size_t al) MI_FORWARD2(mi_new_aligned, n, al)
216219
void* _ZnajSt11align_val_t(size_t n, size_t al) MI_FORWARD2(mi_new_aligned, n, al)
217-
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); }
218-
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); }
220+
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); }
221+
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); }
219222
#else
220223
#error "define overloads for new/delete for this platform (just for performance, can be skipped)"
221224
#endif

0 commit comments

Comments
 (0)