summaryrefslogtreecommitdiffstats
path: root/Modules/binascii.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/binascii.c')
-rw-r--r--Modules/binascii.c84
1 files changed, 42 insertions, 42 deletions
diff --git a/Modules/binascii.c b/Modules/binascii.c
index c1fc675..f9df625 100644
--- a/Modules/binascii.c
+++ b/Modules/binascii.c
@@ -141,7 +141,7 @@ static char table_a2b_base64[] = {
#define BASE64_PAD '='
/* Max binary chunk size; limited only by available memory */
-#define BASE64_MAXBIN (INT_MAX/2 - sizeof(PyStringObject) - 3)
+#define BASE64_MAXBIN (INT_MAX/2 - sizeof(PyBytesObject) - 3)
static unsigned char table_b2a_base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -203,9 +203,9 @@ binascii_a2b_uu(PyObject *self, PyObject *args)
ascii_len--;
/* Allocate the buffer */
- if ( (rv=PyString_FromStringAndSize(NULL, bin_len)) == NULL )
+ if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len)) == NULL )
return NULL;
- bin_data = (unsigned char *)PyString_AsString(rv);
+ bin_data = (unsigned char *)PyBytes_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 @@ binascii_b2a_uu(PyObject *self, PyObject *args)
}
/* We're lazy and allocate to much (fixed up later) */
- if ( (rv=PyString_FromStringAndSize(NULL, bin_len*2+2)) == NULL )
+ if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len*2+2)) == NULL )
return NULL;
- ascii_data = (unsigned char *)PyString_AsString(rv);
+ ascii_data = (unsigned char *)PyBytes_AsString(rv);
/* Store the length */
*ascii_data++ = ' ' + (bin_len & 077);
@@ -304,8 +304,8 @@ binascii_b2a_uu(PyObject *self, PyObject *args)
}
*ascii_data++ = '\n'; /* Append a courtesy newline */
- _PyString_Resize(&rv, (ascii_data -
- (unsigned char *)PyString_AsString(rv)));
+ _PyBytes_Resize(&rv, (ascii_data -
+ (unsigned char *)PyBytes_AsString(rv)));
return rv;
}
@@ -354,9 +354,9 @@ binascii_a2b_base64(PyObject *self, PyObject *args)
bin_len = ((ascii_len+3)/4)*3; /* Upper bound, corrected later */
/* Allocate the buffer */
- if ( (rv=PyString_FromStringAndSize(NULL, bin_len)) == NULL )
+ if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len)) == NULL )
return NULL;
- bin_data = (unsigned char *)PyString_AsString(rv);
+ bin_data = (unsigned char *)PyBytes_AsString(rv);
bin_len = 0;
for( ; ascii_len > 0; ascii_len--, ascii_data++) {
@@ -415,13 +415,13 @@ 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; _PyString_Resize() won't do this for us.
+ ** string instead; _PyBytes_Resize() won't do this for us.
*/
if (bin_len > 0)
- _PyString_Resize(&rv, bin_len);
+ _PyBytes_Resize(&rv, bin_len);
else {
Py_DECREF(rv);
- rv = PyString_FromString("");
+ rv = PyBytes_FromString("");
}
return rv;
}
@@ -448,9 +448,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=PyString_FromStringAndSize(NULL, bin_len*2 + 3)) == NULL )
+ if ( (rv=PyBytes_FromStringAndSize(NULL, bin_len*2 + 3)) == NULL )
return NULL;
- ascii_data = (unsigned char *)PyString_AsString(rv);
+ ascii_data = (unsigned char *)PyBytes_AsString(rv);
for( ; bin_len > 0 ; bin_len--, bin_data++ ) {
/* Shift the data into our buffer */
@@ -474,8 +474,8 @@ binascii_b2a_base64(PyObject *self, PyObject *args)
}
*ascii_data++ = '\n'; /* Append a courtesy newline */
- _PyString_Resize(&rv, (ascii_data -
- (unsigned char *)PyString_AsString(rv)));
+ _PyBytes_Resize(&rv, (ascii_data -
+ (unsigned char *)PyBytes_AsString(rv)));
return rv;
}
@@ -498,9 +498,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=PyString_FromStringAndSize(NULL, len+2)) == NULL )
+ if ( (rv=PyBytes_FromStringAndSize(NULL, len+2)) == NULL )
return NULL;
- bin_data = (unsigned char *)PyString_AsString(rv);
+ bin_data = (unsigned char *)PyBytes_AsString(rv);
for( ; len > 0 ; len--, ascii_data++ ) {
/* Get the byte and look it up */
@@ -534,8 +534,8 @@ binascii_a2b_hqx(PyObject *self, PyObject *args)
Py_DECREF(rv);
return NULL;
}
- _PyString_Resize(
- &rv, (bin_data - (unsigned char *)PyString_AsString(rv)));
+ _PyBytes_Resize(
+ &rv, (bin_data - (unsigned char *)PyBytes_AsString(rv)));
if (rv) {
PyObject *rrv = Py_BuildValue("Oi", rv, done);
Py_DECREF(rv);
@@ -559,9 +559,9 @@ binascii_rlecode_hqx(PyObject *self, PyObject *args)
return NULL;
/* Worst case: output is twice as big as input (fixed later) */
- if ( (rv=PyString_FromStringAndSize(NULL, len*2+2)) == NULL )
+ if ( (rv=PyBytes_FromStringAndSize(NULL, len*2+2)) == NULL )
return NULL;
- out_data = (unsigned char *)PyString_AsString(rv);
+ out_data = (unsigned char *)PyBytes_AsString(rv);
for( in=0; in<len; in++) {
ch = in_data[in];
@@ -587,8 +587,8 @@ binascii_rlecode_hqx(PyObject *self, PyObject *args)
}
}
}
- _PyString_Resize(&rv, (out_data -
- (unsigned char *)PyString_AsString(rv)));
+ _PyBytes_Resize(&rv, (out_data -
+ (unsigned char *)PyBytes_AsString(rv)));
return rv;
}
@@ -608,9 +608,9 @@ binascii_b2a_hqx(PyObject *self, PyObject *args)
return NULL;
/* Allocate a buffer that is at least large enough */
- if ( (rv=PyString_FromStringAndSize(NULL, len*2+2)) == NULL )
+ if ( (rv=PyBytes_FromStringAndSize(NULL, len*2+2)) == NULL )
return NULL;
- ascii_data = (unsigned char *)PyString_AsString(rv);
+ ascii_data = (unsigned char *)PyBytes_AsString(rv);
for( ; len > 0 ; len--, bin_data++ ) {
/* Shift into our buffer, and output any 6bits ready */
@@ -627,8 +627,8 @@ binascii_b2a_hqx(PyObject *self, PyObject *args)
leftchar <<= (6-leftbits);
*ascii_data++ = table_b2a_hqx[leftchar & 0x3f];
}
- _PyString_Resize(&rv, (ascii_data -
- (unsigned char *)PyString_AsString(rv)));
+ _PyBytes_Resize(&rv, (ascii_data -
+ (unsigned char *)PyBytes_AsString(rv)));
return rv;
}
@@ -647,14 +647,14 @@ binascii_rledecode_hqx(PyObject *self, PyObject *args)
/* Empty string is a special case */
if ( in_len == 0 )
- return PyString_FromString("");
+ return PyBytes_FromString("");
/* Allocate a buffer of reasonable size. Resized when needed */
out_len = in_len*2;
- if ( (rv=PyString_FromStringAndSize(NULL, out_len)) == NULL )
+ if ( (rv=PyBytes_FromStringAndSize(NULL, out_len)) == NULL )
return NULL;
out_len_left = out_len;
- out_data = (unsigned char *)PyString_AsString(rv);
+ out_data = (unsigned char *)PyBytes_AsString(rv);
/*
** We need two macros here to get/put bytes and handle
@@ -673,9 +673,9 @@ binascii_rledecode_hqx(PyObject *self, PyObject *args)
#define OUTBYTE(b) \
do { \
if ( --out_len_left < 0 ) { \
- _PyString_Resize(&rv, 2*out_len); \
+ _PyBytes_Resize(&rv, 2*out_len); \
if ( rv == NULL ) return NULL; \
- out_data = (unsigned char *)PyString_AsString(rv) \
+ out_data = (unsigned char *)PyBytes_AsString(rv) \
+ out_len; \
out_len_left = out_len-1; \
out_len = out_len * 2; \
@@ -723,8 +723,8 @@ binascii_rledecode_hqx(PyObject *self, PyObject *args)
OUTBYTE(in_byte);
}
}
- _PyString_Resize(&rv, (out_data -
- (unsigned char *)PyString_AsString(rv)));
+ _PyBytes_Resize(&rv, (out_data -
+ (unsigned char *)PyBytes_AsString(rv)));
return rv;
}
@@ -923,10 +923,10 @@ binascii_hexlify(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "s#:b2a_hex", &argbuf, &arglen))
return NULL;
- retval = PyString_FromStringAndSize(NULL, arglen*2);
+ retval = PyBytes_FromStringAndSize(NULL, arglen*2);
if (!retval)
return NULL;
- retbuf = PyString_AsString(retval);
+ retbuf = PyBytes_AsString(retval);
if (!retbuf)
goto finally;
@@ -989,10 +989,10 @@ binascii_unhexlify(PyObject *self, PyObject *args)
return NULL;
}
- retval = PyString_FromStringAndSize(NULL, (arglen/2));
+ retval = PyBytes_FromStringAndSize(NULL, (arglen/2));
if (!retval)
return NULL;
- retbuf = PyString_AsString(retval);
+ retbuf = PyBytes_AsString(retval);
if (!retbuf)
goto finally;
@@ -1106,7 +1106,7 @@ binascii_a2b_qp(PyObject *self, PyObject *args, PyObject *kwargs)
out++;
}
}
- if ((rv = PyString_FromStringAndSize((char *)odata, out)) == NULL) {
+ if ((rv = PyBytes_FromStringAndSize((char *)odata, out)) == NULL) {
PyMem_Free(odata);
return NULL;
}
@@ -1306,7 +1306,7 @@ binascii_b2a_qp (PyObject *self, PyObject *args, PyObject *kwargs)
}
}
}
- if ((rv = PyString_FromStringAndSize((char *)odata, out)) == NULL) {
+ if ((rv = PyBytes_FromStringAndSize((char *)odata, out)) == NULL) {
PyMem_Free(odata);
return NULL;
}
@@ -1354,7 +1354,7 @@ initbinascii(void)
return;
d = PyModule_GetDict(m);
- x = PyString_FromString(doc_binascii);
+ x = PyBytes_FromString(doc_binascii);
PyDict_SetItemString(d, "__doc__", x);
Py_XDECREF(x);