Skip to content

Commit 9737fa5

Browse files
committed
bpo-44348: Revert "bpo-39573: Py_TYPE becomes a static inline function (pythonGH-26493)"
This reverts commit f3fa63e as is causing crashes in some Windows tests in the buildbots.
1 parent fa106a6 commit 9737fa5

File tree

5 files changed

+9
-52
lines changed

5 files changed

+9
-52
lines changed

Doc/c-api/structures.rst

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,7 @@ the definition of all other Python objects.
9999
100100
Return a :term:`borrowed reference`.
101101
102-
Use the :c:func:`Py_SET_TYPE` function to set an object type.
103-
104-
.. versionchanged:: 3.11
105-
:c:func:`Py_TYPE()` is changed to an inline static function.
102+
The :c:func:`Py_SET_TYPE` function must be used to set an object type.
106103
107104
108105
.. c:function:: int Py_IS_TYPE(PyObject *o, PyTypeObject *type)
@@ -124,10 +121,9 @@ the definition of all other Python objects.
124121
125122
Get the reference count of the Python object *o*.
126123
127-
Use the :c:func:`Py_SET_REFCNT()` function to set an object reference count.
128-
129124
.. versionchanged:: 3.10
130125
:c:func:`Py_REFCNT()` is changed to the inline static function.
126+
Use :c:func:`Py_SET_REFCNT()` to set an object reference count.
131127
132128
133129
.. c:function:: void Py_SET_REFCNT(PyObject *o, Py_ssize_t refcnt)
@@ -141,10 +137,7 @@ the definition of all other Python objects.
141137
142138
Get the size of the Python object *o*.
143139
144-
Use the :c:func:`Py_SET_SIZE` function to set an object size.
145-
146-
.. versionchanged:: 3.11
147-
:c:func:`Py_SIZE()` is changed to an inline static function.
140+
The :c:func:`Py_SET_SIZE` function must be used to set an object size.
148141
149142
150143
.. c:function:: void Py_SET_SIZE(PyVarObject *o, Py_ssize_t size)

Doc/whatsnew/3.11.rst

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -149,34 +149,6 @@ Porting to Python 3.11
149149
(:c:member:`PyTypeObject.tp_traverse`).
150150
(Contributed by Victor Stinner in :issue:`44263`.)
151151

152-
* Since :c:func:`Py_TYPE()` is changed to a inline static function,
153-
``Py_TYPE(obj) = new_type`` must be replaced with
154-
``Py_SET_TYPE(obj, new_type)``: see the :c:func:`Py_SET_TYPE()` function
155-
(available since Python 3.9). For backward compatibility, this macro can be
156-
used::
157-
158-
#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE)
159-
static inline void _Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
160-
{ ob->ob_type = type; }
161-
#define Py_SET_TYPE(ob, type) _Py_SET_TYPE(_PyObject_CAST(ob), type)
162-
#endif
163-
164-
(Contributed by Victor Stinner in :issue:`39573`.)
165-
166-
* Since :c:func:`Py_SIZE()` is changed to a inline static function,
167-
``Py_SIZE(obj) = new_size`` must be replaced with
168-
``Py_SET_SIZE(obj, new_size)``: see the :c:func:`Py_SET_SIZE()` function
169-
(available since Python 3.9). For backward compatibility, this macro can be
170-
used::
171-
172-
#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_SIZE)
173-
static inline void _Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size)
174-
{ ob->ob_size = size; }
175-
#define Py_SET_SIZE(ob, size) _Py_SET_SIZE((PyVarObject*)(ob), size)
176-
#endif
177-
178-
(Contributed by Victor Stinner in :issue:`39573`.)
179-
180152
Deprecated
181153
----------
182154

Include/object.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,10 @@ static inline Py_ssize_t _Py_REFCNT(const PyObject *ob) {
134134

135135

136136
// bpo-39573: The Py_SET_TYPE() function must be used to set an object type.
137-
static inline PyTypeObject* _Py_TYPE(const PyObject *ob) {
138-
return ob->ob_type;
139-
}
140-
#define Py_TYPE(ob) _Py_TYPE(_PyObject_CAST_CONST(ob))
137+
#define Py_TYPE(ob) (_PyObject_CAST(ob)->ob_type)
141138

142139
// bpo-39573: The Py_SET_SIZE() function must be used to set an object size.
143-
static inline Py_ssize_t _Py_SIZE(const PyVarObject *ob) {
144-
return ob->ob_size;
145-
}
146-
#define Py_SIZE(ob) _Py_SIZE(_PyVarObject_CAST_CONST(ob))
140+
#define Py_SIZE(ob) (_PyVarObject_CAST(ob)->ob_size)
147141

148142

149143
static inline int _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) {

Misc/NEWS.d/next/C API/2021-06-03-00-59-48.bpo-39573.-elHTJ.rst

Lines changed: 0 additions & 3 deletions
This file was deleted.

Modules/_testcapimodule.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5423,9 +5423,10 @@ test_set_type_size(PyObject *self, PyObject *Py_UNUSED(ignored))
54235423
assert(Py_TYPE(obj) == &PyList_Type);
54245424
assert(Py_SIZE(obj) == 0);
54255425

5426-
// bpo-39573: Test Py_SET_TYPE() and Py_SET_SIZE() functions.
5427-
Py_SET_TYPE(obj, &PyList_Type);
5428-
Py_SET_SIZE(obj, 0);
5426+
// bpo-39573: Check that Py_TYPE() and Py_SIZE() can be used
5427+
// as l-values to set an object type and size.
5428+
Py_TYPE(obj) = &PyList_Type;
5429+
Py_SIZE(obj) = 0;
54295430

54305431
Py_DECREF(obj);
54315432
Py_RETURN_NONE;

0 commit comments

Comments
 (0)