[Python-checkins] cpython: Close #16281: handle tailmatch() failure and remove useless comment

victor.stinner python-checkins at python.org
Thu Jan 3 03:20:27 CET 2013


http://hg.python.org/cpython/rev/49eb2488145d
changeset:   81265:49eb2488145d
parent:      81262:5a2560cb4a8d
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Thu Jan 03 03:18:09 2013 +0100
summary:
  Close #16281: handle tailmatch() failure and remove useless comment

"honor direction and do a forward or backwards search": the runtime speed may
be different, but I consider that it doesn't really matter in practice. The
direction was never honored before: Python 2.7 uses memcmp() for the str type
for example.

files:
  Objects/unicodeobject.c |  11 +++++++++--
  1 files changed, 9 insertions(+), 2 deletions(-)


diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -8935,7 +8935,7 @@
 
     if (PyUnicode_READY(self) == -1 ||
         PyUnicode_READY(substring) == -1)
-        return 0;
+        return -1;
 
     if (PyUnicode_GET_LENGTH(substring) == 0)
         return 1;
@@ -8973,7 +8973,6 @@
             /* We do not need to compare 0 and len(substring)-1 because
                the if statement above ensured already that they are equal
                when we end up here. */
-            /* TODO: honor direction and do a forward or backwards search */
             for (i = 1; i < end_sub; ++i) {
                 if (PyUnicode_READ(kind_self, data_self, offset + i) !=
                     PyUnicode_READ(kind_sub, data_sub, i))
@@ -12597,6 +12596,8 @@
                 return NULL;
             result = tailmatch(self, substring, start, end, -1);
             Py_DECREF(substring);
+            if (result == -1)
+                return NULL;
             if (result) {
                 Py_RETURN_TRUE;
             }
@@ -12613,6 +12614,8 @@
     }
     result = tailmatch(self, substring, start, end, -1);
     Py_DECREF(substring);
+    if (result == -1)
+        return NULL;
     return PyBool_FromLong(result);
 }
 
@@ -12646,6 +12649,8 @@
                 return NULL;
             result = tailmatch(self, substring, start, end, +1);
             Py_DECREF(substring);
+            if (result == -1)
+                return NULL;
             if (result) {
                 Py_RETURN_TRUE;
             }
@@ -12660,6 +12665,8 @@
         return NULL;
     }
     result = tailmatch(self, substring, start, end, +1);
+    if (result == -1)
+        return NULL;
     Py_DECREF(substring);
     return PyBool_FromLong(result);
 }

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list