summaryrefslogtreecommitdiffstats
path: root/Modules/binascii.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/binascii.c')
-rw-r--r--Modules/binascii.c39
1 files changed, 7 insertions, 32 deletions
diff --git a/Modules/binascii.c b/Modules/binascii.c
index ea14d3c..d920d23 100644
--- a/Modules/binascii.c
+++ b/Modules/binascii.c
@@ -56,6 +56,7 @@
#define PY_SSIZE_T_CLEAN
#include "Python.h"
+#include "pystrhex.h"
#ifdef USE_ZLIB_CRC32
#include "zlib.h"
#endif
@@ -184,10 +185,9 @@ static unsigned short crctab_hqx[256] = {
};
/*[clinic input]
-output preset file
module binascii
[clinic start generated code]*/
-/*[clinic end generated code: output=da39a3ee5e6b4b0d input=44c6f840ce708f0c]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=de89fb46bcaf3fec]*/
/*[python input]
@@ -1118,33 +1118,7 @@ static PyObject *
binascii_b2a_hex_impl(PyModuleDef *module, Py_buffer *data)
/*[clinic end generated code: output=179318922c2f8fda input=96423cfa299ff3b1]*/
{
- char* argbuf;
- Py_ssize_t arglen;
- PyObject *retval;
- char* retbuf;
- Py_ssize_t i, j;
-
- argbuf = data->buf;
- arglen = data->len;
-
- assert(arglen >= 0);
- if (arglen > PY_SSIZE_T_MAX / 2)
- return PyErr_NoMemory();
-
- retval = PyBytes_FromStringAndSize(NULL, arglen*2);
- if (!retval)
- return NULL;
- retbuf = PyBytes_AS_STRING(retval);
-
- /* make hex version of string, taken from shamodule.c */
- for (i=j=0; i < arglen; i++) {
- unsigned char c;
- c = (argbuf[i] >> 4) & 0xf;
- retbuf[j++] = Py_hexdigits[c];
- c = argbuf[i] & 0xf;
- retbuf[j++] = Py_hexdigits[c];
- }
- return retval;
+ return _Py_strhex_bytes((const char *)data->buf, data->len);
}
/*[clinic input]
@@ -1159,7 +1133,7 @@ static PyObject *
binascii_hexlify_impl(PyModuleDef *module, Py_buffer *data)
/*[clinic end generated code: output=6098440091fb61dc input=2e3afae7f083f061]*/
{
- return binascii_b2a_hex_impl(module, data);
+ return _Py_strhex_bytes((const char *)data->buf, data->len);
}
static int
@@ -1382,8 +1356,9 @@ are both encoded. When quotetabs is set, space and tabs are encoded.
[clinic start generated code]*/
static PyObject *
-binascii_b2a_qp_impl(PyModuleDef *module, Py_buffer *data, int quotetabs, int istext, int header)
-/*[clinic end generated code: output=ff2991ba640fff3e input=7f2a9aaa008e92b2]*/
+binascii_b2a_qp_impl(PyModuleDef *module, Py_buffer *data, int quotetabs,
+ int istext, int header)
+/*[clinic end generated code: output=a87ca9ccb94e2a9f input=7f2a9aaa008e92b2]*/
{
Py_ssize_t in, out;
unsigned char *databuf, *odata;