Commit 9a0a5c5d authored by Stefan Behnel's avatar Stefan Behnel

move constant type name table into utility function as it is only used in that one place

parent 5a6e79fd
...@@ -1961,16 +1961,17 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1961,16 +1961,17 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
def generate_import_star(self, env, code): def generate_import_star(self, env, code):
env.use_utility_code(streq_utility_code) env.use_utility_code(streq_utility_code)
code.putln() 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()): for name, entry in sorted(env.entries.items()):
if entry.is_type: if entry.is_type:
code.putln('"%s",' % name) code.putln('"%s",' % name)
code.putln("0") code.putln("0")
code.putln("};") code.putln("};")
code.putln()
code.enter_cfunc_scope() # as we need labels code.putln("const char** type_name = type_names;")
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("while (*type_name) {") code.putln("while (*type_name) {")
code.putln("if (__Pyx_StrEq(name, *type_name)) {") code.putln("if (__Pyx_StrEq(name, *type_name)) {")
code.putln('PyErr_Format(PyExc_TypeError, "Cannot overwrite C type %s", name);') code.putln('PyErr_Format(PyExc_TypeError, "Cannot overwrite C type %s", name);')
...@@ -1978,6 +1979,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1978,6 +1979,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("}") code.putln("}")
code.putln("type_name++;") code.putln("type_name++;")
code.putln("}") code.putln("}")
old_error_label = code.new_error_label() old_error_label = code.new_error_label()
code.putln("if (0);") # so the first one can be "else if" code.putln("if (0);") # so the first one can be "else if"
for name, entry in env.entries.items(): for name, entry in env.entries.items():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment