summaryrefslogtreecommitdiffstats
path: root/Modules/cPickle.c
Commit message (Collapse)AuthorAgeFilesLines
* 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
|
* ANSIfication: add proper prototypes to function-pointers and declarations.Thomas Wouters2000-07-221-24/+13
| | | | | Also, fix a bug found by said declarations, where a string was defined as unsigned char*, but used as signed.
* replace PyXXX_Length calls with PyXXX_Size callsJeremy Hylton2000-07-121-2/+2
|
* final patches from Neil Schemenauer for garbage collectionJeremy Hylton2000-06-301-1/+1
|
* Trent Mick:Guido van Rossum2000-06-281-8/+7
| | | | | | | | | | | | This patch fixes cPickle.c for 64-bit platforms. - The false assumption sizeof(long) == size(void*) exists where PyInt_FromLong is used to represent a pointer. The safe Python call for this is PyLong_FromVoidPtr. (On platforms where the above assumption *is* true a PyInt is returned as before so there is no effective change.) - use size_t instead of int for some variables
* New version from Jim Fulton to fix a problem that Eric Raymond ranGuido van Rossum2000-05-091-6/+20
| | | | | | | | | | | | | | | | | | | | | | into. Jim writes: The core dump was due to a C decrement operation in a macro invocation in load_pop. (BAD) I fixed this by moving the decrement outside the macro call. I added a comment to load_pop and load_mark to document the fact that cPickle separates the unpickling stack into two separate stacks, one for objects and one for marks. I also moved some increments out of some macro calls (PyTuple_SET_ITEM and PyList_SET_ITEM). This wasn't necessary, but made me feel better. :) I tested these changes in *my* cPickle, which doesn't have the new Unicode stuff.
* Vladimir Marangozov's long-awaited malloc restructuring.Guido van Rossum2000-05-031-7/+7
| | | | | | | | | | For more comments, read the patches@python.org archives. For documentation read the comments in mymalloc.h and objimpl.h. (This is not exactly what Vladimir posted to the patches list; I've made a few changes, and Vladimir sent me a fix in private email for a problem that only occurs in debug mode. I'm also holding back on his change to main.c, which seems unnecessary to me.)
* Charles Waldman writes:Guido van Rossum2000-04-211-14/+11
| | | | | | | | | | | | | | | | | | | | """ Problem description: Run the following script: import test.test_cpickle for x in xrange(1000000): reload(test.test_cpickle) Watch Python's memory use go up up and away! In the course of debugging this I also saw that cPickle is inconsistent with pickle - if you attempt a pickle.load or pickle.dump on a closed file, you get a ValueError, whereas the corresponding cPickle operations give an IOError. Since cPickle is advertised as being compatible with pickle, I changed these exceptions to match. """
* Marc-Andre Lemburg: support pickling Unicode objects, both in textGuido van Rossum2000-03-101-0/+149
| | | | mode ('V') and in binary mode ('X').
* Massive patch by Skip Montanaro to add ":name" to as manyGuido van Rossum2000-02-291-11/+11
| | | | PyArg_ParseTuple() format string arguments as possible.
* Patch by Stephen Turner, who writes:Guido van Rossum1999-07-131-18/+27
| | | | | | | | | | | | | | | | | | | | | | | """ It fixes a memory corruption error resulting from BadPickleGet exceptions in load_get, load_binget and load_long_binget. This was initially reported on c.l.py as a problem with Cookie.py; see the thread titled "python core dump (SIGBUS) on Solaris" for more details. If PyDict_GetItem(self->memo, py_key) call failed, then py_key was being Py_DECREF'd out of existence before call was made to PyErr_SetObject(BadPickleGet, py_key). The bug can be duplicated as follows: import cPickle cPickle.loads('garyp') This raises a BadPickleGet exception whose value is a freed object. A core dump will soon follow. """ Jim Fulton approves of the patch.
* New version from Jim:Guido van Rossum1999-06-151-50/+30
| | | | | | | | - Don't call Py_FatalError() when initialization fails. - Fix bogus use of return value from PyRun_String(). - Fix misc. compiler errors on some platforms.
* Jim Fulton writes:Guido van Rossum1999-06-091-10/+56
| | | | | | | | | | | | | | | | | | I've updated cPickle.c to use class exceptions: Changed pickle error types to classes: PickleError PicklingError UnpickleableError UnpicklingError And change the handling of unpickleable objects so that an UnpickleableError is raised with the unpickleable object as the argument. UnpickleableError has a reasonable string representation and provides access to the problem object, which is useful during debugging. [I'm still waiting for patches to do the same to pickle.py.]
* Jim Fulton writes:Guido van Rossum1999-04-191-13/+41
| | | | | | | | | | | | | | I have attached a new cPickle that adds a new control attribute to unpicklers: Added new Unpickler attribute, find_global. If set to None, then global and instance pickles are disabled. Otherwise, it should be set to a callable object that takes two arguments, a module name and an object name, and returns an object. If the attribute is unset, then the default mechanism is used. This feature provides an additional mechanism for controlling which classes can be used for unpickling.
* Fix accidentally reversed NULL test in load_mark(). Suggested byGuido van Rossum1999-04-121-1/+1
| | | | | Tamito Kajiyama. (This caused a bug only on platforms where malloc(0) returns NULL.)
* Protection against picling to/from closed (real) file.Guido van Rossum1999-03-291-0/+8
| | | | The problem was reported by Moshe Zadka.
* Fix buglet in load_put -- the test for bad readline result tested theGuido van Rossum1999-02-081-1/+1
| | | | wrong variable.
* Jim Fulton: this fixes seg faults with bad pickles like "c".Guido van Rossum1999-02-041-3/+22
|
* Make sure not to call realloc() with a NULL pointer -- call malloc()Guido van Rossum1999-01-251-1/+4
| | | | in that case. Tamito Kajiyama.
* Need to initialize self->safe_constructors early on to prevent crashGuido van Rossum1998-12-111-0/+1
| | | | in early dealloc. Patch by Andrew Dalke.
* Make VC++ 5.0 compiler happy.Guido van Rossum1998-12-081-12/+8
|
* Fix two small bugs; add DL_EXPORT() to initcPickle decl.Guido van Rossum1998-12-041-2/+3
|
* New version from Jim Fulton:Guido van Rossum1998-11-251-1172/+1110
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - New copyright. (Open source) - Added new protocol for binary string pickles that takes out unneeded puts: p=Pickler() p.dump(x) p.dump(y) thePickle=p.getvalue() This has little or no impact on pickling time, but often reduces unpickling time and pickle size, sometimes significantly. - Changed unpickler to use internal data structure instead of list to reduce unpickling times by about a third. - Many cleanups to get rid of obfuscated error handling involving 'goto finally' and status variables. - Extensive reGuidofication. (formatting :) - Fixed binary floating-point pickling bug. 0.0 was not pickled correctly. - Now use binary floating point format when saving floats in binary mode. - Fixed some error message spelling error.
* Enter Jim Fulton's latest version. He writes:Jeremy Hylton1998-08-131-20/+80
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | I had to make a slight diddle to work with Python 1.4, which we and some of our customers are still using. :( I've also made a few minor enhancements: - You can now both get and set the memo using a 'memo' attribute. This is handy for certain advanced applications that we have. - Added a 'binary' attribute to get and set the binary mode for a pickler. - Added a somewhat experimental 'fast' attribute. When this is set, objects are not placed in the memo during pickling. This should lead to faster pickling and smaller pickles in cases where: o you *know* there are no circular references, and o either you've: - preloaded the memo with class information by pickling classes in non-fast mode or by manipilating the memo directly, or - aren't pickling instances.
* Two fixes to find_class:Jeremy Hylton1998-08-111-9/+22
| | | | | | | | | | | | | | | 1. Only DECREF the class's module when the module is retrieved via PyImport_Import. If it is retrieved from the modules dictionary with PyDict_GetItem, it is using a borrowed reference. 2. If the module doesn't define the desired class, raise the same SystemError that pickle.py does instead of returning an AttributeError (which is cryptic at best). Also, fix the PyArg_ParseTuple in cpm_loads (the externally visible loads) function: Use "S" instead of "O" because cStringIO will croak with a "bad arguments to internal function" if passed anything other than a string.
* Jim Fulton's patches to get rid of the class_map().Guido van Rossum1998-08-081-73/+27
|
* Use PyErr_ExceptionMatches(...) instead of PyErr_Occurred() == ... in twoFred Drake1998-05-281-2/+4
| | | | places.
* whichmodule(): remove redundant PyErr_Clear(); add explicit settingGuido van Rossum1998-05-141-4/+3
| | | | of error when sys.modules isn't there.
* Use %.17f to format floats/doublesGuido van Rossum1998-04-031-1/+1
|
* Clear class_map in constructor so that when it later detects an errorGuido van Rossum1998-03-061-1/+2
| | | | and the destructor is called early, it doesn't DECREF garbage.
* Renamed Jim's PyErr_[JF]Format() to cPickle_ErrFormat(). It's not aGuido van Rossum1998-01-191-11/+10
| | | | standard Python API function so it should not have a Py prefix.
* Jim Fulton:Guido van Rossum1997-12-081-24/+50
| | | | | | | | | | | | | | | | | | | | | | - Loading non-binary string pickles checks for insecure strings. This is needed because cPickle (still) uses a restricted eval to parse non-binary string pickles. This change is needed to prevent untrusted pickles like:: "S'hello world'*2000000\012p0\012." from hosing an application. - User-defined types can now support unpickling without executing a constructor. The second value returned from __reduce__ can now be None, rather than an argument tuple. On unpickling, if the second value returned from __reduce__ during pickling was None, then rather than calling the first value returned from __reduce__, directly, the __basicnew__ method of the first value returned from __reduce__ is called without arguments.
* New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1Guido van Rossum1997-12-041-246/+633
| | | | distribution.
* Initialize __version__ to the correct version string regardless ofGuido van Rossum1997-12-011-3/+14
| | | | | what RCS checkout options are used. Problem first diagnosed by Marc Lemburg.
* In whichmodule(), use __module__ if set.Guido van Rossum1997-09-281-0/+4
|
* #Plug small memory leaks in constructors.Guido van Rossum1997-09-031-2/+5
|
* Removed JF's dollar-Log-dollar RCS turd that caused compilation toBarry Warsaw1997-08-211-52/+0
| | | | | crash due to GvR's last check in message :-). Will try to convince JF to remove all this evilness.
* Added /**/ around #end tagsGuido van Rossum1997-08-211-1/+4
|