|
- #include <python2.7/Python.h>
- #include <numpy/arrayobject.h>
-
- PyDoc_STRVAR(hello_doc, "Print hello message from Python module");
-
- /* Output hello message */
- static PyObject *pymod_hello(PyObject *self, PyObject *args)
- {
- PyObject *r = NULL;
-
- npy_int dims[2] = {940, 2};
-
- if (PyArg_ParseTuple(args, "")) {
- printf("Hello from Python module\n");
-
- r = PyArray_New(&PyArray_Type, 2, dims, NPY_INT16, NULL, NULL, 2, 0, NULL);
- }
-
- return r;
- }
-
- /* Exported methods */
- static PyMethodDef pymod_methods[] = {
- {"hello", (PyCFunction)pymod_hello,
- METH_VARARGS, hello_doc},
- {NULL, NULL} /* sentinel */
- };
-
- PyDoc_STRVAR(module_doc, "Simple test module");
-
- /* Module initialisation, called by Python on import */
- PyMODINIT_FUNC
- initpymod2(void)
- {
- PyObject *m;
-
- puts("Hoi, module pymod2 loaded.");
- m = Py_InitModule3("pymod2", pymod_methods, module_doc);
- if (m == NULL)
- return;
-
- /* Our module requires the GIL to be available */
- if (!PyEval_ThreadsInitialized()) {
- puts("Initialising multithreading for Python");
- PyEval_InitThreads();
- }
-
- /* Initialise NumPy */
- import_array();
-
- return;
- }
|