Skip to content

bpo-40170: Remove PyHeapType_GET_MEMBERS() macro #30942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -951,3 +951,8 @@ Removed
worked since the :c:type:`PyWeakReference` structure is opaque in the
limited C API.
(Contributed by Victor Stinner in :issue:`35134`.)

* Remove the ``PyHeapType_GET_MEMBERS()`` macro. It was exposed in the
public C API by mistake, it must only be used by Python internally.
Use the ``PyTypeObject.tp_members`` member instead.
(Contributed by Victor Stinner in :issue:`40170`.)
4 changes: 0 additions & 4 deletions Include/cpython/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,6 @@ typedef struct _heaptypeobject {
/* here are optional user slots, followed by the members. */
} PyHeapTypeObject;

/* access macro to the members which are floating "behind" the object */
#define PyHeapType_GET_MEMBERS(etype) \
((PyMemberDef *)(((char *)etype) + Py_TYPE(etype)->tp_basicsize))

PyAPI_FUNC(const char *) _PyType_Name(PyTypeObject *);
PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);
PyAPI_FUNC(PyObject *) _PyType_LookupId(PyTypeObject *, _Py_Identifier *);
Expand Down
4 changes: 4 additions & 0 deletions Include/internal/pycore_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ extern void _PyObject_FreeInstanceAttributes(PyObject *self);
extern int _PyObject_IsInstanceDictEmpty(PyObject *);
extern PyObject* _PyType_GetSubclasses(PyTypeObject *);

// Access macro to the members which are floating "behind" the object
#define _PyHeapType_GET_MEMBERS(etype) \
((PyMemberDef *)(((char *)etype) + Py_TYPE(etype)->tp_basicsize))

#ifdef __cplusplus
}
#endif
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Remove the ``PyHeapType_GET_MEMBERS()`` macro. It was exposed in the public C
API by mistake, it must only be used by Python internally. Use the
``PyTypeObject.tp_members`` member instead. Patch by Victor Stinner.

12 changes: 6 additions & 6 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ traverse_slots(PyTypeObject *type, PyObject *self, visitproc visit, void *arg)
PyMemberDef *mp;

n = Py_SIZE(type);
mp = PyHeapType_GET_MEMBERS((PyHeapTypeObject *)type);
mp = _PyHeapType_GET_MEMBERS((PyHeapTypeObject *)type);
for (i = 0; i < n; i++, mp++) {
if (mp->type == T_OBJECT_EX) {
char *addr = (char *)self + mp->offset;
Expand Down Expand Up @@ -1281,7 +1281,7 @@ clear_slots(PyTypeObject *type, PyObject *self)
PyMemberDef *mp;

n = Py_SIZE(type);
mp = PyHeapType_GET_MEMBERS((PyHeapTypeObject *)type);
mp = _PyHeapType_GET_MEMBERS((PyHeapTypeObject *)type);
for (i = 0; i < n; i++, mp++) {
if (mp->type == T_OBJECT_EX && !(mp->flags & READONLY)) {
char *addr = (char *)self + mp->offset;
Expand Down Expand Up @@ -2968,7 +2968,7 @@ type_new_descriptors(const type_new_ctx *ctx, PyTypeObject *type)
PyHeapTypeObject *et = (PyHeapTypeObject *)type;
Py_ssize_t slotoffset = ctx->base->tp_basicsize;
if (et->ht_slots != NULL) {
PyMemberDef *mp = PyHeapType_GET_MEMBERS(et);
PyMemberDef *mp = _PyHeapType_GET_MEMBERS(et);
Py_ssize_t nslot = PyTuple_GET_SIZE(et->ht_slots);
for (Py_ssize_t i = 0; i < nslot; i++, mp++) {
mp->name = PyUnicode_AsUTF8(
Expand Down Expand Up @@ -3005,7 +3005,7 @@ type_new_descriptors(const type_new_ctx *ctx, PyTypeObject *type)

type->tp_basicsize = slotoffset;
type->tp_itemsize = ctx->base->tp_itemsize;
type->tp_members = PyHeapType_GET_MEMBERS(et);
type->tp_members = _PyHeapType_GET_MEMBERS(et);
return 0;
}

Expand Down Expand Up @@ -3561,8 +3561,8 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases)
else if (slot->slot == Py_tp_members) {
/* Move the slots to the heap type itself */
size_t len = Py_TYPE(type)->tp_itemsize * nmembers;
memcpy(PyHeapType_GET_MEMBERS(res), slot->pfunc, len);
type->tp_members = PyHeapType_GET_MEMBERS(res);
memcpy(_PyHeapType_GET_MEMBERS(res), slot->pfunc, len);
type->tp_members = _PyHeapType_GET_MEMBERS(res);
}
else {
/* Copy other slots directly */
Expand Down