[Python-checkins] cpython: Use PyUnicode_AsUnicodeAndSize() instead of PyUnicode_GET_SIZE()

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


http://hg.python.org/cpython/rev/6358e5d29dea
changeset:   72861:6358e5d29dea
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Tue Oct 11 21:55:01 2011 +0200
summary:
  Use PyUnicode_AsUnicodeAndSize() instead of PyUnicode_GET_SIZE()

files:
  Modules/posixmodule.c |   3 +--
  Python/getargs.c      |  10 ++++++----
  Python/import.c       |  11 ++++++++---
  3 files changed, 15 insertions(+), 9 deletions(-)


diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -2529,10 +2529,9 @@
             po_wchars = L".";
             len = 1;
         } else {
-            po_wchars = PyUnicode_AsUnicode(po);
+            po_wchars = PyUnicode_AsUnicodeAndSize(po, &len);
             if (po_wchars == NULL)
                 return NULL;
-            len = PyUnicode_GET_SIZE(po);
         }
         /* Overallocate for \\*.*\0 */
         wnamebuf = malloc((len + 5) * sizeof(wchar_t));
diff --git a/Python/getargs.c b/Python/getargs.c
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -982,10 +982,11 @@
                 STORE_SIZE(0);
             }
             else if (PyUnicode_Check(arg)) {
-                *p = PyUnicode_AS_UNICODE(arg);
+                Py_ssize_t len;
+                *p = PyUnicode_AsUnicodeAndSize(arg, &len);
                 if (*p == NULL)
                     RETURN_ERR_OCCURRED;
-                STORE_SIZE(PyUnicode_GET_SIZE(arg));
+                STORE_SIZE(len);
             }
             else
                 return converterr("str or None", arg, msgbuf, bufsize);
@@ -995,10 +996,11 @@
             if (c == 'Z' && arg == Py_None)
                 *p = NULL;
             else if (PyUnicode_Check(arg)) {
-                *p = PyUnicode_AS_UNICODE(arg);
+                Py_ssize_t len;
+                *p = PyUnicode_AsUnicodeAndSize(arg, &len);
                 if (*p == NULL)
                     RETURN_ERR_OCCURRED;
-                if (Py_UNICODE_strlen(*p) != PyUnicode_GET_SIZE(arg))
+                if (Py_UNICODE_strlen(*p) != len)
                     return converterr(
                         "str without null character or None",
                         arg, msgbuf, bufsize);
diff --git a/Python/import.c b/Python/import.c
--- a/Python/import.c
+++ b/Python/import.c
@@ -2282,6 +2282,8 @@
     WIN32_FIND_DATAW data;
     HANDLE h;
     int cmp;
+    wchar_t *wname;
+    Py_ssizet wname_len;
 
     if (Py_GETENV("PYTHONCASEOK") != NULL)
         return 1;
@@ -2294,9 +2296,12 @@
         return 0;
     }
     FindClose(h);
-    cmp = wcsncmp(data.cFileName,
-                  PyUnicode_AS_UNICODE(name),
-                  PyUnicode_GET_SIZE(name));
+
+    wname = PyUnicode_AsUnicodeAndSize(name, &wname_len);
+    if (wname == NULL)
+        return -1;
+
+    cmp = wcsncmp(data.cFileName, wname, wname_len);
     return cmp == 0;
 #elif defined(USE_CASE_OK_BYTES)
     int match;

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


More information about the Python-checkins mailing list