1
0

TEST_spam.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #if !defined(_WIN32)
  2. /* Disabled for Windows to avoid to link with the wrong library specified by
  3. * #pragma */
  4. # define Py_LIMITED_API 3
  5. #endif
  6. #include <Python.h>
  7. static PyObject* spam_system(PyObject* self, PyObject* args)
  8. {
  9. char const* command;
  10. int sts;
  11. if (!PyArg_ParseTuple(args, "s", &command))
  12. return NULL;
  13. sts = system(command);
  14. /* return PyLong_FromLong(sts); */
  15. return Py_BuildValue("i", sts);
  16. }
  17. static PyMethodDef SpamMethods[] = {
  18. { "system", spam_system, METH_VARARGS, "Execute a shell command." },
  19. { NULL, NULL, 0, NULL } /* Sentinel */
  20. };
  21. #if defined(PYTHON2)
  22. PyMODINIT_FUNC initTEST_spam2(void)
  23. {
  24. (void)Py_InitModule("TEST_spam2", SpamMethods);
  25. }
  26. #endif
  27. #if defined(PYTHON3)
  28. static struct PyModuleDef spammodule = {
  29. PyModuleDef_HEAD_INIT, "TEST_spam3", /* name of module */
  30. NULL, /* module documentation, may be NULL */
  31. -1, /* size of per-interpreter state of the module,
  32. or -1 if the module keeps state in global variables. */
  33. SpamMethods
  34. };
  35. PyMODINIT_FUNC PyInit_TEST_spam3(void)
  36. {
  37. return PyModule_Create(&spammodule);
  38. }
  39. #endif