<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Mon, Jun 22, 2015 at 3:13 PM Ian Henriksen <<a href="mailto:insertinterestingnamehere@gmail.com">insertinterestingnamehere@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Tue, Feb 17, 2015 at 2:51 AM Ulrich Dobramysl <<a href="mailto:uli-do@gmx.at" target="_blank">uli-do@gmx.at</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote">On Fri Feb 13 2015 at 11:07:39 PM Greg Ewing <<a href="mailto:greg.ewing@canterbury.ac.nz" target="_blank">greg.ewing@canterbury.ac.nz</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Ulrich Dobramysl wrote:<br>
<br>
> Thanks! I haven't figured out how to call heap allocated objects, as the<br>
> code<br>
> ---<br>
> cdef OperatorTest *t = new OperatorTest()<br>
> t()<br>
> ---<br>
> is not translatable by Cython.<br>
<br>
Have you tried:<br>
<br>
    t[0]()<br>
<br>
?<br></blockquote><div> </div></div></div><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div>Thanks, I didn't think about the t[0] trick!</div><div><br></div></div></div></div><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
I haven't been following the development of Cython's internals,<br>
so I may be speaking naively here, but it looks wrong to me that<br>
the cname of that entry should be 'operator()' rather than the<br>
c-level name of the variable that the NameNode refers to.<br>
<br></blockquote><div><br></div></div></div></div><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div>The cname of the entry is correct IMO, because it cannot have any knowledge about the cname of the object it is being called as later. The logic dealing with the special case of an operator() member function of a c++ class in SimpleCallNode.analyse_c_function_call() needs to be changed slightly to not treat operator() as an overloaded entry. Rather, the function type of the SimpleCallNode needs to be set to the type of the looked-up operator() entry. Then, at the code generation stage, the correct cname of the SimpleCallNode entry is used and not the entry of operator(). With the patch below my test case compiles and runs without problems:</div><div>----</div><div><div>diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py</div><div>index f99ec6e..88522c9 100644</div><div>--- a/Cython/Compiler/ExprNodes.py</div><div>+++ b/Cython/Compiler/ExprNodes.py</div><div>@@ -4569,11 +4569,13 @@ class SimpleCallNode(CallNode):</div><div>             args = self.args</div><div> </div><div>         if func_type.is_cpp_class:</div><div>-            overloaded_entry = self.function.type.scope.lookup("operator()")</div><div>-            if overloaded_entry is None:</div><div>+            call_operator = self.function.type.scope.lookup("operator()")</div><div>+            if call_operator is None:</div><div>                 self.type = PyrexTypes.error_type</div><div>                 self.result_code = "<error>"</div><div>                 return</div><div>+            self.function.type = call_operator.type</div><div>+            overloaded_entry = None</div><div>         elif hasattr(self.function, 'entry'):</div><div>             overloaded_entry = self.function.entry</div><div>         elif (isinstance(self.function, IndexNode) and</div><div>@@ -4603,7 +4605,7 @@ class SimpleCallNode(CallNode):</div><div>         else:</div><div>             entry = None</div><div>             func_type = self.function_type()</div><div>-            if not func_type.is_cfunction:</div><div>+            if not (func_type.is_cfunction or func_type.is_cpp_class):</div><div>                 error(self.pos, "Calling non-function type '%s'" % func_type)</div><div>                 self.type = PyrexTypes.error_type</div><div>                 self.result_code = "<error>"</div></div><div>----</div><div>What do you think? I don't know a lot about cython's internals, so there might be use cases which break this code.</div></div></div></div><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div><br></div><div>Ulrich</div><div><br></div></div></div></div>
_______________________________________________<br>
cython-devel mailing list<br>
<a href="mailto:cython-devel@python.org" target="_blank">cython-devel@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/cython-devel" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/cython-devel</a></blockquote><div><br></div></div></div><div dir="ltr"><div class="gmail_quote"><div>What is the status on this? The most recent patch appears to work</div><div>if the first two changed lines are ignored. If it would help move this</div><div>along, I can open a PR with the modified patch and a commit that still</div><div>attributes the patch to the original author.</div><div>Thanks!</div></div></div><div dir="ltr"><div class="gmail_quote"><div>-Ian Henriksen</div></div></div></blockquote><div><br></div><div>Alright, I've put up a pull request at</div><div><a href="https://github.com/cython/cython/pull/400">https://github.com/cython/cython/pull/400</a>.</div><div>I hope this makes things a bit easier.</div><div>-Ian Henriksen</div></div></div>