]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44363: Get test_capi passing with address sanitizer (GH-26639)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 10 Jun 2021 12:02:22 +0000 (05:02 -0700)
committerGitHub <noreply@github.com>
Thu, 10 Jun 2021 12:02:22 +0000 (05:02 -0700)
(cherry picked from commit 31aa0dbff4c1d39c9d77c6c8f4a61d0e46c1268b)

Co-authored-by: Mark Shannon <mark@hotpy.org>
Include/Python.h
Misc/NEWS.d/next/Tests/2021-06-10-11-19-43.bpo-44363.-K9jD0.rst [new file with mode: 0644]
Modules/_testcapimodule.c

index 4d0335d3c52c368069051a0fef2ccf081be8577a..04858f281cab8d8d636e380b6a5dfc898388ad2b 100644 (file)
 #include "pyport.h"
 #include "pymacro.h"
 
-/* A convenient way for code to know if clang's memory sanitizer is enabled. */
+/* A convenient way for code to know if sanitizers are enabled. */
 #if defined(__has_feature)
 #  if __has_feature(memory_sanitizer)
 #    if !defined(_Py_MEMORY_SANITIZER)
 #      define _Py_MEMORY_SANITIZER
 #    endif
 #  endif
+#  if __has_feature(address_sanitizer)
+#    if !defined(_Py_ADDRESS_SANITIZER)
+#      define _Py_ADDRESS_SANITIZER
+#    endif
+#  endif
+#elif defined(__GNUC__)
+#  if defined(__SANITIZE_ADDRESS__)
+#    define _Py_ADDRESS_SANITIZER
+#  endif
 #endif
 
 #include "pymath.h"
diff --git a/Misc/NEWS.d/next/Tests/2021-06-10-11-19-43.bpo-44363.-K9jD0.rst b/Misc/NEWS.d/next/Tests/2021-06-10-11-19-43.bpo-44363.-K9jD0.rst
new file mode 100644 (file)
index 0000000..28468cb
--- /dev/null
@@ -0,0 +1,2 @@
+Account for address sanitizer in test_capi. test_capi now passes when run
+GCC address sanitizer.
index c759dcc0f152bf6cb600c91582004d1fd3d52560..ef1fb71cc90487864bd4959b24181254220ce416 100644 (file)
@@ -4829,6 +4829,10 @@ check_pyobject_forbidden_bytes_is_freed(PyObject *self, PyObject *Py_UNUSED(args
 static PyObject*
 check_pyobject_freed_is_freed(PyObject *self, PyObject *Py_UNUSED(args))
 {
+    /* This test would fail if run with the address sanitizer */
+#ifdef _Py_ADDRESS_SANITIZER
+    Py_RETURN_NONE;
+#else
     PyObject *op = _PyObject_CallNoArg((PyObject *)&PyBaseObject_Type);
     if (op == NULL) {
         return NULL;
@@ -4838,6 +4842,7 @@ check_pyobject_freed_is_freed(PyObject *self, PyObject *Py_UNUSED(args))
     Py_SET_REFCNT(op, 1);
     /* object memory is freed! */
     return test_pyobject_is_freed("check_pyobject_freed_is_freed", op);
+#endif
 }