summaryrefslogtreecommitdiff
path: root/Cython/Compiler/ModuleNode.py
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2015-01-01 15:45:28 +0100
committerStefan Behnel <stefan_ml@behnel.de>2015-01-01 15:45:28 +0100
commit9a0a5c5dfc103ddee775ebfd7d5f1e37f3ee000d (patch)
treeb9051ab2d39c6e0986595fd2ba279d69125b3dc6 /Cython/Compiler/ModuleNode.py
parent5a6e79fd0ec0023b88a313c0a8755ac7c3db06ea (diff)
downloadcython-9a0a5c5dfc103ddee775ebfd7d5f1e37f3ee000d.tar.gz
move constant type name table into utility function as it is only used in that one place
Diffstat (limited to 'Cython/Compiler/ModuleNode.py')
-rw-r--r--Cython/Compiler/ModuleNode.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py
index 72817a235..78822b8e2 100644
--- a/Cython/Compiler/ModuleNode.py
+++ b/Cython/Compiler/ModuleNode.py
@@ -1961,16 +1961,17 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
def generate_import_star(self, env, code):
env.use_utility_code(streq_utility_code)
code.putln()
- code.putln("static const char* %s_type_names[] = {" % Naming.import_star)
+ code.enter_cfunc_scope() # as we need labels
+ code.putln("static int %s(PyObject *o, PyObject* py_name, char *name) {" % Naming.import_star_set)
+
+ code.putln("static const char* type_names[] = {")
for name, entry in sorted(env.entries.items()):
if entry.is_type:
code.putln('"%s",' % name)
code.putln("0")
code.putln("};")
- code.putln()
- code.enter_cfunc_scope() # as we need labels
- code.putln("static int %s(PyObject *o, PyObject* py_name, char *name) {" % Naming.import_star_set)
- code.putln("const char** type_name = %s_type_names;" % Naming.import_star)
+
+ code.putln("const char** type_name = type_names;")
code.putln("while (*type_name) {")
code.putln("if (__Pyx_StrEq(name, *type_name)) {")
code.putln('PyErr_Format(PyExc_TypeError, "Cannot overwrite C type %s", name);')
@@ -1978,6 +1979,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("}")
code.putln("type_name++;")
code.putln("}")
+
old_error_label = code.new_error_label()
code.putln("if (0);") # so the first one can be "else if"
for name, entry in env.entries.items():