[Python-checkins] cpython: Fix usage of PyUnicode_READY in unicodeobject.c

victor.stinner python-checkins at python.org
Sat Oct 1 02:49:30 CEST 2011


http://hg.python.org/cpython/rev/beaa42dcbaec
changeset:   72553:beaa42dcbaec
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Sat Oct 01 02:14:59 2011 +0200
summary:
  Fix usage of PyUnicode_READY in unicodeobject.c

files:
  Objects/unicodeobject.c |  35 +++++++++++-----------------
  1 files changed, 14 insertions(+), 21 deletions(-)


diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -7933,7 +7933,7 @@
     if (!str_obj || PyUnicode_READY(str_obj) == -1)
         return -1;
     sub_obj = (PyUnicodeObject*) PyUnicode_FromObject(substr);
-    if (!sub_obj || PyUnicode_READY(str_obj) == -1) {
+    if (!sub_obj || PyUnicode_READY(sub_obj) == -1) {
         Py_DECREF(str_obj);
         return -1;
     }
@@ -8460,7 +8460,7 @@
         if (separator == NULL) {
             /* fall back to a blank space separator */
             sep = PyUnicode_FromOrdinal(' ');
-            if (!sep || PyUnicode_READY(sep) == -1)
+            if (!sep)
                 goto onError;
         }
         else {
@@ -9190,10 +9190,6 @@
         Py_DECREF(uniobj);
         return 0;
     }
-    if (PyUnicode_READY(uniobj)) {
-        Py_DECREF(uniobj);
-        return 0;
-    }
     *fillcharloc = PyUnicode_READ_CHAR(uniobj, 0);
     Py_DECREF(uniobj);
     return 1;
@@ -9212,12 +9208,12 @@
     Py_ssize_t width;
     Py_UCS4 fillchar = ' ';
 
+    if (!PyArg_ParseTuple(args, "n|O&:center", &width, convert_uc, &fillchar))
+        return NULL;
+
     if (PyUnicode_READY(self) == -1)
         return NULL;
 
-    if (!PyArg_ParseTuple(args, "n|O&:center", &width, convert_uc, &fillchar))
-        return NULL;
-
     if (_PyUnicode_LENGTH(self) >= width && PyUnicode_CheckExact(self)) {
         Py_INCREF(self);
         return (PyObject*) self;
@@ -9437,7 +9433,7 @@
         return -1;
 
     str = PyUnicode_FromObject(container);
-    if (!str || PyUnicode_READY(container) == -1) {
+    if (!str || PyUnicode_READY(str) == -1) {
         Py_DECREF(sub);
         return -1;
     }
@@ -9515,9 +9511,6 @@
         return v;
     }
 
-    if (PyUnicode_READY(u) == -1 || PyUnicode_READY(v) == -1)
-        goto onError;
-
     maxchar = PyUnicode_MAX_CHAR_VALUE(u);
     maxchar = Py_MAX(maxchar, PyUnicode_MAX_CHAR_VALUE(v));
 
@@ -10662,15 +10655,15 @@
     PyObject *result;
 
     self = PyUnicode_FromObject(obj);
-    if (self == NULL || PyUnicode_READY(obj) == -1)
+    if (self == NULL || PyUnicode_READY(self) == -1)
         return NULL;
     str1 = PyUnicode_FromObject(subobj);
-    if (str1 == NULL || PyUnicode_READY(obj) == -1) {
+    if (str1 == NULL || PyUnicode_READY(str1) == -1) {
         Py_DECREF(self);
         return NULL;
     }
     str2 = PyUnicode_FromObject(replobj);
-    if (str2 == NULL || PyUnicode_READY(obj)) {
+    if (str2 == NULL || PyUnicode_READY(str2)) {
         Py_DECREF(self);
         Py_DECREF(str1);
         return NULL;
@@ -10705,7 +10698,7 @@
     if (str1 == NULL || PyUnicode_READY(str1) == -1)
         return NULL;
     str2 = PyUnicode_FromObject(str2);
-    if (str2 == NULL || PyUnicode_READY(str1) == -1) {
+    if (str2 == NULL || PyUnicode_READY(str2) == -1) {
         Py_DECREF(str1);
         return NULL;
     }
@@ -10958,12 +10951,12 @@
     Py_ssize_t width;
     Py_UCS4 fillchar = ' ';
 
+    if (!PyArg_ParseTuple(args, "n|O&:rjust", &width, convert_uc, &fillchar))
+        return NULL;
+
     if (PyUnicode_READY(self) == -1)
         return NULL;
 
-    if (!PyArg_ParseTuple(args, "n|O&:rjust", &width, convert_uc, &fillchar))
-        return NULL;
-
     if (_PyUnicode_LENGTH(self) >= width && PyUnicode_CheckExact(self)) {
         Py_INCREF(self);
         return (PyObject*) self;
@@ -11032,7 +11025,7 @@
     Py_ssize_t len1, len2;
 
     str_obj = PyUnicode_FromObject(str_in);
-    if (!str_obj || PyUnicode_READY(str_in) == -1)
+    if (!str_obj || PyUnicode_READY(str_obj) == -1)
         return NULL;
     sep_obj = PyUnicode_FromObject(sep_in);
     if (!sep_obj || PyUnicode_READY(sep_obj) == -1) {

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


More information about the Python-checkins mailing list