diff options
author | Benjamin Peterson <benjamin@python.org> | 2018-09-13 21:05:04 -0700 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2018-09-13 21:05:04 -0700 |
commit | 4e02ec1c6bf5e665a80cf80f24c939ec997f7630 (patch) | |
tree | b9b2818bc6d2d9c651e1660bc087a8e952cdeeba | |
parent | 4e824e96491f33c8a8462aa4970c55942064ae76 (diff) | |
download | cpython-git-4e02ec1c6bf5e665a80cf80f24c939ec997f7630.tar.gz |
bpo-34672: Try to pass the C library's own timezone strings back to it.benjamin-musl-z-workaround
-rw-r--r-- | Misc/NEWS.d/next/Library/2018-09-13-21-04-23.bpo-34672.BYuKKS.rst | 2 | ||||
-rw-r--r-- | Modules/timemodule.c | 23 |
2 files changed, 21 insertions, 4 deletions
diff --git a/Misc/NEWS.d/next/Library/2018-09-13-21-04-23.bpo-34672.BYuKKS.rst b/Misc/NEWS.d/next/Library/2018-09-13-21-04-23.bpo-34672.BYuKKS.rst new file mode 100644 index 0000000000..59d106b600 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-09-13-21-04-23.bpo-34672.BYuKKS.rst @@ -0,0 +1,2 @@ +Add a workaround, so the ``'Z'`` :func:`time.strftime` specifier on the musl +C library can work in some cases. diff --git a/Modules/timemodule.c b/Modules/timemodule.c index dbe2fbaf07..9170505712 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -565,11 +565,26 @@ gettmarg(PyObject *args, struct tm *p, const char *format) if (Py_TYPE(args) == &StructTimeType) { PyObject *item; item = PyTuple_GET_ITEM(args, 9); - p->tm_zone = item == Py_None ? NULL : (char*)PyUnicode_AsUTF8(item); + if (item != Py_None) { + p->tm_zone = PyUnicode_AsUTF8(item); + if (p->tm_zone == NULL) { + return 0; + } + // Make an attempt to return the C library's own timezone strings to + // it. musl refuses to process a tm_zone field unless it produced + // it. See issue #34672. + if (tzname[0] && strcmp(p->tm_zone, tzname[0]) == 0) { + p->tm_zone = tzname[0]; + } else if (tzname[1] && strcmp(p->tm_zone, tzname[1]) == 0) { + p->tm_zone = tzname[1]; + } + } item = PyTuple_GET_ITEM(args, 10); - p->tm_gmtoff = item == Py_None ? 0 : PyLong_AsLong(item); - if (PyErr_Occurred()) - return 0; + if (item != Py_None) { + p->tm_gmtoff = PyLong_AsLong(item); + if (PyErr_Occurred()) + return 0; + } } #endif /* HAVE_STRUCT_TM_TM_ZONE */ return 1; |