On 18 June 2012 13:42, Dmitry Trofimov <
trofimo...@gmail.com> wrote:
> I have following test.pyx
>
> cdef public class Foo[object Foo, type FooType]:
> cdef public char* foo(self):
> r = "Foo"
> return r
>
> Cython compiles that code to test.h and test.c and everything looks fine,
> but I can't figure out how to create Foo object from C-code.
>
> Even if I create it using Cython function:
>
> cdef public Foo create_Foo():
> return Foo()
>
> I can't figure out how to invoke foo method.
>
> While Cython documentation says that it is possible, example is missing.
>
> Thanks.
Public should probably be disallowed for methods, since calling the
functions directly would break subclassing. It's probably easiest to
do in Cython, as Stefan suggested. To elaborate a bit, if you need to
invoke the method from C, write a wrapper function for each method
that takes the object as extra argument, and invoke the method. E.g.
cdef char *foo_wrapper(Foo obj):
return obj.foo()
It's inconvenient if you have many methods, so if you have control
over the design of Foo to begin with, don't use methods but use
functions instead.
BTW, great work on the PyCharm debugger, it's awesome. I only
sometimes wish it were faster, but I presume it's slow due to the
Python tracing. Completely OT, but a post-mortem feature would be
great, since it allows the process to run untraced and start the
debugger on uncaught exceptions.