1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 10:47:59 +08:00
Files
CMake/Tests/RunCMake/FindPython/spam.c
2025-02-28 17:55:24 +01:00

46 lines
1.1 KiB
C

#if !defined(_WIN32)
/* Disabled for Windows to avoid to link with the wrong library specified by
* #pragma */
# define Py_LIMITED_API 3
#endif
#include <Python.h>
static PyObject* spam_system(PyObject* self, PyObject* args)
{
char const* 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