[Python-checkins] cpython: Fix misuse of PyUnicode_GET_SIZE() => PyUnicode_GET_LENGTH()

victor.stinner python-checkins at python.org
Mon Nov 21 02:50:23 CET 2011


http://hg.python.org/cpython/rev/2e37fc70e2dd
changeset:   73655:2e37fc70e2dd
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Mon Nov 21 02:49:52 2011 +0100
summary:
  Fix misuse of PyUnicode_GET_SIZE() => PyUnicode_GET_LENGTH()

And PyUnicode_GetSize() => PyUnicode_GetLength()

files:
  Modules/_csv.c            |   2 +-
  Modules/_datetimemodule.c |   4 ++--
  Modules/_gestalt.c        |   2 +-
  Modules/_io/stringio.c    |   2 +-
  Modules/_io/textio.c      |   4 ++--
  Objects/bytesobject.c     |   2 +-
  Objects/exceptions.c      |   4 ++--
  Objects/unicodeobject.c   |   4 ++--
  PC/import_nt.c            |   3 +--
  Python/_warnings.c        |  10 +++++-----
  10 files changed, 18 insertions(+), 19 deletions(-)


diff --git a/Modules/_csv.c b/Modules/_csv.c
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -207,7 +207,7 @@
         *target = '\0';
         if (src != Py_None) {
             Py_ssize_t len;
-            len = PyUnicode_GetSize(src);
+            len = PyUnicode_GetLength(src);
             if (len > 1) {
                 PyErr_Format(PyExc_TypeError,
                     "\"%s\" must be an 1-character string",
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -1080,7 +1080,7 @@
     PyObject *tzinfo = get_tzinfo_member(object);
     PyObject *Zreplacement = PyUnicode_FromStringAndSize(NULL, 0);
     _Py_IDENTIFIER(replace);
-	
+
     if (Zreplacement == NULL)
         return NULL;
     if (tzinfo == Py_None || tzinfo == NULL)
@@ -2673,7 +2673,7 @@
         return NULL;
 
     /* if the format is zero length, return str(self) */
-    if (PyUnicode_GetSize(format) == 0)
+    if (PyUnicode_GetLength(format) == 0)
         return PyObject_Str((PyObject *)self);
 
     return _PyObject_CallMethodId((PyObject *)self, &PyId_strftime, "O", format);
diff --git a/Modules/_gestalt.c b/Modules/_gestalt.c
--- a/Modules/_gestalt.c
+++ b/Modules/_gestalt.c
@@ -33,7 +33,7 @@
 convert_to_OSType(PyObject *v, OSType *pr)
 {
     uint32_t tmp;
-    if (!PyUnicode_Check(v) || PyUnicode_GetSize(v) != 4) {
+    if (!PyUnicode_Check(v) || PyUnicode_GetLength(v) != 4) {
     PyErr_SetString(PyExc_TypeError,
                     "OSType arg must be string of 4 chars");
     return 0;
diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c
--- a/Modules/_io/stringio.c
+++ b/Modules/_io/stringio.c
@@ -730,7 +730,7 @@
        and copy it */
     self->string_size = 0;
     if (value && value != Py_None)
-        value_len = PyUnicode_GetSize(value);
+        value_len = PyUnicode_GetLength(value);
     else
         value_len = 0;
     if (value_len > 0) {
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -2144,7 +2144,7 @@
         textiowrapper_set_decoded_chars(self, decoded);
 
         /* Skip chars_to_skip of the decoded characters. */
-        if (PyUnicode_GetSize(self->decoded_chars) < cookie.chars_to_skip) {
+        if (PyUnicode_GetLength(self->decoded_chars) < cookie.chars_to_skip) {
             PyErr_SetString(PyExc_IOError, "can't restore logical file position");
             goto fail;
         }
@@ -2208,7 +2208,7 @@
         goto fail;
 
     if (self->decoder == NULL || self->snapshot == NULL) {
-        assert (self->decoded_chars == NULL || PyUnicode_GetSize(self->decoded_chars) == 0);
+        assert (self->decoded_chars == NULL || PyUnicode_GetLength(self->decoded_chars) == 0);
         return posobj;
     }
 
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -2941,7 +2941,7 @@
         PyErr_BadInternalCall();
         return NULL;
     }
-    llen = PyUnicode_GetSize(result);
+    llen = PyUnicode_GetLength(result);
     if (llen > INT_MAX) {
         PyErr_SetString(PyExc_ValueError,
                         "string too large in _PyBytes_FormatLong");
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -1273,7 +1273,7 @@
     if (!obj)
         return -1;
     *start = ((PyUnicodeErrorObject *)exc)->start;
-    size = PyUnicode_GET_SIZE(obj);
+    size = PyUnicode_GET_LENGTH(obj);
     if (*start<0)
         *start = 0; /*XXX check for values <0*/
     if (*start>=size)
@@ -1341,7 +1341,7 @@
     if (!obj)
         return -1;
     *end = ((PyUnicodeErrorObject *)exc)->end;
-    size = PyUnicode_GET_SIZE(obj);
+    size = PyUnicode_GET_LENGTH(obj);
     if (*end<1)
         *end = 1;
     if (*end>size)
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -4784,7 +4784,7 @@
             if (PyBytes_Check(rep))
                 repsize = PyBytes_GET_SIZE(rep);
             else
-                repsize = PyUnicode_GET_SIZE(rep);
+                repsize = PyUnicode_GET_LENGTH(rep);
 
             if (repsize > 4) {
                 Py_ssize_t offset;
@@ -8187,7 +8187,7 @@
             Py_DECREF(repunicode);
             return -1;
         }
-        repsize = PyUnicode_GET_SIZE(repunicode);
+        repsize = PyUnicode_GET_LENGTH(repunicode);
         data = PyUnicode_DATA(repunicode);
         kind = PyUnicode_KIND(repunicode);
         for (index = 0; index < repsize; index++) {
diff --git a/PC/import_nt.c b/PC/import_nt.c
--- a/PC/import_nt.c
+++ b/PC/import_nt.c
@@ -86,12 +86,11 @@
         suffix = PyUnicode_FromString(fdp->suffix);
         if (suffix == NULL)
             return NULL;
-        wsuffix = PyUnicode_AsUnicode(suffix);
+        wsuffix = PyUnicode_AsUnicodeAndSize(suffix, &extLen);
         if (wsuffix == NULL) {
             Py_DECREF(suffix);
             return NULL;
         }
-        extLen = PyUnicode_GET_SIZE(suffix);
         if ((Py_ssize_t)modNameSize > extLen &&
             _wcsnicmp(pathBuf + ((Py_ssize_t)modNameSize-extLen-1),
                       wsuffix,
diff --git a/Python/_warnings.c b/Python/_warnings.c
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -203,13 +203,13 @@
 
     mod_str = _PyUnicode_AsString(filename);
     if (mod_str == NULL)
-            return NULL;
-    len = PyUnicode_GetSize(filename);
+        return NULL;
+    len = PyUnicode_GetLength(filename);
     if (len < 0)
         return NULL;
     if (len >= 3 &&
         strncmp(mod_str + (len - 3), ".py", 3) == 0) {
-        module = PyUnicode_FromStringAndSize(mod_str, len-3);
+        module = PyUnicode_Substring(filename, 0, len-3);
     }
     else {
         module = filename;
@@ -506,7 +506,7 @@
         if (PyUnicode_READY(*filename))
             goto handle_error;
 
-        len = PyUnicode_GetSize(*filename);
+        len = PyUnicode_GetLength(*filename);
         kind = PyUnicode_KIND(*filename);
         data = PyUnicode_DATA(*filename);
 
@@ -690,7 +690,7 @@
         }
 
         /* Split the source into lines. */
-        source_list = PyObject_CallMethodObjArgs(source, 
+        source_list = PyObject_CallMethodObjArgs(source,
                                                  PyId_splitlines.object,
                                                  NULL);
         Py_DECREF(source);

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


More information about the Python-checkins mailing list