PyAPI_FUNC(void *) PyMem_RawRealloc(void *ptr, size_t new_size);
PyAPI_FUNC(void) PyMem_RawFree(void *ptr);
-/* Try to get the allocators name set by _PyMem_SetupAllocators(). */
-PyAPI_FUNC(const char*) _PyMem_GetCurrentAllocatorName(void);
-
-/* strdup() using PyMem_RawMalloc() */
-PyAPI_FUNC(char *) _PyMem_RawStrdup(const char *str);
-
-/* strdup() using PyMem_Malloc() */
-PyAPI_FUNC(char *) _PyMem_Strdup(const char *str);
-
-/* wcsdup() using PyMem_RawMalloc() */
-PyAPI_FUNC(wchar_t*) _PyMem_RawWcsdup(const wchar_t *str);
-
typedef enum {
/* PyMem_RawMalloc(), PyMem_RawRealloc() and PyMem_RawFree() */
# error "this header requires Py_BUILD_CORE define"
#endif
-#include "pymem.h" // PyMemAllocatorName
+// Try to get the allocators name set by _PyMem_SetupAllocators().
+// Return NULL if unknown.
+// Export for shared _testinternalcapi extension.
+PyAPI_FUNC(const char*) _PyMem_GetCurrentAllocatorName(void);
+// strdup() using PyMem_RawMalloc()
+extern char* _PyMem_RawStrdup(const char *str);
+
+// strdup() using PyMem_Malloc().
+// Export for shared _pickle extension.
+PyAPI_FUNC(char*) _PyMem_Strdup(const char *str);
+
+// wcsdup() using PyMem_RawMalloc()
+extern wchar_t* _PyMem_RawWcsdup(const wchar_t *str);
typedef struct {
/* We tag each block with an API ID in order to tag API violations */
def collect_testcapi(info_add):
try:
- import _testcapi
+ import _testinternalcapi
except ImportError:
return
- call_func(info_add, 'pymem.allocator', _testcapi, 'pymem_getallocatorsname')
+ call_func(info_add, 'pymem.allocator', _testinternalcapi, 'pymem_getallocatorsname')
def collect_resource(info_add):
# Memory allocator debug hooks
try:
- import _testcapi
+ import _testinternalcapi
except ImportError:
pass
else:
- code = "import _testcapi; print(_testcapi.pymem_getallocatorsname())"
+ code = "import _testinternalcapi; print(_testinternalcapi.pymem_getallocatorsname())"
with support.SuppressCrashReport():
out = self.run_xdev("-c", code, check_exitcode=False)
if support.with_pymalloc():
self.assertEqual(out, expected_filters)
def check_pythonmalloc(self, env_var, name):
- code = 'import _testcapi; print(_testcapi.pymem_getallocatorsname())'
+ code = 'import _testinternalcapi; print(_testinternalcapi.pymem_getallocatorsname())'
env = dict(os.environ)
env.pop('PYTHONDEVMODE', None)
if env_var is not None:
"sys.getallocatedblocks unavailable on this build")
def test_getallocatedblocks(self):
try:
- import _testcapi
+ import _testinternalcapi
except ImportError:
with_pymalloc = support.with_pymalloc()
else:
try:
- alloc_name = _testcapi.pymem_getallocatorsname()
+ alloc_name = _testinternalcapi.pymem_getallocatorsname()
except RuntimeError as exc:
# "cannot get allocators name" (ex: tracemalloc is used)
with_pymalloc = True
Py_RETURN_NONE;
}
-static PyObject *
-test_pymem_getallocatorsname(PyObject *self, PyObject *args)
-{
- const char *name = _PyMem_GetCurrentAllocatorName();
- if (name == NULL) {
- PyErr_SetString(PyExc_RuntimeError, "cannot get allocators name");
- return NULL;
- }
- return PyUnicode_FromString(name);
-}
-
static PyObject *
test_pymem_setrawallocators(PyObject *self, PyObject *Py_UNUSED(ignored))
{
static PyMethodDef test_methods[] = {
{"pymem_api_misuse", pymem_api_misuse, METH_NOARGS},
{"pymem_buffer_overflow", pymem_buffer_overflow, METH_NOARGS},
- {"pymem_getallocatorsname", test_pymem_getallocatorsname, METH_NOARGS},
{"pymem_malloc_without_gil", pymem_malloc_without_gil, METH_NOARGS},
{"pyobject_malloc_without_gil", pyobject_malloc_without_gil, METH_NOARGS},
{"remove_mem_hooks", remove_mem_hooks, METH_NOARGS,
}
+static PyObject *
+test_pymem_getallocatorsname(PyObject *self, PyObject *args)
+{
+ const char *name = _PyMem_GetCurrentAllocatorName();
+ if (name == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "cannot get allocators name");
+ return NULL;
+ }
+ return PyUnicode_FromString(name);
+}
+
+
static PyMethodDef module_functions[] = {
{"get_configs", get_configs, METH_NOARGS},
{"get_recursion_depth", get_recursion_depth, METH_NOARGS},
{"check_pyobject_null_is_freed", check_pyobject_null_is_freed, METH_NOARGS},
{"check_pyobject_uninitialized_is_freed",
check_pyobject_uninitialized_is_freed, METH_NOARGS},
+ {"pymem_getallocatorsname", test_pymem_getallocatorsname, METH_NOARGS},
{NULL, NULL} /* sentinel */
};
/* Return the initial module search path. */
#include "Python.h"
+#include "pycore_fileutils.h" // _Py_abspath()
+#include "pycore_initconfig.h" // _PyStatus_EXCEPTION()
+#include "pycore_pathconfig.h" // _PyPathConfig_ReadGlobal()
+#include "pycore_pymem.h" // _PyMem_RawWcsdup()
+
#include "marshal.h" // PyMarshal_ReadObjectFromString
#include "osdefs.h" // DELIM
-#include "pycore_initconfig.h"
-#include "pycore_fileutils.h"
-#include "pycore_pathconfig.h"
#include <wchar.h>
#ifdef MS_WINDOWS