summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2015-04-26 00:42:13 (GMT)
committerGregory P. Smith <greg@krypto.org>2015-04-26 00:42:13 (GMT)
commit9c6b916662f34e7dfce847b66d55309e2ae0caae (patch)
tree28ccf7968ef5224b69710055646ef9821db88d8e /Modules
parente3f6393b52b513036e9d3145a4e3802e77d5e3b1 (diff)
downloadcpython-9c6b916662f34e7dfce847b66d55309e2ae0caae.zip
cpython-9c6b916662f34e7dfce847b66d55309e2ae0caae.tar.gz
cpython-9c6b916662f34e7dfce847b66d55309e2ae0caae.tar.bz2
Switch binascii over to using the common _Py_strhex implementation for its hex
and hexlify functions. issue9951.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/binascii.c31
1 files changed, 3 insertions, 28 deletions
diff --git a/Modules/binascii.c b/Modules/binascii.c
index ceee4f1..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
@@ -1117,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]
@@ -1158,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