-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathcoremodule.c
More file actions
44 lines (35 loc) · 932 Bytes
/
coremodule.c
File metadata and controls
44 lines (35 loc) · 932 Bytes
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
#define PY_SSIZE_T_CLEAN
#include <Python.h>
static PyObject *
core_echo(PyObject *self, PyObject *args)
{
const char *str;
PyObject *ret;
if (!PyArg_ParseTuple(args, "s", &str))
return NULL;
printf("%s\n", str);
ret = PyLong_FromLong(42);
Py_INCREF(ret);
return ret;
}
static PyMethodDef CoreMethods[] = {
{"echo", core_echo, METH_VARARGS, "Echo a string and return 42"},
{NULL, NULL, 0, NULL} /* Sentinel */
};
static struct PyModuleDef coremodule = {
PyModuleDef_HEAD_INIT,
"core", /* name of module */
NULL, /* module documentation, may be NULL */
-1, /* size of per-interpreter state of the module,
or -1 if the module keeps state in global variables. */
CoreMethods
};
PyMODINIT_FUNC
PyInit__core(void)
{
PyObject *m;
m = PyModule_Create(&coremodule);
if (m == NULL)
return NULL;
return m;
}