8000 Fix dtype int vs char inconsistencies + dtype hashing by cournape · Pull Request #231 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Fix dtype int vs char inconsistencies + dtype hashing #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
BUG: fix inconsistencies in dtype flag type at the C level.
  • Loading branch information
cournape committed Mar 7, 2012
commit 40e439348611e5d9ffa2854f114c4df6cd9b4b58
35 changes: 24 additions & 11 deletions numpy/core/src/multiarray/descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ _convert_from_array_descr(PyObject *obj, int align)
PyObject *nameslist;
PyArray_Descr *new;
PyArray_Descr *conv;
int dtypeflags = 0;
char dtypeflags = 0;
int maxalign = 0;

n = PyList_GET_SIZE(obj);
Expand Down Expand Up @@ -479,7 +479,7 @@ _convert_from_array_descr(PyObject *obj, int align)
new->fields = fields;
new->names = nameslist;
new->elsize = totalsize;
new->flags=dtypeflags;
new->flags = dtypeflags;

/* Structured arrays get a sticky aligned bit */
if (align) {
Expand Down Expand Up @@ -512,7 +512,7 @@ _convert_from_list(PyObject *obj, int align)
PyObject *nameslist = NULL;
int ret;
int maxalign = 0;
int dtypeflags = 0;
char dtypeflags = 0;

n = PyList_GET_SIZE(obj);
/*
Expand Down Expand Up @@ -844,7 +844,7 @@ _convert_from_dict(PyObject *obj, int align)
int n, i;
int totalsize, itemsize;
int maxalign = 0;
int dtypeflags = 0;
char dtypeflags = 0;
int has_out_of_order_fields = 0;

fields = PyDict_New();
Expand Down Expand Up @@ -2197,10 +2197,10 @@ arraydescr_reduce(PyArray_Descr *self, PyObject *NPY_UNUSED(args))
}

/*
* returns 1 if this data-type has an object portion
* used when setting the state because hasobject is not stored.
* returns NPY_OBJECT_DTYPE_FLAGS if this data-type has an object portion used
* when setting the state because hasobject is not stored.
*/
static int
static char
_descr_find_object(PyArray_Descr *self)
{
if (self->flags
Expand Down Expand Up @@ -2247,7 +2247,8 @@ arraydescr_setstate(PyArray_Descr *self, PyObject *args)
#endif
PyObject *subarray, *fields, *names = NULL, *metadata=NULL;
int incref_names = 1;
int dtypeflags = 0;
int int_dtypeflags = 0;
char dtypeflags;

if (self->fields == Py_None) {
Py_INCREF(Py_None);
Expand All @@ -2267,7 +2268,7 @@ arraydescr_setstate(PyArray_Descr *self, PyObject *args)
#endif
if (!PyArg_ParseTuple(args, _ARGSTR_, &version, &endian,
&subarray, &names, &fields, &elsize,
&alignment, &dtypeflags, &metadata)) {
&alignment, &int_dtypeflags, &metadata)) {
return NULL;
#undef _ARGSTR_
}
Expand All @@ -2280,7 +2281,7 @@ arraydescr_setstate(PyArray_Descr *self, PyObject *args)
#endif
if (!PyArg_ParseTuple(args, _ARGSTR_, &version, &endian,
&subarray, &names, &fields, &elsize,
&alignment, &dtypeflags)) {
&alignment, &int_dtypeflags)) {
return NULL;
#undef _ARGSTR_
}
Expand Down Expand Up @@ -2448,7 +2449,19 @@ arraydescr_setstate(PyArray_Descr *self, PyObject *args)
self->alignment = alignment;
}

self->flags = dtypeflags;
/* We use an integer converted to char for backward compatibility with
* pickled arrays. Pickled arrays created with previous versions encoded
* flags as an int even though it actually was a char in the PyArray_Descr
* structure */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/*
 * blah
 */

dtypeflags = int_dtypeflags;
if (dtypeflags != int_dtypeflags) {
PyErr_Format(PyExc_ValueError,
"incorrect value for flags variable (overflow)");
return NULL;
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
else {

self->flags = dtypeflags;
}

if (version < 3) {
self->flags = _descr_find_object(self);
}
Expand Down
0