Skip to content

Commit 5def03d

Browse files
authored
gh-159808: Sync documented C API structs with their headers (GH-159812)
1 parent a75d1c1 commit 5def03d

6 files changed

Lines changed: 17 additions & 10 deletions

File tree

‎Doc/c-api/import.rst‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,11 @@ Importing Modules
257257
This is the structure type definition for frozen module descriptors, as
258258
generated by the :program:`freeze` utility (see :file:`Tools/freeze/` in the
259259
Python source distribution). Its definition, found in :file:`Include/import.h`,
260-
is::
261-
262-
struct _frozen {
263-
const char *name;
264-
const unsigned char *code;
265-
int size;
266-
bool is_package;
267-
};
260+
is:
261+
262+
.. literalinclude:: ../../Include/cpython/import.h
263+
:start-at: struct _frozen {
264+
:end-at: };
268265
269266
.. versionchanged:: 3.11
270267
The new ``is_package`` field indicates whether the module is a package or not.

‎Doc/c-api/slots.rst‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ Entries of the slots array use the following structure:
4848
typedef struct {
4949
uint16_t sl_id;
5050
uint16_t sl_flags;
51-
uint32_t _reserved; // must be 0
51+
union {
52+
uint32_t sl_reserved; // must be 0
53+
};
5254
union {
5355
void *sl_ptr;
5456
void (*sl_func)(void);

‎Doc/c-api/typeobj.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ definition found there:
480480
.. XXX Drop this?
481481
482482
.. literalinclude:: ../includes/typestruct.h
483+
:end-at: } PyTypeObject;
483484

484485

485486
PyObject Slots

‎Doc/extending/newtypes.rst‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Here is the definition of :c:type:`PyTypeObject`, with some fields only used in
1515
:ref:`debug builds <debug-build>` omitted:
1616

1717
.. literalinclude:: ../includes/typestruct.h
18+
:end-at: } PyTypeObject;
1819

1920

2021
Now that's a *lot* of methods. Don't worry too much though -- if you have
@@ -285,7 +286,7 @@ be read-only or read-write. The structures in the table are defined as::
285286
typedef struct PyMemberDef {
286287
const char *name;
287288
int type;
288-
int offset;
289+
Py_ssize_t offset;
289290
int flags;
290291
const char *doc;
291292
} PyMemberDef;

‎Doc/includes/typestruct.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,7 @@ typedef struct _typeobject {
9393
*/
9494
uint16_t tp_versions_used;
9595
} PyTypeObject;
96+
97+
/* Private fields are intentionally omitted.
98+
* Keep them excluded when updating this definition.
99+
*/

‎Include/cpython/import.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ PyAPI_FUNC(PyObject *) PyImport_CreateModuleFromInitfunc(
1717
PyObject *spec,
1818
PyObject *(*initfunc)(void));
1919

20+
/* This structure is included verbatim in the public documentation
21+
(Doc/c-api/import.rst). */
2022
struct _frozen {
2123
const char *name; /* ASCII encoded string */
2224
const unsigned char *code;

0 commit comments

Comments
 (0)