[Cython] Cython produces invalid code for operator()
Ian Henriksen
insertinterestingnamehere at gmail.com
Thu Jun 11 20:19:41 CEST 2015
On Thu, Jun 11, 2015 at 10:09 AM Michael Enßlin <michael at ensslin.cc> wrote:
> Hi guys,
>
> have a look at this:
>
> $ cat bar.pyx
> cdef extern from "foo.h":
> cdef cppclass Foo:
> int operator() (int arg)
> int do_call (int arg)
>
>
> cdef int bar(int arg):
> cdef Foo foo
> foo.do_call(arg)
> return foo(arg)
>
> $ cython3 --cplus bar.pyx
> $ cat bar.cpp
>
> (...)
>
> static int __pyx_f_3bar_bar(int __pyx_v_arg) {
> Foo __pyx_v_foo;
> int __pyx_r;
> __Pyx_RefNannyDeclarations
> __Pyx_RefNannySetupContext("bar", 0);
>
> /* "bar.pyx":9
> * cdef int bar(int arg):
> * cdef Foo foo
> * foo.do_call(arg) # <<<<<<<<<<<<<<
> * return foo(arg)
> */
> __pyx_v_foo.do_call(__pyx_v_arg);
>
> /* "bar.pyx":10
> * cdef Foo foo
> * foo.do_call(arg)
> * return foo(arg) # <<<<<<<<<<<<<<
> */
> __pyx_r = operator()(__pyx_v_arg);
> goto __pyx_L0;
>
> /* "bar.pyx":7
> *
> *
> * cdef int bar(int arg): # <<<<<<<<<<<<<<
> * cdef Foo foo
> * foo.do_call(arg)
> */
>
> /* function exit code */
> __pyx_L0:;
> __Pyx_RefNannyFinishContext();
> return __pyx_r;
> }
>
> (...)
>
>
>
> Note how the function invocation for "do_call" is generated correctly,
> but the invocation of operator() is nonsensical.
>
> The correct line would be this:
>
> __pyx_r = __pyx_v_foo(__pyx_v_arg);
>
> Happy debugging :D
>
> ~ mic_e
>
> _______________________________________________
> cython-devel mailing list
> cython-devel at python.org
> https://mail.python.org/mailman/listinfo/cython-devel
There was a patch for this in
https://mail.python.org/pipermail/cython-devel/2015-February/004328.html.
I'm not sure what ever became of it though. I wrote up a workaround on SO
at http://stackoverflow.com/a/25955546/1935144 a while ago.
Best of luck!
-Ian Henriksen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20150611/10a9473a/attachment.html>
More information about the cython-devel
mailing list