diff options
author | Marc Chevrier <marc.chevrier@sap.com> | 2018-02-22 15:18:43 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@sap.com> | 2018-03-20 08:29:44 (GMT) |
commit | 352baee2074d12637c65e3113f560bbf98d0640a (patch) | |
tree | 916caf02869368eb32ef955697147e6a2f52ff40 /Tests/FindPython/spam.c | |
parent | dfc9036bcf65afc4aa0fd21092d47da4ccd259cb (diff) | |
download | CMake-352baee2074d12637c65e3113f560bbf98d0640a.zip CMake-352baee2074d12637c65e3113f560bbf98d0640a.tar.gz CMake-352baee2074d12637c65e3113f560bbf98d0640a.tar.bz2 |
FindPython*: New implementation for Python stuff
Fixes: #16142
Diffstat (limited to 'Tests/FindPython/spam.c')
-rw-r--r-- | Tests/FindPython/spam.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Tests/FindPython/spam.c b/Tests/FindPython/spam.c new file mode 100644 index 0000000..1c65d54 --- /dev/null +++ b/Tests/FindPython/spam.c @@ -0,0 +1,41 @@ + +#include <Python.h> + +static PyObject* spam_system(PyObject* self, PyObject* args) +{ + const char* command; + int sts; + + if (!PyArg_ParseTuple(args, "s", &command)) + return NULL; + sts = system(command); + /* return PyLong_FromLong(sts); */ + return Py_BuildValue("i", sts); +} + +static PyMethodDef SpamMethods[] = { + { "system", spam_system, METH_VARARGS, "Execute a shell command." }, + { NULL, NULL, 0, NULL } /* Sentinel */ +}; + +#if defined(PYTHON2) +PyMODINIT_FUNC initspam2(void) +{ + (void)Py_InitModule("spam2", SpamMethods); +} +#endif + +#if defined(PYTHON3) +static struct PyModuleDef spammodule = { + PyModuleDef_HEAD_INIT, "spam3", /* 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. */ + SpamMethods +}; + +PyMODINIT_FUNC PyInit_spam3(void) +{ + return PyModule_Create(&spammodule); +} +#endif |