Skip to content

Commit 9bdd2de

Browse files
authored
bpo-35134: Don't define types twice in header files (GH-10754)
Fix the following clang warning: Include/cpython/pystate.h:217:3: warning: redefinition of typedef 'PyThreadState' is a C11 feature [-Wtypedef-redefinition]
1 parent 1c60715 commit 9bdd2de

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

Include/object.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,12 @@ typedef int (*initproc)(PyObject *, PyObject *, PyObject *);
175175
typedef PyObject *(*newfunc)(struct _typeobject *, PyObject *, PyObject *);
176176
typedef PyObject *(*allocfunc)(struct _typeobject *, Py_ssize_t);
177177

178+
#ifdef Py_LIMITED_API
178179
/* In Py_LIMITED_API, PyTypeObject is an opaque structure. */
179180
typedef struct _typeobject PyTypeObject;
181+
#else
182+
/* PyTypeObject is defined in cpython/object.h */
183+
#endif
180184

181185
typedef struct{
182186
int slot; /* slot id, see below */
@@ -196,30 +200,30 @@ PyAPI_FUNC(PyObject*) PyType_FromSpec(PyType_Spec*);
196200
PyAPI_FUNC(PyObject*) PyType_FromSpecWithBases(PyType_Spec*, PyObject*);
197201
#endif
198202
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03040000
199-
PyAPI_FUNC(void*) PyType_GetSlot(PyTypeObject*, int);
203+
PyAPI_FUNC(void*) PyType_GetSlot(struct _typeobject*, int);
200204
#endif
201205

202206
/* Generic type check */
203-
PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *);
207+
PyAPI_FUNC(int) PyType_IsSubtype(struct _typeobject *, struct _typeobject *);
204208
#define PyObject_TypeCheck(ob, tp) \
205209
(Py_TYPE(ob) == (tp) || PyType_IsSubtype(Py_TYPE(ob), (tp)))
206210

207-
PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */
208-
PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */
209-
PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */
211+
PyAPI_DATA(struct _typeobject) PyType_Type; /* built-in 'type' */
212+
PyAPI_DATA(struct _typeobject) PyBaseObject_Type; /* built-in 'object' */
213+
PyAPI_DATA(struct _typeobject) PySuper_Type; /* built-in 'super' */
210214

211-
PyAPI_FUNC(unsigned long) PyType_GetFlags(PyTypeObject*);
215+
PyAPI_FUNC(unsigned long) PyType_GetFlags(struct _typeobject*);
212216

213217
#define PyType_Check(op) \
214218
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS)
215219
#define PyType_CheckExact(op) (Py_TYPE(op) == &PyType_Type)
216220

217-
PyAPI_FUNC(int) PyType_Ready(PyTypeObject *);
218-
PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t);
219-
PyAPI_FUNC(PyObject *) PyType_GenericNew(PyTypeObject *,
221+
PyAPI_FUNC(int) PyType_Ready(struct _typeobject *);
222+
PyAPI_FUNC(PyObject *) PyType_GenericAlloc(struct _typeobject *, Py_ssize_t);
223+
PyAPI_FUNC(PyObject *) PyType_GenericNew(struct _typeobject *,
220224
PyObject *, PyObject *);
221225
PyAPI_FUNC(unsigned int) PyType_ClearCache(void);
222-
PyAPI_FUNC(void) PyType_Modified(PyTypeObject *);
226+
PyAPI_FUNC(void) PyType_Modified(struct _typeobject *);
223227

224228
/* Generic operations on objects */
225229
PyAPI_FUNC(PyObject *) PyObject_Repr(PyObject *);
@@ -397,8 +401,8 @@ PyAPI_FUNC(void) _PyDebug_PrintTotalRefs(void);
397401
#endif /* Py_REF_DEBUG */
398402

399403
#ifdef COUNT_ALLOCS
400-
PyAPI_FUNC(void) _Py_inc_count(PyTypeObject *);
401-
PyAPI_FUNC(void) _Py_dec_count(PyTypeObject *);
404+
PyAPI_FUNC(void) _Py_inc_count(struct _typeobject *);
405+
PyAPI_FUNC(void) _Py_dec_count(struct _typeobject *);
402406
#define _Py_INC_TPALLOCS(OP) _Py_inc_count(Py_TYPE(OP))
403407
#define _Py_INC_TPFREES(OP) _Py_dec_count(Py_TYPE(OP))
404408
#define _Py_DEC_TPFREES(OP) Py_TYPE(OP)->tp_frees--

Include/pystate.h

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,28 @@ extern "C" {
1414
removed (with effort). */
1515
#define MAX_CO_EXTRA_USERS 255
1616

17-
/* State shared between threads */
18-
19-
struct _ts; /* Forward */
20-
struct _is; /* Forward */
21-
struct _frame; /* Forward declaration for PyFrameObject. */
17+
/* Forward declarations for PyFrameObject, PyThreadState
18+
and PyInterpreterState */
19+
struct _frame;
20+
struct _ts;
21+
struct _is;
2222

23+
#ifdef Py_LIMITED_API
24+
typedef struct _ts PyThreadState;
2325
typedef struct _is PyInterpreterState;
26+
#else
27+
/* PyThreadState and PyInterpreterState are defined in cpython/pystate.h */
28+
#endif
2429

2530
/* State unique per thread */
2631

27-
typedef struct _ts PyThreadState;
28-
29-
PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void);
30-
PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *);
31-
PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *);
32+
PyAPI_FUNC(struct _is *) PyInterpreterState_New(void);
33+
PyAPI_FUNC(void) PyInterpreterState_Clear(struct _is *);
34+
PyAPI_FUNC(void) PyInterpreterState_Delete(struct _is *);
3235

3336
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03070000
3437
/* New in 3.7 */
35-
PyAPI_FUNC(int64_t) PyInterpreterState_GetID(PyInterpreterState *);
38+
PyAPI_FUNC(int64_t) PyInterpreterState_GetID(struct _is *);
3639
#endif
3740
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
3841
/* New in 3.3 */
@@ -41,9 +44,9 @@ PyAPI_FUNC(int) PyState_RemoveModule(struct PyModuleDef*);
4144
#endif
4245
PyAPI_FUNC(PyObject*) PyState_FindModule(struct PyModuleDef*);
4346

44-
PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *);
45-
PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *);
46-
PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *);
47+
PyAPI_FUNC(struct _ts *) PyThreadState_New(struct _is *);
48+
PyAPI_FUNC(void) PyThreadState_Clear(struct _ts *);
49+
PyAPI_FUNC(void) PyThreadState_Delete(struct _ts *);
4750
PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
4851

4952
/* Get the current thread state.
@@ -54,7 +57,7 @@ PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
5457
The caller must hold the GIL.
5558
5659
See also PyThreadState_GET() and _PyThreadState_GET(). */
57-
PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void);
60+
PyAPI_FUNC(struct _ts *) PyThreadState_Get(void);
5861

5962
/* Get the current Python thread state.
6063
@@ -67,7 +70,7 @@ PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void);
6770
See also PyThreadState_Get() and _PyThreadState_GET(). */
6871
#define PyThreadState_GET() PyThreadState_Get()
6972

70-
PyAPI_FUNC(PyThreadState *) PyThreadState_Swap(PyThreadState *);
73+
PyAPI_FUNC(struct _ts *) PyThreadState_Swap(struct _ts *);
7174
PyAPI_FUNC(PyObject *) PyThreadState_GetDict(void);
7275
PyAPI_FUNC(int) PyThreadState_SetAsyncExc(unsigned long, PyObject *);
7376

@@ -115,7 +118,7 @@ PyAPI_FUNC(void) PyGILState_Release(PyGILState_STATE);
115118
thread-state, even if no auto-thread-state call has been made
116119
on the main thread.
117120
*/
118-
PyAPI_FUNC(PyThreadState *) PyGILState_GetThisThreadState(void);
121+
PyAPI_FUNC(struct _ts *) PyGILState_GetThisThreadState(void);
119122

120123

121124
#ifndef Py_LIMITED_API

0 commit comments

Comments
 (0)