[Python-checkins] cpython: Don't use deprecated function PyUnicode_GET_SIZE()

victor.stinner python-checkins at python.org
Wed Nov 13 14:20:06 CET 2013


http://hg.python.org/cpython/rev/28f71af02b69
changeset:   87083:28f71af02b69
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Wed Nov 13 14:17:30 2013 +0100
summary:
  Don't use deprecated function PyUnicode_GET_SIZE()

Replace it with PyUnicode_GET_LENGTH() or PyUnicode_AsUnicodeAndSize()

files:
  Modules/_elementtree.c    |   2 +-
  Modules/posixmodule.c     |  13 ++++++-------
  Objects/namespaceobject.c |   2 +-
  3 files changed, 8 insertions(+), 9 deletions(-)


diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -3461,7 +3461,7 @@
 
         if (PyUnicode_CheckExact(buffer)) {
             /* A unicode object is encoded into bytes using UTF-8 */
-            if (PyUnicode_GET_SIZE(buffer) == 0) {
+            if (PyUnicode_GET_LENGTH(buffer) == 0) {
                 Py_DECREF(buffer);
                 break;
             }
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -829,19 +829,18 @@
     if (unicode) {
 #ifdef MS_WINDOWS
         wchar_t *wide;
-        length = PyUnicode_GET_SIZE(unicode);
+
+        wide = PyUnicode_AsUnicodeAndSize(unicode, &length);
+        if (!wide) {
+            Py_DECREF(unicode);
+            return 0;
+        }
         if (length > 32767) {
             FORMAT_EXCEPTION(PyExc_ValueError, "%s too long for Windows");
             Py_DECREF(unicode);
             return 0;
         }
 
-        wide = PyUnicode_AsUnicode(unicode);
-        if (!wide) {
-            Py_DECREF(unicode);
-            return 0;
-        }
-
         path->wide = wide;
         path->narrow = NULL;
         path->length = length;
diff --git a/Objects/namespaceobject.c b/Objects/namespaceobject.c
--- a/Objects/namespaceobject.c
+++ b/Objects/namespaceobject.c
@@ -101,7 +101,7 @@
         goto error;
 
     while ((key = PyIter_Next(keys_iter)) != NULL) {
-        if (PyUnicode_Check(key) && PyUnicode_GET_SIZE(key) > 0) {
+        if (PyUnicode_Check(key) && PyUnicode_GET_LENGTH(key) > 0) {
             PyObject *value, *item;
 
             value = PyDict_GetItem(d, key);

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


More information about the Python-checkins mailing list