changeset 24574:e97a00bf18ae

parsers: factor out most of asciilower into an internal function We're going to reuse this in upcoming patches. The change to Py_ssize_t is necessary because parsers.c doesn't define PY_SSIZE_T_CLEAN. That macro changes the behavior of PyArg_ParseTuple but not PyBytes_GET_SIZE.
author Siddharth Agarwal <sid0@fb.com>
date Tue, 31 Mar 2015 10:25:29 -0700
parents 701d3554de0e
children a62e957413f7
files mercurial/parsers.c
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/parsers.c	Tue Mar 31 14:01:33 2015 -0700
+++ b/mercurial/parsers.c	Tue Mar 31 10:25:29 2015 -0700
@@ -93,14 +93,14 @@
 	return ret;
 }
 
-static PyObject *asciilower(PyObject *self, PyObject *args)
+static inline PyObject *_asciilower(PyObject *str_obj)
 {
 	char *str, *newstr;
-	int i, len;
+	Py_ssize_t i, len;
 	PyObject *newobj = NULL;
 
-	if (!PyArg_ParseTuple(args, "s#", &str, &len))
-		goto quit;
+	str = PyBytes_AS_STRING(str_obj);
+	len = PyBytes_GET_SIZE(str_obj);
 
 	newobj = PyBytes_FromStringAndSize(NULL, len);
 	if (!newobj)
@@ -127,6 +127,14 @@
 	return NULL;
 }
 
+static PyObject *asciilower(PyObject *self, PyObject *args)
+{
+	PyObject *str_obj;
+	if (!PyArg_ParseTuple(args, "O!:asciilower", &PyBytes_Type, &str_obj))
+		return NULL;
+	return _asciilower(str_obj);
+}
+
 /*
  * This code assumes that a manifest is stitched together with newline
  * ('\n') characters.