From 02a5f1e06c525815342c1bf6b627fc9ea021d72a Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sat, 5 Jan 2013 15:02:29 +0100 Subject: [PATCH] move __Pyx_InitStrings() utility function into StringTools.c --- Cython/Compiler/Code.py | 4 +--- Cython/Compiler/Nodes.py | 38 -------------------------------------- Cython/Utility/StringTools.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 41 deletions(-) diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index deb3a00..c348b16 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -1127,9 +1127,7 @@ class GlobalState(object): py_strings.append((c.cname, len(py_string.cname), py_string)) if py_strings: - import Nodes - self.use_utility_code(Nodes.init_string_tab_utility_code) - + self.use_utility_code(UtilityCode.load_cached("InitStrings", "StringTools.c")) py_strings.sort() w = self.parts['pystring_table'] w.putln("") diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 0a3b0ca..07fc79b 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -8039,44 +8039,6 @@ bad: #------------------------------------------------------------------------------------ -init_string_tab_utility_code = UtilityCode( -proto = """ -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ -""", -impl = """ -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { - while (t->p) { - #if PY_MAJOR_VERSION < 3 - if (t->is_unicode) { - *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); - } else if (t->intern) { - *t->p = PyString_InternFromString(t->s); - } else { - *t->p = PyString_FromStringAndSize(t->s, t->n - 1); - } - #else /* Python 3+ has unicode identifiers */ - if (t->is_unicode | t->is_str) { - if (t->intern) { - *t->p = PyUnicode_InternFromString(t->s); - } else if (t->encoding) { - *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); - } else { - *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); - } - } else { - *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); - } - #endif - if (!*t->p) - return -1; - ++t; - } - return 0; -} -""") - -#------------------------------------------------------------------------------------ - # Note that cPython ignores PyTrace_EXCEPTION, # but maybe some other profilers don't. diff --git a/Cython/Utility/StringTools.c b/Cython/Utility/StringTools.c index 9efb3ca..53dfc77 100644 --- a/Cython/Utility/StringTools.c +++ b/Cython/Utility/StringTools.c @@ -7,6 +7,42 @@ #include +//////////////////// InitStrings.proto //////////////////// + +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ + +//////////////////// InitStrings //////////////////// + +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + while (t->p) { + #if PY_MAJOR_VERSION < 3 + if (t->is_unicode) { + *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); + } else if (t->intern) { + *t->p = PyString_InternFromString(t->s); + } else { + *t->p = PyString_FromStringAndSize(t->s, t->n - 1); + } + #else /* Python 3+ has unicode identifiers */ + if (t->is_unicode | t->is_str) { + if (t->intern) { + *t->p = PyUnicode_InternFromString(t->s); + } else if (t->encoding) { + *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); + } else { + *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); + } + } else { + *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); + } + #endif + if (!*t->p) + return -1; + ++t; + } + return 0; +} + //////////////////// BytesContains.proto //////////////////// static CYTHON_INLINE int __Pyx_BytesContains(PyObject* bytes, char character); /*proto*/ -- 2.7.4