summaryrefslogtreecommitdiffstats
path: root/Modules/binascii.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-11-06 21:34:58 (GMT)
committerGuido van Rossum <guido@python.org>2007-11-06 21:34:58 (GMT)
commit98297ee7815939b124156e438b22bd652d67b5db (patch)
treea9d239ebd87c73af2571ab48003984c4e18e27e5 /Modules/binascii.c
parenta19f80c6df2df5e8a5d0cff37131097835ef971e (diff)
downloadcpython-98297ee7815939b124156e438b22bd652d67b5db.zip
cpython-98297ee7815939b124156e438b22bd652d67b5db.tar.gz
cpython-98297ee7815939b124156e438b22bd652d67b5db.tar.bz2
Merging the py3k-pep3137 branch back into the py3k branch.
No detailed change log; just check out the change log for the py3k-pep3137 branch. The most obvious changes: - str8 renamed to bytes (PyString at the C level); - bytes renamed to buffer (PyBytes at the C level); - PyString and PyUnicode are no longer compatible. I.e. we now have an immutable bytes type and a mutable bytes type. The behavior of PyString was modified quite a bit, to make it more bytes-like. Some changes are still on the to-do list.
Diffstat (limited to 'Modules/binascii.c')
-rw-r--r--Modules/binascii.c80
1 files changed, 40 insertions, 40 deletions
diff --git a/Modules/binascii.c b/Modules/binascii.c
index 3b55a35..62fc8c2 100644
--- a/Modules/binascii.c
+++ b/Modules/binascii.c
@@ -200,9 +200,9 @@ binascii_a2b_uu(PyObject *self, PyObject *args)
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_AS_STRING(rv);
+ bin_data = (unsigned char *)PyString_AS_STRING(rv);
for( ; bin_len > 0 ; ascii_len--, ascii_data++ ) {
/* XXX is it really best to add NULs if there's no more data */
@@ -277,9 +277,9 @@ binascii_b2a_uu(PyObject *self, PyObject *args)
}
/* 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_AS_STRING(rv);
+ ascii_data = (unsigned char *)PyString_AS_STRING(rv);
/* Store the length */
*ascii_data++ = ' ' + (bin_len & 077);
@@ -301,9 +301,9 @@ binascii_b2a_uu(PyObject *self, PyObject *args)
}
*ascii_data++ = '\n'; /* Append a courtesy newline */
- if (PyBytes_Resize(rv,
+ if (_PyString_Resize(&rv,
(ascii_data -
- (unsigned char *)PyBytes_AS_STRING(rv))) < 0) {
+ (unsigned char *)PyString_AS_STRING(rv))) < 0) {
Py_DECREF(rv);
rv = NULL;
}
@@ -355,9 +355,9 @@ binascii_a2b_base64(PyObject *self, PyObject *args)
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_AS_STRING(rv);
+ bin_data = (unsigned char *)PyString_AS_STRING(rv);
bin_len = 0;
for( ; ascii_len > 0; ascii_len--, ascii_data++) {
@@ -416,17 +416,17 @@ binascii_a2b_base64(PyObject *self, PyObject *args)
/* 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) {
- if (PyBytes_Resize(rv, bin_len) < 0) {
+ if (_PyString_Resize(&rv, bin_len) < 0) {
Py_DECREF(rv);
rv = NULL;
}
}
else {
Py_DECREF(rv);
- rv = PyBytes_FromStringAndSize("", 0);
+ rv = PyString_FromStringAndSize("", 0);
}
return rv;
}
@@ -453,9 +453,9 @@ binascii_b2a_base64(PyObject *self, PyObject *args)
/* 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_AS_STRING(rv);
+ ascii_data = (unsigned char *)PyString_AS_STRING(rv);
for( ; bin_len > 0 ; bin_len--, bin_data++ ) {
/* Shift the data into our buffer */
@@ -479,9 +479,9 @@ binascii_b2a_base64(PyObject *self, PyObject *args)
}
*ascii_data++ = '\n'; /* Append a courtesy newline */
- if (PyBytes_Resize(rv,
+ if (_PyString_Resize(&rv,
(ascii_data -
- (unsigned char *)PyBytes_AS_STRING(rv))) < 0) {
+ (unsigned char *)PyString_AS_STRING(rv))) < 0) {
Py_DECREF(rv);
rv = NULL;
}
@@ -507,9 +507,9 @@ binascii_a2b_hqx(PyObject *self, PyObject *args)
/* 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_AS_STRING(rv);
+ bin_data = (unsigned char *)PyString_AS_STRING(rv);
for( ; len > 0 ; len--, ascii_data++ ) {
/* Get the byte and look it up */
@@ -543,9 +543,9 @@ binascii_a2b_hqx(PyObject *self, PyObject *args)
Py_DECREF(rv);
return NULL;
}
- if (PyBytes_Resize(rv,
+ if (_PyString_Resize(&rv,
(bin_data -
- (unsigned char *)PyBytes_AS_STRING(rv))) < 0) {
+ (unsigned char *)PyString_AS_STRING(rv))) < 0) {
Py_DECREF(rv);
rv = NULL;
}
@@ -572,9 +572,9 @@ binascii_rlecode_hqx(PyObject *self, PyObject *args)
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_AS_STRING(rv);
+ out_data = (unsigned char *)PyString_AS_STRING(rv);
for( in=0; in<len; in++) {
ch = in_data[in];
@@ -600,9 +600,9 @@ binascii_rlecode_hqx(PyObject *self, PyObject *args)
}
}
}
- if (PyBytes_Resize(rv,
+ if (_PyString_Resize(&rv,
(out_data -
- (unsigned char *)PyBytes_AS_STRING(rv))) < 0) {
+ (unsigned char *)PyString_AS_STRING(rv))) < 0) {
Py_DECREF(rv);
rv = NULL;
}
@@ -625,9 +625,9 @@ binascii_b2a_hqx(PyObject *self, PyObject *args)
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_AS_STRING(rv);
+ ascii_data = (unsigned char *)PyString_AS_STRING(rv);
for( ; len > 0 ; len--, bin_data++ ) {
/* Shift into our buffer, and output any 6bits ready */
@@ -644,9 +644,9 @@ binascii_b2a_hqx(PyObject *self, PyObject *args)
leftchar <<= (6-leftbits);
*ascii_data++ = table_b2a_hqx[leftchar & 0x3f];
}
- if (PyBytes_Resize(rv,
+ if (_PyString_Resize(&rv,
(ascii_data -
- (unsigned char *)PyBytes_AS_STRING(rv))) < 0) {
+ (unsigned char *)PyString_AS_STRING(rv))) < 0) {
Py_DECREF(rv);
rv = NULL;
}
@@ -668,14 +668,14 @@ binascii_rledecode_hqx(PyObject *self, PyObject *args)
/* Empty string is a special case */
if ( in_len == 0 )
- return PyBytes_FromStringAndSize("", 0);
+ return PyString_FromStringAndSize("", 0);
/* 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_AS_STRING(rv);
+ out_data = (unsigned char *)PyString_AS_STRING(rv);
/*
** We need two macros here to get/put bytes and handle
@@ -694,9 +694,9 @@ binascii_rledecode_hqx(PyObject *self, PyObject *args)
#define OUTBYTE(b) \
do { \
if ( --out_len_left < 0 ) { \
- if (PyBytes_Resize(rv, 2*out_len) < 0) \
+ if (_PyString_Resize(&rv, 2*out_len) < 0) \
{ Py_DECREF(rv); return NULL; } \
- out_data = (unsigned char *)PyBytes_AS_STRING(rv) \
+ out_data = (unsigned char *)PyString_AS_STRING(rv) \
+ out_len; \
out_len_left = out_len-1; \
out_len = out_len * 2; \
@@ -744,9 +744,9 @@ binascii_rledecode_hqx(PyObject *self, PyObject *args)
OUTBYTE(in_byte);
}
}
- if (PyBytes_Resize(rv,
+ if (_PyString_Resize(&rv,
(out_data -
- (unsigned char *)PyBytes_AS_STRING(rv))) < 0) {
+ (unsigned char *)PyString_AS_STRING(rv))) < 0) {
Py_DECREF(rv);
rv = NULL;
}
@@ -940,10 +940,10 @@ binascii_hexlify(PyObject *self, PyObject *args)
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_AS_STRING(retval);
+ retbuf = PyString_AS_STRING(retval);
/* make hex version of string, taken from shamodule.c */
for (i=j=0; i < arglen; i++) {
@@ -1000,10 +1000,10 @@ binascii_unhexlify(PyObject *self, PyObject *args)
return NULL;
}
- retval = PyBytes_FromStringAndSize(NULL, (arglen/2));
+ retval = PyString_FromStringAndSize(NULL, (arglen/2));
if (!retval)
return NULL;
- retbuf = PyBytes_AS_STRING(retval);
+ retbuf = PyString_AS_STRING(retval);
for (i=j=0; i < arglen; i += 2) {
int top = to_int(Py_CHARMASK(argbuf[i]));
@@ -1115,7 +1115,7 @@ binascii_a2b_qp(PyObject *self, PyObject *args, PyObject *kwargs)
out++;
}
}
- if ((rv = PyBytes_FromStringAndSize((char *)odata, out)) == NULL) {
+ if ((rv = PyString_FromStringAndSize((char *)odata, out)) == NULL) {
PyMem_Free(odata);
return NULL;
}
@@ -1315,7 +1315,7 @@ binascii_b2a_qp (PyObject *self, PyObject *args, PyObject *kwargs)
}
}
}
- if ((rv = PyBytes_FromStringAndSize((char *)odata, out)) == NULL) {
+ if ((rv = PyString_FromStringAndSize((char *)odata, out)) == NULL) {
PyMem_Free(odata);
return NULL;
}