Skip to content

Commit 3d5826b

Browse files
committed
Added new type member 'tp_obj_offset'.
This member is the companion member required for 'Py_TPFLAGS_USES_OPAQUE_OBJECT' flag.
1 parent d0981e6 commit 3d5826b

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

Doc/c-api/typeobj.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ Quick Reference
147147
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
148148
| :c:member:`~PyTypeObject.tp_vectorcall` | :c:type:`vectorcallfunc` | | | | | |
149149
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
150+
| :c:member:`~PyTypeObject.tp_obj_offset` | const Py_ssize_t | | | X | ~ | |
151+
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
150152

151153
.. [#slots]
152154
A slot name in parentheses indicates it is (effectively) deprecated.
@@ -1015,6 +1017,12 @@ and :c:type:`PyType_Type` effectively act as defaults.)
10151017
:c:func:`PyType_HasFeature` takes a type and a flags value, *tp* and *f*, and
10161018
checks whether ``tp->tp_flags & f`` is non-zero.
10171019

1020+
.. data:: Py_TPFLAGS_USES_OPAQUE_OBJECT
1021+
1022+
This bit is set when the type object's :c:member:`PyTypeObject.tp_basicsize` is configured
1023+
for an opaque :c:type:`PyObject` structure. The value of :c:member:`PyTypeObject.tp_basicsize` is the size of the type's
1024+
internal object structure EXCLUDING the base type's structure size.
1025+
10181026
.. data:: Py_TPFLAGS_HEAPTYPE
10191027

10201028
This bit is set when the type object itself is allocated on the heap, for

Include/cpython/object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ struct _typeobject {
263263

264264
destructor tp_finalize;
265265
vectorcallfunc tp_vectorcall;
266+
/* INTERNAL USE ONLY! MODIFYING THIS CAN CRASH PYTHON! */
267+
const Py_ssize_t tp_obj_offset;
266268
};
267269

268270
/* The *real* layout of a type object when allocated on the heap */

Include/object.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ Code can use PyType_HasFeature(type_ob, flag_value) to test whether the
317317
given type object has a specified feature.
318318
*/
319319

320+
/* Set if the type object's tp_basicsize is set for opague object */
321+
#define Py_TPFLAGS_OPAQUE_OBJECT (1UL << 8)
322+
320323
/* Set if the type object is dynamically allocated */
321324
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
322325

0 commit comments

Comments
 (0)