From c8599c340f52261822802f3c4275d668b2203972 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 3 Mar 2011 07:59:52 -0500 Subject: [PATCH] Convert CFuncDefNode to use explicit visibilities. --- Cython/Compiler/Nodes.py | 30 +++++++++++++++----------- Cython/Compiler/ParseTreeTransforms.py | 2 +- Cython/Compiler/Parsing.py | 9 +++----- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index cfced8c6..edd0f4db 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1618,17 +1618,19 @@ class CFuncDefNode(FuncDefNode): # C function definition. # # modifiers ['inline'] - # visibility 'private' or 'public' or 'extern' + # extern (same as Binding.extern) + # c_visibility (same as Binding.c_visibility) + # visibility (same as Binding.visibility) # base_type CBaseTypeNode # declarator CDeclaratorNode # body StatListNode - # api boolean + # api (same as Binding.api) # decorators [DecoratorNode] list of decorators # # with_gil boolean Acquire GIL around body # type CFuncType # py_func wrapper for calling from Python - # overridable whether or not this is a cpdef function + # overridable (same as Binding.overridable) # inline_in_pxd whether this is an inline function in a pxd file child_attrs = ["base_type", "declarator", "body", "py_func"] @@ -1664,16 +1666,16 @@ class CFuncDefNode(FuncDefNode): formal_arg.cname = type_arg.cname if type_arg.type.is_buffer and 'inline' in self.modifiers: warning(formal_arg.pos, "Buffer unpacking not optimized away.", 1) - name = name_declarator.name - cname = name_declarator.cname - self.entry = env.declare_cfunction( - name, type, self.pos, - cname = cname, visibility = self.visibility, - defining = self.body is not None, - api = self.api, modifiers = self.modifiers) + binding = Binding() + binding.pull(self) + binding.name = name_declarator.name + binding.cname = name_declarator.cname + self.entry = env.WTK_declare_cfunction( + binding, type = type, defining = self.body is not None, + modifiers = self.modifiers, pos = self.pos) self.entry.inline_func_in_pxd = self.inline_in_pxd self.return_type = type.return_type - if self.return_type.is_array and visibility != 'extern': + if self.return_type.is_array and not self.extern: error(self.pos, "Function cannot return an array") @@ -1697,7 +1699,7 @@ class CFuncDefNode(FuncDefNode): self.py_func.analyse_declarations(env) self.entry.as_variable = self.py_func.entry # Reset scope entry the above cfunction - env.entries[name] = self.entry + env.entries[self.entry.name] = self.entry if not env.is_module_scope or Options.lookup_module_cpdef: self.override = OverrideCheckNode(self.pos, py_func = self.py_func) self.body = StatListNode(self.pos, stats=[self.override, self.body]) @@ -1990,7 +1992,9 @@ class DefNode(FuncDefNode): type = cfunc_type, with_gil = cfunc_type.with_gil, nogil = cfunc_type.nogil, - visibility = 'private', + extern = 0, + c_visibility = 'private', + visibility = 'public', api = False, directive_locals = getattr(cfunc, 'directive_locals', {})) diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index e4f0a00e..b99c9d59 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -518,7 +518,7 @@ class PxdPostParse(CythonTransform, SkipDeclarations): if isinstance(node, Nodes.CFuncDefNode): if u'inline' in node.modifiers and self.scope_type == 'pxd': node.inline_in_pxd = True - if node.visibility != 'private': + if node.c_visibility != 'private': err = self.ERR_NOGO_WITH_INLINE % node.visibility elif node.api: err = self.ERR_NOGO_WITH_INLINE % 'api' diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index f6c68422..a8967d91 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -2722,15 +2722,12 @@ def p_c_func_or_var_declaration(s, pos, ctx, decorators=None): if ctx.level not in ('module', 'c_class', 'module_pxd', 'c_class_pxd') and not ctx.templates: s.error("C function definition not allowed here") doc, suite = p_suite(s, Ctx(level = 'function'), with_doc = 1) - visibility = 'private' - if ctx.extern: - visibility = 'extern' - elif ctx.c_visibility != 'private': - visibility = ctx.c_visibility result = Nodes.CFuncDefNode(pos, cdef_flag = ctx.cdef_flag, overridable = ctx.overridable, - visibility = visibility, + extern = ctx.extern, + c_visibility = ctx.c_visibility, + visibility = ctx.visibility, base_type = base_type, declarator = declarator, decorators = decorators, -- 2.26.2