Submitter | Siddharth Agarwal |
---|---|
Date | April 1, 2015, 5:28 p.m. |
Message ID | <719010b9a74187eb3139.1427909284@devbig136.prn2.facebook.com> |
Download | mbox | patch |
Permalink | /patch/8415/ |
State | Superseded |
Commit | e97a00bf18ae4156ba1590ae08bf204db29ca132 |
Headers | show |
Comments
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.
Patch
diff --git a/mercurial/parsers.c b/mercurial/parsers.c --- a/mercurial/parsers.c +++ b/mercurial/parsers.c @@ -93,14 +93,15 @@ 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; + 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; +} + +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); } /*