[Python-checkins] r69665 - in python/branches/release30-maint: Misc/NEWS Modules/timemodule.c
hirokazu.yamamoto
python-checkins at python.org
Mon Feb 16 10:29:32 CET 2009
Author: hirokazu.yamamoto
Date: Mon Feb 16 10:29:31 2009
New Revision: 69665
Log:
Merged revisions 69664 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r69664 | hirokazu.yamamoto | 2009-02-16 18:13:20 +0900 | 2 lines
Issue #5249: time.strftime returned malformed string when format string
contained non ascii character on windows.
........
Modified:
python/branches/release30-maint/ (props changed)
python/branches/release30-maint/Misc/NEWS
python/branches/release30-maint/Modules/timemodule.c
Modified: python/branches/release30-maint/Misc/NEWS
==============================================================================
--- python/branches/release30-maint/Misc/NEWS (original)
+++ python/branches/release30-maint/Misc/NEWS Mon Feb 16 10:29:31 2009
@@ -12,6 +12,9 @@
Core and Builtins
-----------------
+- Issue #5249: time.strftime returned malformed string when format string
+ contained non ascii character on windows.
+
Library
-------
Modified: python/branches/release30-maint/Modules/timemodule.c
==============================================================================
--- python/branches/release30-maint/Modules/timemodule.c (original)
+++ python/branches/release30-maint/Modules/timemodule.c Mon Feb 16 10:29:31 2009
@@ -508,9 +508,11 @@
return NULL;
}
- /* Convert the unicode string to an ascii one */
- fmt = _PyUnicode_AsString(format);
-
+ /* Convert the unicode string to an ascii one */
+ format = PyUnicode_AsEncodedString(format, TZNAME_ENCODING, NULL);
+ if (format == NULL)
+ return NULL;
+ fmt = PyBytes_AS_STRING(format);
fmtlen = strlen(fmt);
/* I hate these functions that presume you know how big the output
@@ -519,6 +521,7 @@
for (i = 1024; ; i += i) {
outbuf = (char *)PyMem_Malloc(i);
if (outbuf == NULL) {
+ Py_DECREF(format);
return PyErr_NoMemory();
}
buflen = strftime(outbuf, i, fmt, &buf);
@@ -532,6 +535,7 @@
ret = PyUnicode_Decode(outbuf, buflen,
TZNAME_ENCODING, NULL);
PyMem_Free(outbuf);
+ Py_DECREF(format);
return ret;
}
PyMem_Free(outbuf);
@@ -539,6 +543,7 @@
/* VisualStudio .NET 2005 does this properly */
if (buflen == 0 && errno == EINVAL) {
PyErr_SetString(PyExc_ValueError, "Invalid format string");
+ Py_DECREF(format);
return 0;
}
#endif
More information about the Python-checkins
mailing list