Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(190349)

Side by Side Diff: Modules/_testcapimodule.c

Issue 28822: Fix indices handling in PyUnicode_FindChar
Patch Set: Created 2 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * C Extension module to test Python interpreter C APIs. 2 * C Extension module to test Python interpreter C APIs.
3 * 3 *
4 * The 'test_*' functions exported by this module are run as part of the 4 * The 'test_*' functions exported by this module are run as part of the
5 * standard Python regression test, via Lib/test/test_capi.py. 5 * standard Python regression test, via Lib/test/test_capi.py.
6 */ 6 */
7 7
8 #define PY_SSIZE_T_CLEAN 8 #define PY_SSIZE_T_CLEAN
9 9
10 #include "Python.h" 10 #include "Python.h"
(...skipping 1854 matching lines...) Expand 10 before | Expand all | Expand 10 after
1865 buffer[str_len] = 0xffffU; 1865 buffer[str_len] = 0xffffU;
1866 1866
1867 if (!PyUnicode_AsUCS4(unicode, buffer, buf_len, copy_null)) { 1867 if (!PyUnicode_AsUCS4(unicode, buffer, buf_len, copy_null)) {
1868 PyMem_FREE(buffer); 1868 PyMem_FREE(buffer);
1869 return NULL; 1869 return NULL;
1870 } 1870 }
1871 1871
1872 result = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, buffer, buf_len); 1872 result = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, buffer, buf_len);
1873 PyMem_FREE(buffer); 1873 PyMem_FREE(buffer);
1874 return result; 1874 return result;
1875 }
1876
1877 static PyObject *
1878 unicode_findchar(PyObject *self, PyObject *args)
1879 {
1880 PyObject *str;
1881 int direction;
1882 unsigned int ch;
1883 Py_ssize_t result;
1884 Py_ssize_t start, end;
1885
1886 if (!PyArg_ParseTuple(args, "UInni:unicode_findchar", &str, &ch,
1887 &start, &end, &direction)) {
1888 return NULL;
1889 }
1890
1891 result = PyUnicode_FindChar(str, (Py_UCS4)ch, start, end, direction);
1892 if (result == -2)
1893 return NULL;
1894 else
1895 return PyLong_FromSsize_t(result);
1875 } 1896 }
1876 1897
1877 static PyObject * 1898 static PyObject *
1878 unicode_copycharacters(PyObject *self, PyObject *args) 1899 unicode_copycharacters(PyObject *self, PyObject *args)
1879 { 1900 {
1880 PyObject *from, *to, *to_copy; 1901 PyObject *from, *to, *to_copy;
1881 Py_ssize_t from_start, to_start, how_many, copied; 1902 Py_ssize_t from_start, to_start, how_many, copied;
1882 1903
1883 if (!PyArg_ParseTuple(args, "UnOnn:unicode_copycharacters", &to, &to_start, 1904 if (!PyArg_ParseTuple(args, "UnOnn:unicode_copycharacters", &to, &to_start,
1884 &from, &from_start, &how_many)) { 1905 &from, &from_start, &how_many)) {
(...skipping 2215 matching lines...) Expand 10 before | Expand all | Expand 10 after
4100 (PyCFunction)codec_incrementalencoder, METH_VARARGS}, 4121 (PyCFunction)codec_incrementalencoder, METH_VARARGS},
4101 {"codec_incrementaldecoder", 4122 {"codec_incrementaldecoder",
4102 (PyCFunction)codec_incrementaldecoder, METH_VARARGS}, 4123 (PyCFunction)codec_incrementaldecoder, METH_VARARGS},
4103 {"test_s_code", (PyCFunction)test_s_code, METH_NOARGS}, 4124 {"test_s_code", (PyCFunction)test_s_code, METH_NOARGS},
4104 {"test_u_code", (PyCFunction)test_u_code, METH_NOARGS}, 4125 {"test_u_code", (PyCFunction)test_u_code, METH_NOARGS},
4105 {"test_Z_code", (PyCFunction)test_Z_code, METH_NOARGS}, 4126 {"test_Z_code", (PyCFunction)test_Z_code, METH_NOARGS},
4106 {"test_widechar", (PyCFunction)test_widechar, METH_NOARGS}, 4127 {"test_widechar", (PyCFunction)test_widechar, METH_NOARGS},
4107 {"unicode_aswidechar", unicode_aswidechar, METH_VARARGS}, 4128 {"unicode_aswidechar", unicode_aswidechar, METH_VARARGS},
4108 {"unicode_aswidecharstring",unicode_aswidecharstring, METH_VARARGS}, 4129 {"unicode_aswidecharstring",unicode_aswidecharstring, METH_VARARGS},
4109 {"unicode_asucs4", unicode_asucs4, METH_VARARGS}, 4130 {"unicode_asucs4", unicode_asucs4, METH_VARARGS},
4131 {"unicode_findchar", unicode_findchar, METH_VARARGS},
4110 {"unicode_copycharacters", unicode_copycharacters, METH_VARARGS}, 4132 {"unicode_copycharacters", unicode_copycharacters, METH_VARARGS},
4111 {"unicode_encodedecimal", unicode_encodedecimal, METH_VARARGS}, 4133 {"unicode_encodedecimal", unicode_encodedecimal, METH_VARARGS},
4112 {"unicode_transformdecimaltoascii", unicode_transformdecimaltoascii, METH_VA RARGS}, 4134 {"unicode_transformdecimaltoascii", unicode_transformdecimaltoascii, METH_VA RARGS},
4113 {"unicode_legacy_string", unicode_legacy_string, METH_VARARGS}, 4135 {"unicode_legacy_string", unicode_legacy_string, METH_VARARGS},
4114 #ifdef WITH_THREAD 4136 #ifdef WITH_THREAD
4115 {"_test_thread_state", test_thread_state, METH_VARARGS}, 4137 {"_test_thread_state", test_thread_state, METH_VARARGS},
4116 {"_pending_threadfunc", pending_threadfunc, METH_VARARGS}, 4138 {"_pending_threadfunc", pending_threadfunc, METH_VARARGS},
4117 #endif 4139 #endif
4118 #ifdef HAVE_GETTIMEOFDAY 4140 #ifdef HAVE_GETTIMEOFDAY
4119 {"profile_int", profile_int, METH_NOARGS}, 4141 {"profile_int", profile_int, METH_NOARGS},
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
4618 Py_INCREF(&PyInstanceMethod_Type); 4640 Py_INCREF(&PyInstanceMethod_Type);
4619 PyModule_AddObject(m, "instancemethod", (PyObject *)&PyInstanceMethod_Type); 4641 PyModule_AddObject(m, "instancemethod", (PyObject *)&PyInstanceMethod_Type);
4620 4642
4621 PyModule_AddIntConstant(m, "the_number_three", 3); 4643 PyModule_AddIntConstant(m, "the_number_three", 3);
4622 4644
4623 TestError = PyErr_NewException("_testcapi.error", NULL, NULL); 4645 TestError = PyErr_NewException("_testcapi.error", NULL, NULL);
4624 Py_INCREF(TestError); 4646 Py_INCREF(TestError);
4625 PyModule_AddObject(m, "error", TestError); 4647 PyModule_AddObject(m, "error", TestError);
4626 return m; 4648 return m;
4627 } 4649 }
OLDNEW

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+