From 77256df067c7e89cc5da875604d1371058687a8b Mon Sep 17 00:00:00 2001 From: Brian Crowell Date: Sat, 13 Oct 2012 13:43:54 -0500 Subject: [PATCH] py3k: Remove HAVE_UNICODE from _imagingft I'm pretty sure this preserves the intent of the code. HAVE_UNICODE is now assumed, and PyString is only used if we're not in Py3k. Since this is the only file that uses PyUnicode, I'm going to go ahead and #define PyUnicode and PyBytes back to PyString for 2.6, and explicitly change out every call so I have to check them all. --- _imagingft.c | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/_imagingft.c b/_imagingft.c index 634d8b914..36b7ec5e4 100644 --- a/_imagingft.c +++ b/_imagingft.c @@ -40,13 +40,6 @@ #define PyObject_Del PyMem_DEL #endif -#if PY_VERSION_HEX >= 0x01060000 -#if PY_VERSION_HEX < 0x02020000 || defined(Py_USING_UNICODE) -/* defining this enables unicode support (default under 1.6a1 and later) */ -#define HAVE_UNICODE -#endif -#endif - #if !defined(Py_RETURN_NONE) #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None #endif @@ -118,16 +111,10 @@ getfont(PyObject* self_, PyObject* args, PyObject* kw) "filename", "size", "index", "encoding", NULL }; -#if defined(HAVE_UNICODE) && PY_VERSION_HEX >= 0x02020000 if (!PyArg_ParseTupleAndKeywords(args, kw, "eti|is", kwlist, Py_FileSystemDefaultEncoding, &filename, &size, &index, &encoding)) return NULL; -#else - if (!PyArg_ParseTupleAndKeywords(args, kw, "si|is", kwlist, - &filename, &size, &index, &encoding)) - return NULL; -#endif if (!library) { PyErr_SetString( @@ -164,7 +151,6 @@ getfont(PyObject* self_, PyObject* args, PyObject* kw) static int font_getchar(PyObject* string, int index, FT_ULong* char_out) { -#if defined(HAVE_UNICODE) if (PyUnicode_Check(string)) { Py_UNICODE* p = PyUnicode_AS_UNICODE(string); int size = PyUnicode_GET_SIZE(string); @@ -173,7 +159,8 @@ font_getchar(PyObject* string, int index, FT_ULong* char_out) *char_out = p[index]; return 1; } -#endif + +#if PY_VERSION_HEX < 0x03000000 if (PyString_Check(string)) { unsigned char* p = (unsigned char*) PyString_AS_STRING(string); int size = PyString_GET_SIZE(string); @@ -182,6 +169,8 @@ font_getchar(PyObject* string, int index, FT_ULong* char_out) *char_out = (unsigned char) p[index]; return 1; } +#endif + return 0; } @@ -201,10 +190,10 @@ font_getsize(FontObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "O:getsize", &string)) return NULL; -#if defined(HAVE_UNICODE) - if (!PyUnicode_Check(string) && !PyString_Check(string)) { +#if PY_VERSION_HEX >= 0x03000000 + if (!PyUnicode_Check(string)) { #else - if (!PyString_Check(string)) { + if (!PyUnicode_Check(string) && !PyString_Check(string)) { #endif PyErr_SetString(PyExc_TypeError, "expected string"); return NULL; @@ -267,10 +256,10 @@ font_getabc(FontObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "O:getabc", &string)) return NULL; -#if defined(HAVE_UNICODE) - if (!PyUnicode_Check(string) && !PyString_Check(string)) { +#if PY_VERSION_HEX >= 0x03000000 + if (!PyUnicode_Check(string)) { #else - if (!PyString_Check(string)) { + if (!PyUnicode_Check(string) && !PyString_Check(string)) { #endif PyErr_SetString(PyExc_TypeError, "expected string"); return NULL; @@ -315,10 +304,10 @@ font_render(FontObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "Ol|i:render", &string, &id, &mask)) return NULL; -#if defined(HAVE_UNICODE) - if (!PyUnicode_Check(string) && !PyString_Check(string)) { +#if PY_VERSION_HEX >= 0x03000000 + if (!PyUnicode_Check(string)) { #else - if (!PyString_Check(string)) { + if (!PyUnicode_Check(string) && !PyString_Check(string)) { #endif PyErr_SetString(PyExc_TypeError, "expected string"); return NULL;