Skip to content

Commit 042f31d

Browse files
authored
bpo-45459: C API uses type names rather than structure names (GH-31528)
Thanks to the new pytypedefs.h, it becomes to use type names like PyObject rather like structure names like "struct _object".
1 parent ec091bd commit 042f31d

23 files changed

+69
-75
lines changed

Include/boolobject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ PyAPI_DATA(PyTypeObject) PyBool_Type;
1515
Don't forget to apply Py_INCREF() when returning either!!! */
1616

1717
/* Don't use these directly */
18-
PyAPI_DATA(struct _longobject) _Py_FalseStruct;
19-
PyAPI_DATA(struct _longobject) _Py_TrueStruct;
18+
PyAPI_DATA(PyLongObject) _Py_FalseStruct;
19+
PyAPI_DATA(PyLongObject) _Py_TrueStruct;
2020

2121
/* Use these macros */
2222
#define Py_False ((PyObject *) &_Py_FalseStruct)

Include/cpython/abstract.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ PyAPI_FUNC(PyObject *) _PyObject_CallMethodId_SizeT(PyObject *obj,
133133

134134
PyAPI_FUNC(PyObject *) _PyObject_CallMethodIdObjArgs(
135135
PyObject *obj,
136-
struct _Py_Identifier *name,
136+
_Py_Identifier *name,
137137
...);
138138

139139
static inline PyObject *

Include/cpython/descrobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typedef struct {
4343

4444
typedef struct {
4545
PyDescr_COMMON;
46-
struct PyMemberDef *d_member;
46+
PyMemberDef *d_member;
4747
} PyMemberDescrObject;
4848

4949
typedef struct {

Include/cpython/dictobject.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key,
3232
Py_hash_t hash);
3333
PyAPI_FUNC(PyObject *) _PyDict_GetItemWithError(PyObject *dp, PyObject *key);
3434
PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp,
35-
struct _Py_Identifier *key);
35+
_Py_Identifier *key);
3636
PyAPI_FUNC(PyObject *) _PyDict_GetItemStringWithError(PyObject *, const char *);
3737
PyAPI_FUNC(PyObject *) PyDict_SetDefault(
3838
PyObject *mp, PyObject *key, PyObject *defaultobj);
@@ -49,7 +49,7 @@ PyAPI_FUNC(int) _PyDict_Next(
4949
/* Get the number of items of a dictionary. */
5050
#define PyDict_GET_SIZE(mp) (assert(PyDict_Check(mp)),((PyDictObject *)mp)->ma_used)
5151
PyAPI_FUNC(int) _PyDict_Contains_KnownHash(PyObject *, PyObject *, Py_hash_t);
52-
PyAPI_FUNC(int) _PyDict_ContainsId(PyObject *, struct _Py_Identifier *);
52+
PyAPI_FUNC(int) _PyDict_ContainsId(PyObject *, _Py_Identifier *);
5353
PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);
5454
PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp);
5555
PyAPI_FUNC(int) _PyDict_HasOnlyStringKeys(PyObject *mp);
@@ -66,9 +66,9 @@ PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *);
6666
argument is raised.
6767
*/
6868
PyAPI_FUNC(int) _PyDict_MergeEx(PyObject *mp, PyObject *other, int override);
69-
PyAPI_FUNC(int) _PyDict_SetItemId(PyObject *dp, struct _Py_Identifier *key, PyObject *item);
69+
PyAPI_FUNC(int) _PyDict_SetItemId(PyObject *dp, _Py_Identifier *key, PyObject *item);
7070

71-
PyAPI_FUNC(int) _PyDict_DelItemId(PyObject *mp, struct _Py_Identifier *key);
71+
PyAPI_FUNC(int) _PyDict_DelItemId(PyObject *mp, _Py_Identifier *key);
7272
PyAPI_FUNC(void) _PyDict_DebugMallocStats(FILE *out);
7373

7474
int _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, PyObject *name, PyObject *value);

Include/cpython/frameobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
struct _frame {
88
PyObject_HEAD
9-
struct _frame *f_back; /* previous frame, or NULL */
9+
PyFrameObject *f_back; /* previous frame, or NULL */
1010
struct _interpreter_frame *f_frame; /* points to the frame data */
1111
PyObject *f_trace; /* Trace function */
1212
int f_lineno; /* Current line number. Only valid if non-zero */

Include/cpython/import.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ PyMODINIT_FUNC PyInit__imp(void);
66

77
PyAPI_FUNC(int) _PyImport_IsInitialized(PyInterpreterState *);
88

9-
PyAPI_FUNC(PyObject *) _PyImport_GetModuleId(struct _Py_Identifier *name);
9+
PyAPI_FUNC(PyObject *) _PyImport_GetModuleId(_Py_Identifier *name);
1010
PyAPI_FUNC(int) _PyImport_SetModule(PyObject *name, PyObject *module);
1111
PyAPI_FUNC(int) _PyImport_SetModuleString(const char *name, PyObject* module);
1212

Include/cpython/object.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ struct _typeobject {
201201
iternextfunc tp_iternext;
202202

203203
/* Attribute descriptor and subclassing stuff */
204-
struct PyMethodDef *tp_methods;
205-
struct PyMemberDef *tp_members;
206-
struct PyGetSetDef *tp_getset;
204+
PyMethodDef *tp_methods;
205+
PyMemberDef *tp_members;
206+
PyGetSetDef *tp_getset;
207207
// Strong reference on a heap type, borrowed reference on a static type
208-
struct _typeobject *tp_base;
208+
PyTypeObject *tp_base;
209209
PyObject *tp_dict;
210210
descrgetfunc tp_descr_get;
211211
descrsetfunc tp_descr_set;
@@ -262,16 +262,16 @@ PyAPI_FUNC(PyObject *) _PyObject_LookupSpecialId(PyObject *, _Py_Identifier *);
262262
PyAPI_FUNC(PyTypeObject *) _PyType_CalculateMetaclass(PyTypeObject *, PyObject *);
263263
PyAPI_FUNC(PyObject *) _PyType_GetDocFromInternalDoc(const char *, const char *);
264264
PyAPI_FUNC(PyObject *) _PyType_GetTextSignatureFromInternalDoc(const char *, const char *);
265-
PyAPI_FUNC(PyObject *) PyType_GetModuleByDef(PyTypeObject *, struct PyModuleDef *);
265+
PyAPI_FUNC(PyObject *) PyType_GetModuleByDef(PyTypeObject *, PyModuleDef *);
266266

267267
PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);
268268
PyAPI_FUNC(void) _Py_BreakPoint(void);
269269
PyAPI_FUNC(void) _PyObject_Dump(PyObject *);
270270
PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *);
271271

272272
PyAPI_FUNC(int) _PyObject_IsAbstract(PyObject *);
273-
PyAPI_FUNC(PyObject *) _PyObject_GetAttrId(PyObject *, struct _Py_Identifier *);
274-
PyAPI_FUNC(int) _PyObject_SetAttrId(PyObject *, struct _Py_Identifier *, PyObject *);
273+
PyAPI_FUNC(PyObject *) _PyObject_GetAttrId(PyObject *, _Py_Identifier *);
274+
PyAPI_FUNC(int) _PyObject_SetAttrId(PyObject *, _Py_Identifier *, PyObject *);
275275
/* Replacements of PyObject_GetAttr() and _PyObject_GetAttrId() which
276276
don't raise AttributeError.
277277
@@ -282,7 +282,7 @@ PyAPI_FUNC(int) _PyObject_SetAttrId(PyObject *, struct _Py_Identifier *, PyObjec
282282
is raised.
283283
*/
284284
PyAPI_FUNC(int) _PyObject_LookupAttr(PyObject *, PyObject *, PyObject **);
285-
PyAPI_FUNC(int) _PyObject_LookupAttrId(PyObject *, struct _Py_Identifier *, PyObject **);
285+
PyAPI_FUNC(int) _PyObject_LookupAttrId(PyObject *, _Py_Identifier *, PyObject **);
286286

287287
PyAPI_FUNC(int) _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method);
288288

@@ -461,8 +461,8 @@ passed as second argument to Py_TRASHCAN_BEGIN().
461461
*/
462462

463463
/* Python 3.9 private API, invoked by the macros below. */
464-
PyAPI_FUNC(int) _PyTrash_begin(struct _ts *tstate, PyObject *op);
465-
PyAPI_FUNC(void) _PyTrash_end(struct _ts *tstate);
464+
PyAPI_FUNC(int) _PyTrash_begin(PyThreadState *tstate, PyObject *op);
465+
PyAPI_FUNC(void) _PyTrash_end(PyThreadState *tstate);
466466
/* Python 3.10 private API, invoked by the Py_TRASHCAN_BEGIN(). */
467467
PyAPI_FUNC(int) _PyTrash_cond(PyObject *op, destructor dealloc);
468468

Include/cpython/pystate.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,11 @@ typedef struct _stack_chunk {
7979
PyObject * data[1]; /* Variable sized */
8080
} _PyStackChunk;
8181

82-
// The PyThreadState typedef is in Include/pystate.h.
8382
struct _ts {
8483
/* See Python/ceval.c for comments explaining most fields */
8584

86-
struct _ts *prev;
87-
struct _ts *next;
85+
PyThreadState *prev;
86+
PyThreadState *next;
8887
PyInterpreterState *interp;
8988

9089
/* Has been initialized to a safe state.
@@ -308,12 +307,12 @@ PyAPI_FUNC(const PyConfig*) _Py_GetConfig(void);
308307

309308
/* cross-interpreter data */
310309

311-
struct _xid;
312-
313310
// _PyCrossInterpreterData is similar to Py_buffer as an effectively
314311
// opaque struct that holds data outside the object machinery. This
315312
// is necessary to pass safely between interpreters in the same process.
316-
typedef struct _xid {
313+
typedef struct _xid _PyCrossInterpreterData;
314+
315+
struct _xid {
317316
// data is the cross-interpreter-safe derivation of a Python object
318317
// (see _PyObject_GetCrossInterpreterData). It will be NULL if the
319318
// new_object func (below) encodes the data.
@@ -339,7 +338,7 @@ typedef struct _xid {
339338
// interpreter given the data. The resulting object (a new
340339
// reference) will be equivalent to the original object. This field
341340
// is required.
342-
PyObject *(*new_object)(struct _xid *);
341+
PyObject *(*new_object)(_PyCrossInterpreterData *);
343342
// free is called when the data is released. If it is NULL then
344343
// nothing will be done to free the data. For some types this is
345344
// okay (e.g. bytes) and for those types this field should be set
@@ -350,7 +349,7 @@ typedef struct _xid {
350349
// to PyMem_RawFree (the default if not explicitly set to NULL).
351350
// The call will happen with the original interpreter activated.
352351
void (*free)(void *);
353-
} _PyCrossInterpreterData;
352+
};
354353

355354
PyAPI_FUNC(int) _PyObject_GetCrossInterpreterData(PyObject *, _PyCrossInterpreterData *);
356355
PyAPI_FUNC(PyObject *) _PyCrossInterpreterData_NewObject(_PyCrossInterpreterData *);
@@ -360,7 +359,7 @@ PyAPI_FUNC(int) _PyObject_CheckCrossInterpreterData(PyObject *);
360359

361360
/* cross-interpreter data registry */
362361

363-
typedef int (*crossinterpdatafunc)(PyObject *, struct _xid *);
362+
typedef int (*crossinterpdatafunc)(PyObject *, _PyCrossInterpreterData *);
364363

365364
PyAPI_FUNC(int) _PyCrossInterpreterData_RegisterClass(PyTypeObject *, crossinterpdatafunc);
366365
PyAPI_FUNC(crossinterpdatafunc) _PyCrossInterpreterData_Lookup(PyObject *);

Include/cpython/traceback.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
# error "this header file must not be included directly"
33
#endif
44

5-
typedef struct _traceback {
5+
typedef struct _traceback PyTracebackObject;
6+
7+
struct _traceback {
68
PyObject_HEAD
7-
struct _traceback *tb_next;
9+
PyTracebackObject *tb_next;
810
PyFrameObject *tb_frame;
911
int tb_lasti;
1012
int tb_lineno;
11-
} PyTracebackObject;
13+
};
1214

1315
PyAPI_FUNC(int) _Py_DisplaySourceLine(PyObject *, PyObject *, int, int, int *, PyObject **);
1416
PyAPI_FUNC(void) _PyTraceback_Add(const char *, const char *, int);

Include/descrobject.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,11 @@ PyAPI_DATA(PyTypeObject) PyMethodDescr_Type;
2323
PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type;
2424
PyAPI_DATA(PyTypeObject) PyDictProxy_Type;
2525
PyAPI_DATA(PyTypeObject) PyProperty_Type;
26-
// Forward declaration for following prototype
27-
struct PyMemberDef;
2826

2927
PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);
3028
PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *);
31-
PyAPI_FUNC(PyObject *) PyDescr_NewMember(PyTypeObject *,
32-
struct PyMemberDef *);
33-
PyAPI_FUNC(PyObject *) PyDescr_NewGetSet(PyTypeObject *,
34-
struct PyGetSetDef *);
29+
PyAPI_FUNC(PyObject *) PyDescr_NewMember(PyTypeObject *, PyMemberDef *);
30+
PyAPI_FUNC(PyObject *) PyDescr_NewGetSet(PyTypeObject *, PyGetSetDef *);
3531

3632
PyAPI_FUNC(PyObject *) PyDictProxy_New(PyObject *);
3733
PyAPI_FUNC(PyObject *) PyWrapper_New(PyObject *, PyObject *);

Include/modsupport.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,9 @@ PyAPI_FUNC(int) PyModule_ExecDef(PyObject *module, PyModuleDef *def);
232232
#define PyModule_FromDefAndSpec2 PyModule_FromDefAndSpec2TraceRefs
233233
#endif
234234

235-
PyAPI_FUNC(PyObject *) PyModule_Create2(struct PyModuleDef*,
236-
int apiver);
235+
PyAPI_FUNC(PyObject *) PyModule_Create2(PyModuleDef*, int apiver);
237236
#ifndef Py_LIMITED_API
238-
PyAPI_FUNC(PyObject *) _PyModule_CreateInitialized(struct PyModuleDef*,
239-
int apiver);
237+
PyAPI_FUNC(PyObject *) _PyModule_CreateInitialized(PyModuleDef*, int apiver);
240238
#endif
241239

242240
#ifdef Py_LIMITED_API

Include/moduleobject.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ PyAPI_FUNC(void) _PyModule_Clear(PyObject *);
3232
PyAPI_FUNC(void) _PyModule_ClearDict(PyObject *);
3333
PyAPI_FUNC(int) _PyModuleSpec_IsInitializing(PyObject *);
3434
#endif
35-
PyAPI_FUNC(struct PyModuleDef*) PyModule_GetDef(PyObject*);
35+
PyAPI_FUNC(PyModuleDef*) PyModule_GetDef(PyObject*);
3636
PyAPI_FUNC(void*) PyModule_GetState(PyObject*);
3737

3838
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
3939
/* New in 3.5 */
40-
PyAPI_FUNC(PyObject *) PyModuleDef_Init(struct PyModuleDef*);
40+
PyAPI_FUNC(PyObject *) PyModuleDef_Init(PyModuleDef*);
4141
PyAPI_DATA(PyTypeObject) PyModuleDef_Type;
4242
#endif
4343

@@ -56,6 +56,7 @@ typedef struct PyModuleDef_Base {
5656
}
5757

5858
struct PyModuleDef_Slot;
59+
5960
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
6061
/* New in 3.5 */
6162
typedef struct PyModuleDef_Slot{
@@ -78,7 +79,7 @@ struct PyModuleDef {
7879
const char* m_doc;
7980
Py_ssize_t m_size;
8081
PyMethodDef *m_methods;
81-
struct PyModuleDef_Slot* m_slots;
82+
PyModuleDef_Slot *m_slots;
8283
traverseproc m_traverse;
8384
inquiry m_clear;
8485
freefunc m_free;

Include/object.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ whose size is determined when the object is allocated.
6363
#ifdef Py_TRACE_REFS
6464
/* Define pointers to support a doubly-linked list of all live heap objects. */
6565
#define _PyObject_HEAD_EXTRA \
66-
struct _object *_ob_next; \
67-
struct _object *_ob_prev;
66+
PyObject *_ob_next; \
67+
PyObject *_ob_prev;
6868

6969
#define _PyObject_EXTRA_INIT 0, 0,
7070

@@ -237,8 +237,8 @@ PyAPI_FUNC(void*) PyType_GetSlot(PyTypeObject*, int);
237237
#endif
238238
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
239239
PyAPI_FUNC(PyObject*) PyType_FromModuleAndSpec(PyObject *, PyType_Spec *, PyObject *);
240-
PyAPI_FUNC(PyObject *) PyType_GetModule(struct _typeobject *);
241-
PyAPI_FUNC(void *) PyType_GetModuleState(struct _typeobject *);
240+
PyAPI_FUNC(PyObject *) PyType_GetModule(PyTypeObject *);
241+
PyAPI_FUNC(void *) PyType_GetModuleState(PyTypeObject *);
242242
#endif
243243
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030B0000
244244
PyAPI_FUNC(PyObject *) PyType_GetName(PyTypeObject *);

Include/pystate.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ PyAPI_FUNC(int64_t) PyInterpreterState_GetID(PyInterpreterState *);
4040
/* State unique per thread */
4141

4242
/* New in 3.3 */
43-
PyAPI_FUNC(int) PyState_AddModule(PyObject*, struct PyModuleDef*);
44-
PyAPI_FUNC(int) PyState_RemoveModule(struct PyModuleDef*);
43+
PyAPI_FUNC(int) PyState_AddModule(PyObject*, PyModuleDef*);
44+
PyAPI_FUNC(int) PyState_RemoveModule(PyModuleDef*);
4545
#endif
46-
PyAPI_FUNC(PyObject*) PyState_FindModule(struct PyModuleDef*);
46+
PyAPI_FUNC(PyObject*) PyState_FindModule(PyModuleDef*);
4747

4848
PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *);
4949
PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *);

Include/structmember.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ struct PyMemberDef {
6565
#define PY_AUDIT_READ READ_RESTRICTED
6666

6767
/* Current API, use this */
68-
PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, struct PyMemberDef *);
69-
PyAPI_FUNC(int) PyMember_SetOne(char *, struct PyMemberDef *, PyObject *);
68+
PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, PyMemberDef *);
69+
PyAPI_FUNC(int) PyMember_SetOne(char *, PyMemberDef *, PyObject *);
7070

7171

7272
#ifdef __cplusplus

Include/structseq.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ typedef struct PyStructSequence_Field {
1515
typedef struct PyStructSequence_Desc {
1616
const char *name;
1717
const char *doc;
18-
struct PyStructSequence_Field *fields;
18+
PyStructSequence_Field *fields;
1919
int n_in_sequence;
2020
} PyStructSequence_Desc;
2121

Objects/call.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,8 +884,7 @@ PyObject_CallMethodObjArgs(PyObject *obj, PyObject *name, ...)
884884

885885

886886
PyObject *
887-
_PyObject_CallMethodIdObjArgs(PyObject *obj,
888-
struct _Py_Identifier *name, ...)
887+
_PyObject_CallMethodIdObjArgs(PyObject *obj, _Py_Identifier *name, ...)
889888
{
890889
PyThreadState *tstate = _PyThreadState_GET();
891890
if (obj == NULL || name == NULL) {

Objects/dictobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ _PyDict_GetItemWithError(PyObject *dp, PyObject *kv)
15001500
}
15011501

15021502
PyObject *
1503-
_PyDict_GetItemIdWithError(PyObject *dp, struct _Py_Identifier *key)
1503+
_PyDict_GetItemIdWithError(PyObject *dp, _Py_Identifier *key)
15041504
{
15051505
PyObject *kv;
15061506
kv = _PyUnicode_FromId(key); /* borrowed */
@@ -3411,7 +3411,7 @@ _PyDict_Contains_KnownHash(PyObject *op, PyObject *key, Py_hash_t hash)
34113411
}
34123412

34133413
int
3414-
_PyDict_ContainsId(PyObject *op, struct _Py_Identifier *key)
3414+
_PyDict_ContainsId(PyObject *op, _Py_Identifier *key)
34153415
{
34163416
PyObject *kv = _PyUnicode_FromId(key); /* borrowed */
34173417
if (kv == NULL) {
@@ -3589,7 +3589,7 @@ PyDict_GetItemString(PyObject *v, const char *key)
35893589
}
35903590

35913591
int
3592-
_PyDict_SetItemId(PyObject *v, struct _Py_Identifier *key, PyObject *item)
3592+
_PyDict_SetItemId(PyObject *v, _Py_Identifier *key, PyObject *item)
35933593
{
35943594
PyObject *kv;
35953595
kv = _PyUnicode_FromId(key); /* borrowed */

0 commit comments

Comments
 (0)