On Fri Feb 13 2015 at 2:23:45 PM Stefan Behnel <stefan...@behnel.de> wrote:
> Ulrich Dobramysl schrieb am 11.02.2015 um 09:56: > > From what I've been able to work out, the problem seems to be that the > call > > to "t()" is treated as a NameNode in ExprNodes.py and not an > AttributeNode. > > However, I don't know enough about Cython's internals to track where > > exactly this decision is made. > > > > Curiously, this bug isn't always triggered in more complex situations. I > > had a larger pxd file with multiple external declarations where one class > > operator() was treated correctly, while others weren't. I haven't been > able > > to find out why this was the case. > > It happens only with stack allocated C++ objects, not with heap objects > (i.e. pointers). That can be used as a work-around, I guess. > > 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. Is there a special syntax for calling cython "function pointers"? The trick dereference(t)() doesn't work either. However, one thing that works is if the (stack-allocated) called object is not a local variable (a NameNode), but an attribute of some object (an AttributeNode). 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 return entry.cname def generate_result_code(self, code): --- But I have no idea what other side effects that might have. Ulrich
_______________________________________________ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel