[Python-checkins] cpython (merge 3.6 -> default): Issue #28701: _PyUnicode_EqualToASCIIId and _PyUnicode_EqualToASCIIString now

serhiy.storchaka python-checkins at python.org
Wed Nov 16 13:03:21 EST 2016


https://hg.python.org/cpython/rev/44874b20e612
changeset: 105160:44874b20e612
parent: 105158:15e5e476e4a1
parent: 105159:6dd22ed7140e
user: Serhiy Storchaka <storchaka at gmail.com>
date: Wed Nov 16 20:03:03 2016 +0200
summary:
 Issue #28701: _PyUnicode_EqualToASCIIId and _PyUnicode_EqualToASCIIString now
require ASCII right argument and assert this condition in debug build.
files:
 Include/unicodeobject.h | 4 ++--
 Objects/unicodeobject.c | 11 +++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -2038,7 +2038,7 @@
 
 #ifndef Py_LIMITED_API
 /* Test whether a unicode is equal to ASCII identifier. Return 1 if true,
- 0 otherwise. Return 0 if any argument contains non-ASCII characters.
+ 0 otherwise. The right argument must be ASCII identifier.
 Any error occurs inside will be cleared before return. */
 
 PyAPI_FUNC(int) _PyUnicode_EqualToASCIIId(
@@ -2060,7 +2060,7 @@
 
 #ifndef Py_LIMITED_API
 /* Test whether a unicode is equal to ASCII string. Return 1 if true,
- 0 otherwise. Return 0 if any argument contains non-ASCII characters.
+ 0 otherwise. The right argument must be ASCII-encoded string.
 Any error occurs inside will be cleared before return. */
 
 PyAPI_FUNC(int) _PyUnicode_EqualToASCIIString(
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -11062,6 +11062,12 @@
 {
 size_t len;
 assert(_PyUnicode_CHECK(unicode));
+ assert(str);
+#ifndef NDEBUG
+ for (const char *p = str; *p; p++) {
+ assert((unsigned char)*p < 128);
+ }
+#endif
 if (PyUnicode_READY(unicode) == -1) {
 /* Memory error or bad data */
 PyErr_Clear();
@@ -11082,6 +11088,11 @@
 
 assert(_PyUnicode_CHECK(left));
 assert(right->string);
+#ifndef NDEBUG
+ for (const char *p = right->string; *p; p++) {
+ assert((unsigned char)*p < 128);
+ }
+#endif
 
 if (PyUnicode_READY(left) == -1) {
 /* memory error or bad data */
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /