diff options
author | Robert Bradshaw <robertwb@gmail.com> | 2014-07-10 00:32:12 -0700 |
---|---|---|
committer | Robert Bradshaw <robertwb@gmail.com> | 2014-07-10 00:42:11 -0700 |
commit | 50133b5a91eea348eddaaad22a606a7fa1c7c457 (patch) | |
tree | 792a20c13437e31fb9c49798de0bb8d09a131f45 /Cython/Compiler/ModuleNode.py | |
parent | 6a9c3fe9ccc40d7b0102d4b8eb6c27441cd14d61 (diff) | |
download | cython-50133b5a91eea348eddaaad22a606a7fa1c7c457.tar.gz |
Allow extern cpdef enum to export values into Python-level namespace.
Diffstat (limited to 'Cython/Compiler/ModuleNode.py')
-rw-r--r-- | Cython/Compiler/ModuleNode.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 1db73495e..cd2711aca 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -2112,6 +2112,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): self.body.generate_execution_code(code) + code.putln() + code.putln("/*--- Wrapped vars code ---*/") + self.generate_wrapped_entries_code(env, code) + code.putln() + if Options.generate_cleanup_code: code.globalstate.use_utility_code( UtilityCode.load_cached("RegisterModuleCleanup", "ModuleSetupCode.c")) @@ -2370,6 +2375,23 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): if entry.used: entry.type.global_init_code(entry, code) + def generate_wrapped_entries_code(self, env, code): + for name, entry in env.entries.items(): + if entry.create_wrapper and not entry.is_type: + if not entry.type.create_to_py_utility_code(env): + error(entry.pos, "Cannot convert '%s' to Python object" % entry.type) + code.putln("{") + code.putln("PyObject* wrapped = %s(%s);" % ( + entry.type.to_py_function, + entry.cname)) + code.putln(code.error_goto_if_null("wrapped", entry.pos)) + code.putln( + 'if (__Pyx_SetAttrString(%s, "%s", wrapped) < 0) %s;' % ( + env.module_cname, + name, + code.error_goto(entry.pos))) + code.putln("}") + def generate_c_variable_export_code(self, env, code): # Generate code to create PyCFunction wrappers for exported C functions. entries = [] |