Commit 184f7edc authored by Stefan Behnel's avatar Stefan Behnel

do not create (potentially unused) C function coercion code when all we do is ask if it's possible

parent afb84985
...@@ -2650,12 +2650,25 @@ class CFuncType(CType): ...@@ -2650,12 +2650,25 @@ class CFuncType(CType):
assert not self.is_fused assert not self.is_fused
specialize_entry(entry, cname) specialize_entry(entry, cname)
def create_to_py_utility_code(self, env): def can_coerce_to_pyobject(self, env):
# FIXME: it seems we're trying to coerce in more cases than we should # duplicating the decisions from create_to_py_utility_code() here avoids writing out unused code
if self.has_varargs or self.optional_arg_count: if self.has_varargs or self.optional_arg_count:
return False return False
if self.to_py_function is not None: if self.to_py_function is not None:
return self.to_py_function return self.to_py_function
for arg in self.args:
if not arg.type.is_pyobject and not arg.type.can_coerce_to_pyobject(env):
return False
if not self.return_type.is_pyobject and not self.return_type.can_coerce_to_pyobject(env):
return False
return True
def create_to_py_utility_code(self, env):
# FIXME: it seems we're trying to coerce in more cases than we should
if self.to_py_function is not None:
return self.to_py_function
if not self.can_coerce_to_pyobject(env):
return False
from .UtilityCode import CythonUtilityCode from .UtilityCode import CythonUtilityCode
import re import re
safe_typename = re.sub('[^a-zA-Z0-9]', '__', self.declaration_code("", pyrex=1)) safe_typename = re.sub('[^a-zA-Z0-9]', '__', self.declaration_code("", pyrex=1))
...@@ -2664,8 +2677,7 @@ class CFuncType(CType): ...@@ -2664,8 +2677,7 @@ class CFuncType(CType):
for arg in self.args: for arg in self.args:
if not arg.type.is_pyobject and not arg.type.create_from_py_utility_code(env): if not arg.type.is_pyobject and not arg.type.create_from_py_utility_code(env):
return False return False
if not (self.return_type.is_pyobject or self.return_type.is_void or if not self.return_type.is_pyobject and not self.return_type.create_to_py_utility_code(env):
self.return_type.create_to_py_utility_code(env)):
return False return False
def declared_type(ctype): def declared_type(ctype):
......
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