Skip to content

Commit d9f6361

Browse files
committed
Reuse Py_TYPE() and Py_SET_TYPE() names
1 parent a1e2ebf commit d9f6361

File tree

6 files changed

+46
-34
lines changed

6 files changed

+46
-34
lines changed

Doc/data/stable_abi.dat

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/object.h

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,26 @@ _Py_IsOwnedByCurrentThread(PyObject *ob)
244244
}
245245
#endif
246246

247-
PyAPI_FUNC(PyTypeObject*) _Py_TYPE(PyObject *ob);
247+
// Py_TYPE() implementation for the stable ABI
248+
PyAPI_FUNC(PyTypeObject*) Py_TYPE(PyObject *ob);
248249

249-
// bpo-39573: The Py_SET_TYPE() function must be used to set an object type.
250-
static inline PyTypeObject* Py_TYPE(PyObject *ob) {
251250
#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030e0000
252251
// Stable ABI implements Py_TYPE() as a function call
253252
// on limited C API version 3.14 and newer.
254-
return _Py_TYPE(ob);
255-
#elif defined(Py_GIL_DISABLED)
256-
return (PyTypeObject *)_Py_atomic_load_ptr_relaxed(&ob->ob_type);
257253
#else
258-
return ob->ob_type;
259-
#endif
260-
}
261-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
262-
# define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
254+
static inline PyTypeObject* _Py_TYPE(PyObject *ob)
255+
{
256+
#if defined(Py_GIL_DISABLED)
257+
return (PyTypeObject *)_Py_atomic_load_ptr_relaxed(&ob->ob_type);
258+
#else
259+
return ob->ob_type;
260+
#endif
261+
}
262+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
263+
# define Py_TYPE(ob) _Py_TYPE(_PyObject_CAST(ob))
264+
#else
265+
# define Py_TYPE(ob) _Py_TYPE(ob)
266+
#endif
263267
#endif
264268

265269
PyAPI_DATA(PyTypeObject) PyLong_Type;
@@ -283,22 +287,28 @@ static inline int Py_IS_TYPE(PyObject *ob, PyTypeObject *type) {
283287
#endif
284288

285289

286-
PyAPI_FUNC(void) _Py_SET_TYPE(PyObject *ob, PyTypeObject *type);
290+
// Py_SET_TYPE() implementation for the stable ABI
291+
PyAPI_FUNC(void) Py_SET_TYPE(PyObject *ob, PyTypeObject *type);
287292

288-
static inline void Py_SET_TYPE(PyObject *ob, PyTypeObject *type) {
289293
#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030e0000
290294
// Stable ABI implements Py_SET_TYPE() as a function call
291295
// on limited C API version 3.14 and newer.
292-
return _Py_SET_TYPE(ob, type);
293-
#elif defined(Py_GIL_DISABLED)
294-
_Py_atomic_store_ptr(&ob->ob_type, type);
295296
#else
296-
ob->ob_type = type;
297-
#endif
298-
}
299-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
300-
# define Py_SET_TYPE(ob, type) Py_SET_TYPE(_PyObject_CAST(ob), type)
301-
#endif
297+
static inline void _Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
298+
{
299+
#if defined(Py_GIL_DISABLED)
300+
_Py_atomic_store_ptr(&ob->ob_type, type);
301+
#else
302+
ob->ob_type = type;
303+
#endif
304+
}
305+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
306+
# define Py_SET_TYPE(ob, type) _Py_SET_TYPE(_PyObject_CAST(ob), (type))
307+
#else
308+
# define Py_SET_TYPE(ob, type) _Py_SET_TYPE((ob), (type))
309+
#endif
310+
#endif // Py_LIMITED_API
311+
302312

303313
static inline void Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size) {
304314
assert(ob->ob_base.ob_type != &PyLong_Type);

Lib/test/test_stable_abi_ctypes.py

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Misc/stable_abi.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,9 +2507,7 @@
25072507
added = '3.13'
25082508
[function.PyEval_GetFrameLocals]
25092509
added = '3.13'
2510-
[function._Py_TYPE]
2510+
[function.Py_TYPE]
25112511
added = '3.14'
2512-
abi_only = true
2513-
[function._Py_SET_TYPE]
2512+
[function.Py_SET_TYPE]
25142513
added = '3.14'
2515-
abi_only = true

Objects/object.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3004,14 +3004,16 @@ Py_GetConstantBorrowed(unsigned int constant_id)
30043004

30053005

30063006
// Py_TYPE() implementation for the stable ABI
3007-
PyTypeObject* _Py_TYPE(PyObject *ob)
3007+
#undef Py_TYPE
3008+
PyTypeObject* Py_TYPE(PyObject *ob)
30083009
{
3009-
return Py_TYPE(ob);
3010+
return _Py_TYPE(ob);
30103011
}
30113012

30123013

30133014
// Py_SET_TYPE() implementation for the stable ABI
3014-
void _Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
3015+
#undef Py_SET_TYPE
3016+
void Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
30153017
{
3016-
Py_SET_TYPE(ob, type);
3018+
_Py_SET_TYPE(ob, type);
30173019
}

PC/python3dll.c

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)