[Python-checkins] cpython: Fix misuse of PyUnicode_GET_SIZE, use PyUnicode_GET_LENGTH instead

victor.stinner python-checkins at python.org
Tue Oct 11 22:13:03 CEST 2011


http://hg.python.org/cpython/rev/afa42c04f0a3
changeset:   72863:afa42c04f0a3
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Tue Oct 11 22:11:42 2011 +0200
summary:
  Fix misuse of PyUnicode_GET_SIZE, use PyUnicode_GET_LENGTH instead

files:
  Modules/_cursesmodule.c    |  2 +-
  Modules/_io/stringio.c     |  2 +-
  Modules/_json.c            |  2 +-
  Modules/syslogmodule.c     |  8 +++-----
  Objects/unicodeobject.c    |  6 +++---
  Python/formatter_unicode.c |  2 +-
  6 files changed, 10 insertions(+), 12 deletions(-)


diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -2719,7 +2719,7 @@
             PyErr_Format(PyExc_TypeError,
                          "expect bytes or str of length 1, or int, "
                          "got a str of length %zi",
-                         PyUnicode_GET_SIZE(obj));
+                         PyUnicode_GET_LENGTH(obj));
             return 0;
         }
         *wch = buffer[0];
diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c
--- a/Modules/_io/stringio.c
+++ b/Modules/_io/stringio.c
@@ -343,7 +343,7 @@
     if (line == NULL)
         return NULL;
 
-    if (PyUnicode_GET_SIZE(line) == 0) {
+    if (PyUnicode_GET_LENGTH(line) == 0) {
         /* Reached EOF */
         Py_DECREF(line);
         return NULL;
diff --git a/Modules/_json.c b/Modules/_json.c
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -837,7 +837,7 @@
 
     /* rval = parse_constant(constant) */
     rval = PyObject_CallFunctionObjArgs(s->parse_constant, cstr, NULL);
-    idx += PyUnicode_GET_SIZE(cstr);
+    idx += PyUnicode_GET_LENGTH(cstr);
     Py_DECREF(cstr);
     *next_idx_ptr = idx;
     return rval;
diff --git a/Modules/syslogmodule.c b/Modules/syslogmodule.c
--- a/Modules/syslogmodule.c
+++ b/Modules/syslogmodule.c
@@ -90,18 +90,16 @@
     if (!PyUnicode_Check(scriptobj)) {
         return(NULL);
     }
-    scriptlen = PyUnicode_GET_SIZE(scriptobj);
+    scriptlen = PyUnicode_GET_LENGTH(scriptobj);
     if (scriptlen == 0) {
         return(NULL);
     }
 
-    slash = PyUnicode_FindChar(scriptobj, SEP,
-                               0, PyUnicode_GET_LENGTH(scriptobj), -1);
+    slash = PyUnicode_FindChar(scriptobj, SEP, 0, scriptlen, -1);
     if (slash == -2)
         return NULL;
     if (slash != -1) {
-        return PyUnicode_Substring(scriptobj, slash,
-                                   PyUnicode_GET_LENGTH(scriptobj));
+        return PyUnicode_Substring(scriptobj, slash, scriptlen);
     } else {
         Py_INCREF(scriptobj);
         return(scriptobj);
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -12181,7 +12181,7 @@
         if (z != NULL) {
             z_kind = PyUnicode_KIND(z);
             z_data = PyUnicode_DATA(z);
-            for (i = 0; i < PyUnicode_GET_SIZE(z); i++) {
+            for (i = 0; i < PyUnicode_GET_LENGTH(z); i++) {
                 key = PyLong_FromLong(PyUnicode_READ(z_kind, z_data, i));
                 if (!key)
                     goto err;
@@ -12206,7 +12206,7 @@
             if (PyUnicode_Check(key)) {
                 /* convert string keys to integer keys */
                 PyObject *newkey;
-                if (PyUnicode_GET_SIZE(key) != 1) {
+                if (PyUnicode_GET_LENGTH(key) != 1) {
                     PyErr_SetString(PyExc_ValueError, "string keys in translate "
                                     "table must be of length 1");
                     goto err;
@@ -13694,7 +13694,7 @@
 {
     Py_ssize_t len = 0;
     if (it->it_seq)
-        len = PyUnicode_GET_SIZE(it->it_seq) - it->it_index;
+        len = PyUnicode_GET_LENGTH(it->it_seq) - it->it_index;
     return PyLong_FromSsize_t(len);
 }
 
diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c
--- a/Python/formatter_unicode.c
+++ b/Python/formatter_unicode.c
@@ -693,7 +693,7 @@
     Py_ssize_t rpad;
     Py_ssize_t total;
     Py_ssize_t pos;
-    Py_ssize_t len = PyUnicode_GET_SIZE(value);
+    Py_ssize_t len = PyUnicode_GET_LENGTH(value);
     PyObject *result = NULL;
     int maxchar = 127;
 

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


More information about the Python-checkins mailing list