From a7a7743a2367540cafeaa1741e3285851865a96a Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 17 Apr 2013 11:39:29 -0400 Subject: [PATCH] spammify.c: Add the basic extension code From http://docs.python.org/3/extending/extending.html --- spammify.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 spammify.c diff --git a/spammify.c b/spammify.c new file mode 100644 index 0000000..d586aac --- /dev/null +++ b/spammify.c @@ -0,0 +1,34 @@ +#include +#include + +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); +} + +static PyMethodDef SpamMethods[] = { + {"system", spam_system, METH_VARARGS, + "Execute a shell command."}, + {NULL, NULL, 0, NULL} /* Sentinel */ +}; + +static struct PyModuleDef spammodule = { + PyModuleDef_HEAD_INIT, + "spam", /* name of module */ + spam_doc, /* module documentation, may be NULL */ + 0, /* size of per-interpreter state of the module */ + SpamMethods +}; + +PyMODINIT_FUNC +PyInit_spam(void) +{ + return PyModule_Create(&spammodule); +} -- 2.26.2