summaryrefslogtreecommitdiffstats
path: root/Modules/cPickle.c
Commit message (Collapse)AuthorAgeFilesLines
* Make BadPickleGet a class. Fixes #609164.Martin v. Löwis2002-09-161-3/+4
|
* Patch #505705: Remove eval in pickle and cPickle.Martin v. Löwis2002-08-141-31/+20
|
* Allow more docstrings to be removed during compilation in some modulesNeal Norwitz2002-08-131-15/+16
|
* Add recursion counter for pickling. Fixes #576084.Martin v. Löwis2002-08-041-0/+9
| | | | | 2.2 bugfix candidate (may cause RuntimeError for applications that currently work fine).
* Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototypeMark Hammond2002-08-021-3/+3
| | | | | | for Py_Main(). Thanks to Kalle Svensson and Skip Montanaro for the patches.
* Fix indentation.Jeremy Hylton2002-07-181-5/+5
|
* staticforward bites the dust.Jeremy Hylton2002-07-171-2/+2
| | | | | | | | | | | | | | | 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.
* Given the persistent id code a shot at a class before calling save_global().Jeremy Hylton2002-07-161-5/+5
| | | | | Some persistent picklers (well, probably, the *only* persistent pickler) would like to pickle some classes in a special way.
* remove decl of unused variableJeremy Hylton2002-07-111-1/+1
|
* Do more robust test of whether global objects are accessible.Jeremy Hylton2002-07-111-4/+3
| | | | | | | | 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.
* Undefine TRUE and FALSE before redefining them.Jack Jansen2002-06-261-0/+2
|
* Patch #568124: Add doc string macros.Martin v. Löwis2002-06-131-10/+9
|
* Pickler_clear_memo(): convert to METH_NOARGS.Fred Drake2002-05-011-5/+2
|
* Repair widespread misuse of _PyString_Resize. Since it's clear peopleTim Peters2002-04-271-7/+1
| | | | | | | | | | | | | | | | | | | | | | 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.
* #546156, Remove load_false()/load_true(), they are not usedNeal Norwitz2002-04-211-14/+0
|
* Implement an idea by Paul Rubin:Guido van Rossum2002-04-051-15/+11
| | | | | | | | 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.
* Removed old Digital Creations copyright/license notices (withGuido van Rossum2002-04-041-48/+0
| | | | | permission from Paul Everitt). Also removed a few other references to Digital Creations and changed the remaining ones to Zope Corporation.
* Add the 'bool' type and its values 'False' and 'True', as described inGuido van Rossum2002-04-031-0/+44
| | | | | | | | | | | | | 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.
* Reindent. Break long lines. Move comments before the statements.Martin v. Löwis2002-04-011-3482/+3641
|
* Remove UNLESS.Martin v. Löwis2002-04-011-152/+152
|
* Use symbolic METH_VARARGS/METH_OLDARGS instead of 1/0 for ml_flagsNeal Norwitz2002-03-311-11/+11
|
* Match behavior of the pickle.py module more closely.Neil Schemenauer2002-03-221-0/+5
|
* Merge of the release22 branch changes back into the trunk.Barry Warsaw2001-12-211-3/+5
|
* save(): Fix for SF bug #494904: Cannot pickle a class with aGuido van Rossum2001-12-191-0/+5
| | | | | | | | | | | | 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().
* Patch supplied by Burton Radons for his own SF bug #487390: ModifyingGuido van Rossum2001-12-081-3/+3
| | | | | | | | | | | | | 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.
* Use PyOS_snprintf() instead of sprintf().Jeremy Hylton2001-11-281-4/+4
|
* A change to sync with pickle.py:Barry Warsaw2001-11-151-8/+0
| | | | | | | | | | 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.
* load_string(): Force use of unsigned compare in a context that wasTim Peters2001-11-121-6/+8
| | | | clearly (but incorrectly) assuming it.
* Fixes to compile cPickle.c & socketmodule.c on cygwin and possiblyMichael W. Hudson2001-11-091-2/+4
| | | | | other platforms that have funny ideas about whether addresses of functions in dlls are compile-time constants.
* Must terminate the Pickler_members[] and Pickler_getsets with NULL.Jeremy Hylton2001-10-161-1/+3
|
* Better fix for core dumps on recursive objects in fast mode.Jeremy Hylton2001-10-151-32/+64
| | | | | | | | | | | | | | | | | | | Raise ValueError when an object contains an arbitrarily nested reference to itself. (The previous fix just produced invalid pickles.) Solution is very much like Py_ReprEnter() and Py_ReprLeave(): fast_save_enter() and fast_save_leave() that tracks the fast_container limit and keeps a fast_memo of objects currently being pickled. The cost of the solution is moderately expensive for deeply nested structures, but it still seems to be faster than normal pickling, based on tests with deeply nested lists. Once FAST_LIMIT is exceeded, the new code is about twice as slow as fast-mode code that doesn't check for recursion. It's still twice as fast as the normal pickling code. In the absence of deeply nested structures, I couldn't measure a difference.
* Progress on SF bug #466175 and general cleanup.Jeremy Hylton2001-10-121-187/+197
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a fast_container member to Picklerobject. If fast is true, then fast_container counts the depth of nested container calls. If the depth exceeds FAST_LIMIT (2000), the fast flag is ignored and the normal checks occur. This approach is much like the approach for prevent stack overflow for comparison and reprs of recursive objects (e.g. [[...]]). - Fast container used for save_list(), save_dict(), and save_inst(). XXX Not clear which other save_xxx() functions should use it. Make Picklerobject into new-style types, using PyObject_GenericGetAttr() and PyObject_GenericSetAttr(). - Use PyMemberDef for binary and fast members - Use PyGetSetDef for persistent_id, inst_persistent_id, memo, and PicklingError. XXX Not all of these seem like they need to use getset, but it's not clear why the old getattr() and setattr() had such odd semantics. One change is that the getvalue() attribute will exist on all Picklers, not just list-based picklers; I think this is a more rationale interface. There is a long laundry list of other changes: - Remove unused #defines for PyList_SET_ITEM() etc. - Make some of the indentation consistent - Replace uses of cPickle_PyMapping_HasKey() where the first argument is self->memo with calls to PyDict_GetItem(), because self->memo must be a dictionary. - Don't bother to check if cPickle_PyMapping_HasKey() returns < 0, because it can only return 0 or 1. - Replace uses of PyObject_CallObject() with PyObject_Call(), when we can guarantee that the argument tuple is really a tuple. Performance impacts of these changes: - 5% speedup for normal pickling - No change to fast-mode pickling. XXX Really need tests for all the features in cPickle that aren't in pickle.
* load_int: The fallback to long ints was coded in such a way that itTim Peters2001-08-281-4/+3
| | | | couldn't succeed. Fixed.
* SF patch #452239 by Gordon McMillan, to fix SF bug #451547.Guido van Rossum2001-08-181-1/+25
| | | | | | | | | | This patch attempts to do to cPickle what Guido did for pickle.py v 1.50. That is: save_global tries importing the module, and fetching the name from the module. If that fails, or the returned object is not the same one we started with, it raises a PicklingError. (All this so pickling a lambda will fail at save time, rather than load time).
* Patch #445762: Support --disable-unicodeMartin v. Löwis2001-08-171-0/+14
| | | | | | | | - Do not compile unicodeobject, unicodectype, and unicodedata if Unicode is disabled - check for Py_USING_UNICODE in all places that use Unicode functions - disables unicode literals, and the builtin functions - add the types.StringTypes list - remove Unicode literals from most tests.
* Merge of descr-branch back into trunk.Tim Peters2001-08-021-0/+4
|
* Remove code to initialize globals that are never used.Fred Drake2001-07-171-22/+11
| | | | | | Add some casts to quiet warnings from an unspecified non-GCC compiler. This closes SF patch #436258.
* Ack -- this module mixes tabs and spaces, and what appears to be a mixTim Peters2001-04-101-5/+5
| | | | | | | of 2-space and 4-space indents. Whatever, when I saw the checkin diff it was clear that what my editor thinks a tab means didn't match this module's belief. Removed all the tabs from the lines I added and changed, left everything else alone.
* On a sizeof(long)==8 machine, ints in range(2**31, 2**32) were gettingTim Peters2001-04-101-5/+21
| | | | | | | | | | | | | | | | pickled into the signed(!) 4-byte BININT format, so were getting unpickled again as negative ints. Repaired that. Added some minimal docs at the top about what I've learned about the pickle format codes (little of which was obvious from staring at the code, although that's partly because all the size-related bugs greatly obscured the true intent of the code). Happy side effect: because save_int() needed to grow a *proper* range check in order to fix this bug, it can now use the more-efficient BININT1, BININT2 and BININT formats when the long's value is small enough to fit in a signed 4-byte int (before this, on a sizeof(long)==8 box it always used the general INT format for negative ints). test_cpickle works again on sizeof(long)==8 machines. test_pickle is still busted big-time.
* Critical fix: if cPickle on a sizeof(long)==8 box is used to read aTim Peters2001-04-101-1/+8
| | | | | | | | | | | binary pickle, and the latter contains a pickle of a negative Python int i written on a sizeof(long)==4 box (and whether by cPickle or pickle.py), it's read incorrectly as i + 2**32. The patch repairs that, and allows test_cpickle.py (to which I added a relevant test case earlier today) to work again on sizeof(long)==8 boxes. There's another (at least one) sizeof(long)==8 binary pickle bug, but in pickle.py instead. That bug is still there, and test_pickle.py doesn't catch it yet (try pickling and unpickling, e.g., 1 << 46).
* Make cPickle use the recently-added PyInstance_NewRaw() API to createFred Drake2001-03-221-11/+3
| | | | | instance objects without calling the constructor. This is the same as the new.instance() function.
* SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.Tim Peters2001-03-171-173/+182
| | | | | | | http://sourceforge.net/tracker/?func=detail&aid=233200&group_id=5470&atid=105470 Wrapped the fread/fwrite calls in thread BEGIN_ALLOW/END_ALLOW brackets Afraid I hit the "delete trailing whitespace key" too! Only two "real" sections of code changed here.
* Minimal fix for the complaints about pickling Unicode objects. (SFGuido van Rossum2000-12-191-2/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | bugs #126161 and 123634). The solution doesn't use the unicode-escape encoding; that has other problems (it seems not 100% reversible). Rather, it transforms the input Unicode object slightly before encoding it using raw-unicode-escape, so that the decoding will reconstruct the original string: backslash and newline characters are translated into their \uXXXX counterparts. This is backwards incompatible for strings containing backslashes, but for some of those strings, the pickling was already broken. Note that SF bug #123634 complains specifically that cPickle fails to unpickle the pickle for u'' (the empty Unicode string) correctly. This was an off-by-one error in load_unicode(). XXX Ugliness: in order to do the modified raw-unicode-escape, I've cut-and-pasted a copy of PyUnicode_EncodeRawUnicodeEscape() into this file that also encodes '\\' and '\n'. It might be nice to migrate this into the Unicode implementation and give this encoding a new name ('half-raw-unicode-escape'? 'pickle-unicode-escape'?); that would help pickle.py too. But right now I can't be bothered with the necessary infrastructural changes.
* - Fix a GC bug caused by PyDict_New() failing.Neil Schemenauer2000-10-041-1/+2
|
* Oops. Jim's fix didn't. This one does -- I tested it a bit betterGuido van Rossum2000-09-071-4/+19
| | | | this time!
* Simple fix from Jin Fulton to avoid returning a half-initializedGuido van Rossum2000-09-071-2/+2
| | | | | | module when e.g. copy_reg.py doesn't exist. This caused a core dump. This closes SF bug 112944.
* Use safer comparisons (only matters when sizeof(int) != sizeof(size_t)). freadTrent Mick2000-08-121-2/+2
| | | | | and fwrite return size_t, so it is safer to cast up to the largest type for the comparison. I believe the cast is required at all to remove compiler warnings.
* merge Include/my*.h into Include/pyport.hPeter Schneider-Kamp2000-07-311-1/+0
| | | | marked my*.h as obsolete
* ANSIfy some more forward declarations.Thomas Wouters2000-07-241-4/+4
|
* ... and yet more ANSIfications...Thomas Wouters2000-07-241-3/+4
|