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/binascii.c b/Modules/binascii.c
index f9df625..c1fc675 100644
--- a/Modules/binascii.c
+++ b/Modules/binascii.c
@@ -141,7 +141,7 @@
#define BASE64_PAD '='
/* Max binary chunk size; limited only by available memory */
-#define BASE64_MAXBIN (INT_MAX/2 - sizeof(PyBytesObject) - 3)
+#define BASE64_MAXBIN (INT_MAX/2 - sizeof(PyStringObject) - 3)
static unsigned char table_b2a_base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -203,9 +203,9 @@
ascii_len--;
/* Allocate the buffer */
- if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len)) == NULL )
+ if ( (rv=PyString_FromStringAndSize(NULL, bin_len)) == NULL )
return NULL;
- bin_data = (unsigned char *)PyBytes_AsString(rv);
+ bin_data = (unsigned char *)PyString_AsString(rv);
for( ; bin_len > 0 ; ascii_len--, ascii_data++ ) {
/* XXX is it really best to add NULs if there's no more data */
@@ -280,9 +280,9 @@
}
/* We're lazy and allocate to much (fixed up later) */
- if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len*2+2)) == NULL )
+ if ( (rv=PyString_FromStringAndSize(NULL, bin_len*2+2)) == NULL )
return NULL;
- ascii_data = (unsigned char *)PyBytes_AsString(rv);
+ ascii_data = (unsigned char *)PyString_AsString(rv);
/* Store the length */
*ascii_data++ = ' ' + (bin_len & 077);
@@ -304,8 +304,8 @@
}
*ascii_data++ = '\n'; /* Append a courtesy newline */
- _PyBytes_Resize(&rv, (ascii_data -
- (unsigned char *)PyBytes_AsString(rv)));
+ _PyString_Resize(&rv, (ascii_data -
+ (unsigned char *)PyString_AsString(rv)));
return rv;
}
@@ -354,9 +354,9 @@
bin_len = ((ascii_len+3)/4)*3; /* Upper bound, corrected later */
/* Allocate the buffer */
- if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len)) == NULL )
+ if ( (rv=PyString_FromStringAndSize(NULL, bin_len)) == NULL )
return NULL;
- bin_data = (unsigned char *)PyBytes_AsString(rv);
+ bin_data = (unsigned char *)PyString_AsString(rv);
bin_len = 0;
for( ; ascii_len > 0; ascii_len--, ascii_data++) {
@@ -415,13 +415,13 @@
/* And set string size correctly. If the result string is empty
** (because the input was all invalid) return the shared empty
- ** string instead; _PyBytes_Resize() won't do this for us.
+ ** string instead; _PyString_Resize() won't do this for us.
*/
if (bin_len > 0)
- _PyBytes_Resize(&rv, bin_len);
+ _PyString_Resize(&rv, bin_len);
else {
Py_DECREF(rv);
- rv = PyBytes_FromString("");
+ rv = PyString_FromString("");
}
return rv;
}
@@ -448,9 +448,9 @@
/* We're lazy and allocate too much (fixed up later).
"+3" leaves room for up to two pad characters and a trailing
newline. Note that 'b' gets encoded as 'Yg==\n' (1 in, 5 out). */
- if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len*2 + 3)) == NULL )
+ if ( (rv=PyString_FromStringAndSize(NULL, bin_len*2 + 3)) == NULL )
return NULL;
- ascii_data = (unsigned char *)PyBytes_AsString(rv);
+ ascii_data = (unsigned char *)PyString_AsString(rv);
for( ; bin_len > 0 ; bin_len--, bin_data++ ) {
/* Shift the data into our buffer */
@@ -474,8 +474,8 @@
}
*ascii_data++ = '\n'; /* Append a courtesy newline */
- _PyBytes_Resize(&rv, (ascii_data -
- (unsigned char *)PyBytes_AsString(rv)));
+ _PyString_Resize(&rv, (ascii_data -
+ (unsigned char *)PyString_AsString(rv)));
return rv;
}
@@ -498,9 +498,9 @@
/* Allocate a string that is too big (fixed later)
Add two to the initial length to prevent interning which
would preclude subsequent resizing. */
- if ( (rv=PyBytes_FromStringAndSize(NULL, len+2)) == NULL )
+ if ( (rv=PyString_FromStringAndSize(NULL, len+2)) == NULL )
return NULL;
- bin_data = (unsigned char *)PyBytes_AsString(rv);
+ bin_data = (unsigned char *)PyString_AsString(rv);
for( ; len > 0 ; len--, ascii_data++ ) {
/* Get the byte and look it up */
@@ -534,8 +534,8 @@
Py_DECREF(rv);
return NULL;
}
- _PyBytes_Resize(
- &rv, (bin_data - (unsigned char *)PyBytes_AsString(rv)));
+ _PyString_Resize(
+ &rv, (bin_data - (unsigned char *)PyString_AsString(rv)));
if (rv) {
PyObject *rrv = Py_BuildValue("Oi", rv, done);
Py_DECREF(rv);
@@ -559,9 +559,9 @@
return NULL;
/* Worst case: output is twice as big as input (fixed later) */
- if ( (rv=PyBytes_FromStringAndSize(NULL, len*2+2)) == NULL )
+ if ( (rv=PyString_FromStringAndSize(NULL, len*2+2)) == NULL )
return NULL;
- out_data = (unsigned char *)PyBytes_AsString(rv);
+ out_data = (unsigned char *)PyString_AsString(rv);
for( in=0; in<len; in++) {
ch = in_data[in];
@@ -587,8 +587,8 @@
}
}
}
- _PyBytes_Resize(&rv, (out_data -
- (unsigned char *)PyBytes_AsString(rv)));
+ _PyString_Resize(&rv, (out_data -
+ (unsigned char *)PyString_AsString(rv)));
return rv;
}
@@ -608,9 +608,9 @@
return NULL;
/* Allocate a buffer that is at least large enough */
- if ( (rv=PyBytes_FromStringAndSize(NULL, len*2+2)) == NULL )
+ if ( (rv=PyString_FromStringAndSize(NULL, len*2+2)) == NULL )
return NULL;
- ascii_data = (unsigned char *)PyBytes_AsString(rv);
+ ascii_data = (unsigned char *)PyString_AsString(rv);
for( ; len > 0 ; len--, bin_data++ ) {
/* Shift into our buffer, and output any 6bits ready */
@@ -627,8 +627,8 @@
leftchar <<= (6-leftbits);
*ascii_data++ = table_b2a_hqx[leftchar & 0x3f];
}
- _PyBytes_Resize(&rv, (ascii_data -
- (unsigned char *)PyBytes_AsString(rv)));
+ _PyString_Resize(&rv, (ascii_data -
+ (unsigned char *)PyString_AsString(rv)));
return rv;
}
@@ -647,14 +647,14 @@
/* Empty string is a special case */
if ( in_len == 0 )
- return PyBytes_FromString("");
+ return PyString_FromString("");
/* Allocate a buffer of reasonable size. Resized when needed */
out_len = in_len*2;
- if ( (rv=PyBytes_FromStringAndSize(NULL, out_len)) == NULL )
+ if ( (rv=PyString_FromStringAndSize(NULL, out_len)) == NULL )
return NULL;
out_len_left = out_len;
- out_data = (unsigned char *)PyBytes_AsString(rv);
+ out_data = (unsigned char *)PyString_AsString(rv);
/*
** We need two macros here to get/put bytes and handle
@@ -673,9 +673,9 @@
#define OUTBYTE(b) \
do { \
if ( --out_len_left < 0 ) { \
- _PyBytes_Resize(&rv, 2*out_len); \
+ _PyString_Resize(&rv, 2*out_len); \
if ( rv == NULL ) return NULL; \
- out_data = (unsigned char *)PyBytes_AsString(rv) \
+ out_data = (unsigned char *)PyString_AsString(rv) \
+ out_len; \
out_len_left = out_len-1; \
out_len = out_len * 2; \
@@ -723,8 +723,8 @@
OUTBYTE(in_byte);
}
}
- _PyBytes_Resize(&rv, (out_data -
- (unsigned char *)PyBytes_AsString(rv)));
+ _PyString_Resize(&rv, (out_data -
+ (unsigned char *)PyString_AsString(rv)));
return rv;
}
@@ -923,10 +923,10 @@
if (!PyArg_ParseTuple(args, "s#:b2a_hex", &argbuf, &arglen))
return NULL;
- retval = PyBytes_FromStringAndSize(NULL, arglen*2);
+ retval = PyString_FromStringAndSize(NULL, arglen*2);
if (!retval)
return NULL;
- retbuf = PyBytes_AsString(retval);
+ retbuf = PyString_AsString(retval);
if (!retbuf)
goto finally;
@@ -989,10 +989,10 @@
return NULL;
}
- retval = PyBytes_FromStringAndSize(NULL, (arglen/2));
+ retval = PyString_FromStringAndSize(NULL, (arglen/2));
if (!retval)
return NULL;
- retbuf = PyBytes_AsString(retval);
+ retbuf = PyString_AsString(retval);
if (!retbuf)
goto finally;
@@ -1106,7 +1106,7 @@
out++;
}
}
- if ((rv = PyBytes_FromStringAndSize((char *)odata, out)) == NULL) {
+ if ((rv = PyString_FromStringAndSize((char *)odata, out)) == NULL) {
PyMem_Free(odata);
return NULL;
}
@@ -1306,7 +1306,7 @@
}
}
}
- if ((rv = PyBytes_FromStringAndSize((char *)odata, out)) == NULL) {
+ if ((rv = PyString_FromStringAndSize((char *)odata, out)) == NULL) {
PyMem_Free(odata);
return NULL;
}
@@ -1354,7 +1354,7 @@
return;
d = PyModule_GetDict(m);
- x = PyBytes_FromString(doc_binascii);
+ x = PyString_FromString(doc_binascii);
PyDict_SetItemString(d, "__doc__", x);
Py_XDECREF(x);