https://github.com/python/cpython/commit/72714c0266ce6d39c7c7fb63f617573b8f5a3cb2
commit: 72714c0266ce6d39c7c7fb63f617573b8f5a3cb2
branch: main
author: Sam Gross <[email protected]>
committer: colesbury <[email protected]>
date: 2024-03-05T13:54:20-05:00
summary:

gh-115103: Enable internal mimalloc assertions in debug builds (#116343)

This sets `MI_DEBUG` to `2` in debug builds to enable `mi_assert_internal()`
calls. Expensive internal assertions are not enabled.

This also disables an assertion in free-threaded builds that would be
triggered by the free-threaded GC because we traverse heaps that are not
owned by the current thread.

files:
M Include/internal/pycore_mimalloc.h
M Objects/mimalloc/alloc.c

diff --git a/Include/internal/pycore_mimalloc.h 
b/Include/internal/pycore_mimalloc.h
index 14c98108ec131e..44c160b7ac19bf 100644
--- a/Include/internal/pycore_mimalloc.h
+++ b/Include/internal/pycore_mimalloc.h
@@ -27,7 +27,7 @@ typedef enum {
 #  define MI_DEBUG_FREED      PYMEM_DEADBYTE
 #  define MI_DEBUG_PADDING    PYMEM_FORBIDDENBYTE
 #ifdef Py_DEBUG
-#  define MI_DEBUG 1
+#  define MI_DEBUG 2
 #else
 #  define MI_DEBUG 0
 #endif
diff --git a/Objects/mimalloc/alloc.c b/Objects/mimalloc/alloc.c
index e6286b54bedc14..c133f23fc9830d 100644
--- a/Objects/mimalloc/alloc.c
+++ b/Objects/mimalloc/alloc.c
@@ -609,7 +609,10 @@ bool _mi_free_delayed_block(mi_block_t* block) {
   // get segment and page
   const mi_segment_t* const segment = _mi_ptr_segment(block);
   mi_assert_internal(_mi_ptr_cookie(segment) == segment->cookie);
+#ifndef Py_GIL_DISABLED
+  // The GC traverses heaps of other threads, which can trigger this assert.
   mi_assert_internal(_mi_thread_id() == segment->thread_id);
+#endif
   mi_page_t* const page = _mi_segment_page_of(segment, block);
 
   // Clear the no-delayed flag so delayed freeing is used again for this page.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to