summaryrefslogtreecommitdiffstats
path: root/Objects/bytes_methods.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/bytes_methods.c')
-rw-r--r--Objects/bytes_methods.c27
1 files changed, 7 insertions, 20 deletions
diff --git a/Objects/bytes_methods.c b/Objects/bytes_methods.c
index 9ff7ace..a299915 100644
--- a/Objects/bytes_methods.c
+++ b/Objects/bytes_methods.c
@@ -364,39 +364,26 @@ in frm is mapped to the byte at the same position in to.\n\
The bytes objects frm and to must be of the same length.");
PyObject *
-_Py_bytes_maketrans(PyObject *args)
+_Py_bytes_maketrans(Py_buffer *frm, Py_buffer *to)
{
PyObject *res = NULL;
- Py_buffer bfrm = {NULL, NULL};
- Py_buffer bto = {NULL, NULL};
Py_ssize_t i;
char *p;
- bfrm.len = -1;
- bto.len = -1;
-
- if (!PyArg_ParseTuple(args, "y*y*:maketrans", &bfrm, &bto))
- return NULL;
- if (bfrm.len != bto.len) {
+ if (frm->len != to->len) {
PyErr_Format(PyExc_ValueError,
"maketrans arguments must have same length");
- goto done;
+ return NULL;
}
res = PyBytes_FromStringAndSize(NULL, 256);
- if (!res) {
- goto done;
- }
+ if (!res)
+ return NULL;
p = PyBytes_AS_STRING(res);
for (i = 0; i < 256; i++)
p[i] = (char) i;
- for (i = 0; i < bfrm.len; i++) {
- p[((unsigned char *)bfrm.buf)[i]] = ((char *)bto.buf)[i];
+ for (i = 0; i < frm->len; i++) {
+ p[((unsigned char *)frm->buf)[i]] = ((char *)to->buf)[i];
}
-done:
- if (bfrm.obj != NULL)
- PyBuffer_Release(&bfrm);
- if (bfrm.obj != NULL)
- PyBuffer_Release(&bto);
return res;
}