Skip to content

Commit

Permalink
Update trunk version to 2.0 and fix descriptor pickle code so that it…
Browse files Browse the repository at this point in the history
… produces 1.3-compatible pickle unless it cannot.
  • Loading branch information
teoliphant committed Feb 12, 2010
1 parent 2f7b48c commit 7c0908e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 44 deletions.
95 changes: 53 additions & 42 deletions numpy/core/src/multiarray/descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -2032,8 +2032,27 @@ arraydescr_reduce(PyArray_Descr *self, PyObject *NPY_UNUSED(args))
endian = '>';
}
}
state = PyTuple_New(9);
PyTuple_SET_ITEM(state, 0, PyInt_FromLong(version));
if (self->metadata) {
state = PyTuple_New(9);
PyTuple_SET_ITEM(state, 0, PyInt_FromLong(version));
if (PyDataType_ISDATETIME(self)) {
PyObject *newobj;
/* Handle CObject in NPY_METADATA_DTSTR key separately */
/* newobj is a tuple of cleaned metadata dictionary
and tuple of date_time info (str, num, den, events) */
newobj = _get_pickleabletype_from_metadata(self->metadata);
PyTuple_SET_ITEM(state, 8, newobj);
}
else {
Py_INCREF(self->metadata);
PyTuple_SET_ITEM(state, 8, self->metadata);
}
}
else { /* Use version 3 pickle format */
state = PyTuple_New(8);
PyTuple_SET_ITEM(state, 0, PyInt_FromLong(3));
}

PyTuple_SET_ITEM(state, 1, PyUString_FromFormat("%c", endian));
PyTuple_SET_ITEM(state, 2, arraydescr_subdescr_get(self));
if (self->names) {
Expand Down Expand Up @@ -2061,24 +2080,6 @@ arraydescr_reduce(PyArray_Descr *self, PyObject *NPY_UNUSED(args))
PyTuple_SET_ITEM(state, 5, PyInt_FromLong(elsize));
PyTuple_SET_ITEM(state, 6, PyInt_FromLong(alignment));
PyTuple_SET_ITEM(state, 7, PyInt_FromLong(self->hasobject));
if (self->metadata) {
if (PyDataType_ISDATETIME(self)) {
PyObject *newobj;
/* Handle CObject in NPY_METADATA_DTSTR key separately */
/* newobj is a tuple of cleaned metadata dictionary
and tuple of date_time info (str, num, den, events) */
newobj = _get_pickleabletype_from_metadata(self->metadata);
PyTuple_SET_ITEM(state, 8, newobj);
}
else {
Py_INCREF(self->metadata);
PyTuple_SET_ITEM(state, 8, self->metadata);
}
}
else {
PyTuple_SET_ITEM(state, 8, Py_None);
Py_INCREF(Py_None);
}

PyTuple_SET_ITEM(ret, 2, state);
return ret;
Expand Down Expand Up @@ -2143,67 +2144,77 @@ arraydescr_setstate(PyArray_Descr *self, PyObject *args)
!(PyTuple_Check(PyTuple_GET_ITEM(args, 0)))) {
PyErr_BadInternalCall();
return NULL;
}
}
switch (PyTuple_GET_SIZE(PyTuple_GET_ITEM(args,0))) {
case 9:
#if defined(NPY_PY3K)
if (!PyArg_ParseTuple(args, "(iCOOOiiiO)", &version, &endian,
#define _ARGSTR_ "(iCOOOiiiO)"
#else
if (!PyArg_ParseTuple(args, "(icOOOiiiO)", &version, &endian,
#define _ARGSTR_ "(icOOOiiiO)"
#endif
&subarray, &names, &fields, &elsize,
&alignment, &dtypeflags, &metadata)) {
if (!PyArg_ParseTuple(args, _ARGSTR_, &version, &endian,
&subarray, &names, &fields, &elsize,
&alignment, &dtypeflags, &metadata)) {
return NULL;
}
break;
case 8:
#if defined(NPY_PY3K)
if (!PyArg_ParseTuple(args, "(iCOOOiii)", &version, &endian,
#define _ARGSTR_ "(iCOOOiii)"
#else
if (!PyArg_ParseTuple(args, "(icOOOiii)", &version, &endian,
#define _ARGSTR_ "(icOOOiii)"
#endif
&subarray, &names, &fields, &elsize,
&alignment, &dtypeflags)) {
if (!PyArg_ParseTuple(args, _ARGSTR_, &version, &endian,
&subarray, &names, &fields, &elsize,
&alignment, &dtypeflags)) {
return NULL;
}
break;
case 7:
#if defined(NPY_PY3K)
if (!PyArg_ParseTuple(args, "(iCOOOii)", &version, &endian,
#define _ARGSTR_ "(iCOOOii)"
#else
if (!PyArg_ParseTuple(args, "(icOOOii)", &version, &endian,
#define _ARGSTR_ "(icOOOii)"
#endif
&subarray, &names, &fields, &elsize,
&alignment)) {
if (!PyArg_ParseTuple(args, _ARGSTR_, &version, &endian,
&subarray, &names, &fields, &elsize,
&alignment)) {
return NULL;
}
break;
case 6:
#if defined(NPY_PY3K)
if (!PyArg_ParseTuple(args, "(iCOOii)", &version,
#define _ARGSTR_ "(iCOOii)"
#else
if (!PyArg_ParseTuple(args, "(icOOii)", &version,
#define _ARGSTR_ "(icOOii)"
#endif
&endian, &subarray, &fields,
&elsize, &alignment)) {
if (!PyArg_ParseTuple(args, _ARGSTR_, &version,
&endian, &subarray, &fields,
&elsize, &alignment)) {
PyErr_Clear();
}
break;
case 5:
version = 0;
#if defined(NPY_PY3K)
if (!PyArg_ParseTuple(args, "(COOii)",
#define _ARGSTR_ "(COOii)"
#else
if (!PyArg_ParseTuple(args, "(cOOii)",
#define _ARGSTR_ "(cOOii)"
#endif
&endian, &subarray, &fields, &elsize,
&alignment)) {
if (!PyArg_ParseTuple(args, _ARGSTR_,
&endian, &subarray, &fields, &elsize,
&alignment)) {
return NULL;
}
break;
default:
/* raise an error */
version = -1;
if (PyTuple_GET_SIZE(PyTuple_GET_ITEM(args,0)) > 5) {
version = PyInt_AsLong(PyTuple_GET_ITEM(args, 0));
}
else {
version = -1;
}
}

/*
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
AUTHOR = "Travis E. Oliphant, et.al."
AUTHOR_EMAIL = "[email protected]"
PLATFORMS = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"]
MAJOR = 1
MINOR = 5
MAJOR = 2
MINOR = 0
MICRO = 0
ISRELEASED = False
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
Expand Down

0 comments on commit 7c0908e

Please sign in to comment.