]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40170: Remove PyHeapType_GET_MEMBERS() macro (GH-30942)
authorVictor Stinner <vstinner@python.org>
Thu, 27 Jan 2022 23:39:52 +0000 (00:39 +0100)
committerGitHub <noreply@github.com>
Thu, 27 Jan 2022 23:39:52 +0000 (00:39 +0100)
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.

Rename PyHeapType_GET_MEMBERS() to _PyHeapType_GET_MEMBERS() and move
it to the internal C API.

Doc/whatsnew/3.11.rst
Include/cpython/object.h
Include/internal/pycore_object.h
Misc/NEWS.d/next/C API/2022-01-27-02-51-22.bpo-40170.uPolek.rst [new file with mode: 0644]
Objects/typeobject.c

index adf38b6b0145c25ad6706a067f8e65194f7d7c5c..daa0a2af0619b79b963560cd120079841952241d 100644 (file)
@@ -929,3 +929,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`.)
index 0c3957aff4b5d319d3b89024068b0cfccb937f72..7b9f3acbc439d699f30e3c36b292114e610a44d9 100644 (file)
@@ -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 *);
index 5fe4ddb2efbe1e87c20fe1f7903dd9e5bff3d622..e2da2537c11c1401a02bfe219de8d6349830e12b 100644 (file)
@@ -232,6 +232,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
diff --git a/Misc/NEWS.d/next/C API/2022-01-27-02-51-22.bpo-40170.uPolek.rst b/Misc/NEWS.d/next/C API/2022-01-27-02-51-22.bpo-40170.uPolek.rst
new file mode 100644 (file)
index 0000000..6b185f0
--- /dev/null
@@ -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.
+
index 39e8b466ce82dd835d9525ee2aee04221133cae3..621ad9745d8448c994c078229e86dec5af985f65 100644 (file)
@@ -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;
@@ -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;
@@ -2977,7 +2977,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(
@@ -3014,7 +3014,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;
 }
 
@@ -3570,8 +3570,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 */