All pastes #935051 Raw Edit

Stuff

public text v1 · immutable
·published 2008-03-09 09:39 UTC
rendered paste body
generator.c
-----------
#include <Python.h>

PyObject *
seed_generator(PyObject *self, PyObject *args)
{
        int a;
        int ok = PyArg_ParseTuple(args, "i",&a);
        if(!ok) return NULL;
        srand((int)a);
        PyObject *py_result = Py_BuildValue("i", (int)0);
        return py_result;
}

void initgenerator(void)
{
        PyMethodDef generatorMethods[] =
        {
                {"seed", seed_generator, METH_VARARGS},
                {NULL, NULL},
        };
        PyObject *m =
                Py_InitModule4(
                        "generator",
                        generatorMethods,
                        "Some rubbish",
                        0,
                        PYTHON_API_VERSION);
        return;
}

begin usage
-----------
>>> import generator
>>> generator.seed(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
SystemError: ../Objects/methodobject.c:112: bad argument to internal function
>>>