diff options
author | Petr Viktorin <encukou@gmail.com> | 2020-05-28 16:14:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-28 16:14:46 (GMT) |
commit | 459acc551656785bc4a3363d65c7a60f822da8e3 (patch) | |
tree | d521a0e2a2de518d2d93f1040eb4def13b4094cb | |
parent | 60398512c86c5535edd817c99ccb50453b3b0471 (diff) | |
download | cpython-459acc551656785bc4a3363d65c7a60f822da8e3.zip cpython-459acc551656785bc4a3363d65c7a60f822da8e3.tar.gz cpython-459acc551656785bc4a3363d65c7a60f822da8e3.tar.bz2 |
bpo-40777: Initialize PyDateTime_IsoCalendarDateType.tp_base at run-time (GH-20493)
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.
-rw-r--r-- | Misc/NEWS.d/next/Library/2020-05-28-17-32-29.bpo-40777.1kJU6N.rst | 2 | ||||
-rw-r--r-- | Modules/_datetimemodule.c | 13 |
2 files changed, 12 insertions, 3 deletions
diff --git a/Misc/NEWS.d/next/Library/2020-05-28-17-32-29.bpo-40777.1kJU6N.rst b/Misc/NEWS.d/next/Library/2020-05-28-17-32-29.bpo-40777.1kJU6N.rst new file mode 100644 index 0000000..761bc83 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-28-17-32-29.bpo-40777.1kJU6N.rst @@ -0,0 +1,2 @@ +Initialize PyDateTime_IsoCalendarDateType.tp_base at run-time to avoid +errors on some compilers. diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 7a5efd2..acdde83 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -3325,7 +3325,7 @@ static PyTypeObject PyDateTime_IsoCalendarDateType = { .tp_doc = iso_calendar_date__doc__, .tp_methods = iso_calendar_date_methods, .tp_getset = iso_calendar_date_getset, - .tp_base = &PyTuple_Type, + // .tp_base = &PyTuple_Type, // filled in PyInit__datetime .tp_new = iso_calendar_date_new, }; @@ -4079,7 +4079,7 @@ static PyTypeObject PyDateTime_TimeZoneType = { timezone_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - &PyDateTime_TZInfoType, /* tp_base */ + 0, /* tp_base; filled in PyInit__datetime */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -6458,7 +6458,8 @@ static PyTypeObject PyDateTime_DateTimeType = { datetime_methods, /* tp_methods */ 0, /* tp_members */ datetime_getset, /* tp_getset */ - &PyDateTime_DateType, /* tp_base */ + 0, /* tp_base; filled in + PyInit__datetime */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -6524,6 +6525,12 @@ PyInit__datetime(void) if (m == NULL) return NULL; + // `&...` is not a constant expression according to a strict reading + // of C standards. Fill tp_base at run-time rather than statically. + // See https://bugs.python.org/issue40777 + PyDateTime_IsoCalendarDateType.tp_base = &PyTuple_Type; + PyDateTime_TimeZoneType.tp_base = &PyDateTime_TZInfoType; + PyDateTime_DateTimeType.tp_base = &PyDateTime_DateType; PyTypeObject *types[] = { &PyDateTime_DateType, |