diff options
author | Ćukasz Langa <lukasz@langa.pl> | 2018-04-04 06:06:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-04 06:06:53 (GMT) |
commit | c51d8c9ba6211d77db639487501f89aa9b4bcbb1 (patch) | |
tree | cabc297cea85143550c1755cbd9a19ec9c2c2603 /Modules | |
parent | 42ec190761a2e8503aaa06f0bfaaabe98749179b (diff) | |
download | cpython-c51d8c9ba6211d77db639487501f89aa9b4bcbb1.zip cpython-c51d8c9ba6211d77db639487501f89aa9b4bcbb1.tar.gz cpython-c51d8c9ba6211d77db639487501f89aa9b4bcbb1.tar.bz2 |
bpo-23403: Bump pickle.DEFAULT_PROTOCOL to 4 (#6355)
This makes performance better and produces shorter pickles. This change is backwards compatible up to the oldest currently supported version of Python (3.4).
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_pickle.c | 18 | ||||
-rw-r--r-- | Modules/clinic/_pickle.c.h | 10 |
2 files changed, 17 insertions, 11 deletions
diff --git a/Modules/_pickle.c b/Modules/_pickle.c index 6a684f2..aa672af 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -20,10 +20,12 @@ class _pickle.UnpicklerMemoProxy "UnpicklerMemoProxyObject *" "&UnpicklerMemoPro [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=4b3e113468a58e6c]*/ -/* Bump this when new opcodes are added to the pickle protocol. */ +/* Bump HIGHEST_PROTOCOL when new opcodes are added to the pickle protocol. + Bump DEFAULT_PROTOCOL only when the oldest still supported version of Python + already includes it. */ enum { HIGHEST_PROTOCOL = 4, - DEFAULT_PROTOCOL = 3 + DEFAULT_PROTOCOL = 4 }; /* Pickle opcodes. These must be kept updated with pickle.py. @@ -7176,8 +7178,9 @@ This is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more efficient. The optional *protocol* argument tells the pickler to use the given -protocol supported protocols are 0, 1, 2, 3 and 4. The default -protocol is 3; a backward-incompatible protocol designed for Python 3. +protocol; supported protocols are 0, 1, 2, 3 and 4. The default +protocol is 4. It was introduced in Python 3.4, it is incompatible +with previous versions. Specifying a negative protocol version selects the highest protocol version supported. The higher the protocol used, the more recent the @@ -7196,7 +7199,7 @@ to map the new Python 3 names to the old module names used in Python static PyObject * _pickle_dump_impl(PyObject *module, PyObject *obj, PyObject *file, PyObject *protocol, int fix_imports) -/*[clinic end generated code: output=a4774d5fde7d34de input=830f8a64cef6f042]*/ +/*[clinic end generated code: output=a4774d5fde7d34de input=93f1408489a87472]*/ { PicklerObject *pickler = _Pickler_New(); @@ -7236,7 +7239,8 @@ Return the pickled representation of the object as a bytes object. The optional *protocol* argument tells the pickler to use the given protocol; supported protocols are 0, 1, 2, 3 and 4. The default -protocol is 3; a backward-incompatible protocol designed for Python 3. +protocol is 4. It was introduced in Python 3.4, it is incompatible +with previous versions. Specifying a negative protocol version selects the highest protocol version supported. The higher the protocol used, the more recent the @@ -7250,7 +7254,7 @@ Python 2, so that the pickle data stream is readable with Python 2. static PyObject * _pickle_dumps_impl(PyObject *module, PyObject *obj, PyObject *protocol, int fix_imports) -/*[clinic end generated code: output=d75d5cda456fd261 input=293dbeda181580b7]*/ +/*[clinic end generated code: output=d75d5cda456fd261 input=b6efb45a7d19b5ab]*/ { PyObject *result; PicklerObject *pickler = _Pickler_New(); diff --git a/Modules/clinic/_pickle.c.h b/Modules/clinic/_pickle.c.h index 7fc00a0..6d90728 100644 --- a/Modules/clinic/_pickle.c.h +++ b/Modules/clinic/_pickle.c.h @@ -367,8 +367,9 @@ PyDoc_STRVAR(_pickle_dump__doc__, "be more efficient.\n" "\n" "The optional *protocol* argument tells the pickler to use the given\n" -"protocol supported protocols are 0, 1, 2, 3 and 4. The default\n" -"protocol is 3; a backward-incompatible protocol designed for Python 3.\n" +"protocol; supported protocols are 0, 1, 2, 3 and 4. The default\n" +"protocol is 4. It was introduced in Python 3.4, it is incompatible\n" +"with previous versions.\n" "\n" "Specifying a negative protocol version selects the highest protocol\n" "version supported. The higher the protocol used, the more recent the\n" @@ -419,7 +420,8 @@ PyDoc_STRVAR(_pickle_dumps__doc__, "\n" "The optional *protocol* argument tells the pickler to use the given\n" "protocol; supported protocols are 0, 1, 2, 3 and 4. The default\n" -"protocol is 3; a backward-incompatible protocol designed for Python 3.\n" +"protocol is 4. It was introduced in Python 3.4, it is incompatible\n" +"with previous versions.\n" "\n" "Specifying a negative protocol version selects the highest protocol\n" "version supported. The higher the protocol used, the more recent the\n" @@ -560,4 +562,4 @@ _pickle_loads(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec exit: return return_value; } -/*[clinic end generated code: output=e995dd494045d876 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=6fc104b8299c82dd input=a9049054013a1b77]*/ |