[Cython] Cython produces invalid code for operator()

Michael Enßlin michael at ensslin.cc
Thu Jun 11 18:03:32 CEST 2015


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20150611/868f5dad/attachment.sig>


More information about the cython-devel mailing list