diff options
author | Benjamin Peterson <benjamin@python.org> | 2010-01-09 21:45:28 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2010-01-09 21:45:28 (GMT) |
commit | 8667a9b6ea414fb78c0c71d411d86c5cfffbf549 (patch) | |
tree | de4e301e504d9b734a543f441581e99ee307537e /Modules/_testcapimodule.c | |
parent | c36c3789dee99b3e2d01ee47731b62200157ba16 (diff) | |
download | cpython-8667a9b6ea414fb78c0c71d411d86c5cfffbf549.zip cpython-8667a9b6ea414fb78c0c71d411d86c5cfffbf549.tar.gz cpython-8667a9b6ea414fb78c0c71d411d86c5cfffbf549.tar.bz2 |
Python strings ending with '\0' should not be equivalent to their C counterparts in PyUnicode_CompareWithASCIIString
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r-- | Modules/_testcapimodule.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 19afbf2..5671783 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -1287,6 +1287,23 @@ test_string_from_format(PyObject *self, PyObject *args) #undef CHECK_1_FORMAT } + +static PyObject * +test_unicode_compare_with_ascii(PyObject *self) { + PyObject *py_s = PyUnicode_FromStringAndSize("str\0", 4); + int result; + if (py_s == NULL) + return NULL; + result = PyUnicode_CompareWithASCIIString(py_s, "str"); + Py_DECREF(py_s); + if (!result) { + PyErr_SetString(TestError, "Python string ending in NULL " + "should not compare equal to c string."); + return NULL; + } + Py_RETURN_NONE; +}; + /* This is here to provide a docstring for test_descr. */ static PyObject * test_with_docstring(PyObject *self) @@ -1756,6 +1773,7 @@ static PyMethodDef TestMethods[] = { {"test_with_docstring", (PyCFunction)test_with_docstring, METH_NOARGS, PyDoc_STR("This is a pretty normal docstring.")}, {"test_string_to_double", (PyCFunction)test_string_to_double, METH_NOARGS}, + {"test_unicode_compare_with_ascii", (PyCFunction)test_unicode_compare_with_ascii, METH_NOARGS}, {"test_capsule", (PyCFunction)test_capsule, METH_NOARGS}, {"getargs_tuple", getargs_tuple, METH_VARARGS}, {"getargs_keywords", (PyCFunction)getargs_keywords, |