bpo-44348: Revert "bpo-39573: Py_TYPE becomes a static inline functio… · python/cpython@6d518bb (original) (raw)
5 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -99,10 +99,7 @@ the definition of all other Python objects. | ||
99 | 99 | |
100 | 100 | Return a :term:`borrowed reference`. |
101 | 101 | |
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. | |
106 | 103 | |
107 | 104 | |
108 | 105 | .. c:function:: int Py_IS_TYPE(PyObject *o, PyTypeObject *type) |
@@ -124,10 +121,9 @@ the definition of all other Python objects. | ||
124 | 121 | |
125 | 122 | Get the reference count of the Python object *o*. |
126 | 123 | |
127 | - Use the :c:func:`Py_SET_REFCNT()` function to set an object reference count. | |
128 | - | |
129 | 124 | .. versionchanged:: 3.10 |
130 | 125 | :c:func:`Py_REFCNT()` is changed to the inline static function. |
126 | + Use :c:func:`Py_SET_REFCNT()` to set an object reference count. | |
131 | 127 | |
132 | 128 | |
133 | 129 | .. c:function:: void Py_SET_REFCNT(PyObject *o, Py_ssize_t refcnt) |
@@ -141,10 +137,7 @@ the definition of all other Python objects. | ||
141 | 137 | |
142 | 138 | Get the size of the Python object *o*. |
143 | 139 | |
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. | |
148 | 141 | |
149 | 142 | |
150 | 143 | .. c:function:: void Py_SET_SIZE(PyVarObject *o, Py_ssize_t size) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -154,34 +154,6 @@ Porting to Python 3.11 | ||
154 | 154 | (:c:member:`PyTypeObject.tp_traverse`). |
155 | 155 | (Contributed by Victor Stinner in :issue:`44263`.) |
156 | 156 | |
157 | -* Since :c:func:`Py_TYPE()` is changed to a inline static function, | |
158 | - ``Py_TYPE(obj) = new_type`` must be replaced with | |
159 | - ``Py_SET_TYPE(obj, new_type)``: see the :c:func:`Py_SET_TYPE()` function | |
160 | - (available since Python 3.9). For backward compatibility, this macro can be | |
161 | - used:: | |
162 | - | |
163 | - #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE) | |
164 | - static inline void _Py_SET_TYPE(PyObject *ob, PyTypeObject *type) | |
165 | - { ob->ob_type = type; } | |
166 | - #define Py_SET_TYPE(ob, type) _Py_SET_TYPE(_PyObject_CAST(ob), type) | |
167 | - #endif | |
168 | - | |
169 | - (Contributed by Victor Stinner in :issue:`39573`.) | |
170 | - | |
171 | -* Since :c:func:`Py_SIZE()` is changed to a inline static function, | |
172 | - ``Py_SIZE(obj) = new_size`` must be replaced with | |
173 | - ``Py_SET_SIZE(obj, new_size)``: see the :c:func:`Py_SET_SIZE()` function | |
174 | - (available since Python 3.9). For backward compatibility, this macro can be | |
175 | - used:: | |
176 | - | |
177 | - #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_SIZE) | |
178 | - static inline void _Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size) | |
179 | - { ob->ob_size = size; } | |
180 | - #define Py_SET_SIZE(ob, size) _Py_SET_SIZE((PyVarObject*)(ob), size) | |
181 | - #endif | |
182 | - | |
183 | - (Contributed by Victor Stinner in :issue:`39573`.) | |
184 | - | |
185 | 157 | Deprecated |
186 | 158 | ---------- |
187 | 159 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -134,16 +134,10 @@ static inline Py_ssize_t _Py_REFCNT(const PyObject *ob) { | ||
134 | 134 | |
135 | 135 | |
136 | 136 | // 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) | |
141 | 138 | |
142 | 139 | // 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) | |
147 | 141 | |
148 | 142 | |
149 | 143 | static inline int _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) { |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -5423,9 +5423,10 @@ test_set_type_size(PyObject *self, PyObject *Py_UNUSED(ignored)) | ||
5423 | 5423 | assert(Py_TYPE(obj) == &PyList_Type); |
5424 | 5424 | assert(Py_SIZE(obj) == 0); |
5425 | 5425 | |
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; | |
5429 | 5430 | |
5430 | 5431 | Py_DECREF(obj); |
5431 | 5432 | Py_RETURN_NONE; |