From a97883ff9a09d15fb35e63b60c0223a88b45cff5 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sun, 10 Mar 2024 20:13:01 +0900 Subject: [PATCH 1/5] gh-112536: Define MI_TSAN to 1 for --with-mimalloc and --with-thread-sanitizer --- configure | 8 ++++++++ configure.ac | 6 ++++++ pyconfig.h.in | 3 +++ 3 files changed, 17 insertions(+) diff --git a/configure b/configure index 5e8c9af7befde0..d3114cc47fdaad 100755 --- a/configure +++ b/configure @@ -17298,6 +17298,14 @@ elif test "$disable_gil" = "yes"; then as_fn_error $? "--disable-gil requires mimalloc memory allocator (--with-mimalloc)." "$LINENO" 5 fi +if test "$with_mimalloc" = yes; then + if test "$with_tsan" = yes; then + +printf "%s\n" "#define MI_TSAN 1" >>confdefs.h + + fi +fi + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_mimalloc" >&5 printf "%s\n" "$with_mimalloc" >&6; } diff --git a/configure.ac b/configure.ac index e615259dcb1fca..5a1a03b8860b78 100644 --- a/configure.ac +++ b/configure.ac @@ -4750,6 +4750,12 @@ elif test "$disable_gil" = "yes"; then AC_MSG_ERROR([--disable-gil requires mimalloc memory allocator (--with-mimalloc).]) fi +if test "$with_mimalloc" = yes; then + if test "$with_tsan" = yes; then + AC_DEFINE([MI_TSAN], [1], [Define MI_TSAN for thread sanitizer]) + fi +fi + AC_MSG_RESULT([$with_mimalloc]) AC_SUBST([WITH_MIMALLOC]) AC_SUBST([MIMALLOC_HEADERS]) diff --git a/pyconfig.h.in b/pyconfig.h.in index e28baef51d5737..cff177154dd0bd 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1588,6 +1588,9 @@ . */ #undef MAJOR_IN_SYSMACROS +/* Define MI_TSAN for thread sanitizer */ +#undef MI_TSAN + /* Define if mvwdelch in curses.h is an expression. */ #undef MVWDELCH_IS_EXPRESSION From c2a4bae9552d3c2cd31734434404fcd57e611b18 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sun, 10 Mar 2024 20:32:01 +0900 Subject: [PATCH 2/5] Address code review --- configure.ac | 2 +- pyconfig.h.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 5a1a03b8860b78..c919e6af1efaa7 100644 --- a/configure.ac +++ b/configure.ac @@ -4752,7 +4752,7 @@ fi if test "$with_mimalloc" = yes; then if test "$with_tsan" = yes; then - AC_DEFINE([MI_TSAN], [1], [Define MI_TSAN for thread sanitizer]) + AC_DEFINE([MI_TSAN], [1], [Define MI_TSAN for mimalloc thread sanitizer support]) fi fi diff --git a/pyconfig.h.in b/pyconfig.h.in index cff177154dd0bd..f6bfb4f37ef82a 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1588,7 +1588,7 @@ . */ #undef MAJOR_IN_SYSMACROS -/* Define MI_TSAN for thread sanitizer */ +/* Define MI_TSAN for mimalloc thread sanitizer support */ #undef MI_TSAN /* Define if mvwdelch in curses.h is an expression. */ From c97684ae7493a19db4201ffda3f13ebedd55ac0e Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Mon, 11 Mar 2024 18:21:30 +0900 Subject: [PATCH 3/5] Revert "Address code review" This reverts commit c2a4bae9552d3c2cd31734434404fcd57e611b18. --- configure.ac | 2 +- pyconfig.h.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index c919e6af1efaa7..5a1a03b8860b78 100644 --- a/configure.ac +++ b/configure.ac @@ -4752,7 +4752,7 @@ fi if test "$with_mimalloc" = yes; then if test "$with_tsan" = yes; then - AC_DEFINE([MI_TSAN], [1], [Define MI_TSAN for mimalloc thread sanitizer support]) + AC_DEFINE([MI_TSAN], [1], [Define MI_TSAN for thread sanitizer]) fi fi diff --git a/pyconfig.h.in b/pyconfig.h.in index f6bfb4f37ef82a..cff177154dd0bd 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1588,7 +1588,7 @@ . */ #undef MAJOR_IN_SYSMACROS -/* Define MI_TSAN for mimalloc thread sanitizer support */ +/* Define MI_TSAN for thread sanitizer */ #undef MI_TSAN /* Define if mvwdelch in curses.h is an expression. */ From 058edaf67c6abc7c8f5609ef97f7e79562fd0ab7 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Mon, 11 Mar 2024 18:21:38 +0900 Subject: [PATCH 4/5] Revert "gh-112536: Define MI_TSAN to 1 for --with-mimalloc and --with-thread-sanitizer" This reverts commit a97883ff9a09d15fb35e63b60c0223a88b45cff5. --- configure | 8 -------- configure.ac | 6 ------ pyconfig.h.in | 3 --- 3 files changed, 17 deletions(-) diff --git a/configure b/configure index d3114cc47fdaad..5e8c9af7befde0 100755 --- a/configure +++ b/configure @@ -17298,14 +17298,6 @@ elif test "$disable_gil" = "yes"; then as_fn_error $? "--disable-gil requires mimalloc memory allocator (--with-mimalloc)." "$LINENO" 5 fi -if test "$with_mimalloc" = yes; then - if test "$with_tsan" = yes; then - -printf "%s\n" "#define MI_TSAN 1" >>confdefs.h - - fi -fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_mimalloc" >&5 printf "%s\n" "$with_mimalloc" >&6; } diff --git a/configure.ac b/configure.ac index 5a1a03b8860b78..e615259dcb1fca 100644 --- a/configure.ac +++ b/configure.ac @@ -4750,12 +4750,6 @@ elif test "$disable_gil" = "yes"; then AC_MSG_ERROR([--disable-gil requires mimalloc memory allocator (--with-mimalloc).]) fi -if test "$with_mimalloc" = yes; then - if test "$with_tsan" = yes; then - AC_DEFINE([MI_TSAN], [1], [Define MI_TSAN for thread sanitizer]) - fi -fi - AC_MSG_RESULT([$with_mimalloc]) AC_SUBST([WITH_MIMALLOC]) AC_SUBST([MIMALLOC_HEADERS]) diff --git a/pyconfig.h.in b/pyconfig.h.in index cff177154dd0bd..e28baef51d5737 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1588,9 +1588,6 @@ . */ #undef MAJOR_IN_SYSMACROS -/* Define MI_TSAN for thread sanitizer */ -#undef MI_TSAN - /* Define if mvwdelch in curses.h is an expression. */ #undef MVWDELCH_IS_EXPRESSION From 724d12ad4e63c5220462f3af81e7b432dd40c63c Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Mon, 11 Mar 2024 18:25:23 +0900 Subject: [PATCH 5/5] Address code review --- Include/internal/pycore_mimalloc.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Include/internal/pycore_mimalloc.h b/Include/internal/pycore_mimalloc.h index 3ef0154ba76d20..10d451398f1410 100644 --- a/Include/internal/pycore_mimalloc.h +++ b/Include/internal/pycore_mimalloc.h @@ -32,6 +32,10 @@ typedef enum { # define MI_DEBUG 0 #endif +#ifdef _Py_THREAD_SANITIZER +# define MI_TSAN 1 +#endif + #include "mimalloc.h" #include "mimalloc/types.h" #include "mimalloc/internal.h"