/*
- cPickle.c,v 1.48 1997/12/07 14:37:39 jim Exp
+ cPickle.c,v 1.53 1998/05/05 15:41:31 jim Exp
Copyright
- Copyright 1996 Digital Creations, L.C., 910 Princess Anne
- Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All
- rights reserved. Copyright in this software is owned by DCLC,
- unless otherwise indicated. Permission to use, copy and
- distribute this software is hereby granted, provided that the
- above copyright notice appear in all copies and that both that
- copyright notice and this permission notice appear. Note that
- any product, process or technology described in this software
- may be the subject of other Intellectual Property rights
- reserved by Digital Creations, L.C. and are not licensed
- hereunder.
+ Copyright 1996, 1997, 1998 Digital Creations, Inc., 910
+ Princess Anne Street, Suite 300, Fredericksburg, Virginia 22401
+ U.S.A. All rights reserved. Copyright in this software is
+ owned by DCLC, unless otherwise indicated. Permission to use,
+ copy and distribute this software is hereby granted, provided
+ that the above copyright notice appear in all copies and that
+ both that copyright notice and this permission notice
+ appear. Note that any product, process or technology described
+ in this software may be the subject of other Intellectual
+ Property rights reserved by Digital Creations, L.C. and are not
+ licensed hereunder.
Trademarks
static char cPickle_module_documentation[] =
"C implementation and optimization of the Python pickle module\n"
"\n"
-"cPickle.c,v 1.48 1997/12/07 14:37:39 jim Exp\n"
+"cPickle.c,v 1.53 1998/05/05 15:41:31 jim Exp\n"
;
#include "Python.h"
static PyObject *dispatch_table;
static PyObject *safe_constructors;
-static PyObject *class_map;
static PyObject *empty_tuple;
static PyObject *__class___str, *__getinitargs___str, *__dict___str,
char *write_buf;
int buf_size;
PyObject *dispatch_table;
- PyObject *class_map;
} Picklerobject;
staticforward PyTypeObject Picklertype;
int buf_size;
char *buf;
PyObject *safe_constructors;
- PyObject *class_map;
} Unpicklerobject;
staticforward PyTypeObject Unpicklertype;
}
static PyObject *
-whichmodule(PyObject *class_map, PyObject *global, PyObject *global_name) {
+whichmodule(PyObject *global, PyObject *global_name) {
int i, j;
PyObject *module = 0, *modules_dict = 0,
*global_name_attr = 0, *name = 0;
if (module) return module;
PyErr_Clear();
- if ((module = PyDict_GetItem(class_map, global))) {
- Py_INCREF(module);
- return module;
- }
-
UNLESS(modules_dict = PySys_GetObject("modules")) {
PyErr_SetString(PyExc_SystemError, "lost sys.modules");
return NULL;
j=1;
name=__main___str;
}
-
- /*
- if (!j) {
- cPickle_ErrFormat(PicklingError, "Could not find module for %s.",
- "O", global_name);
- return NULL;
- }
- */
-
- PyDict_SetItem(class_map, global, name);
Py_INCREF(name);
return name;
goto finally;
}
- UNLESS(module = whichmodule(self->class_map, class, name))
+ UNLESS(module = whichmodule(class, name))
goto finally;
module_str = PyString_AS_STRING((PyStringObject *)module);
goto finally;
}
- UNLESS(module = whichmodule(self->class_map, args, global_name))
+ UNLESS(module = whichmodule(args, global_name))
goto finally;
module_str = PyString_AS_STRING((PyStringObject *)module);
self->write_buf = NULL;
self->bin = bin;
self->buf_size = 0;
- self->class_map = NULL;
self->dispatch_table = NULL;
Py_INCREF(file);
/* Restricted execution, get private tables */
PyObject *m;
- UNLESS(self->class_map=PyDict_New()) goto err;
UNLESS(m=PyImport_Import(copy_reg_str)) goto err;
self->dispatch_table=PyObject_GetAttr(m, dispatch_table_str);
Py_DECREF(m);
UNLESS(self->dispatch_table) goto err;
}
else {
- self->class_map=class_map;
- Py_INCREF(class_map);
self->dispatch_table=dispatch_table;
Py_INCREF(dispatch_table);
}
Py_XDECREF(self->file);
Py_XDECREF(self->pers_func);
Py_XDECREF(self->inst_pers_func);
- Py_XDECREF(self->class_map);
Py_XDECREF(self->dispatch_table);
if (self->write_buf) {
};
static PyObject *
-find_class(PyObject *class_map,
- PyObject *py_module_name, PyObject *py_global_name) {
- PyObject *global = 0, *t = 0, *module;
+find_class(PyObject *py_module_name, PyObject *py_global_name) {
+ PyObject *global = 0, *module;
- UNLESS(t = PyTuple_New(2)) return NULL;
-
- PyTuple_SET_ITEM((PyTupleObject *)t, 0, py_module_name);
- Py_INCREF(py_module_name);
- PyTuple_SET_ITEM((PyTupleObject *)t, 1, py_global_name);
- Py_INCREF(py_global_name);
-
- global=PyDict_GetItem(class_map, t);
-
- if (global) {
- Py_DECREF(t);
- Py_INCREF(global);
- return global;
+ UNLESS(module=PySys_GetObject("modules")) return NULL;
+ UNLESS(module=PyDict_GetItem(module, py_module_name)) {
+ PyErr_Clear();
+ UNLESS(module=PyImport_Import(py_module_name)) return NULL;
}
- PyErr_Clear();
-
- UNLESS(module=PyImport_Import(py_module_name)) return NULL;
global=PyObject_GetAttr(module, py_global_name);
Py_DECREF(module);
- UNLESS(global) return NULL;
-
- if (PyDict_SetItem(class_map, t, global) < 0) global=NULL;
- Py_DECREF(t);
return global;
}
if (!has_key)
if(!(safe = PyObject_GetAttr(cls, __safe_for_unpickling___str)) ||
!PyObject_IsTrue(safe)) {
- cPickle_ErrFormat(UnpicklingError, "%s is not safe for unpickling", "O", cls);
+ cPickle_ErrFormat(UnpicklingError,
+ "%s is not safe for unpickling", "O", cls);
Py_XDECREF(safe);
return NULL;
}
UNLESS(class_name = PyString_FromStringAndSize(s, len - 1)) goto finally;
- UNLESS(class = find_class(self->class_map, module_name, class_name))
+ UNLESS(class = find_class(module_name, class_name))
goto finally;
UNLESS(obj = Instance_New(class, arg_tup)) goto finally;
UNLESS(class_name = PyString_FromStringAndSize(s, len - 1))
goto finally;
- UNLESS(class = find_class(self->class_map, module_name, class_name))
+ UNLESS(class = find_class(module_name, class_name))
goto finally;
if (PyList_Append(self->stack, class) < 0)
self->buf_size = 0;
self->read = NULL;
self->readline = NULL;
- self->class_map = NULL;
UNLESS(self->memo = PyDict_New()) {
Py_XDECREF((PyObject *)self);
/* Restricted execution, get private tables */
PyObject *m;
- UNLESS(self->class_map=PyDict_New()) goto err;
UNLESS(m=PyImport_Import(copy_reg_str)) goto err;
self->safe_constructors=PyObject_GetAttr(m, safe_constructors_str);
Py_DECREF(m);
UNLESS(self->safe_constructors) goto err;
}
else {
- self->class_map=class_map;
- Py_INCREF(class_map);
self->safe_constructors=safe_constructors;
Py_INCREF(safe_constructors);
}
Py_XDECREF(self->pers_func);
Py_XDECREF(self->arg);
Py_XDECREF(self->last_string);
- Py_XDECREF(self->class_map);
Py_XDECREF(self->safe_constructors);
if (self->marks) {
Py_DECREF(copy_reg);
- UNLESS(class_map = PyDict_New()) return -1;
-
/* Down to here ********************************** */
UNLESS(string = PyImport_ImportModule("string"))
void
initcPickle() {
PyObject *m, *d, *v;
- char *rev="1.48";
+ char *rev="1.53";
PyObject *format_version;
PyObject *compatible_formats;