Skip to content

Commit eaac871

Browse files
vstinnerasvetlov
authored andcommitted
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 d285118 commit eaac871

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 *);

0 commit comments

Comments
 (0)