[Patches] marshalling recursive objects

Vladimir Marangozov Vladimir.Marangozov@inrialpes.fr
Sat, 13 May 2000 18:29:45 +0200 (CEST)


Guido van Rossum wrote:
> 
> I'm not sure I like it to write different marshalling strings for data
> structures that aren't recursive.
> 
> Here's an example:
> 
> >>> a = []
> >>> b = [a,a,a]
> >>> marshal.dumps(b)
> '[\003\000\000\000[\000\000\000\000o\001\000\000\000o\001\000\000\000'
> >>> 
> 
> Before your patch, this produced:
> 
> '[\003\000\000\000[\000\000\000\000[\000\000\000\000[\000\000\000\000'
> 
> ...
>
> I'm not sure how to fix it -- if the easiest solution is to raise an
> exception for recursive objects, that's fine.  (It's a heck of a lot
> better than Memory fault!)

Agreed.

Both of these can be implemented:

1) Handle recursions by preserving the current rules, i.e. add
   additional processing for recursions only (the 'o' type). This
   preserves backwards compatibility, but marshalled recursion objects
   in the new version won't be readable by older versions.
   I actually implemented this one.

>>> a = []
>>> b = [a,a,a]
>>> marshal.dumps(b)
'[\003\000\000\000[\000\000\000\000[\000\000\000\000[\000\000\000\000'
>>>
>>> a.append(b)
>>> marshal.dumps(b)
'[\003\000\000\000[\001\000\000\000o\000\000\000\000[\001\000\000\000o\000\000\000\000[\001\000\000\000o\000\000\000\000'

2) Remain conservative and raise a "recursive object cannot be marshalled"
   exception.

Which one is better?

-- 
       Vladimir MARANGOZOV          | Vladimir.Marangozov@inrialpes.fr
http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252