diff options
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r-- | Modules/_testcapimodule.c | 79 |
1 files changed, 40 insertions, 39 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index f09205f63c..03a4acbc79 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -64,8 +64,7 @@ test_config(PyObject *self) #undef CHECK_SIZEOF - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject* @@ -118,8 +117,7 @@ test_sizeof_c_types(PyObject *self) CHECK_SIZEOF(intptr_t, sizeof(void *)); CHECK_SIGNNESS(intptr_t, 1); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; #undef IS_SIGNED #undef CHECK_SIGNESS @@ -169,8 +167,7 @@ test_list_api(PyObject *self) Py_DECREF(list); #undef NLIST - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static int @@ -234,8 +231,7 @@ test_dict_iteration(PyObject* self) } } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject* @@ -614,8 +610,7 @@ test_long_and_overflow(PyObject *self) return raiseTestError("test_long_and_overflow", "overflow was not cleared"); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /* Test the PyLong_AsLongLongAndOverflow API. General conversion to @@ -779,8 +774,7 @@ test_long_long_and_overflow(PyObject *self) return raiseTestError("test_long_long_and_overflow", "overflow was not cleared"); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /* Test the PyLong_As{Size,Ssize}_t API. At present this just tests that @@ -887,8 +881,7 @@ test_L_code(PyObject *self) "L code returned wrong value for int 42"); Py_DECREF(tuple); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -1224,8 +1217,7 @@ test_k_code(PyObject *self) "k code returned wrong value for long -0xFFF..000042"); Py_DECREF(tuple); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -1411,11 +1403,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 +1415,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 +1438,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; } @@ -1676,8 +1664,7 @@ test_u_code(PyObject *self) "u# code returned wrong values for u'test'"); Py_DECREF(tuple); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /* Test Z and Z# codes for PyArg_ParseTuple */ @@ -1892,6 +1879,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 +1910,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; @@ -2105,8 +2109,7 @@ test_long_numbits(PyObject *self) return raiseTestError("test_long_numbits", "wrong result for _PyLong_Sign"); } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /* Example passing NULLs to PyObject_Str(NULL). */ @@ -2298,7 +2301,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; @@ -2323,11 +2326,9 @@ PyObject *pending_threadfunc(PyObject *self, PyObject *arg) if (r<0) { Py_DECREF(callable); /* unsuccessful add, destroy the extra reference */ - Py_INCREF(Py_False); - return Py_False; + Py_RETURN_FALSE; } - Py_INCREF(Py_True); - return Py_True; + Py_RETURN_TRUE; } #endif @@ -2713,8 +2714,7 @@ profile_int(PyObject *self, PyObject* args) Py_DECREF(op1); print_delta(7, &start, &stop); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } #endif @@ -4129,6 +4129,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}, |