Index: Modules/timemodule.c =================================================================== --- Modules/timemodule.c (revision 69496) +++ Modules/timemodule.c (working copy) @@ -422,10 +422,13 @@ { PyObject *tup = NULL; struct tm buf; +#ifdef MS_WINDOWS + const wchar_t *fmt; +#else const char *fmt; +#endif PyObject *format; size_t fmtlen, buflen; - char *outbuf = 0; size_t i; memset((void *) &buf, '\0', sizeof(buf)); @@ -508,20 +511,32 @@ return NULL; } - /* Convert the unicode string to an ascii one */ - fmt = _PyUnicode_AsString(format); - +#ifdef MS_WINDOWS + fmt = PyUnicode_AS_UNICODE(format); + fmtlen = wcslen(fmt); +#else + /* Convert the unicode string to an ascii one */ + fmt = _PyUnicode_AsString(format); fmtlen = strlen(fmt); +#endif /* I hate these functions that presume you know how big the output * will be ahead of time... */ for (i = 1024; ; i += i) { - outbuf = (char *)PyMem_Malloc(i); +#ifdef MS_WINDOWS + wchar_t* outbuf = PyMem_New(wchar_t, i); +#else + char* outbuf = PyMem_New(char, i); +#endif if (outbuf == NULL) { return PyErr_NoMemory(); } +#ifdef MS_WINDOWS + buflen = wcsftime(outbuf, i, fmt, &buf); +#else buflen = strftime(outbuf, i, fmt, &buf); +#endif if (buflen > 0 || i >= 256 * fmtlen) { /* If the buffer is 256 times as long as the format, it's probably not failing for lack of room! @@ -529,8 +544,11 @@ e.g. an empty format, or %Z when the timezone is unknown. */ PyObject *ret; - ret = PyUnicode_Decode(outbuf, buflen, - TZNAME_ENCODING, NULL); +#ifdef MS_WINDOWS + ret = PyUnicode_FromWideChar(outbuf, buflen); +#else + ret = PyUnicode_DecodeUTF8(outbuf, buflen, NULL); +#endif PyMem_Free(outbuf); return ret; }