Change time.strftime() to return a unicode string.
Use PyMem_Malloc() to allocate temporary storage.
This commit is contained in:
parent
baf853c537
commit
cf47af4d71
@ -475,7 +475,7 @@ time_strftime(PyObject *self, PyObject *args)
|
|||||||
* will be ahead of time...
|
* will be ahead of time...
|
||||||
*/
|
*/
|
||||||
for (i = 1024; ; i += i) {
|
for (i = 1024; ; i += i) {
|
||||||
outbuf = (char *)malloc(i);
|
outbuf = (char *)PyMem_Malloc(i);
|
||||||
if (outbuf == NULL) {
|
if (outbuf == NULL) {
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
}
|
}
|
||||||
@ -487,11 +487,11 @@ time_strftime(PyObject *self, PyObject *args)
|
|||||||
e.g. an empty format, or %Z when the timezone
|
e.g. an empty format, or %Z when the timezone
|
||||||
is unknown. */
|
is unknown. */
|
||||||
PyObject *ret;
|
PyObject *ret;
|
||||||
ret = PyString_FromStringAndSize(outbuf, buflen);
|
ret = PyUnicode_FromStringAndSize(outbuf, buflen);
|
||||||
free(outbuf);
|
PyMem_Free(outbuf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
free(outbuf);
|
PyMem_Free(outbuf);
|
||||||
#if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__)
|
#if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__)
|
||||||
/* VisualStudio .NET 2005 does this properly */
|
/* VisualStudio .NET 2005 does this properly */
|
||||||
if (buflen == 0 && errno == EINVAL) {
|
if (buflen == 0 && errno == EINVAL) {
|
||||||
@ -499,7 +499,6 @@ time_strftime(PyObject *self, PyObject *args)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user