Mercurial > cpython-lru_cache-weakref
diff Python/getargs.c @ 47527:52294af4b663 legacy-trunk
This reverts r63675 based on the discussion in this thread:
http://mail.python.org/pipermail/python-dev/2008-June/079988.html
Python 2.6 should stick with PyString_* in its codebase. The PyBytes_* names
in the spirit of 3.0 are available via a #define only. See the email thread.
| author | Gregory P. Smith <greg@mad-scientist.com> |
|---|---|
| date | Mon, 09 Jun 2008 04:58:54 +0000 |
| parents | 4fe192d48960 |
| children | b8c4bf393794 |
line wrap: on
line diff
--- a/Python/getargs.c Mon Jun 09 01:28:30 2008 +0000 +++ b/Python/getargs.c Mon Jun 09 04:58:54 2008 +0000 @@ -418,7 +418,7 @@ n++; } - if (!PySequence_Check(arg) || PyBytes_Check(arg)) { + if (!PySequence_Check(arg) || PyString_Check(arg)) { levels[0] = 0; PyOS_snprintf(msgbuf, bufsize, toplevel ? "expected %d arguments, not %.50s" : @@ -765,8 +765,8 @@ case 'c': {/* char */ char *p = va_arg(*p_va, char *); - if (PyBytes_Check(arg) && PyBytes_Size(arg) == 1) - *p = PyBytes_AS_STRING(arg)[0]; + if (PyString_Check(arg) && PyString_Size(arg) == 1) + *p = PyString_AS_STRING(arg)[0]; else return converterr("char", arg, msgbuf, bufsize); break; @@ -777,9 +777,9 @@ void **p = (void **)va_arg(*p_va, char **); FETCH_SIZE; - if (PyBytes_Check(arg)) { - *p = PyBytes_AS_STRING(arg); - STORE_SIZE(PyBytes_GET_SIZE(arg)); + if (PyString_Check(arg)) { + *p = PyString_AS_STRING(arg); + STORE_SIZE(PyString_GET_SIZE(arg)); } #ifdef Py_USING_UNICODE else if (PyUnicode_Check(arg)) { @@ -787,8 +787,8 @@ if (uarg == NULL) return converterr(CONV_UNICODE, arg, msgbuf, bufsize); - *p = PyBytes_AS_STRING(uarg); - STORE_SIZE(PyBytes_GET_SIZE(uarg)); + *p = PyString_AS_STRING(uarg); + STORE_SIZE(PyString_GET_SIZE(uarg)); } #endif else { /* any buffer-like object */ @@ -802,20 +802,20 @@ } else { char **p = va_arg(*p_va, char **); - if (PyBytes_Check(arg)) - *p = PyBytes_AS_STRING(arg); + if (PyString_Check(arg)) + *p = PyString_AS_STRING(arg); #ifdef Py_USING_UNICODE else if (PyUnicode_Check(arg)) { uarg = UNICODE_DEFAULT_ENCODING(arg); if (uarg == NULL) return converterr(CONV_UNICODE, arg, msgbuf, bufsize); - *p = PyBytes_AS_STRING(uarg); + *p = PyString_AS_STRING(uarg); } #endif else return converterr("string", arg, msgbuf, bufsize); - if ((Py_ssize_t)strlen(*p) != PyBytes_Size(arg)) + if ((Py_ssize_t)strlen(*p) != PyString_Size(arg)) return converterr("string without null bytes", arg, msgbuf, bufsize); } @@ -831,9 +831,9 @@ *p = 0; STORE_SIZE(0); } - else if (PyBytes_Check(arg)) { - *p = PyBytes_AS_STRING(arg); - STORE_SIZE(PyBytes_GET_SIZE(arg)); + else if (PyString_Check(arg)) { + *p = PyString_AS_STRING(arg); + STORE_SIZE(PyString_GET_SIZE(arg)); } #ifdef Py_USING_UNICODE else if (PyUnicode_Check(arg)) { @@ -841,8 +841,8 @@ if (uarg == NULL) return converterr(CONV_UNICODE, arg, msgbuf, bufsize); - *p = PyBytes_AS_STRING(uarg); - STORE_SIZE(PyBytes_GET_SIZE(uarg)); + *p = PyString_AS_STRING(uarg); + STORE_SIZE(PyString_GET_SIZE(uarg)); } #endif else { /* any buffer-like object */ @@ -858,15 +858,15 @@ if (arg == Py_None) *p = 0; - else if (PyBytes_Check(arg)) - *p = PyBytes_AS_STRING(arg); + else if (PyString_Check(arg)) + *p = PyString_AS_STRING(arg); #ifdef Py_USING_UNICODE else if (PyUnicode_Check(arg)) { uarg = UNICODE_DEFAULT_ENCODING(arg); if (uarg == NULL) return converterr(CONV_UNICODE, arg, msgbuf, bufsize); - *p = PyBytes_AS_STRING(uarg); + *p = PyString_AS_STRING(uarg); } #endif else @@ -878,11 +878,11 @@ if (arg == Py_None) *q = 0; else - *q = PyBytes_Size(arg); + *q = PyString_Size(arg); format++; } else if (*p != NULL && - (Py_ssize_t)strlen(*p) != PyBytes_Size(arg)) + (Py_ssize_t)strlen(*p) != PyString_Size(arg)) return converterr( "string without null bytes or None", arg, msgbuf, bufsize); @@ -923,7 +923,7 @@ arg, msgbuf, bufsize); /* Encode object */ - if (!recode_strings && PyBytes_Check(arg)) { + if (!recode_strings && PyString_Check(arg)) { s = arg; Py_INCREF(s); } @@ -946,7 +946,7 @@ if (s == NULL) return converterr("(encoding failed)", arg, msgbuf, bufsize); - if (!PyBytes_Check(s)) { + if (!PyString_Check(s)) { Py_DECREF(s); return converterr( "(encoder failed to return a string)", @@ -956,7 +956,7 @@ return converterr("string<e>", arg, msgbuf, bufsize); #endif } - size = PyBytes_GET_SIZE(s); + size = PyString_GET_SIZE(s); /* Write output; output is guaranteed to be 0-terminated */ if (*format == '#') { @@ -1013,7 +1013,7 @@ } } memcpy(*buffer, - PyBytes_AS_STRING(s), + PyString_AS_STRING(s), size + 1); STORE_SIZE(size); } else { @@ -1030,7 +1030,7 @@ PyMem_Free()ing it after usage */ - if ((Py_ssize_t)strlen(PyBytes_AS_STRING(s)) + if ((Py_ssize_t)strlen(PyString_AS_STRING(s)) != size) { Py_DECREF(s); return converterr( @@ -1049,7 +1049,7 @@ arg, msgbuf, bufsize); } memcpy(*buffer, - PyBytes_AS_STRING(s), + PyString_AS_STRING(s), size + 1); } Py_DECREF(s); @@ -1083,7 +1083,7 @@ case 'S': { /* string object */ PyObject **p = va_arg(*p_va, PyObject **); - if (PyBytes_Check(arg)) + if (PyString_Check(arg)) *p = arg; else return converterr("string", arg, msgbuf, bufsize); @@ -1473,12 +1473,12 @@ while (PyDict_Next(keywords, &pos, &key, &value)) { int match = 0; char *ks; - if (!PyBytes_Check(key)) { + if (!PyString_Check(key)) { PyErr_SetString(PyExc_TypeError, "keywords must be strings"); return cleanreturn(0, freelist); } - ks = PyBytes_AsString(key); + ks = PyString_AsString(key); for (i = 0; i < len; i++) { if (!strcmp(ks, kwlist[i])) { match = 1;
