]> granicus.if.org Git - python/commitdiff
Change time.strftime() to return a unicode string.
authorWalter Dörwald <walter@livinglogic.de>
Thu, 31 May 2007 19:23:17 +0000 (19:23 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Thu, 31 May 2007 19:23:17 +0000 (19:23 +0000)
Use PyMem_Malloc() to allocate temporary storage.

Modules/timemodule.c

index 4e242992118960f23a01ddfac8db941e14294395..c7cd340cfe9cce7d896cd9ba8fc641b7d1a05ad0 100644 (file)
@@ -475,7 +475,7 @@ time_strftime(PyObject *self, PyObject *args)
         * will be ahead of time...
         */
        for (i = 1024; ; i += i) {
-               outbuf = (char *)malloc(i);
+               outbuf = (char *)PyMem_Malloc(i);
                if (outbuf == NULL) {
                        return PyErr_NoMemory();
                }
@@ -487,11 +487,11 @@ time_strftime(PyObject *self, PyObject *args)
                           e.g. an empty format, or %Z when the timezone
                           is unknown. */
                        PyObject *ret;
-                       ret = PyString_FromStringAndSize(outbuf, buflen);
-                       free(outbuf);
+                       ret = PyUnicode_FromStringAndSize(outbuf, buflen);
+                       PyMem_Free(outbuf);
                        return ret;
                }
-               free(outbuf);
+               PyMem_Free(outbuf);
 #if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__)
                /* VisualStudio .NET 2005 does this properly */
                if (buflen == 0 && errno == EINVAL) {
@@ -499,7 +499,6 @@ time_strftime(PyObject *self, PyObject *args)
                        return 0;
                }
 #endif
-               
        }
 }