updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / python3-pydde / Py3-C-API.diff
blob0c911bf06486d64b74497e866e89b5317ecd556d
1 --- wrapper.c 2008-12-07 14:24:01.000000000 -0200
2 +++ wrapper3.c 2011-04-19 18:03:18.826666759 -0300
3 @@ -544,19 +544,84 @@
4 /* All the required Python module stuff */
5 /****************************************/
7 +struct module_state {
8 + PyObject *error;
9 +};
11 +#if PY_MAJOR_VERSION >= 3
12 +#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
13 +#else
14 +#define GETSTATE(m) (&_state)
15 +static struct module_state _state;
16 +#endif
18 // method definitions
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 },
24 - { NULL, NULL }
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 },
30 + { NULL, NULL }
31 };
33 -// module initialisation
34 -void initddesolve(void) {
35 - PyObject *m;
36 - m = Py_InitModule("ddesolve", ddesolveMethods);
37 - import_array();
38 -}
40 +#if PY_MAJOR_VERSION >= 3
42 +static int ddesolve_traverse(PyObject *m, visitproc visit, void *arg) {
43 + Py_VISIT(GETSTATE(m)->error);
44 + return 0;
47 +static int ddesolve_clear(PyObject *m) {
48 + Py_CLEAR(GETSTATE(m)->error);
49 + return 0;
53 +static struct PyModuleDef moduledef = {
54 + PyModuleDef_HEAD_INIT,
55 + "ddesolve",
56 + NULL,
57 + sizeof(struct module_state),
58 + ddesolve_methods,
59 + NULL,
60 + ddesolve_traverse,
61 + ddesolve_clear,
62 + NULL
63 +};
65 +#define INITERROR return NULL
67 + PyObject *
68 +PyInit_ddesolve(void)
70 +#else
71 +#define INITERROR return
73 + void
74 +initddesolve(void)
75 +#endif
77 +#if PY_MAJOR_VERSION >= 3
78 + PyObject *module = PyModule_Create(&moduledef);
79 +#else
80 + PyObject *module = Py_InitModule("ddesolve", ddesolve_methods);
81 +#endif
83 + import_array();
85 + if (module == NULL)
86 + INITERROR;
87 + struct module_state *st = GETSTATE(module);
89 + st->error = PyErr_NewException("ddesolve.Error", NULL, NULL);
90 + if (st->error == NULL) {
91 + Py_DECREF(module);
92 + INITERROR;
93 + }
95 +#if PY_MAJOR_VERSION >= 3
96 + return module;
97 +#endif