[Python-checkins] python/dist/src/Modules cPickle.c,2.123,2.124
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Tue, 04 Feb 2003 12:56:50 -0800
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv7825/Modules
Modified Files:
cPickle.c
Log Message:
cPickle now generates proto 2 EXT[124] when appropriate.
Moved such EXT tests as currently exist from TempAbstractPickleTests to
AbstractPickleTests, so that test_cpickle runs them too.
Index: cPickle.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/cPickle.c,v
retrieving revision 2.123
retrieving revision 2.124
diff -C2 -d -r2.123 -r2.124
*** cPickle.c 4 Feb 2003 05:20:32 -0000 2.123
--- cPickle.c 4 Feb 2003 20:56:09 -0000 2.124
***************
*** 110,113 ****
--- 110,116 ----
static PyObject *extension_cache;
+ /* For looking up name pairs in copy_reg._extension_registry. */
+ static PyObject *two_tuple;
+
static PyObject *__class___str, *__getinitargs___str, *__dict___str,
*__getstate___str, *__setstate___str, *__name___str, *__reduce___str,
***************
*** 1932,1936 ****
Py_DECREF(klass);
cPickle_ErrFormat(PicklingError,
! "Can't pickle %s: it's not the same object as %s.%s",
"OSS", args, module, global_name);
goto finally;
--- 1935,1940 ----
Py_DECREF(klass);
cPickle_ErrFormat(PicklingError,
! "Can't pickle %s: it's not the same object "
! "as %s.%s",
"OSS", args, module, global_name);
goto finally;
***************
*** 1938,1941 ****
--- 1942,2002 ----
Py_DECREF(klass);
+ if (self->proto >= 2) {
+ /* See whether this is in the extension registry, and if
+ * so generate an EXT opcode.
+ */
+ PyObject *py_code; /* extension code as Python object */
+ long code; /* extensoin code as C value */
+ char c_str[5];
+ int n;
+
+ PyTuple_SET_ITEM(two_tuple, 0, module);
+ PyTuple_SET_ITEM(two_tuple, 1, global_name);
+ py_code = PyDict_GetItem(extension_registry, two_tuple);
+ if (py_code == NULL)
+ goto gen_global; /* not registered */
+
+ /* Verify py_code has the right type and value. */
+ if (!PyInt_Check(py_code)) {
+ cPickle_ErrFormat(PicklingError, "Can't pickle %s: "
+ "extension code %s isn't n integer",
+ "OO", args, py_code);
+ goto finally;
+ }
+ code = PyInt_AS_LONG(py_code);
+ if (code <= 0 || code > 0x7fffffffL) {
+ cPickle_ErrFormat(PicklingError, "Can't pickle %s: "
+ "extension code %ld is out of range",
+ "Ol", args, code);
+ goto finally;
+ }
+
+ /* Generate an EXT opcode. */
+ if (code <= 0xff) {
+ c_str[0] = EXT1;
+ c_str[1] = (char)code;
+ n = 2;
+ }
+ else if (code <= 0xffff) {
+ c_str[0] = EXT2;
+ c_str[1] = (char)(code & 0xff);
+ c_str[2] = (char)((code >> 8) & 0xff);
+ n = 3;
+ }
+ else {
+ c_str[0] = EXT4;
+ c_str[1] = (char)(code & 0xff);
+ c_str[2] = (char)((code >> 8) & 0xff);
+ c_str[3] = (char)((code >> 16) & 0xff);
+ c_str[4] = (char)((code >> 24) & 0xff);
+ n = 5;
+ }
+
+ if (self->write_func(self, c_str, n) >= 0)
+ res = 0;
+ goto finally; /* and don't memoize */
+ }
+
+ gen_global:
if (self->write_func(self, &global, 1) < 0)
goto finally;
***************
*** 5214,5218 ****
Py_DECREF(copy_reg);
! if (!( empty_tuple = PyTuple_New(0)))
return -1;
--- 5275,5283 ----
Py_DECREF(copy_reg);
! if (!(empty_tuple = PyTuple_New(0)))
! return -1;
!
! two_tuple = PyTuple_New(2);
! if (two_tuple == NULL)
return -1;