(Merge 3.2) Issue #12342: Improve _tkinter error message on unencodable character
authorVictor Stinner <victor.stinner@haypocalc.com>
Thu, 3 Nov 2011 23:43:35 +0000 (00:43 +0100)
committerVictor Stinner <victor.stinner@haypocalc.com>
Thu, 3 Nov 2011 23:43:35 +0000 (00:43 +0100)
1  2 
Modules/_tkinter.c

index ffb8ab08c95a4781d61e1dcccc5996e9eb65df9d,3608e2d993a26d72dd1ddadd1048018cb2521796..f42f068bb3892094a3035de892c5ba35073fcaec
@@@ -984,19 -991,16 +984,21 @@@ AsObj(PyObject *value
              return NULL;
          }
          for (i = 0; i < size; i++) {
 -            if (inbuf[i] >= 0x10000) {
 +            Py_UCS4 ch = PyUnicode_READ(kind, inbuf, i);
 +            /* We cannot test for sizeof(Tcl_UniChar) directly,
 +               so we test for UTF-8 size instead. */
 +#if TCL_UTF_MAX == 3
 +            if (ch >= 0x10000) {
                  /* Tcl doesn't do UTF-16, yet. */
-                 PyErr_SetString(PyExc_ValueError,
-                                 "unsupported character");
+                 PyErr_Format(PyExc_ValueError,
+                              "character U+%x is above the range "
+                              "(U+0000-U+FFFF) allowed by Tcl",
+                              inbuf[i]);
                  ckfree(FREECAST outbuf);
                  return NULL;
 +#endif
              }
 -            outbuf[i] = inbuf[i];
 +            outbuf[i] = ch;
          }
          result = Tcl_NewUnicodeObj(outbuf, size);
          ckfree(FREECAST outbuf);