| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
| |
_reconstructor (whose import here is a mystery to me).
|
|
|
|
|
| |
if it exists in preference over __reduce__. Now Tim can go implement this
in cPickle.c.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
the optional proto 2 slot state.
pickle.py, load_build(): CAUTION: Noted that cPickle's
load_build and pickle's load_build really don't do the same
things with the state, and didn't before this patch either.
cPickle never tries to do .update(), and has no backoff if
instance.__dict__ can't be retrieved. There are no tests
that can tell the difference, and part of what cPickle's
load_build() did looked accidental to me, so I don't know
what the true intent is here.
pickletester.py, test_pickle.py: Got rid of the hack for
exempting cPickle from running some of the proto 2 tests.
dictobject.c, PyDict_Next(): documented intended use.
|
| |
|
|
|
|
|
| |
attempts to merge the C list-batch and dict-batch code -- they worked, but
it was a godawful mess to read.
|
| |
|
| |
|
|
|
|
| |
pickle.py, where it makes save_newobj() unnecessary. Tests pass.
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
|
|
| |
this clarifies that they are part of an internal API (albeit shared
between pickle.py, copy_reg.py and cPickle.c).
I'd like to do the same for copy_reg.dispatch_table, but worry that it
might be used by existing code. This risk doesn't exist for the
extension registry.
|
|
|
|
|
|
|
| |
outcome as __slotnames__ on the class. (Like __slots__, it's not safe
to ask for this as an attribute -- you must look for it in the
specific class's __dict__. But it must be set using attribute
notation, because __dict__ is a read-only proxy.)
|
|
|
|
| |
slots even though they can be listed in __slots__.
|
| |
|
|
|
|
| |
overflow holes in Pdata_grow().
|
|
|
|
|
| |
power of 2. Enabled the tail end of test_long() in pickletester.py
because it no longer takes forever when run from test_pickle.py.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Assorted code cleanups; e.g., sizeof(char) is 1 by definition, so there's
no need to do things like multiply by sizeof(char) in hairy malloc
arguments. Fixed an undetected-overflow bug in readline_file().
longobject.c: Fixed a really stupid bug in the new _PyLong_NumBits.
pickle.py: Fixed stupid bug in save_long(): When proto is 2, it
wrote LONG1 or LONG4, but forgot to return then -- it went on to
append the proto 1 LONG opcode too.
Fixed equally stupid cancelling bugs in load_long1() and
load_long4(): they *returned* the unpickled long instead of pushing
it on the stack. The return values were ignored. Tests passed
before only because save_long() pickled the long twice.
Fixed bugs in encode_long().
Noted that decode_long() is quadratic-time despite our hopes,
because long(string, 16) is still quadratic-time in len(string).
It's hex() that's linear-time. I don't know a way to make decode_long()
linear-time in Python, short of maybe transforming the 256's-complement
bytes into marshal's funky internal format, and letting marshal decode
that. It would be more valuable to make long(string, 16) linear time.
pickletester.py: Added a global "protocols" vector so tests can try
all the protocols in a sane way. Changed test_ints() and test_unicode()
to do so. Added a new test_long(), but the tail end of it is disabled
because it "takes forever" under pickle.py (but runs very quickly under
cPickle: cPickle proto 2 for longs is linear-time).
|
|
|
|
| |
code cleanups, and purged more references to text-vs-binary modes.
|
|
|
|
|
| |
Add a feature suggested by Tim: a negative protocol value means to use
the largest protocol value supported.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The 4th item can be None or an iterator yielding list items, which are
used to append() or extend() the object. The 5th item can be None or
an iterator yielding a dict's (key, value) pairs, which are stuffed
into the object using __setitem__.
Also (as a separate, though related, feature) add "batching" for list
and dict items. If you pickled a dict or list with a million items in
the past, it would push a million items onto the stack. It now pushes
only 1000 items at a time on the stack, using repeated APPENDS or
SETITEMS opcodes. (For lists, I hope that using many short extend()
calls doesn't exhibit quadratic behavior.)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
__module__ is the string name of the module the function was defined
in, just like __module__ of classes. In some cases, particularly for
C functions, the __module__ may be None.
Change PyCFunction_New() from a function to a macro, but keep an
unused copy of the function around so that we don't change the binary
API.
Change pickle's save_global() to use whichmodule() if __module__ is
None, but add the __module__ logic to whichmodule() since it might be
used outside of pickle.
|
|
|
|
|
| |
save_reduce(), before the state is pickled. This makes it possible
for an object to be referenced from its own (mutable) state.
|
|
|
|
| |
NEWOBJ to be generated.
|
|
|
|
|
| |
shortcut meaning 0L. This allows LONG1 to encode 0L in two bytes
total.
|
| |
|
| |
|
|
|
|
| |
_instantiate() method.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
on the type instead of self.save(t). This defeated the purpose of
NEWOBJ, because it didn't generate a BINGET opcode when t was already
memoized; but moreover, it would generate multiple BINPUT opcodes for
the same type! pickletools.dis() doesn't like this.
How I found this? I was playing with picklesize.py in the datetime
sandbox, and noticed that protocol 2 pickles for multiple objects were
in fact larger than protocol 1 pickles! That was suspicious, so I
decided to disassemble one of the pickles.
This really needs a unit test, but I'm exhausted. I'll be late for
work as it is. :-(
|
| |
|
|
|
|
|
|
|
|
|
| |
the same function, don't save the state or write a BUILD opcode. This
is so that a type (e.g. datetime :-) can support protocol 2 using
__getnewargs__ while also supporting protocol 0 and 1 using
__getstate__. (Without this, the state would be pickled twice with
protocol 2, unless __getstate__ is defined to return None, which
breaks protocol 0 and 1.)
|
| |
|
|
|
|
|
|
|
|
| |
types. The special handling for these can now be removed from save_newobj().
Add some testing for this.
Also add support for setting the 'fast' flag on the Python Pickler class,
which suppresses use of the memo.
|
| |
|
| |
|
|
|
|
| |
pickletools: Import decode_long from pickle instead of duplicating it.
|
|
|
|
| |
__getnewargs__ method.
|
|
|
|
| |
Also tidied up a few lines, got rid of apply(), added a comment.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
object.__reduce__, do a getattr() on the class so we can explicitly
test for it. The reduce()-calling code becomes a bit more regular as
a result.
Also add support slots: if an object has slots, the default state is
(dict, slots) where dict is the __dict__ or None, and slots is a dict
mapping slot names to slot values. We do a best-effort approach to
find slot names, assuming the __slots__ fields of classes aren't
modified after class definition time to misrepresent the actual list
of slots defined by a class.
|
|
|
|
|
|
| |
possibility of calling save_reduce(). Add a special hack for this.
The tests for this are much simpler now (no __getstate__ or
__getnewargs__ needed).
|
|
|
|
| |
after checking for __reduce__.
|
|
|
|
| |
fixed a bug in load_newobj().
|
| |
|
| |
|
|
|
|
| |
was used before string-escape codecs were added to the core.)
|
|
|
|
|
|
| |
checks to save_reduce(), which can also be called from a subclass.)
Also tweaked some more comments.
|
| |
|
|
|
|
|
|
|
| |
be one of 0, 1 or 2).
I should note that the previous checkin also added NEWOBJ support to
the unpickler -- but there's nothing yet that generates this.
|
|
|
|
|
| |
type 'object'. Also minor docstring tweakage, and rearranged a few
lines in save().
|