]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-36142: Add _PyMem_GetDebugAllocatorsName() (GH-12185)
authorVictor Stinner <vstinner@redhat.com>
Tue, 5 Mar 2019 22:31:54 +0000 (23:31 +0100)
committerGitHub <noreply@github.com>
Tue, 5 Mar 2019 22:31:54 +0000 (23:31 +0100)
The development mode now uses the effective name of the debug memory
allocator ("pymalloc_debug" or "malloc_debug"). So the name doesn't
change after setting the memory allocator.

Include/internal/pycore_pymem.h
Lib/test/test_embed.py
Objects/obmalloc.c
Programs/_testembed.c
Python/preconfig.c

index 1e7da87cd75c0aa9e4b7adb79634c5781a00bb7d..fedc7cc119bfb5d11ad4dca9f268d06976c13f6e 100644 (file)
@@ -155,6 +155,8 @@ PyAPI_FUNC(int) _PyMem_SetDefaultAllocator(
     PyMemAllocatorDomain domain,
     PyMemAllocatorEx *old_alloc);
 
+PyAPI_FUNC(const char*) _PyMem_GetDebugAllocatorsName(void);
+
 #ifdef __cplusplus
 }
 #endif
index 1f236a985ad6a25f1b19dbbbfacd8cd9e2528cd7..2827e8708e114d34b639b2237f0bb77cd766e179 100644 (file)
@@ -336,6 +336,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
             'legacy_windows_fs_encoding': 0,
             'legacy_windows_stdio': 0,
         })
+    DEBUG_ALLOCATOR = 'pymalloc_debug' if support.with_pymalloc() else 'malloc_debug'
 
     # main config
     COPY_MAIN_CONFIG = (
@@ -588,7 +589,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
 
     def test_init_env_dev_mode(self):
         config = dict(self.INIT_ENV_CONFIG,
-                      allocator='debug',
+                      allocator=self.DEBUG_ALLOCATOR,
                       dev_mode=1)
         self.check_config("init_env_dev_mode", config)
 
@@ -596,7 +597,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
         config = {
             'dev_mode': 1,
             'faulthandler': 1,
-            'allocator': 'debug',
+            'allocator': self.DEBUG_ALLOCATOR,
         }
         self.check_config("init_dev_mode", config)
 
index 1c2a32050f9381e0a8aab3591a42e191e8401644..1afbcca14f28aa7039135c336714e0c0cc3f38e5 100644 (file)
@@ -221,6 +221,20 @@ static PyMemAllocatorEx _PyObject = PYOBJ_ALLOC;
 #endif
 
 
+/* Get the effective name of "debug" memory allocators,
+   as if _PyMem_GetAllocatorsName() is called after
+   _PyMem_SetupAllocators("debug"). */
+const char*
+_PyMem_GetDebugAllocatorsName(void)
+{
+#ifdef WITH_PYMALLOC
+    return "pymalloc_debug";
+#else
+    return "malloc_debug";
+#endif
+}
+
+
 static int
 pymem_set_default_allocator(PyMemAllocatorDomain domain, int debug,
                             PyMemAllocatorEx *old_alloc)
index 70bf96036a2a93c12294b43276dcde37879d180a..170672e4439ac75c216ebaf86c1c7eab72ce10b4 100644 (file)
@@ -139,6 +139,9 @@ static int test_forced_io_encoding(void)
 
 static int test_pre_initialization_api(void)
 {
+    /* the test doesn't support custom memory allocators */
+    putenv("PYTHONMALLOC=");
+
     /* Leading "./" ensures getpath.c can still find the standard library */
     _Py_EMBED_PREINIT_CHECK("Checking Py_DecodeLocale\n");
     wchar_t *program = Py_DecodeLocale("./spam", NULL);
@@ -235,6 +238,9 @@ static void bpo20891_thread(void *lockp)
 
 static int test_bpo20891(void)
 {
+    /* the test doesn't support custom memory allocators */
+    putenv("PYTHONMALLOC=");
+
     /* bpo-20891: Calling PyGILState_Ensure in a non-Python thread before
        calling PyEval_InitThreads() must not crash. PyGILState_Ensure() must
        call PyEval_InitThreads() for us in this case. */
index 98e0edead1773d952b64e4fde06c0e59a5d5400e..46e1809fc548396b42c324280ea971510f3a0ed5 100644 (file)
@@ -453,7 +453,8 @@ preconfig_read(_PyPreConfig *config, const _PyPreCmdline *cmdline)
 
     /* allocator */
     if (config->dev_mode && config->allocator == NULL) {
-        config->allocator = _PyMem_RawStrdup("debug");
+        const char *allocator = _PyMem_GetDebugAllocatorsName();
+        config->allocator = _PyMem_RawStrdup(allocator);
         if (config->allocator == NULL) {
             return _Py_INIT_NO_MEMORY();
         }