question about handling pointers in C extensions

Harald Kirsch kirschh at lionbioscience.com
Thu Jul 26 03:17:47 EDT 2001


"Russell E. Owen" <owen at astrono.junkwashington.emu> writes:

> You and Chris Liechti both then go on to suggest creating a new Python 
> type. I'm a bit confused here. This would create a Python class or an 
> actual new Python data type? "Python Essential Reference" makes creating 
> a new data type scary, but I haven't been able to figure out if that 
> applies equally to creating a Python object.

I don't think so. If you look into your Python sources you'll find the
file Modules/xxmodule.c. It is intended as a template. Going from
top to bottom I took care mainly of

-- defining my own XxoObject
-- a function to create such an object, like newXxoObject
-- a corresponding Xxo_dealloc
-- some functions working with this object
-- you can actually skip setattr and getattr needs only call
   Py_FindMethod such that in your python code you can write

     x = aNewOneOfMyObjectType()    # calls newXxoObject
     x.doSomeThing()             <---- via Py_FindMethod

   You don't need setattr at the beginning.
-- defining my Xxo_Type. I you can set the getattr, setattr there to
   NULL.
-- the xx_methods jumptable.
-- the initialization.

  Harald Kirsch
-- 
----------------+------------------------------------------------------
Harald Kirsch   | kirschh at lionbioscience.com | "How old is the epsilon?"
LION bioscience | +49 6221 4038 172          |        -- Paul Erdös
       *** Please do not send me copies of your posts. ***



More information about the Python-list mailing list