Skip to content

Instantly share code, notes, and snippets.

@sdiehl
Created November 11, 2013 21:33
Show Gist options
  • Save sdiehl/7420786 to your computer and use it in GitHub Desktop.
Save sdiehl/7420786 to your computer and use it in GitHub Desktop.
#include <Python.h>
/*
* Usage
$ python
Python 2.7.3 |Anaconda 1.4.0 (64-bit)| (default, Feb 25 2013, 18:46:31)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import evil
>>> True
False
>>> False
True
>>> 2+2
42
*/
static PyMethodDef evilmethods[] = {
{NULL, NULL} /* Sentinel */
};
static PyObject *
int_add(PyIntObject *v, PyIntObject *w)
{
return PyInt_FromLong(42);
}
void initevil(void)
{
PyObject* m;
// Happy debugging suckers
((PyBoolObject*)Py_True)->ob_ival = 0;
((PyBoolObject*)Py_False)->ob_ival = 1;
PyInt_Type.tp_as_number->nb_add = (binaryfunc)int_add;
m = Py_InitModule("evil", NULL);
if (m == NULL)
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment