Skip to content

Commit eceee54

Browse files
[3.9] bpo-40777: Initialize PyDateTime_IsoCalendarDateType.tp_base at run-time (GH-20493) (GH-20495)
Recent changes to _datetimemodule broke compilation on mingw; see the comments in this change for details. FWIW, @corona10: this issue is why `PyType_FromModuleAndSpec` & friends take the `bases` argument at run time. (cherry picked from commit 459acc5) Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent a5936ad commit eceee54

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Initialize PyDateTime_IsoCalendarDateType.tp_base at run-time to avoid
2+
errors on some compilers.

Modules/_datetimemodule.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -3325,7 +3325,7 @@ static PyTypeObject PyDateTime_IsoCalendarDateType = {
33253325
.tp_doc = iso_calendar_date__doc__,
33263326
.tp_methods = iso_calendar_date_methods,
33273327
.tp_getset = iso_calendar_date_getset,
3328-
.tp_base = &PyTuple_Type,
3328+
// .tp_base = &PyTuple_Type, // filled in PyInit__datetime
33293329
.tp_new = iso_calendar_date_new,
33303330
};
33313331

@@ -4079,7 +4079,7 @@ static PyTypeObject PyDateTime_TimeZoneType = {
40794079
timezone_methods, /* tp_methods */
40804080
0, /* tp_members */
40814081
0, /* tp_getset */
4082-
&PyDateTime_TZInfoType, /* tp_base */
4082+
0, /* tp_base; filled in PyInit__datetime */
40834083
0, /* tp_dict */
40844084
0, /* tp_descr_get */
40854085
0, /* tp_descr_set */
@@ -6458,7 +6458,8 @@ static PyTypeObject PyDateTime_DateTimeType = {
64586458
datetime_methods, /* tp_methods */
64596459
0, /* tp_members */
64606460
datetime_getset, /* tp_getset */
6461-
&PyDateTime_DateType, /* tp_base */
6461+
0, /* tp_base; filled in
6462+
PyInit__datetime */
64626463
0, /* tp_dict */
64636464
0, /* tp_descr_get */
64646465
0, /* tp_descr_set */
@@ -6524,6 +6525,12 @@ PyInit__datetime(void)
65246525
if (m == NULL)
65256526
return NULL;
65266527

6528+
// `&...` is not a constant expression according to a strict reading
6529+
// of C standards. Fill tp_base at run-time rather than statically.
6530+
// See https://bugs.python.org/issue40777
6531+
PyDateTime_IsoCalendarDateType.tp_base = &PyTuple_Type;
6532+
PyDateTime_TimeZoneType.tp_base = &PyDateTime_TZInfoType;
6533+
PyDateTime_DateTimeType.tp_base = &PyDateTime_DateType;
65276534

65286535
PyTypeObject *types[] = {
65296536
&PyDateTime_DateType,

0 commit comments

Comments
 (0)