move __Pyx_InitStrings() utility function into StringTools.c
authorStefan Behnel <stefan_ml@behnel.de>
Sat, 5 Jan 2013 14:02:29 +0000 (15:02 +0100)
committerStefan Behnel <stefan_ml@behnel.de>
Sat, 5 Jan 2013 14:02:29 +0000 (15:02 +0100)
Cython/Compiler/Code.py
Cython/Compiler/Nodes.py
Cython/Utility/StringTools.c

index deb3a00..c348b16 100644 (file)
@@ -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("")
index 0a3b0ca..07fc79b 100644 (file)
@@ -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.
 
index 9efb3ca..53dfc77 100644 (file)
@@ -7,6 +7,42 @@
 
 #include <string>
 
+//////////////////// 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*/