Commit e8517aa7 authored by Mat's avatar Mat
Browse files

Fix taking address of packed structure member

parent d5804033
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ static PyObject *do_attach(const char *name)
	void *map_addr;
	PyObject *array;
	PyMapOwnerObject *map_owner;
	npy_intp dims[NPY_MAXDIMS];

	/* Open the file */
	if ((fd = open_file(name, O_RDWR, 0)) < 0)
@@ -92,8 +93,12 @@ static PyObject *do_attach(const char *name)
	map_owner->map_size = map_size;
	map_owner->name = strdup(name);

	/* Copy the dims[] array out of the packed structure */
	for (int i = 0; i < meta->ndims; i++)
		dims[i] = meta->dims[i];

	/* Create the array object */
	array = PyArray_New(&PyArray_Type, meta->ndims, meta->dims,
	array = PyArray_New(&PyArray_Type, meta->ndims, dims,
	                    meta->typenum, NULL, map_addr, meta->itemsize,
	                    NPY_ARRAY_CARRAY, NULL);

+2 −2
Original line number Diff line number Diff line
@@ -104,8 +104,8 @@ static PyObject *do_create(const char *name, int ndims, npy_intp *dims, PyArray_
	map_owner->name = strdup(name);

	/* Create the array object */
	array = PyArray_New(&PyArray_Type, meta->ndims, meta->dims,
	                    meta->typenum, NULL, map_addr, meta->itemsize,
	array = PyArray_New(&PyArray_Type, ndims, dims, dtype->type_num,
	                    NULL, map_addr, dtype->elsize,
	                    NPY_ARRAY_CARRAY, NULL);

	/* Attach MapOwner to the array */
+6 −1
Original line number Diff line number Diff line
@@ -108,6 +108,11 @@ static PyObject *convert_dims(int ndims, npy_intp *dims)
static struct list *list_extend(struct list *next, struct array_meta *meta, const char *name)
{
	struct list *list;
	npy_intp dims[NPY_MAXDIMS];

	/* Copy the dims[] array out of the packed structure */
	for (int i = 0; i < meta->ndims; i++)
		dims[i] = meta->dims[i];

	/* Allocate the new list element */
	if (!(list = malloc(sizeof (*list)))) {
@@ -121,7 +126,7 @@ static struct list *list_extend(struct list *next, struct array_meta *meta, cons

	PyStructSequence_SET_ITEM(list->desc, 0, PyBytes_FromString(name));
	PyStructSequence_SET_ITEM(list->desc, 1, PyArray_TypeObjectFromType(meta->typenum));
	PyStructSequence_SET_ITEM(list->desc, 2, convert_dims(meta->ndims, meta->dims));
	PyStructSequence_SET_ITEM(list->desc, 2, convert_dims(meta->ndims, dims));

	/* Return the new element */
	return list;