1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| #include <Python.h>
extern "C" void initLeFlamanc(void); /* Forward */
/* A static module */
/* 'self' is not used */
static PyObject *return2NiC(PyObject * self, PyObject * args)
{
int ni;
int nj;
int nk;
int _ni;
int _nj;
int _nk;
PyObject * array1; // nouvelle reference
if (!PyArg_ParseTuple(args, "iiiO", &ni, &nj, &nk,&array1))
return NULL;
_ni = ni * 2;
_nj = nj * 2;
_nk = nk * 2;
// create the tuple
PyObject *pTuple = PyTuple_New(10); // new reference
assert(PyTuple_Check(pTuple)); // Test de comoportement sur le type et la taille du Tuple
assert(PyTuple_Size(pTuple) == 10);
// set the item
for (int i=0;i<=(10-1) ;i++)
{
PyTuple_SetItem(pTuple, i, Py_BuildValue("f",1));
}
// parse tuple items
float f;
if(!PyArg_ParseTuple(pTuple, "f",&f))
PyErr_SetString(PyExc_TypeError, "invalid parameter");
// cleanup
Py_DECREF(pTuple);
//return Py_BuildValue("iiiO",_ni,_nj,_nk,array1); // creation d'un objet pour retour à python
return pTuple;
}
static PyMethodDef LeFlamancMethods[] = {
{"return2Ni", return2NiC, METH_VARARGS,
"Compute two times an integer."},
{NULL, NULL, 0, NULL} /* Sentinel */
};
void initLeFlamanc(void)
{
// PyImport_AddModule("LeFlamanc");
Py_InitModule("LeFlamanc", LeFlamancMethods);
} |
Partager