8000 bpo-39542: Define PyTypeObject earlier in object.h (GH-18366) · python/cpython@0e4e735 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e4e735

Browse files
authored
bpo-39542: Define PyTypeObject earlier in object.h (GH-18366)
Replace "struct _typeobject" with PyTypeObject in object.h.
1 parent 509dd90 commit 0e4e735

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

Include/object.h

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ whose size is determined when the object is allocated.
6161
#error Py_LIMITED_API is incompatible with Py_DEBUG, Py_TRACE_REFS, and Py_REF_DEBUG
6262
#endif
6363

64+
/* PyTypeObject structure is defined in cpython/object.h.
65+
In Py_LIMITED_API, PyTypeObject is an opaque structure. */
66+
typedef struct _typeobject PyTypeObject;
6467

6568
#ifdef Py_TRACE_REFS
6669
/* Define pointers to support a doubly-linked list of all live heap objects. */
@@ -102,7 +105,7 @@ whose size is determined when the object is allocated.
102105
typedef struct _object {
103106
_PyObject_HEAD_EXTRA
104107
Py_ssize_t ob_refcnt;
105-
struct _typeobject *ob_type;
108+
PyTypeObject *ob_type;
106109
} PyObject;
107110

108111
/* Cast argument to PyObject* type. */
@@ -165,15 +168,8 @@ typedef PyObject *(*iternextfunc) (PyObject *);
165168
typedef PyObject *(*descrgetfunc) (PyObject *, PyObject *, PyObject *);
166169
typedef int (*descrsetfunc) (PyObject *, PyObject *, PyObject *);
167170
typedef int (*initproc)(PyObject *, PyObject *, PyObject *);
168-
typedef PyObject *(*newfunc)(struct _typeobject *, PyObject *, PyObject *);
169-
typedef PyObject *(*allocfunc)(struct _typeobject *, Py_ssize_t);
170-
171-
#ifdef Py_LIMITED_API
172-
/* In Py_LIMITED_API, PyTypeObject is an opaque structure. */
173-
typedef struct _typeobject PyTypeObject;
174-
#else
175-
/* PyTypeObject is defined in cpython/object.h */
176-
#endif
171+
typedef PyObject *(*newfunc)(PyTypeObject *, PyObject *, PyObject *);
172+
typedef PyObject *(*allocfunc)(PyTypeObject *, Py_ssize_t);
177173

178174
typedef struct{
179175
int slot; /* slot id, see below */
@@ -193,26 +189,26 @@ PyAPI_FUNC(PyObject*) PyType_FromSpec(PyType_Spec*);
193189
PyAPI_FUNC(PyObject*) PyType_FromSpecWithBases(PyType_Spec*, PyObject*);
194190
#endif
195191
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03040000
196-
PyAPI_FUNC(void*) PyType_GetSlot(struct _typeobject*, int);
192+
PyAPI_FUNC(void*) PyType_GetSlot(PyTypeObject*, int);
197193
#endif
198194

199195
/* Generic type check */
200-
PyAPI_FUNC(int) PyType_IsSubtype(struct _typeobject *, struct _typeobject *);
196+
PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *);
201197
#define PyObject_TypeCheck(ob, tp) \
202198
(Py_TYPE(ob) == (tp) || PyType_IsSubtype(Py_TYPE(ob), (tp)))
203199

204-
PyAPI_DATA(struct _typeobject) PyType_Type; /* built-in 'type' */
205-
PyAPI_DATA(struct _typeobject) PyBaseObject_Type; /* built-in 'object' */
206-
PyAPI_DATA(struct _typeobject) PySuper_Type; /* built-in 'super' */
200+
PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */
201+
PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */
202+
PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */
207203

208-
PyAPI_FUNC(unsigned long) PyType_GetFlags(struct _typeobject*);
204+
PyAPI_FUNC(unsigned long) PyType_GetFlags(PyTypeObject*);
209205

210-
PyAPI_FUNC(int) PyType_Ready(struct _typeobject *);
211-
PyAPI_FUNC(PyObject *) PyType_GenericAlloc(struct _typeobject *, Py_ssize_t);
212-
PyAPI_FUNC(PyObject *) PyType_GenericNew(struct _typeobject *,
206+
PyAPI_FUNC(int) PyType_Ready(PyTypeObject *);
207+
PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t);
208+
PyAPI_FUNC(PyObject *) PyType_GenericNew(PyTypeObject *,
213209
PyObject *, PyObject *);
214210
PyAPI_FUNC(unsigned int) PyType_ClearCache(void);
215-
PyAPI_FUNC(void) PyType_Modified(struct _typeobject *);
211+
PyAPI_FUNC(void) PyType_Modified(PyTypeObject *);
216212

217213
/* Generic operations on objects */
218214
PyAPI_FUNC(PyObject *) PyObject_Repr(PyObject *);

0 commit comments

Comments
 (0)
0