gh-99202: Fix extension type from documentation for compiling in C++20 mode (#102518)

This commit is contained in:
Jeffrey Newman 2023-04-06 10:59:36 -05:00 committed by GitHub
parent 52bc2e7b9d
commit 23cf1e20a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 11 additions and 10 deletions

View File

@ -88,7 +88,7 @@ standard Python floats::
The second bit is the definition of the type object. :: The second bit is the definition of the type object. ::
static PyTypeObject CustomType = { static PyTypeObject CustomType = {
PyVarObject_HEAD_INIT(NULL, 0) .ob_base = PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "custom.Custom", .tp_name = "custom.Custom",
.tp_doc = PyDoc_STR("Custom objects"), .tp_doc = PyDoc_STR("Custom objects"),
.tp_basicsize = sizeof(CustomObject), .tp_basicsize = sizeof(CustomObject),
@ -109,7 +109,7 @@ common practice to not specify them explicitly unless you need them.
We're going to pick it apart, one field at a time:: We're going to pick it apart, one field at a time::
PyVarObject_HEAD_INIT(NULL, 0) .ob_base = PyVarObject_HEAD_INIT(NULL, 0)
This line is mandatory boilerplate to initialize the ``ob_base`` This line is mandatory boilerplate to initialize the ``ob_base``
field mentioned above. :: field mentioned above. ::

View File

@ -7,7 +7,7 @@ typedef struct {
} CustomObject; } CustomObject;
static PyTypeObject CustomType = { static PyTypeObject CustomType = {
PyVarObject_HEAD_INIT(NULL, 0) .ob_base = PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "custom.Custom", .tp_name = "custom.Custom",
.tp_doc = PyDoc_STR("Custom objects"), .tp_doc = PyDoc_STR("Custom objects"),
.tp_basicsize = sizeof(CustomObject), .tp_basicsize = sizeof(CustomObject),
@ -17,7 +17,7 @@ static PyTypeObject CustomType = {
}; };
static PyModuleDef custommodule = { static PyModuleDef custommodule = {
PyModuleDef_HEAD_INIT, .m_base = PyModuleDef_HEAD_INIT,
.m_name = "custom", .m_name = "custom",
.m_doc = "Example module that creates an extension type.", .m_doc = "Example module that creates an extension type.",
.m_size = -1, .m_size = -1,

View File

@ -90,7 +90,7 @@ static PyMethodDef Custom_methods[] = {
}; };
static PyTypeObject CustomType = { static PyTypeObject CustomType = {
PyVarObject_HEAD_INIT(NULL, 0) .ob_base = PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "custom2.Custom", .tp_name = "custom2.Custom",
.tp_doc = PyDoc_STR("Custom objects"), .tp_doc = PyDoc_STR("Custom objects"),
.tp_basicsize = sizeof(CustomObject), .tp_basicsize = sizeof(CustomObject),
@ -104,7 +104,7 @@ static PyTypeObject CustomType = {
}; };
static PyModuleDef custommodule = { static PyModuleDef custommodule = {
PyModuleDef_HEAD_INIT, .m_base =PyModuleDef_HEAD_INIT,
.m_name = "custom2", .m_name = "custom2",
.m_doc = "Example module that creates an extension type.", .m_doc = "Example module that creates an extension type.",
.m_size = -1, .m_size = -1,

View File

@ -130,7 +130,7 @@ static PyMethodDef Custom_methods[] = {
}; };
static PyTypeObject CustomType = { static PyTypeObject CustomType = {
PyVarObject_HEAD_INIT(NULL, 0) .ob_base = PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "custom3.Custom", .tp_name = "custom3.Custom",
.tp_doc = PyDoc_STR("Custom objects"), .tp_doc = PyDoc_STR("Custom objects"),
.tp_basicsize = sizeof(CustomObject), .tp_basicsize = sizeof(CustomObject),
@ -145,7 +145,7 @@ static PyTypeObject CustomType = {
}; };
static PyModuleDef custommodule = { static PyModuleDef custommodule = {
PyModuleDef_HEAD_INIT, .m_base = PyModuleDef_HEAD_INIT,
.m_name = "custom3", .m_name = "custom3",
.m_doc = "Example module that creates an extension type.", .m_doc = "Example module that creates an extension type.",
.m_size = -1, .m_size = -1,

View File

@ -146,7 +146,7 @@ static PyMethodDef Custom_methods[] = {
}; };
static PyTypeObject CustomType = { static PyTypeObject CustomType = {
PyVarObject_HEAD_INIT(NULL, 0) .ob_base = PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "custom4.Custom", .tp_name = "custom4.Custom",
.tp_doc = PyDoc_STR("Custom objects"), .tp_doc = PyDoc_STR("Custom objects"),
.tp_basicsize = sizeof(CustomObject), .tp_basicsize = sizeof(CustomObject),
@ -163,7 +163,7 @@ static PyTypeObject CustomType = {
}; };
static PyModuleDef custommodule = { static PyModuleDef custommodule = {
PyModuleDef_HEAD_INIT, .m_base = PyModuleDef_HEAD_INIT,
.m_name = "custom4", .m_name = "custom4",
.m_doc = "Example module that creates an extension type.", .m_doc = "Example module that creates an extension type.",
.m_size = -1, .m_size = -1,

View File

@ -0,0 +1 @@
Fix extension type from documentation for compiling in C++20 mode