Skip to content

Commit 568dacd

Browse files
committed
Better _ZSt15get_new_handlerv fix
1 parent 622cf69 commit 568dacd

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

‎Include/internal/pycore_mimalloc.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
#ifdef WITH_MIMALLOC
1616
# define MI_NO_PTHREAD_ATFORK 1
17+
// CPython never uses mimalloc's C++ operator new APIs, so don't define a weak
18+
// std::get_new_handler() (_ZSt15get_new_handlerv) in libpython.
19+
# define MI_NO_CXX_NEW_HANDLER 1
1720
# ifdef MS_WINDOWS
1821
// Initialize from a CRT initializer and use FLS for thread cleanup instead
1922
// of TLS callbacks, which run during DLL attach before the CRT is set up.

‎Objects/mimalloc/alloc/alloc.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,9 @@ static bool mi_try_new_handler(void) {
822822
#else
823823
typedef void (*std_new_handler_t)(void);
824824

825-
#if (defined(__GNUC__) || (defined(__clang__) && !defined(_MSC_VER))) // exclude clang-cl, see issue #631
825+
// Define MI_NO_CXX_NEW_HANDLER to not define a weak `std::get_new_handler` (`_ZSt15get_new_handlerv`)
826+
// when the C++ new-handler is never used (e.g. when only the C API is used).
827+
#if (defined(__GNUC__) || (defined(__clang__) && !defined(_MSC_VER))) && !defined(MI_NO_CXX_NEW_HANDLER) // exclude clang-cl, see issue #631
826828
std_new_handler_t __attribute__((weak)) _ZSt15get_new_handlerv(void) {
827829
return NULL;
828830
}

‎Tools/build/smelly.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# mimalloc doesn't use static, but it's symbols are not exported
2121
# from the shared library. They do show up in the static library
2222
# before its linked into an executable.
23-
ALLOWED_STATIC_PREFIXES = ('mi_', '_mi_', '__mi', '_ZSt')
23+
ALLOWED_STATIC_PREFIXES = ('mi_', '_mi_', '__mi')
2424

2525
# "Legacy": some old symbols are prefixed by "PY_".
2626
EXCEPTIONS = frozenset({

0 commit comments

Comments
 (0)