/* 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
}
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
--- /dev/null
+Convert the :c:func:`PyObject_GET_WEAKREFS_LISTPTR` macro to a function to hide
+implementation details: the macro accessed directly to the
+:c:member:`PyTypeObject.tp_weaklistoffset` member.
#include "Python.h"
+#include "pycore_object.h" // _PyObject_GET_WEAKREFS_LISTPTR
#define GET_WEAKREFS_LISTPTR(o) \
- ((PyWeakReference **) PyObject_GET_WEAKREFS_LISTPTR(o))
+ ((PyWeakReference **) _PyObject_GET_WEAKREFS_LISTPTR(o))
/*[clinic input]
module _weakref
/* It supports weakrefs. Does it have any? */
wrlist = (PyWeakReference **)
- PyObject_GET_WEAKREFS_LISTPTR(op);
+ _PyObject_GET_WEAKREFS_LISTPTR(op);
/* `op` may have some weakrefs. March over the list, clear
* all the weakrefs, and move the weakrefs with callbacks
(*dealloc)(op);
}
+
+PyObject **
+PyObject_GET_WEAKREFS_LISTPTR(PyObject *op)
+{
+ return _PyObject_GET_WEAKREFS_LISTPTR(op);
+}
+
+
#ifdef __cplusplus
}
#endif
if (type->tp_weaklistoffset && !base->tp_weaklistoffset) {
/* Modeled after GET_WEAKREFS_LISTPTR() */
PyWeakReference **list = (PyWeakReference **) \
- PyObject_GET_WEAKREFS_LISTPTR(self);
+ _PyObject_GET_WEAKREFS_LISTPTR(self);
while (*list)
_PyWeakref_ClearRef(*list);
}
#include "Python.h"
+#include "pycore_object.h" // _PyObject_GET_WEAKREFS_LISTPTR
#include "structmember.h"
#define GET_WEAKREFS_LISTPTR(o) \
- ((PyWeakReference **) PyObject_GET_WEAKREFS_LISTPTR(o))
+ ((PyWeakReference **) _PyObject_GET_WEAKREFS_LISTPTR(o))
Py_ssize_t