Skip to content

Commit 55a57b6

Browse files
vstinnerarun-mani-j
authored andcommitted
bpo-39573: Porting to Python 3.10: Py_SET_SIZE() macro (pythonGH-20610)
In What's New in Python 3.10, propose Py_SET_SIZE(), Py_SET_REFCNT() and Py_SET_TYPE() macros for backward compatibility with Python 3.9 and older.
1 parent d4043b1 commit 55a57b6

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

Doc/whatsnew/3.10.rst

+21-3
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,35 @@ Porting to Python 3.10
135135

136136
* Since :c:func:`Py_TYPE()` is changed to the inline static function,
137137
``Py_TYPE(obj) = new_type`` must be replaced with ``Py_SET_TYPE(obj, new_type)``:
138-
see :c:func:`Py_SET_TYPE()` (available since Python 3.9).
138+
see :c:func:`Py_SET_TYPE()` (available since Python 3.9). For backward
139+
compatibility, this macro can be used::
140+
141+
#if PY_VERSION_HEX < 0x030900A4
142+
# define Py_SET_TYPE(obj, type) ((Py_TYPE(obj) = (type)), (void)0)
143+
#endif
144+
139145
(Contributed by Dong-hee Na in :issue:`39573`.)
140146

141147
* Since :c:func:`Py_REFCNT()` is changed to the inline static function,
142148
``Py_REFCNT(obj) = new_refcnt`` must be replaced with ``Py_SET_REFCNT(obj, new_refcnt)``:
143-
see :c:func:`Py_SET_REFCNT()` (available since Python 3.9).
149+
see :c:func:`Py_SET_REFCNT()` (available since Python 3.9). For backward
150+
compatibility, this macro can be used::
151+
152+
#if PY_VERSION_HEX < 0x030900A4
153+
# define Py_SET_REFCNT(obj, refcnt) ((Py_REFCNT(obj) = (refcnt)), (void)0)
154+
#endif
155+
144156
(Contributed by Victor Stinner in :issue:`39573`.)
145157

146158
* Since :c:func:`Py_SIZE()` is changed to the inline static function,
147159
``Py_SIZE(obj) = new_size`` must be replaced with ``Py_SET_SIZE(obj, new_size)``:
148-
see :c:func:`Py_SET_SIZE()` (available since Python 3.9).
160+
see :c:func:`Py_SET_SIZE()` (available since Python 3.9). For backward
161+
compatibility, this macro can be used::
162+
163+
#if PY_VERSION_HEX < 0x030900A4
164+
# define Py_SET_SIZE(obj, size) ((Py_SIZE(obj) = (size)), (void)0)
165+
#endif
166+
149167
(Contributed by Victor Stinner in :issue:`39573`.)
150168

151169
* Calling :c:func:`PyDict_GetItem` without :term:`GIL` held had been allowed

0 commit comments

Comments
 (0)