COPYING: Everything I've done is CC0
[cpython-extension.git] / spammify.c
1 #include <Python.h>
2 #include <stdlib.h>
3
4 static PyObject *
5 spam_busy(PyObject *self, PyObject *args)
6 {
7         long int count, i;
8
9         if (!PyArg_ParseTuple(args, "l", &count))
10                 return NULL;
11         Py_BEGIN_ALLOW_THREADS
12         for (i = 0; i < count; i++)
13                 ;
14         Py_END_ALLOW_THREADS
15         return PyLong_FromLong(i);
16 }
17
18 static PyMethodDef SpamMethods[] = {
19         {"busy",  spam_busy, METH_VARARGS,
20          "Drop the GIL and run a busy wait until you count to `count`."},
21         {NULL, NULL, 0, NULL}        /* Sentinel */
22 };
23
24 static struct PyModuleDef spammodule = {
25         PyModuleDef_HEAD_INIT,
26         "spam",   /* name of module */
27         NULL,     /* module documentation, may be NULL */
28         0,        /* size of per-interpreter state of the module */
29         SpamMethods
30 };
31
32 PyMODINIT_FUNC
33 PyInit_spam(void)
34 {
35         return PyModule_Create(&spammodule);
36 }