Commit Graph

207 Commits

Author SHA1 Message Date
Larry Hastings c20472640c Issue #20390: Small fixes and improvements for Argument Clinic. 2014-01-25 20:43:29 -08:00
Larry Hastings 5c66189e88 Issue #20189: Four additional builtin types (PyTypeObject,
PyMethodDescr_Type, _PyMethodWrapper_Type, and PyWrapperDescr_Type)
have been modified to provide introspection information for builtins.
Also: many additional Lib, test suite, and Argument Clinic fixes.
2014-01-24 06:17:25 -08:00
Larry Hastings 462582651c Two minor Argument Clinic bugfixes: use the name of the class in the
docstring for __new__ and __init__, and always use "goto exit" instead of
returning "NULL" for failure to parse (as _new__ and __init__ return ints).
2014-01-22 03:05:49 -08:00
Larry Hastings b7ccb20423 Issue #20294: Argument Clinic now supports argument parsing for __new__ and
__init__ functions.
2014-01-18 23:50:21 -08:00
Larry Hastings bebf73511a Issue #20287: Argument Clinic's output is now configurable, allowing
delaying its output or even redirecting it to a separate file.
2014-01-17 17:47:17 -08:00
Larry Hastings 8666e65206 Issue #20228: Argument Clinic now has special support for class special
methods.
2014-01-12 14:12:59 -08:00
Larry Hastings 61272b77b0 Issue #19273: The marker comments Argument Clinic uses have been changed
to improve readability.
2014-01-07 12:41:53 -08:00
Larry Hastings 3cceb38486 Issue #19976: Argument Clinic METH_NOARGS functions now always
take two parameters.
2014-01-04 11:09:09 -08:00
Stefan Krah f483b0f3a9 Issue #19972: Add rarely used freefunc. This fixes a leak if sys.exit()
is used in a program.
2013-12-14 13:43:10 +01:00
Alexandre Vassalotti d05c9ff845 Issue #6784: Strings from Python 2 can now be unpickled as bytes objects.
Initial patch by Merlijn van Deen.

I've added a few unrelated docstring fixes in the patch while I was at
it, which makes the documentation for pickle a bit more consistent.
2013-12-07 01:09:27 -08:00
Alexandre Vassalotti 6e73ff1a31 Issue #19881: Fix bad pickling of large bytes in cpickle. 2013-12-05 19:29:32 -08:00
Alexandre Vassalotti 2ccf8e969c Issue #6477: Merge with 3.3. 2013-11-30 17:58:53 -08:00
Alexandre Vassalotti 65846c6c51 Issue #6477: Keep PyNotImplemented_Type and PyNone_Type private. 2013-11-30 17:55:48 -08:00
Alexandre Vassalotti 3c23e7a5dc Issue #6477: Merge with 3.3. 2013-11-30 16:21:20 -08:00
Alexandre Vassalotti 19b6fa6ebb Issue #6477: Added support for pickling the types of built-in singletons. 2013-11-30 16:06:39 -08:00
Alexandre Vassalotti a1eedf9ff0 Merge with 3.3. 2013-11-30 13:55:39 -08:00
Alexandre Vassalotti 896414fedf Fixed _pickle.Unpickler to handle empty persistent IDs correctly. 2013-11-30 13:52:35 -08:00
Serhiy Storchaka 6fe39b76a9 Issue #17897: Optimized unpickle prefetching. 2013-11-30 23:15:38 +02:00
Alexandre Vassalotti 567eba1852 Use PyDict_GetItemWithError instead of PyDict_GetItem in cpickle. 2013-11-28 17:09:16 -08:00
Alexandre Vassalotti 6bf41e54a4 Remove explicit empty tuple reuse in cpickle.
PyTuple_New(0) always returns the same empty tuple from its free list anyway,
so we are not saving much here. Plus, the code where this was used is on
uncommon run paths.
2013-11-28 15:17:29 -08:00
Alexandre Vassalotti b13e6bcbd8 Remove the tuple reuse optimization in _Pickle_FastCall.
I have noticed a race-condition occurring on one of the buildbots because of
this optimization. The function called may release the GIL which means
multiple threads may end up accessing the shared tuple. I could fix it up by
storing the tuple to the Pickler and Unipickler object again, but honestly it
really not worth the trouble.

I ran many benchmarks and the only time the optimization helps is when using a
fin-memory file, like io.BytesIO on which reads are super cheap, combined with
pickle protocol less than 4. Even in this contrived case, the speedup is a
about 5%. For everything else, this optimization does not provide any
noticable improvements.
2013-11-28 14:56:09 -08:00
Alexandre Vassalotti 23bdd83053 Encapsulate cpickle global state in a dedicated object.
This implements PEP 3121 module finalization as well. This change does not
cause any significant impact on performance.
2013-11-27 19:36:52 -08:00
Alexandre Vassalotti 20c28c1ea2 Combine the FastCall functions in cpickle.
I fixed the bug that was in my previous attempt of this cleanup. I ran
the full test suite to verify I didn't introduce any obvious bugs.
2013-11-27 02:26:54 -08:00
Alexandre Vassalotti b4a04fb7e6 Reverting e39db21df580 eagerly due to buildbot failures. 2013-11-25 13:25:12 -08:00
Alexandre Vassalotti f94a041f8f Combine _Pickler_FastCall and _Unpickler_FastCall in cpickle. 2013-11-25 13:03:32 -08:00
Alexandre Vassalotti 1048fb5539 Issue #19739: Try to fix compiler warnings on 32-bit Windows. 2013-11-25 11:35:46 -08:00
Alexandre Vassalotti ded929b300 Merge save_int into save_long in cpickle to remove redundant code.
Also, replace unnessary uses of the #if preprocessor directive.
2013-11-24 22:41:13 -08:00
Alexandre Vassalotti 8a67f52463 Simplify save_bool in cpickle. 2013-11-24 21:40:18 -08:00
Alexandre Vassalotti ed8c906127 Use Clinic to process arguments in cpickle.
This doesn't make any functional changes to the exisiting implementation.  The
conversion did help however uncover documentation bugs. The best thing about
this conversion is less C code to maintain by hand.
2013-11-24 12:25:48 -08:00
Alexandre Vassalotti fc91285c93 Remove code path in cpickle that does not exist in pickle. 2013-11-24 03:07:35 -08:00
Alexandre Vassalotti c49477b184 Make Ellipsis and NotImplemented picklable through the reduce protocol. 2013-11-24 02:53:45 -08:00
Alexandre Vassalotti 4c05d3bc56 Make built-in methods picklable through the reduce protocol. 2013-11-24 02:41:05 -08:00
Alexandre Vassalotti b6a2f2a0d1 Make framing optional in pickle protocol 4.
This will allow us to control in the future whether to use framing or not.
For example, we may want to turn it off for tiny pickle where it doesn't
help.

The change also improves performance slightly:

### fastpickle ###
Min: 0.608517 -> 0.557358: 1.09x faster
Avg: 0.798892 -> 0.694738: 1.15x faster
Significant (t=3.45)
Stddev: 0.17145 -> 0.12704: 1.3496x smaller
Timeline: http://goo.gl/3xQE1J

### pickle_dict ###
Min: 0.669920 -> 0.615271: 1.09x faster
Avg: 0.733633 -> 0.645058: 1.14x faster
Significant (t=5.05)
Stddev: 0.12041 -> 0.02961: 4.0662x smaller
Timeline: http://goo.gl/LpLSXI

### pickle_list ###
Min: 0.397583 -> 0.368112: 1.08x faster
Avg: 0.412784 -> 0.397223: 1.04x faster
Significant (t=2.78)
Stddev: 0.01518 -> 0.03653: 2.4068x larger
Timeline: http://goo.gl/v39E59

### unpickle_list ###
Min: 0.692935 -> 0.594870: 1.16x faster
Avg: 0.730012 -> 0.628395: 1.16x faster
Significant (t=17.76)
Stddev: 0.02720 -> 0.02995: 1.1012x larger
Timeline: http://goo.gl/2P9AEt

The following not significant results are hidden, use -v to show them:
fastunpickle.
2013-11-23 20:30:03 -08:00
Antoine Pitrou c1207c1bcf Fix signed / unsigned comparison 2013-11-23 21:34:04 +01:00
Gregory P. Smith 2b38fc187c gcc doesn't realize that dummy is always initialized by the function call
and warns about potential uninitialized use.
Silence that by initializing it to null.
2013-11-23 20:21:28 +00:00
Christian Heimes e8b1ba1699 Issue #17810: Add two missing error checks to save_global
CID 1131946:  Unchecked return value  (CHECKED_RETURN)
2013-11-23 21:13:39 +01:00
Antoine Pitrou 6188d09f1c Merge 2013-11-23 21:06:21 +01:00
Christian Heimes 74d8d63b18 Issue #17810: return -1 on error 2013-11-23 21:05:31 +01:00
Antoine Pitrou 8f2ee6e407 Fix writing out 64-bit size fields on 32-bit builds 2013-11-23 21:05:08 +01:00
Christian Heimes b3d3ee4fef Issue #17810: Add NULL check to save_frozenset
CID 1131949:  Dereference null return value  (NULL_RETURNS)
2013-11-23 21:01:40 +01:00
Antoine Pitrou c9dc4a2a8a Issue #17810: Implement PEP 3154, pickle protocol 4.
Most of the work is by Alexandre.
2013-11-23 18:59:12 +01:00
Victor Stinner 804e05e800 Issue #19437: Use an identifier for "__name__" string in pickle to improve
error handling

The following code didn't handle correctly the failure of
PyUnicode_InternFromString("__name__").

if (newobj_str == NULL) {
    newobj_str = PyUnicode_InternFromString("__newobj__");
    name_str = PyUnicode_InternFromString("__name__");
    if (newobj_str == NULL || name_str == NULL)
        return -1;
}
2013-11-14 01:26:17 +01:00
Victor Stinner bb52020d44 Issue #19512: pickle now uses an identifier to only create the Unicode string
"modules" once
2013-11-06 22:40:41 +01:00
Victor Stinner 2ae57e3cf8 Issue #19437: Fix _pickle, don't call _Unpickler_SkipConsumed() with an
exception set
2013-10-31 13:39:23 +01:00
Victor Stinner b43ad1d569 cleanup _Unpickler_SkipConsumed(): remove 1 level of indentation 2013-10-31 13:38:42 +01:00
Serhiy Storchaka 46e1ce214b Issue #18783: Removed existing mentions of Python long type in docstrings,
error messages and comments.
2013-08-27 20:17:03 +03:00
Serhiy Storchaka 9594942716 Issue #18783: Removed existing mentions of Python long type in docstrings,
error messages and comments.
2013-08-27 19:40:23 +03:00
Christian Heimes f446d21708 Issue #18559: Fix NULL pointer dereference error in _pickle module 2013-07-26 22:45:47 +02:00
Christian Heimes 9ee5c37c8f Issue #18559: Fix NULL pointer dereference error in _pickle module 2013-07-26 22:45:00 +02:00
Victor Stinner 1e53bbaced Issue #18408: handle PySys_GetObject() failure, raise a RuntimeError 2013-07-16 22:26:05 +02:00
Victor Stinner 4202456cd4 Issue #18408: _pickle.c: Add missing PyErr_NoMemory() on memory allocation failures 2013-07-12 00:53:57 +02:00
Victor Stinner 8ca72e2e3d Issue #18408: _PyMemoTable_ResizeTable() now restores the old table if
allocating a bigger table failed

PyMemoTable destructor does crash if mt_table is NULL.
2013-07-12 00:53:26 +02:00
Victor Stinner c31df04234 Issue #18408: Oh, I was wrong: Pickler_New() must call Py_DECREF() to destroy
the newly created pickler, and not PyObject_GC_Del().
2013-07-12 00:08:59 +02:00
Victor Stinner 68c8ea25f1 Issue #18408: Fix _Pickler_New() and _Unpickler_New(): initialize all
attributes before handling errors

_Pickler_New() now calls PyObject_GC_Del() instead of Py_DECREF() on error,
because the pickle object is created using PyObject_GC_New().

Fix a crash in the destructor when an attribute is not initiallized.
2013-07-11 22:56:25 +02:00
Victor Stinner 49fc8ece81 Issue #18203: Add _PyMem_RawStrdup() and _PyMem_Strdup()
Replace strdup() with _PyMem_RawStrdup() or _PyMem_Strdup(), depending if the
GIL is held or not.
2013-07-07 23:30:24 +02:00
Christian Heimes 54882bfc18 Singular form just like the other error message. 2013-07-01 15:23:48 +02:00
Christian Heimes 8087879349 Singular form just like the other error message. 2013-07-01 15:23:39 +02:00
Christian Heimes bfafab1849 Issue #18339: Negative ints keys in unpickler.memo dict no longer cause a
segfault inside the _pickle C extension.
2013-07-01 15:18:49 +02:00
Christian Heimes a24b4d260b Issue #18339: Negative ints keys in unpickler.memo dict no longer cause a
segfault inside the _pickle C extension.
2013-07-01 15:17:45 +02:00
Christian Heimes 82e6b94b95 Fix resource leak in pickle module
CID 983309 (#1 of 1): Resource leak (RESOURCE_LEAK)
leaked_storage: Variable unicode_str going out of scope leaks the storage it points to.
2013-06-29 21:37:34 +02:00
Alexandre Vassalotti 4fe2184a0f Merge 3.3 2013-04-20 21:28:49 -07:00
Alexandre Vassalotti 637c7c475a Fix reference leak in _pickle. 2013-04-20 21:28:21 -07:00
Alexandre Vassalotti 7c5e094cbf Make C and Python implementations of pickle load STRING opcodes the same way.
The C version tried to remove trailing whitespace between the last quote and
the newline character. I am not sure why it had this because pickle never
generated such pickles---for this to happen repr(some_string) would need to
return trailing whitespace. It was maybe there to make it easier for people
to write pickles in text editors. Anyhow, the Python version doesn't do this
so there is no point keeping this around anymore.

Also, I've changed the exception raised when a bad pickle is encountered.
Again this unlikely to make much difference to anyone though it does make
testing slightly nicer for us.
2013-04-15 23:14:55 -07:00
Antoine Pitrou af94051a93 Issue #17710: Fix pickle raising a SystemError on bogus input. 2013-04-15 21:55:14 +02:00
Antoine Pitrou 3034efdd29 Issue #17710: Fix pickle raising a SystemError on bogus input. 2013-04-15 21:51:09 +02:00
Alexandre Vassalotti cc7571727f Style cleanups for pickle.py and _pickle. 2013-04-14 02:25:10 -07:00
Alexandre Vassalotti 6d9e14593e Merge 3.3 2013-04-14 02:11:16 -07:00
Alexandre Vassalotti 00d83f2d05 Clean up error messages raised by save_reduce in _pickle. 2013-04-14 01:28:01 -07:00
Antoine Pitrou 4b7b0f06b4 gibibytes (Arfrever) 2013-04-07 23:46:52 +02:00
Antoine Pitrou 299978dfe3 Issue #15596: Faster pickling of unicode strings. 2013-04-07 17:38:11 +02:00
Serhiy Storchaka f8def28ff0 Issue #17193: Use binary prefixes (KiB, MiB, GiB) for memory units. 2013-02-16 17:29:56 +02:00
Antoine Pitrou 9982c53c2f Issue #12848: The pure Python pickle implementation now treats object lengths as unsigned 32-bit integers, like the C implementation does.
Patch by Serhiy Storchaka.
2012-11-24 20:41:34 +01:00
Antoine Pitrou bf6ecf92fa Issue #12848: The pure Python pickle implementation now treats object lengths as unsigned 32-bit integers, like the C implementation does.
Patch by Serhiy Storchaka.
2012-11-24 20:40:21 +01:00
Benjamin Peterson e80b29b5b6 cleanup Ellipsis and NotImplemented strings after we're done 2012-03-16 18:45:31 -05:00
Łukasz Langa cad1a07bec minor PEP7-related fix 2012-03-12 23:41:07 +01:00
Łukasz Langa dbd7825d56 #13842: check whether PyUnicode_FromString succeeded 2012-03-12 22:59:11 +01:00
Łukasz Langa f3078fbee2 Fixes #13842: cannot pickle Ellipsis or NotImplemented.
Thanks for James Sanders for the bug report and the patch.
2012-03-12 19:46:12 +01:00
Antoine Pitrou 8d3c290de4 Issue #14166: Pickler objects now have an optional `dispatch_table` attribute which allows to set custom per-pickler reduction functions.
Patch by sbt.
2012-03-04 18:31:48 +01:00
Alexandre Vassalotti a23d65ccfe Merge 3.2 2011-12-13 13:22:42 -05:00
Alexandre Vassalotti 3bfc65a25b Issue #13505: Make pickling of bytes object compatible with Python 2.
Initial patch by sbt.
2011-12-13 13:08:09 -05:00
Martin v. Löwis 1c67dd9b15 Port SetAttrString/HasAttrString to SetAttrId/GetAttrId. 2011-10-14 15:16:45 +02:00
Martin v. Löwis bd928fef42 Rename _Py_identifier to _Py_IDENTIFIER. 2011-10-14 10:20:37 +02:00
Victor Stinner f5cff56a1b Issue #13088: Add shared Py_hexdigits constant to format a number into base 16 2011-10-14 02:13:11 +02:00
Martin v. Löwis 1ee1b6fe0d Use identifier API for PyObject_GetAttrString. 2011-10-10 18:11:30 +02:00
Martin v. Löwis afe55bba33 Add API for static strings, primarily good for identifiers.
Thanks to Konrad Schöbel and Jasper Schulz for helping with the mass-editing.
2011-10-09 10:38:36 +02:00
Antoine Pitrou 5a688dbf97 Issue #7689: Allow pickling of dynamically created classes when their
metaclass is registered with copyreg.  Patch by Nicolas M. Thiéry and
Craig Citro.
2011-10-04 09:25:28 +02:00
Antoine Pitrou ffd41d9f10 Issue #7689: Allow pickling of dynamically created classes when their
metaclass is registered with copyreg.  Patch by Nicolas M. Thiéry and
Craig Citro.
2011-10-04 09:23:04 +02:00
Victor Stinner c806fdcd8b raw_unicode_escape() uses the new Unicode API 2011-09-29 23:50:23 +02:00
Victor Stinner 121aab4ba1 Strip trailing spaces of _pickle.c 2011-09-29 23:40:53 +02:00
Martin v. Löwis d63a3b8beb Implement PEP 393. 2011-09-28 07:41:54 +02:00
Benjamin Peterson 3454d52434 merge 3.2 2011-09-23 13:53:06 -04:00
Benjamin Peterson adde86d0e3 fix compiler compliant about \0 not being an opcode 2011-09-23 13:41:41 -04:00
Antoine Pitrou a514eb95f3 Issue #12847: Fix a crash with negative PUT and LONG_BINPUT arguments in
the C pickle implementation.
2011-08-30 00:28:40 +02:00
Antoine Pitrou 55549ec476 Issue #12847: Fix a crash with negative PUT and LONG_BINPUT arguments in
the C pickle implementation.
2011-08-30 00:27:10 +02:00
Antoine Pitrou ee763e2acc Issue #11564: Avoid crashes when trying to pickle huge objects or containers
(more than 2**31 items).  Instead, in most cases, an OverflowError is raised.
2011-08-29 23:14:53 +02:00
Antoine Pitrou 82be19f889 Issue #11564: Avoid crashes when trying to pickle huge objects or containers
(more than 2**31 items).  Instead, in most cases, an OverflowError is raised.
2011-08-29 23:09:33 +02:00
Antoine Pitrou e58bffb8ae Followup to 8e824e09924a: fix regression on 32-bit builds 2011-08-13 20:40:32 +02:00
Antoine Pitrou 3c7e928098 Issue #12744: Fix inefficient representation of integers
between 2**31 and 2**63 on systems with a 64-bit C "long".
2011-08-13 20:15:19 +02:00
Antoine Pitrou fdf4a27422 Issue #12687: Fix a possible buffering bug when unpickling text mode (protocol 0, mostly) pickles. 2011-08-11 21:15:53 +02:00
Antoine Pitrou f6c7a8595e Issue #12687: Fix a possible buffering bug when unpickling text mode (protocol 0, mostly) pickles. 2011-08-11 21:04:02 +02:00