Mercurial > hg
comparison mercurial/parsers.c @ 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 | 90db70de6f9c |
children | a62e957413f7 |
comparison
equal
deleted
inserted
replaced
24573:701d3554de0e | 24574:e97a00bf18ae |
---|---|
91 } | 91 } |
92 | 92 |
93 return ret; | 93 return ret; |
94 } | 94 } |
95 | 95 |
96 static PyObject *asciilower(PyObject *self, PyObject *args) | 96 static inline PyObject *_asciilower(PyObject *str_obj) |
97 { | 97 { |
98 char *str, *newstr; | 98 char *str, *newstr; |
99 int i, len; | 99 Py_ssize_t i, len; |
100 PyObject *newobj = NULL; | 100 PyObject *newobj = NULL; |
101 | 101 |
102 if (!PyArg_ParseTuple(args, "s#", &str, &len)) | 102 str = PyBytes_AS_STRING(str_obj); |
103 goto quit; | 103 len = PyBytes_GET_SIZE(str_obj); |
104 | 104 |
105 newobj = PyBytes_FromStringAndSize(NULL, len); | 105 newobj = PyBytes_FromStringAndSize(NULL, len); |
106 if (!newobj) | 106 if (!newobj) |
107 goto quit; | 107 goto quit; |
108 | 108 |
123 | 123 |
124 return newobj; | 124 return newobj; |
125 quit: | 125 quit: |
126 Py_XDECREF(newobj); | 126 Py_XDECREF(newobj); |
127 return NULL; | 127 return NULL; |
128 } | |
129 | |
130 static PyObject *asciilower(PyObject *self, PyObject *args) | |
131 { | |
132 PyObject *str_obj; | |
133 if (!PyArg_ParseTuple(args, "O!:asciilower", &PyBytes_Type, &str_obj)) | |
134 return NULL; | |
135 return _asciilower(str_obj); | |
128 } | 136 } |
129 | 137 |
130 /* | 138 /* |
131 * This code assumes that a manifest is stitched together with newline | 139 * This code assumes that a manifest is stitched together with newline |
132 * ('\n') characters. | 140 * ('\n') characters. |