summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'Modules')
-rw-r--r--Modules/cjkcodecs/_codecs_cn.c1
-rw-r--r--Modules/unicodedata.c27
2 files changed, 12 insertions, 16 deletions
diff --git a/Modules/cjkcodecs/_codecs_cn.c b/Modules/cjkcodecs/_codecs_cn.c
index c811a67..4542ce6 100644
--- a/Modules/cjkcodecs/_codecs_cn.c
+++ b/Modules/cjkcodecs/_codecs_cn.c
@@ -197,6 +197,7 @@ ENCODER(gb18030)
REQUIRE_OUTBUF(2)
GBK_ENCODE(c, code)
+ else TRYMAP_ENC(gb18030ext, code, c);
else {
const struct _gb18030_to_unibmp_ranges *utrrange;
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c
index 5a2515c..87d71ac 100644
--- a/Modules/unicodedata.c
+++ b/Modules/unicodedata.c
@@ -1077,8 +1077,7 @@ static PyObject *
unicodedata_lookup(PyObject* self, PyObject* args)
{
Py_UCS4 code;
- Py_UNICODE str[1];
- char errbuf[256];
+ Py_UNICODE str[2];
char* name;
int namelen;
@@ -1086,24 +1085,20 @@ unicodedata_lookup(PyObject* self, PyObject* args)
return NULL;
if (!_getcode(self, name, namelen, &code)) {
- /* XXX(nnorwitz): why are we allocating for the error msg?
- Why not always use snprintf? */
- char fmt[] = "undefined character name '%s'";
- char *buf = PyMem_MALLOC(sizeof(fmt) + namelen);
- if (buf)
- sprintf(buf, fmt, name);
- else {
- buf = errbuf;
- PyOS_snprintf(buf, sizeof(errbuf), fmt, name);
- }
- PyErr_SetString(PyExc_KeyError, buf);
- if (buf != errbuf)
- PyMem_FREE(buf);
+ PyErr_Format(PyExc_KeyError, "undefined character name '%s'",
+ name);
return NULL;
}
+#ifndef Py_UNICODE_WIDE
+ if (code >= 0x10000) {
+ str[0] = 0xd800 + ((code - 0x10000) >> 10);
+ str[1] = 0xdc00 + ((code - 0x10000) & 0x3ff);
+ return PyUnicode_FromUnicode(str, 2);
+ }
+#endif
str[0] = (Py_UNICODE) code;
- return PyUnicode_FromUnicode(str, 1);
+ return PyUnicode_FromUnicode(str, 1);
}
/* XXX Add doc strings. */