[pypy-commit] pypy py3.7-tracemalloc: Expose tracemalloc C API
Stian Andreassen
pypy.commits at gmail.com
Mon Dec 9 11:10:30 EST 2019
Author: Stian Andreassen
Branch: py3.7-tracemalloc
Changeset: r98262:c31bb71da53e
Date: 2019-12-09 17:09 +0100
http://bitbucket.org/pypy/pypy/changeset/c31bb71da53e/
Log: Expose tracemalloc C API
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -655,7 +655,7 @@
'PyMem_RawMalloc', 'PyMem_RawCalloc', 'PyMem_RawRealloc', 'PyMem_RawFree',
'PyMem_Malloc', 'PyMem_Calloc', 'PyMem_Realloc', 'PyMem_Free',
'PyObject_CallFinalizerFromDealloc',
- '_PyTraceMalloc_Track', '_PyTraceMalloc_Untrack',
+ 'PyTraceMalloc_Track', 'PyTraceMalloc_Untrack',
'PyBytes_FromFormat', 'PyBytes_FromFormatV',
'PyType_FromSpec',
diff --git a/pypy/module/cpyext/include/pymem.h b/pypy/module/cpyext/include/pymem.h
--- a/pypy/module/cpyext/include/pymem.h
+++ b/pypy/module/cpyext/include/pymem.h
@@ -61,9 +61,9 @@
#define PyMem_DEL PyMem_FREE
-/* From CPython 3.6, with a different goal. _PyTraceMalloc_Track()
+/* From CPython 3.6, with a different goal. PyTraceMalloc_Track()
* is equivalent to __pypy__.add_memory_pressure(size); it works with
- * or without the GIL. _PyTraceMalloc_Untrack() is an empty stub.
+ * or without the GIL. PyTraceMalloc_Untrack() is an empty stub.
* You can check if these functions are available by using:
*
* #if defined(PYPY_TRACEMALLOC) || \
@@ -71,11 +71,9 @@
*/
#define PYPY_TRACEMALLOC 1
-typedef unsigned int _PyTraceMalloc_domain_t;
-
-PyAPI_FUNC(int) _PyTraceMalloc_Track(_PyTraceMalloc_domain_t domain,
+PyAPI_FUNC(int) PyTraceMalloc_Track(unsigned int domain,
uintptr_t ptr, size_t size);
-PyAPI_FUNC(int) _PyTraceMalloc_Untrack(_PyTraceMalloc_domain_t domain,
+PyAPI_FUNC(int) PyTraceMalloc_Untrack(unsigned int domain,
uintptr_t ptr);
diff --git a/pypy/module/cpyext/src/pymem.c b/pypy/module/cpyext/src/pymem.c
--- a/pypy/module/cpyext/src/pymem.c
+++ b/pypy/module/cpyext/src/pymem.c
@@ -94,7 +94,7 @@
free(ptr);
}
-int _PyTraceMalloc_Track(_PyTraceMalloc_domain_t domain,
+int PyTraceMalloc_Track(unsigned int domain,
uintptr_t ptr, size_t size)
{
/* to avoid acquiring/releasing the GIL too often, only do it
@@ -133,7 +133,7 @@
/* Should we return -2 or 0? In theory it should be -2, because
we're not using the info to really track the allocations.
But I'm sure someone is too clever somewhere and stops calling
- _PyTraceMalloc_Track() if it returns -2. On the other hand,
+ PyTraceMalloc_Track() if it returns -2. On the other hand,
returning 0 might lead to expectations that importing
'tracemalloc' works on Python 3. Oh well, in that case we'll
just crash with ImportError during 'import tracemalloc'.
@@ -141,7 +141,7 @@
return 0;
}
-int _PyTraceMalloc_Untrack(_PyTraceMalloc_domain_t domain,
+int PyTraceMalloc_Untrack(unsigned int domain,
uintptr_t ptr)
{
/* nothing to do */
diff --git a/pypy/module/cpyext/test/test_object.py b/pypy/module/cpyext/test/test_object.py
--- a/pypy/module/cpyext/test/test_object.py
+++ b/pypy/module/cpyext/test/test_object.py
@@ -391,7 +391,7 @@
module = self.import_extension('foo', [
("foo", "METH_O",
"""
- _PyTraceMalloc_Track(0, 0, PyLong_AsLong(args) - sizeof(long));
+ PyTraceMalloc_Track(0, 0, PyLong_AsLong(args) - sizeof(long));
Py_INCREF(Py_None);
return Py_None;
""")])
More information about the pypy-commit
mailing list