Commit 5d4e8f62 authored by Mat's avatar Mat
Browse files

Added the list() method for Linux, python3 only

parent b0cd123e
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -49,7 +49,14 @@ from the current process. To delete a shared array use the

This function destroys an array previously created in shared memory
and identified by `name`.  After calling `delete`, the array will not
be attachable anymore, but currents attachments will not be affected.
be attachable anymore, but existing attachments will remain valid
until they are themselves destroyed.

### `SharedArray.list()`

This function returns a list of previously created shared arrays,
their name, data type and dimensions.  At the moment this function
only works on Linux and requires Python 3.

Requirements
------------
+13 −1
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@
#include <Python.h>
#include <numpy/arrayobject.h>
#include "shared_array.h"
#include "shared_array_leon.h"

/* Module name */
static const char module_name[] = "SharedArray";
@@ -48,6 +47,12 @@ static PyMethodDef module_functions[] = {
	  METH_VARARGS,
	  "Delete an existing numpy array from shared memory" },

#if PY_MAJOR_VERSION >= 3
	{ "list", (PyCFunction) shared_array_list,
	  METH_VARARGS,
	  "List all existing numpy arrays from shared memory" },
#endif

	{ NULL, NULL, 0, NULL }
};

@@ -96,6 +101,13 @@ static PyObject *module_init(void)
	Py_INCREF(&PyLeonObject_Type);
	PyModule_AddObject(m, module_name, (PyObject *) &PyLeonObject_Type);

#if PY_MAJOR_VERSION >= 3
	/* Register the Descr type */
	PyStructSequence_InitType(&PyArrayDescObject_Type, &PyArrayDescObject_Desc);
	PyType_Ready(&PyArrayDescObject_Type);
	Py_INCREF(&PyArrayDescObject_Type);
	PyModule_AddObject(m, module_name, (PyObject *) &PyArrayDescObject_Type);
#endif	
	return m;
}

+18 −0
Original line number Diff line number Diff line
@@ -37,9 +37,27 @@ struct array_meta {
	npy_intp dims[SHARED_ARRAY_NDIMS_MAX];
} __attribute__ ((packed));

/* ArrayDesc object */
#if PY_MAJOR_VERSION >= 3
extern PyStructSequence_Desc PyArrayDescObject_Desc;
extern PyTypeObject PyArrayDescObject_Type;
#endif

/* Leon object */
typedef struct {
	PyObject_HEAD
	void	*data;
	size_t	size;
} PyLeonObject;

extern PyTypeObject PyLeonObject_Type;

/* Module functions */
extern PyObject *shared_array_create(PyObject *self, PyObject *args, PyObject *kw);
extern PyObject *shared_array_attach(PyObject *self, PyObject *args);
extern PyObject *shared_array_delete(PyObject *self, PyObject *args);
#if PY_MAJOR_VERSION >= 3
extern PyObject *shared_array_list(PyObject *self, PyObject *args);
#endif

#endif /* !__SHARED_ARRAY_H__ */
+0 −1
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@
#include <fcntl.h>
#include <unistd.h>
#include "shared_array.h"
#include "shared_array_leon.h"

/*
 * Attach a numpy array from shared memory
+0 −1
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@
#include <fcntl.h>
#include <unistd.h>
#include "shared_array.h"
#include "shared_array_leon.h"

/*
 * Create a numpy array in shared memory
Loading