summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-07-29 22:39:05 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-07-29 22:39:05 (GMT)
commit2af8d2f6986bc3d07dc6dd63b77147f5b405b271 (patch)
tree7d7acc468054bce5210aa5834fb2f09bda69c5c7 /Objects
parentaf09c774e57d9c9b265fad0c092b63852d06ed25 (diff)
downloadcpython-2af8d2f6986bc3d07dc6dd63b77147f5b405b271.zip
cpython-2af8d2f6986bc3d07dc6dd63b77147f5b405b271.tar.gz
cpython-2af8d2f6986bc3d07dc6dd63b77147f5b405b271.tar.bz2
Issue #22023: Fix %S, %R and %V formats of PyUnicode_FromFormat().
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 29f9bce..f52ee92 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -690,7 +690,12 @@ makefmt(char *fmt, int longflag, int size_tflag, int zeropad, int width, int pre
*fmt = '\0';
}
-#define appendstring(string) {for (copy = string;*copy;) *s++ = *copy++;}
+#define appendstring(string) \
+ do { \
+ for (copy = string;*copy; copy++) { \
+ *s++ = (unsigned char)*copy; \
+ } \
+ } while (0)
PyObject *
PyUnicode_FromFormatV(const char *format, va_list vargs)
@@ -845,7 +850,7 @@ PyUnicode_FromFormatV(const char *format, va_list vargs)
str = PyObject_Str(obj);
if (!str)
goto fail;
- n += PyUnicode_GET_SIZE(str);
+ n += PyString_GET_SIZE(str);
/* Remember the str and switch to the next slot */
*callresult++ = str;
break;
@@ -1006,15 +1011,10 @@ PyUnicode_FromFormatV(const char *format, va_list vargs)
case 'S':
case 'R':
{
- Py_UNICODE *ucopy;
- Py_ssize_t usize;
- Py_ssize_t upos;
+ const char *str = PyString_AS_STRING(*callresult);
/* unused, since we already have the result */
(void) va_arg(vargs, PyObject *);
- ucopy = PyUnicode_AS_UNICODE(*callresult);
- usize = PyUnicode_GET_SIZE(*callresult);
- for (upos = 0; upos<usize;)
- *s++ = ucopy[upos++];
+ appendstring(str);
/* We're done with the unicode()/repr() => forget it */
Py_DECREF(*callresult);
/* switch to next unicode()/repr() result */