[PATCH 1 of 4 foldmap-in-C] parsers: factor out most of asciilower into an internal function

Siddharth Agarwal sid at less-broken.com
Wed Apr 1 15:53:05 CDT 2015


On 04/01/2015 10:28 AM, Siddharth Agarwal wrote:
> -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;
> +	PyObject *ret = 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)
> @@ -121,10 +122,19 @@
>  		newstr[i] = lowertable[(unsigned char)c];
>  	}
>  
> -	return newobj;
> +	ret = newobj;
> +	Py_INCREF(ret);
>  quit:
>  	Py_XDECREF(newobj);
> -	return NULL;
> +	return ret;
> +}

Huh, I meant to break this up into multiple patches before sending. I'll
fix up and resend.


More information about the Mercurial-devel mailing list