Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3bb0070

Browse files
committed
Explicitly convert tzname to Unicode. Fixes #1040.
1 parent 2cc1f6d commit 3bb0070

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

Modules/timemodule.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ static BOOL WINAPI PyCtrlHandler(DWORD dwCtrlType)
5555
}
5656
static long main_thread;
5757

58+
#define TZNAME_ENCODING "utf-8"
5859

5960
#if defined(__BORLANDC__)
6061
/* These overrides not needed for Win32 */
@@ -68,6 +69,8 @@ static long main_thread;
6869
#if defined(MS_WINDOWS) && !defined(__BORLANDC__)
6970
/* Win32 has better clock replacement; we have our own version below. */
7071
#undef HAVE_CLOCK
72+
#undef TZNAME_ENCODING
73+
#define TZNAME_ENCODING "mbcs"
7174
#endif /* MS_WINDOWS && !defined(__BORLANDC__) */
7275

7376
#if defined(PYOS_OS2)
@@ -710,6 +713,7 @@ void inittimezone(PyObject *m) {
710713
And I'm lazy and hate C so nyer.
711714
*/
712715
#if defined(HAVE_TZNAME) && !defined(__GLIBC__) && !defined(__CYGWIN__)
716+
PyObject *otz0, *otz1;
713717
tzset();
714718
#ifdef PYOS_OS2
715719
PyModule_AddIntConstant(m, "timezone", _timezone);
@@ -726,8 +730,9 @@ void inittimezone(PyObject *m) {
726730
#endif /* PYOS_OS2 */
727731
#endif
728732
PyModule_AddIntConstant(m, "daylight", daylight);
729-
PyModule_AddObject(m, "tzname",
730-
Py_BuildValue("(zz)", tzname[0], tzname[1]));
733+
otz0 = PyUnicode_Decode(tzname[0], strlen(tzname[0]), TZNAME_ENCODING, NULL);
734+
otz1 = PyUnicode_Decode(tzname[1], strlen(tzname[1]), TZNAME_ENCODING, NULL);
735+
PyModule_AddObject(m, "tzname", Py_BuildValue("(NN)", otz0, otz1));
731736
#else /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/
732737
#ifdef HAVE_STRUCT_TM_TM_ZONE
733738
{

0 commit comments

Comments
 (0)