Commit 6bd238cb authored by Walter Dörwald's avatar Walter Dörwald

Use PyString instead of PyBytes in wrap_strftime().

parent f386311f
...@@ -1237,9 +1237,9 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple, ...@@ -1237,9 +1237,9 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
* is expensive, don't unless they're actually used. * is expensive, don't unless they're actually used.
*/ */
totalnew = flen + 1; /* realistic if no %z/%Z */ totalnew = flen + 1; /* realistic if no %z/%Z */
newfmt = PyBytes_FromStringAndSize(NULL, totalnew); newfmt = PyString_FromStringAndSize(NULL, totalnew);
if (newfmt == NULL) goto Done; if (newfmt == NULL) goto Done;
pnew = PyBytes_AsString(newfmt); pnew = PyString_AsString(newfmt);
usednew = 0; usednew = 0;
while ((ch = *pin++) != '\0') { while ((ch = *pin++) != '\0') {
...@@ -1259,7 +1259,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple, ...@@ -1259,7 +1259,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
/* format utcoffset */ /* format utcoffset */
char buf[100]; char buf[100];
PyObject *tzinfo = get_tzinfo_member(object); PyObject *tzinfo = get_tzinfo_member(object);
zreplacement = PyBytes_FromStringAndSize("", 0); zreplacement = PyString_FromStringAndSize("", 0);
if (zreplacement == NULL) goto Done; if (zreplacement == NULL) goto Done;
if (tzinfo != Py_None && tzinfo != NULL) { if (tzinfo != Py_None && tzinfo != NULL) {
assert(tzinfoarg != NULL); assert(tzinfoarg != NULL);
...@@ -1271,15 +1271,15 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple, ...@@ -1271,15 +1271,15 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
goto Done; goto Done;
Py_DECREF(zreplacement); Py_DECREF(zreplacement);
zreplacement = zreplacement =
PyBytes_FromStringAndSize(buf, PyString_FromStringAndSize(buf,
strlen(buf)); strlen(buf));
if (zreplacement == NULL) if (zreplacement == NULL)
goto Done; goto Done;
} }
} }
assert(zreplacement != NULL); assert(zreplacement != NULL);
ptoappend = PyBytes_AS_STRING(zreplacement); ptoappend = PyString_AS_STRING(zreplacement);
ntoappend = PyBytes_GET_SIZE(zreplacement); ntoappend = PyString_GET_SIZE(zreplacement);
} }
else if (ch == 'Z') { else if (ch == 'Z') {
/* format tzname */ /* format tzname */
...@@ -1314,10 +1314,10 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple, ...@@ -1314,10 +1314,10 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
PyErr_NoMemory(); PyErr_NoMemory();
goto Done; goto Done;
} }
if (PyBytes_Resize(newfmt, bigger) < 0) if (_PyString_Resize(&newfmt, bigger) < 0)
goto Done; goto Done;
totalnew = bigger; totalnew = bigger;
pnew = PyBytes_AsString(newfmt) + usednew; pnew = PyString_AsString(newfmt) + usednew;
} }
memcpy(pnew, ptoappend, ntoappend); memcpy(pnew, ptoappend, ntoappend);
pnew += ntoappend; pnew += ntoappend;
...@@ -1325,14 +1325,14 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple, ...@@ -1325,14 +1325,14 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
assert(usednew <= totalnew); assert(usednew <= totalnew);
} /* end while() */ } /* end while() */
if (PyBytes_Resize(newfmt, usednew) < 0) if (_PyString_Resize(&newfmt, usednew) < 0)
goto Done; goto Done;
{ {
PyObject *format; PyObject *format;
PyObject *time = PyImport_ImportModule("time"); PyObject *time = PyImport_ImportModule("time");
if (time == NULL) if (time == NULL)
goto Done; goto Done;
format = PyUnicode_FromString(PyBytes_AS_STRING(newfmt)); format = PyUnicode_FromString(PyString_AS_STRING(newfmt));
if (format != NULL) { if (format != NULL) {
result = PyObject_CallMethod(time, "strftime", "OO", result = PyObject_CallMethod(time, "strftime", "OO",
format, timetuple); format, timetuple);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment