Commit Graph

118 Commits

Author SHA1 Message Date
Tim Peters 0c7c48e02c load_counted_long(): Changed a ValueError to an UnpicklingError, just
because it seems more consistent with the rest of the code.

cPickle_PyMapping_HasKey():  This extern function isn't used anywhere in
Python or Zope, so got rid of it.
2003-02-03 22:07:24 +00:00
Tim Peters e0a3907904 PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
readability.

load_bool():  Now that I know the intended difference between _PUSH and
_APPEND, used the right one.

Pdata_grow():  Squashed out a redundant overflow test.
2003-02-03 15:45:56 +00:00
Tim Peters 1d63c9f151 cPickle support for TUPLE[123]. Incidentally plugged several undetected
overflow holes in Pdata_grow().
2003-02-02 20:29:39 +00:00
Tim Peters 0bc93f5c8b Massive edits. If p is a pointer to a struct, and p->f is a pointer to
a function, then

    p->f(arg1, arg2, ...)

is semantically the same as

    (*p->f)(arg1, arg2, ...)

Changed all instances of the latter into the former.  Given how often
the code embeds this kind of expression in an if test, the unnecessary
parens and dereferening operator were a real drag on readability.
2003-02-02 18:29:33 +00:00
Tim Peters ac5687a515 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
embedded assignments, for readability.
2003-02-02 18:08:34 +00:00
Tim Peters 3c67d795ef Implemented proto 2 NEWTRUE and NEWFALSE in cPickle. 2003-02-02 17:59:11 +00:00
Tim Peters 70b02d79f9 Beefed up the tests by putting in more "for proto in protocols:" outer
loops.  Renamed DATA and BINDATA to DATA0 and DATA1.  Included
disassemblies, but noted why we can't test them.  Added XXX comment to
cPickle about a mysterious comment, where pickle and cPickle diverge
in how they number PUT indices.
2003-02-02 17:26:40 +00:00
Neal Norwitz 529baf2b57 Fix compiler warning 2003-02-02 17:08:33 +00:00
Tim Peters 87482ea055 dump(): Added asserts that self->proto is sane. 2003-02-02 16:16:30 +00:00
Tim Peters 9b1e03ff4b dump(): Fixed a stupid bug in new code. It wasn't possible for the bug
to have an effect before protocol 3 is invented, so no test can be
written for this (yet).
2003-02-02 16:14:23 +00:00
Tim Peters 4190fb8429 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
the hitherto unknown (to me) noload() cPickle function, which is (a)
something we don't test at all, and (b) pickle.py doesn't have.
2003-02-02 16:09:05 +00:00
Tim Peters ee1a53cbb1 cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
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).
2003-02-02 02:57:53 +00:00
Tim Peters 5bd2a79b22 The C pickle now knows how to deal with a proto= argument. Assorted
code cleanups, and purged more references to text-vs-binary modes.
2003-02-01 16:45:06 +00:00
Tim Peters 040e033796 Removed needless include of errno.h. 2003-02-01 06:30:12 +00:00
Tim Peters 64c04d1df3 The module docstring had an RCS ID from 1999 embedded in it. Enough
already <wink>.
2003-02-01 06:27:59 +00:00
Tim Peters cba30e2c96 Trimmed trailing whitespace. 2003-02-01 06:24:36 +00:00
Tim Peters 797ec24e87 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
removed woefully inadequate opcode docs and pointed to pickletools.py
instead.
2003-02-01 06:22:36 +00:00
Tim Peters 1f1b2d2e68 Removed all uses of the out-of-favor __safe_for_unpickling__ magic
attr, and copy_reg.safe_constructors.
2003-02-01 02:16:37 +00:00
Guido van Rossum 8e0ad0cb0b Ignore the state returned by __reduce__ if it is Py_None. 2003-01-31 21:10:31 +00:00
Jason Tishler fb8595df4f Patch #661760: Cygwin auto-import module patch
The attached patch enables shared extension
modules to build cleanly under Cygwin without
moving the static initialization of certain function
pointers (i.e., ones exported from the Python
DLL core) to a module initialization function.

Additionally, this patch fixes the modules that
have been changed in the past to accommodate
Cygwin.
2003-01-06 12:41:26 +00:00
Guido van Rossum 75bfd0585b Add an XXX comment about relative imports. 2002-12-24 18:10:07 +00:00
Tim Peters 4e52ca82ae A patch from Kevin Jacobs, plugging several leaks discovered when
running the sandbox datetime tests.

Bugfix candidate.
2002-12-07 02:43:28 +00:00
Martin v. Löwis 658009afdb Make BadPickleGet a class. Fixes #609164. 2002-09-16 17:26:24 +00:00
Martin v. Löwis 8a8da798a5 Patch #505705: Remove eval in pickle and cPickle. 2002-08-14 07:46:28 +00:00
Neal Norwitz 200788ce45 Allow more docstrings to be removed during compilation in some modules 2002-08-13 22:20:41 +00:00
Martin v. Löwis 5a39530274 Add recursion counter for pickling. Fixes #576084.
2.2 bugfix candidate (may cause RuntimeError for applications that
currently work fine).
2002-08-04 08:20:23 +00:00
Mark Hammond fe51c6d66e Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
for Py_Main().

Thanks to Kalle Svensson and Skip Montanaro for the patches.
2002-08-02 02:27:13 +00:00
Jeremy Hylton 7fa4bfa173 Fix indentation. 2002-07-18 20:58:57 +00:00
Jeremy Hylton 938ace69a0 staticforward bites the dust.
The staticforward define was needed to support certain broken C
compilers (notably SCO ODT 3.0, perhaps early AIX as well) botched the
static keyword when it was used with a forward declaration of a static
initialized structure.  Standard C allows the forward declaration with
static, and we've decided to stop catering to broken C compilers.  (In
fact, we expect that the compilers are all fixed eight years later.)

I'm leaving staticforward and statichere defined in object.h as
static.  This is only for backwards compatibility with C extensions
that might still use it.

XXX I haven't updated the documentation.
2002-07-17 16:30:39 +00:00
Jeremy Hylton 39c6116483 Given the persistent id code a shot at a class before calling save_global().
Some persistent picklers (well, probably, the *only* persistent
pickler) would like to pickle some classes in a special way.
2002-07-16 19:47:43 +00:00
Jeremy Hylton 9ee91f11b3 remove decl of unused variable 2002-07-11 22:02:33 +00:00
Jeremy Hylton 0e1f7a82e9 Do more robust test of whether global objects are accessible.
PyImport_ImportModule() is not guaranteed to return a module object.
When another type of object was returned, the PyModule_GetDict() call
return NULL and the subsequent GetItem() seg faulted.

Bug fix candidate.
2002-07-11 22:01:40 +00:00
Jack Jansen 3a96702b2b Undefine TRUE and FALSE before redefining them. 2002-06-26 20:40:42 +00:00
Martin v. Löwis 14f8b4cfcb Patch #568124: Add doc string macros. 2002-06-13 20:33:02 +00:00
Fred Drake 0ebacc8b38 Pickler_clear_memo(): convert to METH_NOARGS. 2002-05-01 20:36:39 +00:00
Tim Peters 5de9842b34 Repair widespread misuse of _PyString_Resize. Since it's clear people
don't understand how this function works, also beefed up the docs.  The
most common usage error is of this form (often spread out across gotos):

	if (_PyString_Resize(&s, n) < 0) {
		Py_DECREF(s);
		s = NULL;
		goto outtahere;
	}

The error is that if _PyString_Resize runs out of memory, it automatically
decrefs the input string object s (which also deallocates it, since its
refcount must be 1 upon entry), and sets s to NULL.  So if the "if"
branch ever triggers, it's an error to call Py_DECREF(s):  s is already
NULL!  A correct way to write the above is the simpler (and intended)

	if (_PyString_Resize(&s, n) < 0)
		goto outtahere;

Bugfix candidate.
2002-04-27 18:44:32 +00:00
Neal Norwitz 8ee3cd47a9 #546156, Remove load_false()/load_true(), they are not used 2002-04-21 23:44:34 +00:00
Guido van Rossum e276339cea Implement an idea by Paul Rubin:
Change pickling format for bools to use a backwards compatible
encoding.  This means you can pickle True or False on Python 2.3
and Python 2.2 or before will read it back as 1 or 0.  The code
used for pickling bools before would create pickles that could
not be read in previous Python versions.
2002-04-05 19:30:08 +00:00
Guido van Rossum 2e1c09c1fd Removed old Digital Creations copyright/license notices (with
permission from Paul Everitt).  Also removed a few other references to
Digital Creations and changed the remaining ones to Zope Corporation.
2002-04-04 17:52:50 +00:00
Guido van Rossum 77f6a65eb0 Add the 'bool' type and its values 'False' and 'True', as described in
PEP 285.  Everything described in the PEP is here, and there is even
some documentation.  I had to fix 12 unit tests; all but one of these
were printing Boolean outcomes that changed from 0/1 to False/True.
(The exception is test_unicode.py, which did a type(x) == type(y)
style comparison.  I could've fixed that with a single line using
issubtype(x, type(y)), but instead chose to be explicit about those
places where a bool is expected.

Still to do: perhaps more documentation; change standard library
modules to return False/True from predicates.
2002-04-03 22:41:51 +00:00
Martin v. Löwis 2f6ef4c630 Reindent. Break long lines. Move comments before the statements. 2002-04-01 17:40:08 +00:00
Martin v. Löwis 43c9d8ad23 Remove UNLESS. 2002-04-01 12:34:33 +00:00
Neal Norwitz b049325e92 Use symbolic METH_VARARGS/METH_OLDARGS instead of 1/0 for ml_flags 2002-03-31 14:44:22 +00:00
Neil Schemenauer fa79c65235 Match behavior of the pickle.py module more closely. 2002-03-22 23:02:53 +00:00
Barry Warsaw 52acb49298 Merge of the release22 branch changes back into the trunk. 2001-12-21 20:04:22 +00:00
Guido van Rossum 950dce6f01 save(): Fix for SF bug #494904: Cannot pickle a class with a
metaclass, reported by Dan Parisien.

Objects that are instances of custom metaclasses, i.e. whose ob_type
is a subclass of PyType_Type, should be pickled the same as new-style
classes (objects whose ob_type is PyType_Type).  This can't be done
through the existing dispatch switches, and the __reduce__ trick
doesn't work for these, since it finds the unbound __reduce__ for
instances of the class (inherited from PyBaseObject_Type).  So check
explicitly using PyType_IsSubtype().
2001-12-19 16:56:54 +00:00
Guido van Rossum 146483964e Patch supplied by Burton Radons for his own SF bug #487390: Modifying
type.__module__ behavior.

This adds the module name and a dot in front of the type name in every
type object initializer, except for built-in types (and those that
already had this).  Note that it touches lots of Mac modules -- I have
no way to test these but the changes look right.  Apologies if they're
not.  This also touches the weakref docs, which contains a sample type
object initializer.  It also touches the mmap test output, because the
mmap type's repr is included in that output.  It touches object.h to
put the correct description in a comment.
2001-12-08 18:02:58 +00:00
Jeremy Hylton 179c48c60e Use PyOS_snprintf() instead of sprintf(). 2001-11-28 21:49:51 +00:00
Barry Warsaw 9b481ff3d6 A change to sync with pickle.py:
find_class(): We no longer mask all exceptions[1] by transforming them
into SystemError.  The latter is definitely not the right thing to do,
so we let any exceptions that occur in the PyObject_GetAttr() call to
simply propagate up if they occur.

[1] Note that pickle only masked ImportError, KeyError, and
AttributeError, but cPickle masked all exceptions.
2001-11-15 23:45:26 +00:00
Tim Peters bf5ca65c2d load_string(): Force use of unsigned compare in a context that was
clearly (but incorrectly) assuming it.
2001-11-12 22:26:10 +00:00