summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2001-08-17 18:39:25 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2001-08-17 18:39:25 (GMT)
commit339d0f720e86dc34837547c90d3003a4a68d7d46 (patch)
tree2059e5d02f490540e759800b127d50f3fcd8c2b5 /Modules
parentf75976617bb36c892ee8a0f6a6fd3caddbd38cea (diff)
downloadcpython-339d0f720e86dc34837547c90d3003a4a68d7d46.zip
cpython-339d0f720e86dc34837547c90d3003a4a68d7d46.tar.gz
cpython-339d0f720e86dc34837547c90d3003a4a68d7d46.tar.bz2
Patch #445762: Support --disable-unicode
- Do not compile unicodeobject, unicodectype, and unicodedata if Unicode is disabled - check for Py_USING_UNICODE in all places that use Unicode functions - disables unicode literals, and the builtin functions - add the types.StringTypes list - remove Unicode literals from most tests.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_codecsmodule.c4
-rw-r--r--Modules/_sre.c2
-rw-r--r--Modules/_tkinter.c11
-rw-r--r--Modules/cPickle.c14
-rw-r--r--Modules/pyexpat.c27
5 files changed, 45 insertions, 13 deletions
diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c
index 61f25d1..a085bcf 100644
--- a/Modules/_codecsmodule.c
+++ b/Modules/_codecsmodule.c
@@ -71,6 +71,7 @@ PyObject *codeclookup(PyObject *self, PyObject *args)
return NULL;
}
+#ifdef Py_USING_UNICODE
/* --- Helpers ------------------------------------------------------------ */
static
@@ -621,12 +622,14 @@ mbcs_encode(PyObject *self,
}
#endif /* MS_WIN32 */
+#endif /* Py_USING_UNICODE */
/* --- Module API --------------------------------------------------------- */
static PyMethodDef _codecs_functions[] = {
{"register", codecregister, 1},
{"lookup", codeclookup, 1},
+#ifdef Py_USING_UNICODE
{"utf_8_encode", utf_8_encode, 1},
{"utf_8_decode", utf_8_decode, 1},
{"utf_16_encode", utf_16_encode, 1},
@@ -654,6 +657,7 @@ static PyMethodDef _codecs_functions[] = {
{"mbcs_encode", mbcs_encode, 1},
{"mbcs_decode", mbcs_decode, 1},
#endif
+#endif /* Py_USING_UNICODE */
{NULL, NULL} /* sentinel */
};
diff --git a/Modules/_sre.c b/Modules/_sre.c
index 1776a16..9943c30 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -63,7 +63,7 @@ static char copyright[] =
/* defining this one enables tracing */
#undef VERBOSE
-#if PY_VERSION_HEX >= 0x01060000
+#if PY_VERSION_HEX >= 0x01060000 && defined(Py_USING_UNICODE)
/* defining this enables unicode support (default under 1.6a1 and later) */
#define HAVE_UNICODE
#endif
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 9b73307..eedb0c1 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -255,6 +255,7 @@ AsString(PyObject *value, PyObject *tmp)
{
if (PyString_Check(value))
return PyString_AsString(value);
+#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(value)) {
PyObject *v = PyUnicode_AsUTF8String(value);
if (v == NULL)
@@ -266,6 +267,7 @@ AsString(PyObject *value, PyObject *tmp)
Py_DECREF(v);
return PyString_AsString(v);
}
+#endif
else {
PyObject *v = PyObject_Str(value);
if (v == NULL)
@@ -520,6 +522,7 @@ AsObj(PyObject *value)
ckfree(FREECAST argv);
return result;
}
+#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(value)) {
#if TKMAJORMINOR <= 8001
/* In Tcl 8.1 we must use UTF-8 */
@@ -542,6 +545,7 @@ AsObj(PyObject *value)
PyUnicode_GET_SIZE(value));
#endif /* TKMAJORMINOR > 8001 */
}
+#endif
else {
PyObject *v = PyObject_Str(value);
if (!v)
@@ -616,13 +620,16 @@ Tkapp_Call(PyObject *self, PyObject *args)
so would confuse applications that expect a string. */
char *s = Tcl_GetStringResult(interp);
char *p = s;
+
/* If the result contains any bytes with the top bit set,
it's UTF-8 and we should decode it to Unicode */
+#ifdef Py_USING_UNICODE
while (*p != '\0') {
if (*p & 0x80)
break;
p++;
}
+
if (*p == '\0')
res = PyString_FromStringAndSize(s, (int)(p-s));
else {
@@ -634,6 +641,10 @@ Tkapp_Call(PyObject *self, PyObject *args)
res = PyString_FromStringAndSize(s, (int)(p-s));
}
}
+#else
+ p = strchr(p, '\0');
+ res = PyString_FromStringAndSize(s, (int)(p-s));
+#endif
}
LEAVE_OVERLAP_TCL
diff --git a/Modules/cPickle.c b/Modules/cPickle.c
index b27339f..bb0d281 100644
--- a/Modules/cPickle.c
+++ b/Modules/cPickle.c
@@ -1172,6 +1172,7 @@ err:
}
+#ifdef Py_USING_UNICODE
/* A copy of PyUnicode_EncodeRawUnicodeEscape() that also translates
backslash and newline characters to \uXXXX escapes. */
static PyObject *
@@ -1289,6 +1290,7 @@ err:
Py_XDECREF(repr);
return -1;
}
+#endif
static int
@@ -1824,11 +1826,13 @@ save(Picklerobject *self, PyObject *args, int pers_save) {
goto finally;
}
+#ifdef Py_USING_UNICODE
case 'u':
if ((type == &PyUnicode_Type) && (PyString_GET_SIZE(args) < 2)) {
res = save_unicode(self, args, 0);
goto finally;
}
+#endif
}
if (args->ob_refcnt > 1) {
@@ -1857,12 +1861,14 @@ save(Picklerobject *self, PyObject *args, int pers_save) {
}
break;
+#ifdef Py_USING_UNICODE
case 'u':
if (type == &PyUnicode_Type) {
res = save_unicode(self, args, 1);
goto finally;
}
break;
+#endif
case 't':
if (type == &PyTuple_Type) {
@@ -2818,6 +2824,7 @@ load_short_binstring(Unpicklerobject *self) {
}
+#ifdef Py_USING_UNICODE
static int
load_unicode(Unpicklerobject *self) {
PyObject *str = 0;
@@ -2836,8 +2843,10 @@ load_unicode(Unpicklerobject *self) {
finally:
return res;
}
+#endif
+#ifdef Py_USING_UNICODE
static int
load_binunicode(Unpicklerobject *self) {
PyObject *unicode;
@@ -2857,6 +2866,7 @@ load_binunicode(Unpicklerobject *self) {
PDATA_PUSH(self->stack, unicode, -1);
return 0;
}
+#endif
static int
@@ -3615,6 +3625,7 @@ load(Unpicklerobject *self) {
break;
continue;
+#ifdef Py_USING_UNICODE
case UNICODE:
if (load_unicode(self) < 0)
break;
@@ -3624,6 +3635,7 @@ load(Unpicklerobject *self) {
if (load_binunicode(self) < 0)
break;
continue;
+#endif
case EMPTY_TUPLE:
if (load_empty_tuple(self) < 0)
@@ -3905,6 +3917,7 @@ noload(Unpicklerobject *self) {
break;
continue;
+#ifdef Py_USING_UNICODE
case UNICODE:
if (load_unicode(self) < 0)
break;
@@ -3914,6 +3927,7 @@ noload(Unpicklerobject *self) {
if (load_binunicode(self) < 0)
break;
continue;
+#endif
case EMPTY_TUPLE:
if (load_empty_tuple(self) < 0)
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index 4bddc46..3311093 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -28,6 +28,11 @@
#define Py_TPFLAGS_GC 0
#endif
+#if (PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION > 5) || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 2)
+/* In Python 1.6, 2.0 and 2.1, disabling Unicode was not possible. */
+#define Py_USING_UNICODE
+#endif
+
enum HandlerTypes {
StartElement,
EndElement,
@@ -173,7 +178,7 @@ conv_atts_using_string(XML_Char **atts)
}
#endif
-#if !(PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6)
+#ifdef Py_USING_UNICODE
#if EXPAT_VERSION == 0x010200
static PyObject *
conv_atts_using_unicode(XML_Char **atts)
@@ -370,7 +375,7 @@ call_with_frame(PyCodeObject *c, PyObject* func, PyObject* args)
return res;
}
-#if PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6
+#ifndef Py_USING_UNICODE
#define STRING_CONV_FUNC conv_string_to_utf8
#else
/* Python 1.6 and later versions */
@@ -506,7 +511,7 @@ VOID_HANDLER(ProcessingInstruction,
const XML_Char *data),
("(O&O&)",STRING_CONV_FUNC,target, STRING_CONV_FUNC,data))
-#if PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6
+#ifndef Py_USING_UNICODE
VOID_HANDLER(CharacterData,
(void *userData, const XML_Char *data, int len),
("(N)", conv_string_len_to_utf8(data,len)))
@@ -531,7 +536,7 @@ VOID_HANDLER(UnparsedEntityDecl,
STRING_CONV_FUNC,notationName))
#if EXPAT_VERSION >= 0x015f00
-#if PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6
+#ifndef Py_USING_UNICODE
VOID_HANDLER(EntityDecl,
(void *userData,
const XML_Char *entityName,
@@ -608,7 +613,7 @@ conv_content_model_utf8(XML_Content * const model)
return conv_content_model(model, conv_string_to_utf8);
}
-#if !(PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6)
+#ifdef Py_USING_UNICODE
static PyObject *
conv_content_model_unicode(XML_Content * const model)
{
@@ -678,7 +683,7 @@ VOID_HANDLER(EndCdataSection,
(void *userData),
("()"))
-#if PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6
+#ifndef Py_USING_UNICODE
VOID_HANDLER(Default,
(void *userData, const XML_Char *s, int len),
("(N)", conv_string_len_to_utf8(s,len)))
@@ -1064,7 +1069,7 @@ static struct PyMethodDef xmlparse_methods[] = {
/* ---------- */
-#if !(PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6)
+#ifdef Py_USING_UNICODE
/*
pyexpat international encoding support.
@@ -1158,8 +1163,7 @@ newxmlparseobject(char *encoding, char *namespace_separator)
return NULL;
}
XML_SetUserData(self->itself, (void *)self);
-#if PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6
-#else
+#ifdef Py_USING_UNICODE
XML_SetUnknownEncodingHandler(self->itself, (XML_UnknownEncodingHandler) PyUnknownEncodingHandler, NULL);
#endif
@@ -1292,7 +1296,7 @@ xmlparse_setattr(xmlparseobject *self, char *name, PyObject *v)
}
if (strcmp(name, "returns_unicode") == 0) {
if (PyObject_IsTrue(v)) {
-#if PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6
+#ifndef Py_USING_UNICODE
PyErr_SetString(PyExc_ValueError,
"Cannot return Unicode strings in Python 1.5");
return -1;
@@ -1545,8 +1549,7 @@ MODULE_INITFUNC(void)
info.minor, info.micro));
}
#endif
-#if PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6
-#else
+#ifdef Py_USING_UNICODE
init_template_buffer();
#endif
/* XXX When Expat supports some way of figuring out how it was