[ZODB-Dev] subclassing Persistent in C

Nicholas Henke henken at seas.upenn.edu
Thu May 1 18:51:32 EDT 2003


Hey all, I am attempting to subclass/extend the Persistent Class found
in ZODB (cPersistence.c). I have looked through the BTrees code, as well
as Extension.[ch] and come up with my 'PerWrapper' module and class. It
_should_ be a transparent class that behaves exactly like Persistent,
and apparently it does save one thing: it seg faults. I have attached a
sample program that will trigger the segv every time in the exact same
place.This is all using python2.2.2, ZODB3-3.1.1,

The segv will happen in DB.py, in _connectionMap, where it tried to
access ob.__class__ ( quoted inline here ):

    def cacheDetail(self):
        """Return information on objects in the various caches

        Organized by class."""

        detail = {}
        def f(con, detail=detail, have_detail=detail.has_key):
            for oid, ob in con._cache.items():
                module = getattr(ob.__class__, '__module__', '')
                module = module and '%s.' % module or ''
                c = "%s%s" % (module, ob.__class__.__name__)
                if have_detail(c):
                    detail[c] = detail[c] + 1
                else:
                    detail[c] = 1

        self._connectionMap(f)

It appears from the gdb output below that ob in this case hase been
garbage collected prematurely, or the cache is not storing it correctly.
I know I must have missed something in the PerWrapper.c -- I have
commented it to indicate what I understand, and more importantly what I
do not understand.
I have placed the output of gdb below:
(gdb) r test.py db
Starting program: /usr/bin/python2.2 test.py db
[New Thread 1024 (LWP 4923)]
400
256708
2003

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1024 (LWP 4923)]
0x00000002 in ?? ()
(gdb) bt
#0  0x00000002 in ?? ()
#1  0x0807f868 in eval_frame (f=0x83478f4) at Python/ceval.c:1784
#2  0x0808182b in PyEval_EvalCodeEx (co=0x817f948, globals=0x8140444,
locals=0x0, args=0x829968c, argcount=1, kws=0x8299690, kwcount=0,
defs=0x831b660, defcount=2, closure=0x0)
    at Python/ceval.c:2595
#3  0x08082c8b in fast_function (func=0x833da24, pp_stack=0xbffff454,
n=1, na=1, nk=0) at Python/ceval.c:3173
[SNIPPED]

(gdb) up
#1  0x0807f868 in eval_frame (f=0x83478f4) at Python/ceval.c:1784
1784                            x = PyObject_GetAttr(v, w);
(gdb) p PyObject_Print(v, stderr,0)

Program received signal SIGSEGV, Segmentation fault.
0x083624b0 in ?? ()
The program being debugged was signaled while in a function called from
GDB.
GDB remains in the frame where the signal was received.
To change this behavior use "set unwindonsignal on"
Evaluation of the expression containing the function (PyObject_Print)
will be abandoned.
(gdb) up
#1  <function called from gdb>
(gdb) up
#2  0x00000002 in ?? ()
(gdb) up
#3  0x0807f868 in eval_frame (f=0x83478f4) at Python/ceval.c:1784
1784                            x = PyObject_GetAttr(v, w);
(gdb) p PyObject_Print(w, stderr,0)
'__class__'$1 = 0
(gdb) p *f->f_code
$3 = {ob_refcnt = 3, ob_type = 0x8100580, co_argcount = 3, co_nlocals =
7, co_stacksize = 5, co_flags = 3, co_code = 0x817f7f0, co_consts =
0x817f8cc, co_names = 0x817f904,
  co_varnames = 0x817fb14, co_freevars = 0x8116ca4, co_cellvars =
0x8116ca4, co_filename = 0x817fc38, co_name = 0x817fc80, co_firstlineno
= 165, co_lnotab = 0x817fca0}
(gdb) p PyObject_Print(f->f_code->co_filename, stderr, 0)
'/usr/lib/python2.2/site-packages/ZODB/DB.py'$6 = 0



-- 
Nicholas Henke
Penguin Herder & Linux Cluster System Programmer
Liniac Project - Univ. of Pennsylvania
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.py
Type: application/x-python
Size: 823 bytes
Desc: not available
Url : http://lists.zope.org/pipermail/zodb-dev/attachments/20030501/f8532864/test.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: _PerWrap.c
Type: text/x-csrc
Size: 2612 bytes
Desc: not available
Url : http://lists.zope.org/pipermail/zodb-dev/attachments/20030501/f8532864/_PerWrap.bin


More information about the ZODB-Dev mailing list