[Matrix-SIG] problems pickling arrays of PyObjects

Alan Grossfield alan@groucho.med.jhmi.edu
Fri, 23 Oct 1998 10:20:01 -0400


    I think I've found a fairly serious problem with Numeric's pickler:
when you try to use it on arrays of arbitrary objects, it sometimes will
cause a core dump either upon unpickling or upon access to the array
after unpickling.

Consider the following test:


m Numeric import *

class test:
    def __init__(self,a,b):
        self.a=a
        self.b=b


if __name__ == '__main__':
    a=5
    b=7
    t=test(a,b)
    print 'Create instance t of class test --'
    print 't.a=',t.a, 't.b=', t.b

    t2=test(b,a)
    print t2.a, t2.b
    print 'Create instance t2 of class test --'
    print 't2.a=',t2.a, 't2.b=', t2.b
    
    arr=array( [t,t2] )
    print 'Create array arr = array( [t,t2] )'
    print arr
    

    file=open('array.pick', 'w')
    p=Pickler(file)
    p.dump(arr)
    file.close()
    print 'Pickle arr using Numeric pickler'
    
# cut here
    file=open('array.pick', 'r')
    u=Unpickler(file)
    arr2=u.load()
    print 'Extract arr to arr2 using Numeric'
    print arr2
    # dump core on the print
    print 'I managed to extract arr2'


If you just run this as a single script, it works fine.  However, if,
after creating the pickle using this script, you then use last piece
(below #cut here) to unpickle, you'll get a core dump either on the load()
or on the print.  There seems to be some architecture dependence here --
using Konrad's latest distribution under Irix 6.2, the core dump comes upon
access, while using the RPMs from Oliver Andrich's page on Redhat 5.0 the dump comes on load.

Thanks,

Alan Grossfield
--------------------------------------------------------------------------
|"In theory, there is no difference between theory and practice.  In     |
|practice, there is."   Jan L.A. van de Snepscheut                       |
--------------------------------------------------------------------------