[Pyrex] Re: C++, references, deref a pointer...
Lenard Lindstrom
len-l at telus.net
Mon Apr 10 00:09:45 CEST 2006
On 8 Apr 2006 at 12:25, John Sutherland wrote:
> <Sorry for being non-threaded.. My procmail rules seem to have eaten
> your response..>
>
> >> Approx line 1576 was:
> >> if entry.is_variable or entry.is_cmethod:
> >> to
> >> if entry.is_variable or entry.is_cmethod or entry.is_cfunction:
> >>
> >I do not understand this change. An extension class attribute cannot
> >be a C function. It can be a C function pointer, which is just a C
> >attribute. See below.
>
> I was actaully, trying to follow an older example you had done here:
> http://lists.copyleft.no/pipermail/pyrex/2005-November/001518.html
>
In the example:
ctypedef struct myclass "MyClass":
int dosomething(float arg)
should have been:
ctypedef struct myclass "MyClass":
int (* dosomething)(float arg)
I apologize for the typo and the confusion it has caused. My patches
were never intended to add C++ features to the Pyrex language.
Fortunately, tricks such as declaring C++ methods as Cstructure
field function pointers and using C name specifiers such as "new
SomeClass" allow one to do method calls as well as deal with
overloaded functions and operators. It is cheating a little, but it
does avoid the necessity of writing C++ wrapper code when one does
not have to handle C++ exceptions.
> In order for that to work, I had to add that small hack.. As I said,
> it worked for me..
>
Neat.
[snip]
> void (*test1 "test") (int)
> void (*test2 "test") (float)
[snip]
>
> cdef class Test
> def __init__(self):
> self.thisptr = TestFactory()
> def test1(self,i):
> self.thisptr.test1(i)
> def test2(self,a,b):
> self.thisptr.test2(a,b)
>
> I'm sure there's other ways, but this is how *i* solved it for now :)
>
This is the only way I know to handle function/method overloading in
Pyrex.
I guess I could have included a quick guide to using C++ within Pyrex
with one of my patches. But then the first patch was simply to get
some Pyrex module, any module, to compile as C++. The second patch
was to get Pyrex to pass its test suite in C++. Between the two the
idea never occurred to me. However, the cpptest.pyx example included
with the first patch covers what I know.
Lenard Lindstrom
<len-l at telus.net>
More information about the Pyrex
mailing list