Mercurial > cpython-lru_cache-weakref
diff Modules/_struct.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 | 1c964ed35ef9 |
line wrap: on
line diff
--- a/Modules/_struct.c Mon Jun 09 01:28:30 2008 +0000 +++ b/Modules/_struct.c Mon Jun 09 04:58:54 2008 +0000 @@ -413,7 +413,7 @@ if (msg == NULL) return -1; rval = PyErr_WarnEx(PyExc_DeprecationWarning, - PyBytes_AS_STRING(msg), 2); + PyString_AS_STRING(msg), 2); Py_DECREF(msg); if (rval == 0) return 0; @@ -446,7 +446,7 @@ static PyObject * nu_char(const char *p, const formatdef *f) { - return PyBytes_FromStringAndSize(p, 1); + return PyString_FromStringAndSize(p, 1); } static PyObject * @@ -610,12 +610,12 @@ static int np_char(char *p, PyObject *v, const formatdef *f) { - if (!PyBytes_Check(v) || PyBytes_Size(v) != 1) { + if (!PyString_Check(v) || PyString_Size(v) != 1) { PyErr_SetString(StructError, "char format require string of length 1"); return -1; } - *p = *PyBytes_AsString(v); + *p = *PyString_AsString(v); return 0; } @@ -1335,7 +1335,7 @@ char c; Py_ssize_t size, len, num, itemsize, x; - fmt = PyBytes_AS_STRING(self->s_format); + fmt = PyString_AS_STRING(self->s_format); f = whichtable((char **)&fmt); @@ -1503,12 +1503,12 @@ const formatdef *e = code->fmtdef; const char *res = startfrom + code->offset; if (e->format == 's') { - v = PyBytes_FromStringAndSize(res, code->size); + v = PyString_FromStringAndSize(res, code->size); } else if (e->format == 'p') { Py_ssize_t n = *(unsigned char*)res; if (n >= code->size) n = code->size - 1; - v = PyBytes_FromStringAndSize(res + 1, n); + v = PyString_FromStringAndSize(res + 1, n); } else { v = e->unpack(res, e); } @@ -1542,9 +1542,9 @@ assert(soself->s_codes != NULL); if (inputstr == NULL) goto fail; - if (PyBytes_Check(inputstr) && - PyBytes_GET_SIZE(inputstr) == soself->s_size) { - return s_unpack_internal(soself, PyBytes_AS_STRING(inputstr)); + if (PyString_Check(inputstr) && + PyString_GET_SIZE(inputstr) == soself->s_size) { + return s_unpack_internal(soself, PyString_AS_STRING(inputstr)); } args = PyTuple_Pack(1, inputstr); if (args == NULL) @@ -1637,27 +1637,27 @@ const formatdef *e = code->fmtdef; char *res = buf + code->offset; if (e->format == 's') { - if (!PyBytes_Check(v)) { + if (!PyString_Check(v)) { PyErr_SetString(StructError, "argument for 's' must be a string"); return -1; } - n = PyBytes_GET_SIZE(v); + n = PyString_GET_SIZE(v); if (n > code->size) n = code->size; if (n > 0) - memcpy(res, PyBytes_AS_STRING(v), n); + memcpy(res, PyString_AS_STRING(v), n); } else if (e->format == 'p') { - if (!PyBytes_Check(v)) { + if (!PyString_Check(v)) { PyErr_SetString(StructError, "argument for 'p' must be a string"); return -1; } - n = PyBytes_GET_SIZE(v); + n = PyString_GET_SIZE(v); if (n > (code->size - 1)) n = code->size - 1; if (n > 0) - memcpy(res + 1, PyBytes_AS_STRING(v), n); + memcpy(res + 1, PyString_AS_STRING(v), n); if (n > 255) n = 255; *res = Py_SAFE_DOWNCAST(n, Py_ssize_t, unsigned char); @@ -1700,12 +1700,12 @@ } /* Allocate a new string */ - result = PyBytes_FromStringAndSize((char *)NULL, soself->s_size); + result = PyString_FromStringAndSize((char *)NULL, soself->s_size); if (result == NULL) return NULL; /* Call the guts */ - if ( s_pack_internal(soself, args, 0, PyBytes_AS_STRING(result)) != 0 ) { + if ( s_pack_internal(soself, args, 0, PyString_AS_STRING(result)) != 0 ) { Py_DECREF(result); return NULL; } @@ -2061,7 +2061,7 @@ { PyObject *ver, *m; - ver = PyBytes_FromString("0.2"); + ver = PyString_FromString("0.2"); if (ver == NULL) return;
