A bug in cPickle?

"Martin v. Löwis" martin at v.loewis.de
Thu May 17 12:46:00 EDT 2007


> This does seem odd, at the very least.

The differences between the pn codes comes from this comment in cPickle.c:

        /* Make sure memo keys are positive! */
        /* XXX Why?
         * XXX And does "positive" really mean non-negative?
         * XXX pickle.py starts with PUT index 0, not 1.  This makes for
         * XXX gratuitous differences between the pickling modules.
         */
        p++;

The second difference (where sometimes p1 is written and sometimes not)
comes from this block in put:

	if (ob->ob_refcnt < 2 || self->fast)
		return 0;

Here, a reference to the object is only marshalled if the object has
more than one reference to it. The string literal does; the dynamically
computed string does not. If there is only one reference to an object,
there is no need to store it in the memo, as it can't possibly be
referenced later on.

Regards,
Martin



More information about the Python-list mailing list