[Python-checkins] cpython: Issue #13441: _PyUnicode_CheckConsistency() dumps the string if the maximum

victor.stinner python-checkins at python.org
Mon Nov 21 14:31:50 CET 2011


http://hg.python.org/cpython/rev/a19dad38d4e8
changeset:   73661:a19dad38d4e8
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Mon Nov 21 14:31:41 2011 +0100
summary:
  Issue #13441: _PyUnicode_CheckConsistency() dumps the string if the maximum
character is bigger than U+10FFFF and locale.localeconv() dumps the string
before decoding it.

Temporary hack to debug the issue #13441.

files:
  Modules/_localemodule.c |  26 ++++++++++++++++++++++++++
  Objects/unicodeobject.c |  13 +++++++++++++
  2 files changed, 39 insertions(+), 0 deletions(-)


diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c
--- a/Modules/_localemodule.c
+++ b/Modules/_localemodule.c
@@ -79,6 +79,23 @@
     return res2;
 }
 
+#ifdef Py_DEBUG
+void
+dump_str(const char *name, const char *value)
+{
+    size_t i, len = strlen(value);
+    printf("Decode localeconv() %s: {", name);
+    for (i=0; i<len; i++) {
+        unsigned char ch = value[i];
+        if (i)
+            printf(" 0x%02x", ch);
+        else
+            printf("0x%02x", ch);
+    }
+    printf("} (len=%u)\n", len);
+}
+#endif
+
 /* support functions for formatting floating point numbers */
 
 PyDoc_STRVAR(setlocale__doc__,
@@ -184,11 +201,20 @@
     /* hopefully, the localeconv result survives the C library calls
        involved herein */
 
+#ifdef Py_DEBUG
+#define RESULT_STRING(s)\
+    dump_str(#s, l->s); \
+    x = str2uni(l->s);   \
+    if (!x) goto failed;\
+    PyDict_SetItemString(result, #s, x);\
+    Py_XDECREF(x)
+#else
 #define RESULT_STRING(s)\
     x = str2uni(l->s);   \
     if (!x) goto failed;\
     PyDict_SetItemString(result, #s, x);\
     Py_XDECREF(x)
+#endif
 
 #define RESULT_INT(i)\
     x = PyLong_FromLong(l->i);\
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -391,6 +391,19 @@
             if (ch > maxchar)
                 maxchar = ch;
         }
+        if (maxchar > 0x10FFFF) {
+            printf("Invalid Unicode string! {");
+            for (i=0; i < ascii->length; i++)
+            {
+                Py_UCS4 ch = PyUnicode_READ(kind, data, i);
+                if (i)
+                    printf(", U+%04x", ch);
+                else
+                    printf("U+%04x", ch);
+            }
+            printf("} (len=%u)\n", ascii->length);
+            abort();
+        }
         if (kind == PyUnicode_1BYTE_KIND) {
             if (ascii->state.ascii == 0) {
                 assert(maxchar >= 128);

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


More information about the Python-checkins mailing list