Skip to content

Commit 23cf1e2

Browse files
authored
pythongh-99202: Fix extension type from documentation for compiling in C++20 mode (python#102518)
1 parent 52bc2e7 commit 23cf1e2

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

Doc/extending/newtypes_tutorial.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ standard Python floats::
8888
The second bit is the definition of the type object. ::
8989

9090
static PyTypeObject CustomType = {
91-
PyVarObject_HEAD_INIT(NULL, 0)
91+
.ob_base = PyVarObject_HEAD_INIT(NULL, 0)
9292
.tp_name = "custom.Custom",
9393
.tp_doc = PyDoc_STR("Custom objects"),
9494
.tp_basicsize = sizeof(CustomObject),
@@ -109,7 +109,7 @@ common practice to not specify them explicitly unless you need them.
109109

110110
We're going to pick it apart, one field at a time::
111111

112-
PyVarObject_HEAD_INIT(NULL, 0)
112+
.ob_base = PyVarObject_HEAD_INIT(NULL, 0)
113113

114114
This line is mandatory boilerplate to initialize the ``ob_base``
115115
field mentioned above. ::

Doc/includes/custom.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ typedef struct {
77
} CustomObject;
88

99
static PyTypeObject CustomType = {
10-
PyVarObject_HEAD_INIT(NULL, 0)
10+
.ob_base = PyVarObject_HEAD_INIT(NULL, 0)
1111
.tp_name = "custom.Custom",
1212
.tp_doc = PyDoc_STR("Custom objects"),
1313
.tp_basicsize = sizeof(CustomObject),
@@ -17,7 +17,7 @@ static PyTypeObject CustomType = {
1717
};
1818

1919
static PyModuleDef custommodule = {
20-
PyModuleDef_HEAD_INIT,
20+
.m_base = PyModuleDef_HEAD_INIT,
2121
.m_name = "custom",
2222
.m_doc = "Example module that creates an extension type.",
2323
.m_size = -1,

Doc/includes/custom2.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static PyMethodDef Custom_methods[] = {
9090
};
9191

9292
static PyTypeObject CustomType = {
93-
PyVarObject_HEAD_INIT(NULL, 0)
93+
.ob_base = PyVarObject_HEAD_INIT(NULL, 0)
9494
.tp_name = "custom2.Custom",
9595
.tp_doc = PyDoc_STR("Custom objects"),
9696
.tp_basicsize = sizeof(CustomObject),
@@ -104,7 +104,7 @@ static PyTypeObject CustomType = {
104104
};
105105

106106
static PyModuleDef custommodule = {
107-
PyModuleDef_HEAD_INIT,
107+
.m_base =PyModuleDef_HEAD_INIT,
108108
.m_name = "custom2",
109109
.m_doc = "Example module that creates an extension type.",
110110
.m_size = -1,

Doc/includes/custom3.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static PyMethodDef Custom_methods[] = {
130130
};
131131

132132
static PyTypeObject CustomType = {
133-
PyVarObject_HEAD_INIT(NULL, 0)
133+
.ob_base = PyVarObject_HEAD_INIT(NULL, 0)
134134
.tp_name = "custom3.Custom",
135135
.tp_doc = PyDoc_STR("Custom objects"),
136136
.tp_basicsize = sizeof(CustomObject),
@@ -145,7 +145,7 @@ static PyTypeObject CustomType = {
145145
};
146146

147147
static PyModuleDef custommodule = {
148-
PyModuleDef_HEAD_INIT,
148+
.m_base = PyModuleDef_HEAD_INIT,
149149
.m_name = "custom3",
150150
.m_doc = "Example module that creates an extension type.",
151151
.m_size = -1,

Doc/includes/custom4.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static PyMethodDef Custom_methods[] = {
146146
};
147147

148148
static PyTypeObject CustomType = {
149-
PyVarObject_HEAD_INIT(NULL, 0)
149+
.ob_base = PyVarObject_HEAD_INIT(NULL, 0)
150150
.tp_name = "custom4.Custom",
151151
.tp_doc = PyDoc_STR("Custom objects"),
152152
.tp_basicsize = sizeof(CustomObject),
@@ -163,7 +163,7 @@ static PyTypeObject CustomType = {
163163
};
164164

165165
static PyModuleDef custommodule = {
166-
PyModuleDef_HEAD_INIT,
166+
.m_base = PyModuleDef_HEAD_INIT,
167167
.m_name = "custom4",
168168
.m_doc = "Example module that creates an extension type.",
169169
.m_size = -1,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix extension type from documentation for compiling in C++20 mode

0 commit comments

Comments
 (0)