pickle vs .pyc

Hrvoje Niksic hniksic at srce.hr
Thu Jun 3 04:53:22 EDT 1999


Michael Hudson <mwh21 at cam.ac.uk> writes:

> Yes, but usually you get an exception to show that somethings gone
> awry:
> 
> >>> import md5
> >>> marshal.loads(marshal.dumps(md5.md5()))
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> ValueError: unmarshallable object

A good point.  However, that is exactly the kind of behaviour I get
for array objects -- in Python 1.5.1.  In 1.5.2, I can repeat the bug
you describe.  Maybe 1.5.2 is supposed to allow marshalling arrays,
but the support is buggy?

<search search grep grep>

OK, I think I got it.  In 1.5.2, marshal.c contains this code:

	else if ((pb = v->ob_type->tp_as_buffer) != NULL &&
		 pb->bf_getsegcount != NULL &&
		 pb->bf_getreadbuffer != NULL &&
		 (*pb->bf_getsegcount)(v, NULL) == 1)
	{
		/* Write unknown buffer-style objects as a string */
		char *s;
		w_byte(TYPE_STRING, p);
		n = (*pb->bf_getreadbuffer)(v, 0, (void **)&s);
		w_long((long)n, p);
		w_string(s, n, p);
	}

...which means that objects with tp_as_buffer property (whatever that
means) get marshalled as strings.  This wasn't the case in 1.5.1 and I
have no idea why it would be useful to anyone because during
unmarshalling, such simply remain strings instead of getting converted
to the original form.  Not that the conversion would work across
different architectures anyway.

I'm not sure what the new feature is supposed to buy us, but 1.5.1
behaviour looks more correct to me.




More information about the Python-list mailing list