[Cython] operator() bug in cython

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Feb 14 00:07:13 CET 2015


Ulrich Dobramysl wrote:

> Thanks! I haven't figured out how to call heap allocated objects, as the 
> code
> ---
> cdef OperatorTest *t = new OperatorTest()
> t()
> ---
> is not translatable by Cython.

Have you tried:

    t[0]()

?

> A quick and dirty fix for this would be this patch 
> for NameNode.calculate_result_code:
> ---
> diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py
> index f99ec6e..f894a64 100644
> --- a/Cython/Compiler/ExprNodes.py
> +++ b/Cython/Compiler/ExprNodes.py
> @@ -1904,6 +1904,8 @@ class NameNode(AtomicExprNode):
>          entry = self.entry
>          if not entry:
>              return "<error>" # There was an error earlier
> +        if entry.cname=='operator()':
> +            return self.name <http://self.name>
>          return entry.cname

I haven't been following the development of Cython's internals,
so I may be speaking naively here, but it looks wrong to me that
the cname of that entry should be 'operator()' rather than the
c-level name of the variable that the NameNode refers to.

-- 
Greg


More information about the cython-devel mailing list