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
|
#include <Python.h>
PyObject* id(PyObject* self, PyObject* args);
static PyMethodDef functions[] =
{
{"id", id, METH_VARARGS, "id()"},
{NULL, NULL, 0, NULL} /*Sentinel*/
};
static struct PyModuleDef module_def =
{
PyModuleDef_HEAD_INIT,
"mypymod", /* Name */
"My Python Module", /* Module documentation */
-1, /* Size of per-interpreter state */
functions,
NULL, // m_reload
NULL, // m_traverse
NULL, // m_clear
NULL // m_free
};
PyMODINIT_FUNC PyInit_mypymod(void)
{
PyObject* module = NULL;
printf("PyInit_mypymod: enter\n");
module = PyModule_Create(&module_def);
if (module == NULL) {
return NULL;
}
printf("PyInit_mypymod: exit: module=%p\n", module);
return module;
}
PyObject* id(PyObject* self, PyObject* args)
{
static int idval = 0;
idval++;
return Py_BuildValue("i", idval);
}
|