data members. I wrote __getstate__() and __setstate__ in C++ (I have
to, due to the private data). Pickling writes the following file:
ccopy_reg
_reconstructor
p1
(cpyramid
MidiBytes
p2
c__builtin__
object
p3
NtRp4
(S'some unknown MidiBytes'
I1
I2
I3
tb.
But when unpickling I get the following error
TypeError: in method 'MidiBytes___se tstate__', argument 1 of type
'pyramid::MidiB ytes *'
I debugged the swig wrapper and indeed the wrapper is called with just
one tuple argument. No object seems to be present at the time.
All the examples I've seen use python functions for __getstate__ and
__setstate__ and it seems to me that the object itself is already there
when __setstate__ is called.
In a moment of dispair I declared __setstate__() static and have it
create and return a MidiBytes object.
MidiBytes *MidiBytes:: __setstate__ (PyObject * aTuple) {
return new MidiBytes();
}
Then unpickling no longer complains about "argument 1", but the
unpickled object does not work
Traceback (most recent call last):>>nn = cPickle.load(FI LE)
nn.len()
File "<stdin>", line 1, in ?
File "/usr/src/sound.d/pyramid/pyramid.py", line 618, in len
return _pyramid.MidiBy tes_len(*args)
TypeError: in method 'MidiBytes_len' , argument 1 of
type 'pyramid::MidiB ytes *'
whereas the original object behaves well
0>>n = pyramid.MidiByt es()
n.len()
Am I missing something obvious ?