mirror of
https://github.com/python/cpython.git
synced 2025-11-27 05:44:16 +00:00
Brought some module variables into synch with pickle.py's current values.
Imported the extension-registry dicts from copy_reg.py, in preparation for tackling EXT[124].
This commit is contained in:
parent
e7028ac56c
commit
5b7da39f23
2 changed files with 50 additions and 17 deletions
|
|
@ -81,6 +81,8 @@ def _reduce(self):
|
||||||
extension_registry = {} # key -> code
|
extension_registry = {} # key -> code
|
||||||
inverted_registry = {} # code -> key
|
inverted_registry = {} # code -> key
|
||||||
extension_cache = {} # code -> object
|
extension_cache = {} # code -> object
|
||||||
|
# Don't ever rebind those names: cPickle grabs a reference to them when
|
||||||
|
# it's initialized, and won't see a rebinding.
|
||||||
|
|
||||||
def add_extension(module, name, code):
|
def add_extension(module, name, code):
|
||||||
"""Register an extension code."""
|
"""Register an extension code."""
|
||||||
|
|
|
||||||
|
|
@ -95,10 +95,20 @@ static PyObject *UnpickleableError;
|
||||||
static PyObject *UnpicklingError;
|
static PyObject *UnpicklingError;
|
||||||
static PyObject *BadPickleGet;
|
static PyObject *BadPickleGet;
|
||||||
|
|
||||||
|
/* As the name says, an empty tuple. */
|
||||||
static PyObject *dispatch_table;
|
|
||||||
static PyObject *empty_tuple;
|
static PyObject *empty_tuple;
|
||||||
|
|
||||||
|
/* copy_reg.dispatch_table, {type_object: pickling_function} */
|
||||||
|
static PyObject *dispatch_table;
|
||||||
|
|
||||||
|
/* For EXT[124] opcodes. */
|
||||||
|
/* copy_reg.extension_registry, {(module_name, function_name): code} */
|
||||||
|
static PyObject *extension_registry;
|
||||||
|
/* copy_reg.inverted_registry, {code: (module_name, function_name)} */
|
||||||
|
static PyObject *inverted_registry;
|
||||||
|
/* copy_reg.extension_cache, {code: object} */
|
||||||
|
static PyObject *extension_cache;
|
||||||
|
|
||||||
static PyObject *__class___str, *__getinitargs___str, *__dict___str,
|
static PyObject *__class___str, *__getinitargs___str, *__dict___str,
|
||||||
*__getstate___str, *__setstate___str, *__name___str, *__reduce___str,
|
*__getstate___str, *__setstate___str, *__name___str, *__reduce___str,
|
||||||
*write_str, *append_str,
|
*write_str, *append_str,
|
||||||
|
|
@ -2592,12 +2602,14 @@ newPicklerobject(PyObject *file, int proto)
|
||||||
|
|
||||||
if (PyEval_GetRestricted()) {
|
if (PyEval_GetRestricted()) {
|
||||||
/* Restricted execution, get private tables */
|
/* Restricted execution, get private tables */
|
||||||
PyObject *m;
|
PyObject *m = PyImport_Import(copy_reg_str);
|
||||||
|
|
||||||
if (!( m=PyImport_Import(copy_reg_str))) goto err;
|
if (m == NULL)
|
||||||
|
goto err;
|
||||||
self->dispatch_table = PyObject_GetAttr(m, dispatch_table_str);
|
self->dispatch_table = PyObject_GetAttr(m, dispatch_table_str);
|
||||||
Py_DECREF(m);
|
Py_DECREF(m);
|
||||||
if (!( self->dispatch_table )) goto err;
|
if (self->dispatch_table == NULL)
|
||||||
|
goto err;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self->dispatch_table = dispatch_table;
|
self->dispatch_table = dispatch_table;
|
||||||
|
|
@ -5077,8 +5089,19 @@ init_stuff(PyObject *module_dict)
|
||||||
/* This is special because we want to use a different
|
/* This is special because we want to use a different
|
||||||
one in restricted mode. */
|
one in restricted mode. */
|
||||||
dispatch_table = PyObject_GetAttr(copy_reg, dispatch_table_str);
|
dispatch_table = PyObject_GetAttr(copy_reg, dispatch_table_str);
|
||||||
if (!dispatch_table)
|
if (!dispatch_table) return -1;
|
||||||
return -1;
|
|
||||||
|
extension_registry = PyObject_GetAttrString(copy_reg,
|
||||||
|
"extension_registry");
|
||||||
|
if (!extension_registry) return -1;
|
||||||
|
|
||||||
|
inverted_registry = PyObject_GetAttrString(copy_reg,
|
||||||
|
"inverted_registry");
|
||||||
|
if (!inverted_registry) return -1;
|
||||||
|
|
||||||
|
extension_cache = PyObject_GetAttrString(copy_reg,
|
||||||
|
"extension_cache");
|
||||||
|
if (!extension_cache) return -1;
|
||||||
|
|
||||||
Py_DECREF(copy_reg);
|
Py_DECREF(copy_reg);
|
||||||
|
|
||||||
|
|
@ -5168,7 +5191,7 @@ initcPickle(void)
|
||||||
{
|
{
|
||||||
PyObject *m, *d, *di, *v, *k;
|
PyObject *m, *d, *di, *v, *k;
|
||||||
int i;
|
int i;
|
||||||
char *rev="1.71";
|
char *rev = "1.71"; /* XXX when does this change? */
|
||||||
PyObject *format_version;
|
PyObject *format_version;
|
||||||
PyObject *compatible_formats;
|
PyObject *compatible_formats;
|
||||||
|
|
||||||
|
|
@ -5177,7 +5200,7 @@ initcPickle(void)
|
||||||
PdataType.ob_type = &PyType_Type;
|
PdataType.ob_type = &PyType_Type;
|
||||||
|
|
||||||
/* Initialize some pieces. We need to do this before module creation,
|
/* Initialize some pieces. We need to do this before module creation,
|
||||||
so we're forced to use a temporary dictionary. :(
|
* so we're forced to use a temporary dictionary. :(
|
||||||
*/
|
*/
|
||||||
di = PyDict_New();
|
di = PyDict_New();
|
||||||
if (!di) return;
|
if (!di) return;
|
||||||
|
|
@ -5190,7 +5213,8 @@ initcPickle(void)
|
||||||
|
|
||||||
/* Add some symbolic constants to the module */
|
/* Add some symbolic constants to the module */
|
||||||
d = PyModule_GetDict(m);
|
d = PyModule_GetDict(m);
|
||||||
PyDict_SetItemString(d,"__version__", v = PyString_FromString(rev));
|
v = PyString_FromString(rev);
|
||||||
|
PyDict_SetItemString(d, "__version__", v);
|
||||||
Py_XDECREF(v);
|
Py_XDECREF(v);
|
||||||
|
|
||||||
/* Copy data from di. Waaa. */
|
/* Copy data from di. Waaa. */
|
||||||
|
|
@ -5202,9 +5226,16 @@ initcPickle(void)
|
||||||
}
|
}
|
||||||
Py_DECREF(di);
|
Py_DECREF(di);
|
||||||
|
|
||||||
format_version = PyString_FromString("1.3");
|
/* These are purely informational; no code uses them. */
|
||||||
compatible_formats = Py_BuildValue("[sss]", "1.0", "1.1", "1.2");
|
/* File format version we write. */
|
||||||
|
format_version = PyString_FromString("2.0");
|
||||||
|
/* Format versions we can read. */
|
||||||
|
compatible_formats = Py_BuildValue("[sssss]",
|
||||||
|
"1.0", /* Original protocol 0 */
|
||||||
|
"1.1", /* Protocol 0 + INST */
|
||||||
|
"1.2", /* Original protocol 1 */
|
||||||
|
"1.3", /* Protocol 1 + BINFLOAT */
|
||||||
|
"2.0"); /* Oritinal potocol 2 */
|
||||||
PyDict_SetItemString(d, "format_version", format_version);
|
PyDict_SetItemString(d, "format_version", format_version);
|
||||||
PyDict_SetItemString(d, "compatible_formats", compatible_formats);
|
PyDict_SetItemString(d, "compatible_formats", compatible_formats);
|
||||||
Py_XDECREF(format_version);
|
Py_XDECREF(format_version);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue