[ZODB-Dev] subclassing Persistent in C

Jeremy Hylton jeremy at zope.com
Thu May 1 19:40:03 EDT 2003


On Thu, 2003-05-01 at 14:28, Nicholas Henke wrote:
> On Thu, 2003-05-01 at 14:22, Jeremy Hylton wrote:
> > 
> > The example you extracted from your real code is incomplete, so it's
> > hard to see what is really happening.  (I don't know the ExtensionClass
> > details very well, so it helps to see all the code.)
> 
> I am a bit confused there -- which code is incomplete -- the test.py or
> PerWrap.c ?

test.py says "from IndexedCatalog import PerWrapper".
I don't see how that code would work.

There's also the TypeError I reported.  I don't see how you could have
created one of these objects, so I don't see how you could know there
was a bug :-).

> > It's hard to guess what you want PerWrapper to do, so it's not clear
> > what is wrong with it.  For one thing, you haven't defined a tp_dealloc
> > slot, so you can't actually create one.
> 
> I am hoping to use it as a drop-in replacement for Persistent that I can
> add methods to for increasing performance. 

> Is there a proper way to subclass Persistent, instead of creating a new
> type and using its CAPI methods? tp_dealloc is not one of those, and I
> am not sure how I could use the methods defined in cPersistence.c -- or
> for that matter if that is even appropriate.
> 

The BTrees code is probably the best example, but I don't understand all
the ExtensionClass mechanism in ZODB3.  We may need to ask Jim Fulton,
unless we can find some other ExtensionClass experts on the list.  This
should all be much easier in ZODB4, because Persistent is just a type.

For the specific case of tp_dealloc, your dealloc function needs to call
PER_DEL() before freeing the memory.

There are lots of little details to get right, I'm sure.  The BTrees
code does everything that is necessary, but may be hard to separate the
necessary parts from the BTree-specific parts.

Jeremy





More information about the ZODB-Dev mailing list