Commit 3c6d6f2f authored by Martin v. Löwis's avatar Martin v. Löwis

Support UCS-4 builds.

parent 0ba5541a
...@@ -62,6 +62,14 @@ Copyright (C) 1994 Steen Lumholt. ...@@ -62,6 +62,14 @@ Copyright (C) 1994 Steen Lumholt.
#error "Tk older than 8.2 not supported" #error "Tk older than 8.2 not supported"
#endif #endif
/* Unicode conversion assumes that Tcl_UniChar is two bytes.
We cannot test this directly, so we test UTF-8 size instead,
expecting that TCL_UTF_MAX is changed if Tcl ever supports
either UTF-16 or UCS-4. */
#if TCL_UTF_MAX != 3
#error "unsupported Tcl configuration"
#endif
#if defined(macintosh) #if defined(macintosh)
/* Sigh, we have to include this to get at the tcl qd pointer */ /* Sigh, we have to include this to get at the tcl qd pointer */
#include <tkMac.h> #include <tkMac.h>
...@@ -531,15 +539,35 @@ AsObj(PyObject *value) ...@@ -531,15 +539,35 @@ AsObj(PyObject *value)
} }
#ifdef Py_USING_UNICODE #ifdef Py_USING_UNICODE
else if (PyUnicode_Check(value)) { else if (PyUnicode_Check(value)) {
/* In Tcl 8.2 and later, use Tcl_NewUnicodeObj() */ Py_UNICODE *inbuf = PyUnicode_AS_UNICODE(value);
if (sizeof(Py_UNICODE) != sizeof(Tcl_UniChar)) { int size = PyUnicode_GET_SIZE(value);
/* XXX Should really test this at compile time */ /* This #ifdef assumes that Tcl uses UCS-2.
PyErr_SetString(PyExc_SystemError, See TCL_UTF_MAX test above. */
"Py_UNICODE and Tcl_UniChar differ in size"); #ifdef Py_UNICODE_WIDE
return 0; Tcl_UniChar *outbuf;
int i;
outbuf = (Tcl_UniChar*)ckalloc(size * sizeof(Tcl_UniChar));
if (!outbuf) {
PyErr_NoMemory();
return NULL;
} }
return Tcl_NewUnicodeObj(PyUnicode_AS_UNICODE(value), for (i = 0; i < size; i++) {
PyUnicode_GET_SIZE(value)); if (inbuf[i] >= 0x10000) {
/* Tcl doesn't do UTF-16, yet. */
PyErr_SetString(PyExc_ValueError,
"unsupported character");
ckfree(FREECAST outbuf);
return NULL;
}
outbuf[i] = inbuf[i];
}
result = Tcl_NewUnicodeObj(outbuf, size);
ckfree(FREECAST outbuf);
return result;
#else
return Tcl_NewUnicodeObj(inbuf, size);
#endif
} }
#endif #endif
else { else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment