Python/C API question

User audun audun at stud.cs.uit.no
Tue May 2 04:55:52 EDT 2000


I'm working on a Python module written in C, and I keep getting 
impressed by Python's design and it's C/C++ API. However, I find the 
"Python/C API Reference Manual" and the "Extending and embedding" 
manuals weak on one point: The exact protocol in defining custom type 
objects. My implementation has therefore been largely influenced by 
the Python source code on these on this. There is one detail I'd like 
to ask about.

Let's say I've constructed (in C) a Python object of type ekkiekki. In 
the file ekkiekki.c I've defined the methods associated with the object 
in a PyMethodDef structure that is used by ekkiekki's setattr and 
getattr functions. Furthermore, let's imagine that the method static 
PyObject * tapang(self, args) is such a method associated with ekkiekki. 
My question is then: Is it wise and/or necessary to do any type checking 
on the self-argument in such built-in methods (as in calling a 
Ekkiekki_Check(self))? And what about setattr/getattr and the other 
"basic" methods defined in ekkiekki's PyTypeObject-structure? Does the 
interpreter make any guarantees about "who" being able to call an 
object's internal methods?


Note: In the above I've tried to use naming conventions from the Python 
sourcecode for clarity. I hope it helped :)

I tried to look elsewhere for these answers without luck. If these 
questions have been answered elsewhere, I apologize.

Regards,

__ 
Audun Nordal



More information about the Python-list mailing list