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.
diff --git a/Modules/cPickle.c b/Modules/cPickle.c
index 4413272..f130087 100644
--- a/Modules/cPickle.c
+++ b/Modules/cPickle.c
@@ -393,13 +393,13 @@
if (format) args = Py_VaBuildValue(format, va);
va_end(va);
if (format && ! args) return NULL;
- if (stringformat && !(retval=PyBytes_FromString(stringformat)))
+ if (stringformat && !(retval=PyString_FromString(stringformat)))
return NULL;
if (retval) {
if (args) {
PyObject *v;
- v=PyBytes_Format(retval, args);
+ v=PyString_Format(retval, args);
Py_DECREF(retval);
Py_DECREF(args);
if (! v) return NULL;
@@ -477,7 +477,7 @@
n = (int)_n;
if (s == NULL) {
if (!( self->buf_size )) return 0;
- py_str = PyBytes_FromStringAndSize(self->write_buf,
+ py_str = PyString_FromStringAndSize(self->write_buf,
self->buf_size);
if (!py_str)
return -1;
@@ -490,7 +490,7 @@
if (n > WRITE_BUF_SIZE) {
if (!( py_str =
- PyBytes_FromStringAndSize(s, n)))
+ PyString_FromStringAndSize(s, n)))
return -1;
}
else {
@@ -655,7 +655,7 @@
Py_XDECREF(self->last_string);
self->last_string = str;
- if (! (*s = PyBytes_AsString(str))) return -1;
+ if (! (*s = PyString_AsString(str))) return -1;
return n;
}
@@ -670,13 +670,13 @@
return -1;
}
- if ((str_size = PyBytes_Size(str)) < 0)
+ if ((str_size = PyString_Size(str)) < 0)
return -1;
Py_XDECREF(self->last_string);
self->last_string = str;
- if (! (*s = PyBytes_AsString(str)))
+ if (! (*s = PyString_AsString(str)))
return -1;
return str_size;
@@ -1078,9 +1078,9 @@
"to pickle");
goto finally;
}
- repr = PyBytes_FromStringAndSize(NULL, (int)nbytes);
+ repr = PyString_FromStringAndSize(NULL, (int)nbytes);
if (repr == NULL) goto finally;
- pdata = (unsigned char *)PyBytes_AS_STRING(repr);
+ pdata = (unsigned char *)PyString_AS_STRING(repr);
i = _PyLong_AsByteArray((PyLongObject *)args,
pdata, nbytes,
1 /* little endian */, 1 /* signed */);
@@ -1121,14 +1121,14 @@
if (!( repr = PyObject_Repr(args)))
goto finally;
- if ((size = PyBytes_Size(repr)) < 0)
+ if ((size = PyString_Size(repr)) < 0)
goto finally;
if (self->write_func(self, &l, 1) < 0)
goto finally;
if (self->write_func(self,
- PyBytes_AS_STRING((PyBytesObject *)repr),
+ PyString_AS_STRING((PyStringObject *)repr),
size) < 0)
goto finally;
@@ -1177,7 +1177,7 @@
int size, len;
PyObject *repr=0;
- if ((size = PyBytes_Size(args)) < 0)
+ if ((size = PyString_Size(args)) < 0)
return -1;
if (!self->bin) {
@@ -1188,9 +1188,9 @@
if (!( repr = PyObject_Repr(args)))
return -1;
- if ((len = PyBytes_Size(repr)) < 0)
+ if ((len = PyString_Size(repr)) < 0)
goto err;
- repr_str = PyBytes_AS_STRING((PyBytesObject *)repr);
+ repr_str = PyString_AS_STRING((PyStringObject *)repr);
if (self->write_func(self, &string, 1) < 0)
goto err;
@@ -1207,7 +1207,7 @@
int i;
char c_str[5];
- if ((size = PyBytes_Size(args)) < 0)
+ if ((size = PyString_Size(args)) < 0)
return -1;
if (size < 256) {
@@ -1233,8 +1233,8 @@
}
else {
if (self->write_func(self,
- PyBytes_AS_STRING(
- (PyBytesObject *)args),
+ PyString_AS_STRING(
+ (PyStringObject *)args),
size) < 0)
return -1;
}
@@ -1264,13 +1264,13 @@
static const char *hexdigit = "0123456789ABCDEF";
- repr = PyBytes_FromStringAndSize(NULL, 6 * size);
+ repr = PyString_FromStringAndSize(NULL, 6 * size);
if (repr == NULL)
return NULL;
if (size == 0)
return repr;
- p = q = PyBytes_AS_STRING(repr);
+ p = q = PyString_AS_STRING(repr);
while (size-- > 0) {
Py_UNICODE ch = *s++;
/* Map 16-bit characters to '\uxxxx' */
@@ -1287,7 +1287,7 @@
*p++ = (char) ch;
}
*p = '\0';
- _PyBytes_Resize(&repr, p - q);
+ _PyString_Resize(&repr, p - q);
return repr;
}
@@ -1310,9 +1310,9 @@
if (!repr)
return -1;
- if ((len = PyBytes_Size(repr)) < 0)
+ if ((len = PyString_Size(repr)) < 0)
goto err;
- repr_str = PyBytes_AS_STRING((PyBytesObject *)repr);
+ repr_str = PyString_AS_STRING((PyStringObject *)repr);
if (self->write_func(self, &string, 1) < 0)
goto err;
@@ -1332,7 +1332,7 @@
if (!( repr = PyUnicode_AsUTF8String(args)))
return -1;
- if ((size = PyBytes_Size(repr)) < 0)
+ if ((size = PyString_Size(repr)) < 0)
goto err;
if (size > INT_MAX)
return -1; /* string too large */
@@ -1351,7 +1351,7 @@
PDATA_APPEND(self->file, repr, -1);
}
else {
- if (self->write_func(self, PyBytes_AS_STRING(repr),
+ if (self->write_func(self, PyString_AS_STRING(repr),
size) < 0)
goto err;
}
@@ -1861,12 +1861,12 @@
goto finally;
- if ((module_size = PyBytes_Size(module)) < 0 ||
- (name_size = PyBytes_Size(name)) < 0)
+ if ((module_size = PyString_Size(module)) < 0 ||
+ (name_size = PyString_Size(name)) < 0)
goto finally;
- module_str = PyBytes_AS_STRING((PyBytesObject *)module);
- name_str = PyBytes_AS_STRING((PyBytesObject *)name);
+ module_str = PyString_AS_STRING((PyStringObject *)module);
+ name_str = PyString_AS_STRING((PyStringObject *)name);
if (self->write_func(self, &inst, 1) < 0)
goto finally;
@@ -1961,12 +1961,12 @@
if (!( module = whichmodule(args, global_name)))
goto finally;
- if ((module_size = PyBytes_Size(module)) < 0 ||
- (name_size = PyBytes_Size(global_name)) < 0)
+ if ((module_size = PyString_Size(module)) < 0 ||
+ (name_size = PyString_Size(global_name)) < 0)
goto finally;
- module_str = PyBytes_AS_STRING((PyBytesObject *)module);
- name_str = PyBytes_AS_STRING((PyBytesObject *)global_name);
+ module_str = PyString_AS_STRING((PyStringObject *)module);
+ name_str = PyString_AS_STRING((PyStringObject *)global_name);
/* XXX This can be doing a relative import. Clearly it shouldn't,
but I don't know how to stop it. :-( */
@@ -2099,7 +2099,7 @@
if (pid != Py_None) {
if (!self->bin) {
- if (!PyBytes_Check(pid)) {
+ if (!PyString_Check(pid)) {
PyErr_SetString(PicklingError,
"persistent id must be string");
goto finally;
@@ -2108,12 +2108,12 @@
if (self->write_func(self, &persid, 1) < 0)
goto finally;
- if ((size = PyBytes_Size(pid)) < 0)
+ if ((size = PyString_Size(pid)) < 0)
goto finally;
if (self->write_func(self,
- PyBytes_AS_STRING(
- (PyBytesObject *)pid),
+ PyString_AS_STRING(
+ (PyStringObject *)pid),
size) < 0)
goto finally;
@@ -2194,8 +2194,8 @@
use_newobj = 0;
}
else {
- use_newobj = PyBytes_Check(temp) &&
- strcmp(PyBytes_AS_STRING(temp),
+ use_newobj = PyString_Check(temp) &&
+ strcmp(PyString_AS_STRING(temp),
"__newobj__") == 0;
Py_DECREF(temp);
}
@@ -2362,14 +2362,14 @@
break;
case 's':
- if ((type == &PyBytes_Type) && (PyBytes_GET_SIZE(args) < 2)) {
+ if ((type == &PyString_Type) && (PyString_GET_SIZE(args) < 2)) {
res = save_string(self, args, 0);
goto finally;
}
#ifdef Py_USING_UNICODE
case 'u':
- if ((type == &PyUnicode_Type) && (PyBytes_GET_SIZE(args) < 2)) {
+ if ((type == &PyUnicode_Type) && (PyString_GET_SIZE(args) < 2)) {
res = save_unicode(self, args, 0);
goto finally;
}
@@ -2391,7 +2391,7 @@
switch (type->tp_name[0]) {
case 's':
- if (type == &PyBytes_Type) {
+ if (type == &PyString_Type) {
res = save_string(self, args, 1);
goto finally;
}
@@ -2526,7 +2526,7 @@
if (t == NULL)
goto finally;
- if (PyBytes_Check(t)) {
+ if (PyString_Check(t)) {
res = save_global(self, args, t);
goto finally;
}
@@ -2640,8 +2640,8 @@
for (rsize = 0, i = l; --i >= 0; ) {
k = data->data[i];
- if (PyBytes_Check(k))
- rsize += PyBytes_GET_SIZE(k);
+ if (PyString_Check(k))
+ rsize += PyString_GET_SIZE(k);
else if (PyInt_Check(k)) { /* put */
ik = PyInt_AS_LONG((PyIntObject*)k);
@@ -2676,17 +2676,17 @@
}
/* Now generate the result */
- r = PyBytes_FromStringAndSize(NULL, rsize);
+ r = PyString_FromStringAndSize(NULL, rsize);
if (r == NULL) goto err;
- s = PyBytes_AS_STRING((PyBytesObject *)r);
+ s = PyString_AS_STRING((PyStringObject *)r);
for (i = 0; i < l; i++) {
k = data->data[i];
- if (PyBytes_Check(k)) {
- ssize = PyBytes_GET_SIZE(k);
+ if (PyString_Check(k)) {
+ ssize = PyString_GET_SIZE(k);
if (ssize) {
- p=PyBytes_AS_STRING((PyBytesObject *)k);
+ p=PyString_AS_STRING((PyStringObject *)k);
while (--ssize >= 0)
*s++ = *p++;
}
@@ -3410,7 +3410,7 @@
goto insecure;
/********************************************/
- str = PyBytes_DecodeEscape(p, len, NULL, 0, NULL);
+ str = PyString_DecodeEscape(p, len, NULL, 0, NULL);
free(s);
if (str) {
PDATA_PUSH(self->stack, str, -1);
@@ -3439,7 +3439,7 @@
if (self->read_func(self, &s, l) < 0)
return -1;
- if (!( py_string = PyBytes_FromStringAndSize(s, l)))
+ if (!( py_string = PyString_FromStringAndSize(s, l)))
return -1;
PDATA_PUSH(self->stack, py_string, -1);
@@ -3461,7 +3461,7 @@
if (self->read_func(self, &s, l) < 0) return -1;
- if (!( py_string = PyBytes_FromStringAndSize(s, l))) return -1;
+ if (!( py_string = PyString_FromStringAndSize(s, l))) return -1;
PDATA_PUSH(self->stack, py_string, -1);
return 0;
@@ -3688,12 +3688,12 @@
if ((len = self->readline_func(self, &s)) < 0) return -1;
if (len < 2) return bad_readline();
- module_name = PyBytes_FromStringAndSize(s, len - 1);
+ module_name = PyString_FromStringAndSize(s, len - 1);
if (!module_name) return -1;
if ((len = self->readline_func(self, &s)) >= 0) {
if (len < 2) return bad_readline();
- if ((class_name = PyBytes_FromStringAndSize(s, len - 1))) {
+ if ((class_name = PyString_FromStringAndSize(s, len - 1))) {
class = find_class(module_name, class_name,
self->find_class);
Py_DECREF(class_name);
@@ -3772,7 +3772,7 @@
if ((len = self->readline_func(self, &s)) < 0) return -1;
if (len < 2) return bad_readline();
- module_name = PyBytes_FromStringAndSize(s, len - 1);
+ module_name = PyString_FromStringAndSize(s, len - 1);
if (!module_name) return -1;
if ((len = self->readline_func(self, &s)) >= 0) {
@@ -3780,7 +3780,7 @@
Py_DECREF(module_name);
return bad_readline();
}
- if ((class_name = PyBytes_FromStringAndSize(s, len - 1))) {
+ if ((class_name = PyString_FromStringAndSize(s, len - 1))) {
class = find_class(module_name, class_name,
self->find_class);
Py_DECREF(class_name);
@@ -3805,7 +3805,7 @@
if ((len = self->readline_func(self, &s)) < 0) return -1;
if (len < 2) return bad_readline();
- pid = PyBytes_FromStringAndSize(s, len - 1);
+ pid = PyString_FromStringAndSize(s, len - 1);
if (!pid) return -1;
if (PyList_Check(self->pers_func)) {
@@ -3938,7 +3938,7 @@
if ((len = self->readline_func(self, &s)) < 0) return -1;
if (len < 2) return bad_readline();
- if (!( py_str = PyBytes_FromStringAndSize(s, len - 1))) return -1;
+ if (!( py_str = PyString_FromStringAndSize(s, len - 1))) return -1;
value = PyDict_GetItem(self->memo, py_str);
if (! value) {
@@ -4064,8 +4064,8 @@
* confirm that pair is really a 2-tuple of strings.
*/
if (!PyTuple_Check(pair) || PyTuple_Size(pair) != 2 ||
- !PyBytes_Check(module_name = PyTuple_GET_ITEM(pair, 0)) ||
- !PyBytes_Check(class_name = PyTuple_GET_ITEM(pair, 1))) {
+ !PyString_Check(module_name = PyTuple_GET_ITEM(pair, 0)) ||
+ !PyString_Check(class_name = PyTuple_GET_ITEM(pair, 1))) {
Py_DECREF(py_code);
PyErr_Format(PyExc_ValueError, "_inverted_registry[%ld] "
"isn't a 2-tuple of strings", code);
@@ -4098,7 +4098,7 @@
if ((l = self->readline_func(self, &s)) < 0) return -1;
if (l < 2) return bad_readline();
if (!( len=self->stack->length )) return stackUnderflow();
- if (!( py_str = PyBytes_FromStringAndSize(s, l - 1))) return -1;
+ if (!( py_str = PyString_FromStringAndSize(s, l - 1))) return -1;
value=self->stack->data[len-1];
l=PyDict_SetItem(self->memo, py_str, value);
Py_DECREF(py_str);
@@ -5568,7 +5568,7 @@
{
PyObject *copyreg, *t, *r;
-#define INIT_STR(S) if (!( S ## _str=PyBytes_InternFromString(#S))) return -1;
+#define INIT_STR(S) if (!( S ## _str=PyString_InternFromString(#S))) return -1;
if (PyType_Ready(&Unpicklertype) < 0)
return -1;
@@ -5736,7 +5736,7 @@
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
- v = PyBytes_FromString(rev);
+ v = PyString_FromString(rev);
PyDict_SetItemString(d, "__version__", v);
Py_XDECREF(v);
@@ -5755,7 +5755,7 @@
/* These are purely informational; no code uses them. */
/* File format version we write. */
- format_version = PyBytes_FromString("2.0");
+ format_version = PyString_FromString("2.0");
/* Format versions we can read. */
compatible_formats = Py_BuildValue("[sssss]",
"1.0", /* Original protocol 0 */