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
|
#include <Python.h>
#include <structmember.h>
static PyObject *
run(PyObject *self)
{
PyObject *list, *l;
int i;
unsigned int taille = 12000000;
long *tab;
list = PyList_New(0);
tab = malloc(taille*sizeof(long));
for(i=0; i<taille; i++)
{
l = PyInt_FromLong((long)tab[i]*12345);
if(PyList_Append(list, l) == -1)
{
PyErr_Print();
free(tab);
return NULL;
}
}
free(tab);
return list;
}
static PyMethodDef methods[] = {
{"run", (PyCFunction)run, METH_NOARGS, "Return list"},
{NULL, NULL}
};
PyMODINIT_FUNC
inittest(void)
{
Py_InitModule("test", methods);
} |
Partager