[Pyrex] C++, references, deref a pointer...

John Sutherland garionphx at gmail.com
Fri Apr 7 20:52:42 CEST 2006


Hi all... I've been working with Lenard's C++ patches, and found one  
problem, and have some other questions..

The problem I found is when trying his example to wrap C++ methods  
from a previous post (in repsonse to someone else's C++ wrapper).. I  
wasn't able to get it to recongize  the C++ methods of a class.. i  
would get errors say that it the class stucture didn't have that  
attirbute.. So I had to modify Compler/ExprNodes.py to handle it:

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:

then I was able to compile, and it seems to work..

Now for my questions...
I have a couple classes I'm wrapping where one of them takes a  
reference to the other, and I can't seem to figure out the magic to  
get it to work...

Example (not from actaul code. forgive mistakes):

class Record {
	Record()
	~Record()
}

class Set {
	Set()
	~Set()
	addRecord( Record& )
}

Python:
cdef extern from "../rrec.h":
	ctypedef struct record "Record":
		<sturct full of functions>
	record *myRecordFactory "new Record" ()

cdef extern from "../rrset.h":
     ctypedef struct rrset "RRSet":
         int addRecord "addRecord" ( record )
     rrset *myRRSetFactory "new RRSet" ()

cdef class Record:
     cdef rrec *thisptr

     def __init__(self):
         self.thisptr = myRecordFactory()


cdef class RRSet:
	cdef rrset *thisptr
     def __init__(self):
         self.thisptr = myRRSetFactory()

     def addRR( self, RRec rr not None):
         self.thisptr.addRR( <rrec>rr.thisptr )
	
I can't seem to figure out the mojo to get the cast right... I can't  
seem to deref the pointer, or be able to get a reference...


Any ideas?
	




More information about the Pyrex mailing list