Commit a28c097a authored by Benjamin Peterson's avatar Benjamin Peterson

Merged revisions 77395 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r77395 | benjamin.peterson | 2010-01-09 15:45:28 -0600 (Sat, 09 Jan 2010) | 2 lines

  Python strings ending with '\0' should not be equivalent to their C counterparts in PyUnicode_CompareWithASCIIString
........
parent 095d6a78
...@@ -57,7 +57,6 @@ Core and Builtins ...@@ -57,7 +57,6 @@ Core and Builtins
- Issue #6750: A text file opened with io.open() could duplicate its output - Issue #6750: A text file opened with io.open() could duplicate its output
when writing from multiple threads at the same time. when writing from multiple threads at the same time.
Library Library
------- -------
...@@ -280,6 +279,12 @@ Tests ...@@ -280,6 +279,12 @@ Tests
- Issue #7042: Fix test_signal (test_itimer_virtual) failure on OS X 10.6. - Issue #7042: Fix test_signal (test_itimer_virtual) failure on OS X 10.6.
C-API
-----
- Make PyUnicode_CompareWithASCIIString return not equal if the Python string
has '\0' at the end.
Build Build
----- -----
......
...@@ -1093,6 +1093,23 @@ test_string_from_format(PyObject *self, PyObject *args) ...@@ -1093,6 +1093,23 @@ test_string_from_format(PyObject *self, PyObject *args)
#undef CHECK_1_FORMAT #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. */ /* This is here to provide a docstring for test_descr. */
static PyObject * static PyObject *
test_with_docstring(PyObject *self) test_with_docstring(PyObject *self)
...@@ -1524,6 +1541,7 @@ static PyMethodDef TestMethods[] = { ...@@ -1524,6 +1541,7 @@ static PyMethodDef TestMethods[] = {
{"test_with_docstring", (PyCFunction)test_with_docstring, METH_NOARGS, {"test_with_docstring", (PyCFunction)test_with_docstring, METH_NOARGS,
PyDoc_STR("This is a pretty normal docstring.")}, PyDoc_STR("This is a pretty normal docstring.")},
{"test_string_to_double", (PyCFunction)test_string_to_double, METH_NOARGS}, {"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}, {"test_capsule", (PyCFunction)test_capsule, METH_NOARGS},
{"getargs_tuple", getargs_tuple, METH_VARARGS}, {"getargs_tuple", getargs_tuple, METH_VARARGS},
{"getargs_keywords", (PyCFunction)getargs_keywords, {"getargs_keywords", (PyCFunction)getargs_keywords,
......
...@@ -6932,6 +6932,11 @@ PyUnicode_CompareWithASCIIString(PyObject* uni, const char* str) ...@@ -6932,6 +6932,11 @@ PyUnicode_CompareWithASCIIString(PyObject* uni, const char* str)
for (i = 0; id[i] && str[i]; i++) for (i = 0; id[i] && str[i]; i++)
if (id[i] != str[i]) if (id[i] != str[i])
return ((int)id[i] < (int)str[i]) ? -1 : 1; return ((int)id[i] < (int)str[i]) ? -1 : 1;
/* This check keeps Python strings that end in '\0' from comparing equal
to C strings identical up to that point. */
if (PyUnicode_GET_SIZE(uni) != i)
/* We'll say the Python string is longer. */
return 1;
if (id[i]) if (id[i])
return 1; /* uni is longer */ return 1; /* uni is longer */
if (str[i]) if (str[i])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment