1 --- wrapper.c 2008-12-07 14:24:01.000000000 -0200
2 +++ wrapper3.c 2011-04-19 18:03:18.826666759 -0300
4 /* All the required Python module stuff */
5 /****************************************/
11 +#if PY_MAJOR_VERSION >= 3
12 +#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
14 +#define GETSTATE(m) (&_state)
15 +static struct module_state _state;
19 -static PyMethodDef ddesolveMethods[] = {
20 - { "pastgradient", wrap_pastgradient, METH_VARARGS },
21 - { "pastvalue", wrap_pastvalue, METH_VARARGS },
22 - { "clean", wrap_freeglobaldata, METH_VARARGS },
23 - { "dde", wrap_dde, METH_VARARGS },
25 +static PyMethodDef ddesolve_methods[] = {
26 + { "pastgradient", wrap_pastgradient, METH_VARARGS },
27 + { "pastvalue", wrap_pastvalue, METH_VARARGS },
28 + { "clean", wrap_freeglobaldata, METH_VARARGS },
29 + { "dde", wrap_dde, METH_VARARGS },
33 -// module initialisation
34 -void initddesolve(void) {
36 - m = Py_InitModule("ddesolve", ddesolveMethods);
40 +#if PY_MAJOR_VERSION >= 3
42 +static int ddesolve_traverse(PyObject *m, visitproc visit, void *arg) {
43 + Py_VISIT(GETSTATE(m)->error);
47 +static int ddesolve_clear(PyObject *m) {
48 + Py_CLEAR(GETSTATE(m)->error);
53 +static struct PyModuleDef moduledef = {
54 + PyModuleDef_HEAD_INIT,
57 + sizeof(struct module_state),
65 +#define INITERROR return NULL
68 +PyInit_ddesolve(void)
71 +#define INITERROR return
77 +#if PY_MAJOR_VERSION >= 3
78 + PyObject *module = PyModule_Create(&moduledef);
80 + PyObject *module = Py_InitModule("ddesolve", ddesolve_methods);
87 + struct module_state *st = GETSTATE(module);
89 + st->error = PyErr_NewException("ddesolve.Error", NULL, NULL);
90 + if (st->error == NULL) {
95 +#if PY_MAJOR_VERSION >= 3