Working example of extension class in C/C++ ?

Marc Van Riet marcvanriet at
Tue Mar 11 17:43:48 CET 2003


I recently started with making my own extension things in C/C++ for
Python.  Extension functions work OK, but I have more difficulty in
creating an extension class.

I would like to write an extension to access shared memory on Linux. 
I'd like to  implement a class with these methods :
- Attach( key, size, flags )
- Detach( )
- Write( address, value)
- Read( address ).
I also need two members to hold values required for the shared memory
routines in Linux :
- an ID
- a start address

This seems simple enough to implement without using SWIG or SIP or so
(also I'd rather not use these yet, so I get a better understanding of
the details of extending Python with C).

I've read the Python extension guide and several articles on the web.
Unfortunately I couldn't find any working example anywhere to get me
started.  The xxobject.c skeleton in the Python source is just for a
python type, not a class with an __init__ and everything (or am I
missing something ?)

Could anybody direct me to a WORKING EXAMPLE on how to do this ? Or
maybe to some skeleton code to start from ?

Any help would be greatly appreciated,

More information about the Python-list mailing list