Commit 906bbedc authored by Stefan Behnel's avatar Stefan Behnel

fix modifiers of functions with overrides in external .pxd files

parent ffe34c3a
...@@ -46,6 +46,10 @@ uncachable_builtins = [ ...@@ -46,6 +46,10 @@ uncachable_builtins = [
'WindowsError', 'WindowsError',
] ]
modifier_output_mapper = {
'inline': 'CYTHON_INLINE'
}.get
def get_utility_dir(): def get_utility_dir():
# make this a function and not global variables: # make this a function and not global variables:
# http://trac.cython.org/cython_trac/ticket/475 # http://trac.cython.org/cython_trac/ticket/475
...@@ -1566,6 +1570,11 @@ class CCodeWriter(object): ...@@ -1566,6 +1570,11 @@ class CCodeWriter(object):
else: else:
return cond return cond
def build_function_modifiers(self, modifiers, mapper=modifier_output_mapper):
if not modifiers:
return ''
return '%s ' % ' '.join([mapper(m,m) for m in modifiers])
# Python objects and reference counting # Python objects and reference counting
def entry_as_pyobject(self, entry): def entry_as_pyobject(self, entry):
......
...@@ -811,12 +811,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -811,12 +811,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if not method_entry.is_inherited and method_entry.final_func_cname: if not method_entry.is_inherited and method_entry.final_func_cname:
declaration = method_entry.type.declaration_code( declaration = method_entry.type.declaration_code(
method_entry.final_func_cname) method_entry.final_func_cname)
if method_entry.func_modifiers: modifiers = code.build_function_modifiers(method_entry.func_modifiers)
modifiers = " %s " % ' '.join(method_entry.func_modifiers).upper() code.putln("static %s%s;" % (modifiers, declaration))
modifiers = modifiers.replace(" INLINE ", " CYTHON_INLINE ")
else:
modifiers = " "
code.putln("static%s%s;" % (modifiers, declaration))
def generate_objstruct_predeclaration(self, type, code): def generate_objstruct_predeclaration(self, type, code):
if not type.scope: if not type.scope:
...@@ -2336,31 +2332,28 @@ def generate_cfunction_declaration(entry, env, code, definition): ...@@ -2336,31 +2332,28 @@ def generate_cfunction_declaration(entry, env, code, definition):
if entry.used and entry.inline_func_in_pxd or (not entry.in_cinclude and (definition if entry.used and entry.inline_func_in_pxd or (not entry.in_cinclude and (definition
or entry.defined_in_pxd or entry.visibility == 'extern' or from_cy_utility)): or entry.defined_in_pxd or entry.visibility == 'extern' or from_cy_utility)):
if entry.visibility == 'extern': if entry.visibility == 'extern':
storage_class = "%s " % Naming.extern_c_macro storage_class = Naming.extern_c_macro
dll_linkage = "DL_IMPORT" dll_linkage = "DL_IMPORT"
elif entry.visibility == 'public': elif entry.visibility == 'public':
storage_class = "%s " % Naming.extern_c_macro storage_class = Naming.extern_c_macro
dll_linkage = "DL_EXPORT" dll_linkage = "DL_EXPORT"
elif entry.visibility == 'private': elif entry.visibility == 'private':
storage_class = "static " storage_class = "static"
dll_linkage = None dll_linkage = None
else: else:
storage_class = "static " storage_class = "static"
dll_linkage = None dll_linkage = None
type = entry.type type = entry.type
if entry.defined_in_pxd and not definition: if entry.defined_in_pxd and not definition:
storage_class = "static " storage_class = "static"
dll_linkage = None dll_linkage = None
type = CPtrType(type) type = CPtrType(type)
header = type.declaration_code(entry.cname, header = type.declaration_code(
dll_linkage = dll_linkage) entry.cname, dll_linkage = dll_linkage)
if entry.func_modifiers: modifiers = code.build_function_modifiers(entry.func_modifiers)
modifiers = "%s " % ' '.join(entry.func_modifiers).upper() code.putln("%s %s%s; /*proto*/" % (
else:
modifiers = ''
code.putln("%s%s%s; /*proto*/" % (
storage_class, storage_class,
modifiers, modifiers,
header)) header))
......
...@@ -2135,11 +2135,7 @@ class CFuncDefNode(FuncDefNode): ...@@ -2135,11 +2135,7 @@ class CFuncDefNode(FuncDefNode):
else: else:
storage_class = "" storage_class = ""
dll_linkage = None dll_linkage = None
modifiers = "" modifiers = code.build_function_modifiers(self.entry.func_modifiers)
if 'inline' in self.modifiers:
self.modifiers[self.modifiers.index('inline')] = 'cython_inline'
if self.modifiers:
modifiers = "%s " % ' '.join(self.modifiers).upper()
header = self.return_type.declaration_code(entity, dll_linkage=dll_linkage) header = self.return_type.declaration_code(entity, dll_linkage=dll_linkage)
#print (storage_class, modifiers, header) #print (storage_class, modifiers, header)
......
PYTHON setup.py build_ext --inplace
PYTHON -c "import a; assert a.test() == 1"
######## setup.py ########
from Cython.Build.Dependencies import cythonize
from distutils.core import setup
setup(
ext_modules = cythonize("a.py"),
)
######## a.py ########
def inlined_func(x):
return x
def test():
return inlined_func(1)
######## a.pxd ########
cdef inline int inlined_func(int x)
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