[Bf-python] Python 2.2 Type API changes

Yann Vernier yann at algonet.se
Mon Jul 19 00:25:31 CEST 2004


Since Python 2.2, it has been possible to pass attributes in the form of
two lists - one for simple structure members, tp_members, and one for
those requiring functions to define their behaviour, tp_getset. These
fields come right after tp_methods. Together, they make the long lists
of string tests in getattr/setattr unnecessary, which I think must be an
advantage. No need to write a separate list of available attributes for
dir(), and try reading object.EffZoinks to see what slight assumptions
can do. It's also possible to subclass types if written right.

Unfortunately, this interface comes with poor examples and less
documentation. One copy of the example is at
http://python.active-venture.com/ext/node23.html

I've written a partial conversion of Object.c, diff at:
http://donkey.dyndns.org/~yann/blender/Object.c.diff1

Note that the use of PyType_Ready is required. This diff only exchanges
getattr for a getset list; setattr is untouched but can be similarly
converted. Sorry about the macros, I just got too tired of copying the
same stuff.

Again I ran into a crash bug in the original:
 Object_CreatePyObject does not check for NULL. getattr(track)
 didn't, either. Reading object.track in Python for an object
 which is not tracking crashed Blender.

-- 
PGP fingerprint = 9242 DC15 2502 FEAB E15F  84C6 D538 EC09 5380 5746
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20040719/72bf2321/attachment.sig>


More information about the Bf-python mailing list