[Python-checkins] python/dist/src/Lib pickle.py,1.101,1.102
Tim Peters
tim.one@comcast.net
Tue, 28 Jan 2003 00:24:11 -0500
> Modified Files:
> =09pickle.py
> Log Message:
> More protocol 2: TUPLE1, TUPLE2, TUPLE3.
>
> Also moved the special case for empty tuples from save() to save_tu=
ple().
<relief>
> + if proto >=3D 1:
> + n =3D len(object)
> + if n <=3D 3:
> + if not object:
> + write(EMPTY_TUPLE)
> + return
> + if proto >=3D 2:
> + for element in object:
> + save(element)
> + # Subtle. Same as in the big comment below
> + if id(object) in memo:
> + get =3D self.get(memo[id(object)][0])
> + write(POP_MARK + get)
> + else:
> + write(_tuplesize2code[n])
> + return
When proto >=3D 2 and n in (1, 2, 3), the resulting tuple never gets =
memoized,
so it doesn't seem possible for "id(object) in memo" to be true. If =
it were
possible, then the POP_MARK opcode is going to look back for a MARK t=
hat was
never pushed ...
OK, if I try pickling the one-element tuple T containing a one-elemen=
t list
L containing T under proto 2, the opcodes are:
0: =C7 PROTO 2
2: ] EMPTY_LIST
3: q BINPUT 0
5: h BINGET 0
7: =E0 TUPLE1
8: a APPEND
9: =E0 TUPLE1
10: . STOP
That isn't right, but is what happens if "id(object) in memo" is neve=
r true.
I'll try to fix it.