diff options
Diffstat (limited to 'Modules/_testcapimodule.c')
| -rw-r--r-- | Modules/_testcapimodule.c | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index f09205f..ef5f9d4 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -1411,11 +1411,9 @@ static PyObject * getargs_u(PyObject *self, PyObject *args) { Py_UNICODE *str; - Py_ssize_t size; if (!PyArg_ParseTuple(args, "u", &str)) return NULL; - size = Py_UNICODE_strlen(str); - return PyUnicode_FromUnicode(str, size); + return PyUnicode_FromWideChar(str, -1); } static PyObject * @@ -1425,19 +1423,17 @@ getargs_u_hash(PyObject *self, PyObject *args) Py_ssize_t size; if (!PyArg_ParseTuple(args, "u#", &str, &size)) return NULL; - return PyUnicode_FromUnicode(str, size); + return PyUnicode_FromWideChar(str, size); } static PyObject * getargs_Z(PyObject *self, PyObject *args) { Py_UNICODE *str; - Py_ssize_t size; if (!PyArg_ParseTuple(args, "Z", &str)) return NULL; if (str != NULL) { - size = Py_UNICODE_strlen(str); - return PyUnicode_FromUnicode(str, size); + return PyUnicode_FromWideChar(str, -1); } else Py_RETURN_NONE; } @@ -1450,7 +1446,7 @@ getargs_Z_hash(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "Z#", &str, &size)) return NULL; if (str != NULL) - return PyUnicode_FromUnicode(str, size); + return PyUnicode_FromWideChar(str, size); else Py_RETURN_NONE; } @@ -1892,6 +1888,27 @@ unicode_asucs4(PyObject *self, PyObject *args) } static PyObject * +unicode_findchar(PyObject *self, PyObject *args) +{ + PyObject *str; + int direction; + unsigned int ch; + Py_ssize_t result; + Py_ssize_t start, end; + + if (!PyArg_ParseTuple(args, "UInni:unicode_findchar", &str, &ch, + &start, &end, &direction)) { + return NULL; + } + + result = PyUnicode_FindChar(str, (Py_UCS4)ch, start, end, direction); + if (result == -2) + return NULL; + else + return PyLong_FromSsize_t(result); +} + +static PyObject * unicode_copycharacters(PyObject *self, PyObject *args) { PyObject *from, *to, *to_copy; @@ -1902,10 +1919,6 @@ unicode_copycharacters(PyObject *self, PyObject *args) return NULL; } - if (PyUnicode_READY(to) < 0) { - return NULL; - } - if (!(to_copy = PyUnicode_New(PyUnicode_GET_LENGTH(to), PyUnicode_MAX_CHAR_VALUE(to)))) { return NULL; @@ -2298,7 +2311,7 @@ static int _pending_callback(void *arg) { /* we assume the argument is callable object to which we own a reference */ PyObject *callable = (PyObject *)arg; - PyObject *r = PyObject_CallObject(callable, NULL); + PyObject *r = _PyObject_CallNoArg(callable); Py_DECREF(callable); Py_XDECREF(r); return r != NULL ? 0 : -1; @@ -4129,6 +4142,7 @@ static PyMethodDef TestMethods[] = { {"unicode_aswidechar", unicode_aswidechar, METH_VARARGS}, {"unicode_aswidecharstring",unicode_aswidecharstring, METH_VARARGS}, {"unicode_asucs4", unicode_asucs4, METH_VARARGS}, + {"unicode_findchar", unicode_findchar, METH_VARARGS}, {"unicode_copycharacters", unicode_copycharacters, METH_VARARGS}, {"unicode_encodedecimal", unicode_encodedecimal, METH_VARARGS}, {"unicode_transformdecimaltoascii", unicode_transformdecimaltoascii, METH_VARARGS}, |
