Mercurial > cpython-lru_cache-weakref
diff Python/getargs.c @ 41595:2c54763c4504
More coding by random modification.
Encoding now return bytes instead of str8.
eval(), exec(), compile() now accept unicode or bytes.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 04 May 2007 00:41:39 +0000 |
| parents | 15b810e21fe9 |
| children | cfb3e0021b3b |
line wrap: on
line diff
--- a/Python/getargs.c Thu May 03 21:11:35 2007 +0000 +++ b/Python/getargs.c Fri May 04 00:41:39 2007 +0000 @@ -883,7 +883,9 @@ char **buffer; const char *encoding; PyObject *s; - int size, recode_strings; + int recode_strings; + Py_ssize_t size; + char *ptr; /* Get 'e' parameter: the encoding name */ encoding = (const char *)va_arg(*p_va, const char *); @@ -912,6 +914,8 @@ if (!recode_strings && PyString_Check(arg)) { s = arg; Py_INCREF(s); + size = PyString_GET_SIZE(s); + ptr = PyString_AS_STRING(s); } else { PyObject *u; @@ -931,14 +935,15 @@ if (s == NULL) return converterr("(encoding failed)", arg, msgbuf, bufsize); - if (!PyString_Check(s)) { + if (!PyBytes_Check(s)) { Py_DECREF(s); return converterr( - "(encoder failed to return a string)", + "(encoder failed to return bytes)", arg, msgbuf, bufsize); } + size = PyBytes_GET_SIZE(s); + ptr = PyBytes_AS_STRING(s); } - size = PyString_GET_SIZE(s); /* Write output; output is guaranteed to be 0-terminated */ if (*format == '#') { @@ -994,9 +999,7 @@ arg, msgbuf, bufsize); } } - memcpy(*buffer, - PyString_AS_STRING(s), - size + 1); + memcpy(*buffer, ptr, size+1); STORE_SIZE(size); } else { /* Using a 0-terminated buffer: @@ -1012,8 +1015,7 @@ PyMem_Free()ing it after usage */ - if ((Py_ssize_t)strlen(PyString_AS_STRING(s)) - != size) { + if ((Py_ssize_t)strlen(ptr) != size) { Py_DECREF(s); return converterr( "(encoded string without NULL bytes)", @@ -1030,9 +1032,7 @@ return converterr("(cleanup problem)", arg, msgbuf, bufsize); } - memcpy(*buffer, - PyString_AS_STRING(s), - size + 1); + memcpy(*buffer, ptr, size+1); } Py_DECREF(s); break;
