Python/C API question

Will Ware wware at world.std.com
Tue May 2 08:09:31 EDT 2000


User audun (audun at stud.cs.uit.no) wrote:
> ... 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.

The Python sources really are the best available information. Most of
what you want to know will be in the example provided (Objects/xxobject.c,
if memory serves). For the rest, peek around Objects/*.c and Modules/*.c.

> ... 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?

I'm not sure if it's necessary. It's almost certainly wise. The only
argument against it is performance, but it's likely to impose a very tiny
performance penalty. If you really wanted to be able to get rid of it,
you might wrap it in an #ifdef so you could shut it off, once you'd tested
several possible trouble cases.

> Does the 
> interpreter make any guarantees about "who" being able to call an 
> object's internal methods?

That I don't know. I think I've been foolhardy enough not to typecheck
the self argument in C modules I've written, without ever running into
trouble.

-- 
 - - - - - - - - - - - - - - - - - - - - - - - -
Resistance is futile. Capacitance is efficacious.
Will Ware	email:    wware @ world.std.com



More information about the Python-list mailing list