mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
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.
This commit is contained in:
parent
e98839a1f4
commit
dd96db63f6
173 changed files with 2275 additions and 2280 deletions
|
|
@ -64,18 +64,18 @@ w_more(int c, WFILE *p)
|
|||
Py_ssize_t size, newsize;
|
||||
if (p->str == NULL)
|
||||
return; /* An error already occurred */
|
||||
size = PyBytes_Size(p->str);
|
||||
size = PyString_Size(p->str);
|
||||
newsize = size + size + 1024;
|
||||
if (newsize > 32*1024*1024) {
|
||||
newsize = size + 1024*1024;
|
||||
}
|
||||
if (_PyBytes_Resize(&p->str, newsize) != 0) {
|
||||
if (_PyString_Resize(&p->str, newsize) != 0) {
|
||||
p->ptr = p->end = NULL;
|
||||
}
|
||||
else {
|
||||
p->ptr = PyBytes_AS_STRING((PyBytesObject *)p->str) + size;
|
||||
p->ptr = PyString_AS_STRING((PyStringObject *)p->str) + size;
|
||||
p->end =
|
||||
PyBytes_AS_STRING((PyBytesObject *)p->str) + newsize;
|
||||
PyString_AS_STRING((PyStringObject *)p->str) + newsize;
|
||||
*p->ptr++ = Py_SAFE_DOWNCAST(c, int, char);
|
||||
}
|
||||
}
|
||||
|
|
@ -239,8 +239,8 @@ w_object(PyObject *v, WFILE *p)
|
|||
}
|
||||
}
|
||||
#endif
|
||||
else if (PyBytes_CheckExact(v)) {
|
||||
if (p->strings && PyBytes_CHECK_INTERNED(v)) {
|
||||
else if (PyString_CheckExact(v)) {
|
||||
if (p->strings && PyString_CHECK_INTERNED(v)) {
|
||||
PyObject *o = PyDict_GetItem(p->strings, v);
|
||||
if (o) {
|
||||
long w = PyInt_AsLong(o);
|
||||
|
|
@ -265,7 +265,7 @@ w_object(PyObject *v, WFILE *p)
|
|||
else {
|
||||
w_byte(TYPE_STRING, p);
|
||||
}
|
||||
n = PyBytes_GET_SIZE(v);
|
||||
n = PyString_GET_SIZE(v);
|
||||
if (n > INT_MAX) {
|
||||
/* huge strings are not supported */
|
||||
p->depth--;
|
||||
|
|
@ -273,7 +273,7 @@ w_object(PyObject *v, WFILE *p)
|
|||
return;
|
||||
}
|
||||
w_long((long)n, p);
|
||||
w_string(PyBytes_AS_STRING(v), (int)n, p);
|
||||
w_string(PyString_AS_STRING(v), (int)n, p);
|
||||
}
|
||||
#ifdef Py_USING_UNICODE
|
||||
else if (PyUnicode_CheckExact(v)) {
|
||||
|
|
@ -285,14 +285,14 @@ w_object(PyObject *v, WFILE *p)
|
|||
return;
|
||||
}
|
||||
w_byte(TYPE_UNICODE, p);
|
||||
n = PyBytes_GET_SIZE(utf8);
|
||||
n = PyString_GET_SIZE(utf8);
|
||||
if (n > INT_MAX) {
|
||||
p->depth--;
|
||||
p->error = 1;
|
||||
return;
|
||||
}
|
||||
w_long((long)n, p);
|
||||
w_string(PyBytes_AS_STRING(utf8), (int)n, p);
|
||||
w_string(PyString_AS_STRING(utf8), (int)n, p);
|
||||
Py_DECREF(utf8);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -713,12 +713,12 @@ r_object(RFILE *p)
|
|||
retval = NULL;
|
||||
break;
|
||||
}
|
||||
v = PyBytes_FromStringAndSize((char *)NULL, n);
|
||||
v = PyString_FromStringAndSize((char *)NULL, n);
|
||||
if (v == NULL) {
|
||||
retval = NULL;
|
||||
break;
|
||||
}
|
||||
if (r_string(PyBytes_AS_STRING(v), (int)n, p) != n) {
|
||||
if (r_string(PyString_AS_STRING(v), (int)n, p) != n) {
|
||||
Py_DECREF(v);
|
||||
PyErr_SetString(PyExc_EOFError,
|
||||
"EOF read where object expected");
|
||||
|
|
@ -726,7 +726,7 @@ r_object(RFILE *p)
|
|||
break;
|
||||
}
|
||||
if (type == TYPE_INTERNED) {
|
||||
PyBytes_InternInPlace(&v);
|
||||
PyString_InternInPlace(&v);
|
||||
if (PyList_Append(p->strings, v) < 0) {
|
||||
retval = NULL;
|
||||
break;
|
||||
|
|
@ -1113,11 +1113,11 @@ PyMarshal_WriteObjectToString(PyObject *x, int version)
|
|||
{
|
||||
WFILE wf;
|
||||
wf.fp = NULL;
|
||||
wf.str = PyBytes_FromStringAndSize((char *)NULL, 50);
|
||||
wf.str = PyString_FromStringAndSize((char *)NULL, 50);
|
||||
if (wf.str == NULL)
|
||||
return NULL;
|
||||
wf.ptr = PyBytes_AS_STRING((PyBytesObject *)wf.str);
|
||||
wf.end = wf.ptr + PyBytes_Size(wf.str);
|
||||
wf.ptr = PyString_AS_STRING((PyStringObject *)wf.str);
|
||||
wf.end = wf.ptr + PyString_Size(wf.str);
|
||||
wf.error = 0;
|
||||
wf.depth = 0;
|
||||
wf.version = version;
|
||||
|
|
@ -1125,14 +1125,14 @@ PyMarshal_WriteObjectToString(PyObject *x, int version)
|
|||
w_object(x, &wf);
|
||||
Py_XDECREF(wf.strings);
|
||||
if (wf.str != NULL) {
|
||||
char *base = PyBytes_AS_STRING((PyBytesObject *)wf.str);
|
||||
char *base = PyString_AS_STRING((PyStringObject *)wf.str);
|
||||
if (wf.ptr - base > PY_SSIZE_T_MAX) {
|
||||
Py_DECREF(wf.str);
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
"too much marshall data for a string");
|
||||
return NULL;
|
||||
}
|
||||
_PyBytes_Resize(&wf.str, (Py_ssize_t)(wf.ptr - base));
|
||||
_PyString_Resize(&wf.str, (Py_ssize_t)(wf.ptr - base));
|
||||
}
|
||||
if (wf.error) {
|
||||
Py_XDECREF(wf.str);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue