summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-04-06 12:07:02 (GMT)
committerGitHub <noreply@github.com>2020-04-06 12:07:02 (GMT)
commit38aefc585f60a77d66f4fbe5a37594a488b53474 (patch)
tree142fb1765e421b36ee746a6a5f53b0d52161b2c2 /Include
parent08050e959e6c40839cd2c9e5f6a4fd1513e3d605 (diff)
downloadcpython-38aefc585f60a77d66f4fbe5a37594a488b53474.zip
cpython-38aefc585f60a77d66f4fbe5a37594a488b53474.tar.gz
cpython-38aefc585f60a77d66f4fbe5a37594a488b53474.tar.bz2
bpo-40170: PyObject_GET_WEAKREFS_LISTPTR() becomes a function (GH-19377)
Convert the PyObject_GET_WEAKREFS_LISTPTR() macro to a function to hide implementation details: the macro accessed directly to the PyTypeObject.tp_weaklistoffset member. Add _PyObject_GET_WEAKREFS_LISTPTR() static inline function to the internal C API.
Diffstat (limited to 'Include')
-rw-r--r--Include/cpython/objimpl.h3
-rw-r--r--Include/internal/pycore_object.h7
2 files changed, 8 insertions, 2 deletions
diff --git a/Include/cpython/objimpl.h b/Include/cpython/objimpl.h
index 8e3c964..2f802e9 100644
--- a/Include/cpython/objimpl.h
+++ b/Include/cpython/objimpl.h
@@ -138,8 +138,7 @@ PyAPI_FUNC(PyObject *) _PyObject_GC_Calloc(size_t size);
/* Test if a type supports weak references */
#define PyType_SUPPORTS_WEAKREFS(t) ((t)->tp_weaklistoffset > 0)
-#define PyObject_GET_WEAKREFS_LISTPTR(o) \
- ((PyObject **) (((char *) (o)) + Py_TYPE(o)->tp_weaklistoffset))
+PyAPI_FUNC(PyObject **) PyObject_GET_WEAKREFS_LISTPTR(PyObject *op);
#ifdef __cplusplus
}
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index 10a5746..002b700 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -87,6 +87,13 @@ extern void _Py_PrintReferences(FILE *);
extern void _Py_PrintReferenceAddresses(FILE *);
#endif
+static inline PyObject **
+_PyObject_GET_WEAKREFS_LISTPTR(PyObject *op)
+{
+ Py_ssize_t offset = Py_TYPE(op)->tp_weaklistoffset;
+ return (PyObject **)((char *)op + offset);
+}
+
#ifdef __cplusplus
}
#endif