summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2012-06-14 14:00:24 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2012-06-14 14:00:24 (GMT)
commitc838ec1f821e7a79838f37c45119ce028e7c4940 (patch)
treed10f4cb63889cbc46b6e1e28203ac06532bfa3c4
parent474eb23b7fb0f66315eb975a712433ee8c247e68 (diff)
downloadcpython-c838ec1f821e7a79838f37c45119ce028e7c4940.zip
cpython-c838ec1f821e7a79838f37c45119ce028e7c4940.tar.gz
cpython-c838ec1f821e7a79838f37c45119ce028e7c4940.tar.bz2
Issue #14936: curses_panel was converted to PEP 3121 API.
Patch by Robin Schreiber.
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/_curses_panel.c54
2 files changed, 45 insertions, 12 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index f3b886c..ffac575 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -21,6 +21,9 @@ Core and Builtins
Library
-------
+- Issue #14936: curses_panel was converted to PEP 3121 API.
+ Patch by Robin Schreiber.
+
- Issue #1667546: On platforms supporting tm_zone and tm_gmtoff fields
in struct tm, time.struct_time objects returned by time.gmtime(),
time.localtime() and time.strptime() functions now have tm_zone and
diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c
index 8561a2e..7d773d3 100644
--- a/Modules/_curses_panel.c
+++ b/Modules/_curses_panel.c
@@ -16,8 +16,38 @@ static char *PyCursesVersion = "2.1";
#include <panel.h>
-static PyObject *PyCursesError;
+typedef struct {
+ PyObject *PyCursesError;
+} _curses_panelstate;
+
+#define _curses_panelstate(o) ((_curses_panelstate *)PyModule_GetState(o))
+
+/*static PyObject *PyCursesError;*/
+
+static int
+_curses_panel_clear(PyObject *m)
+{
+ Py_CLEAR(_curses_panelstate(m)->PyCursesError);
+ return 0;
+}
+
+static int
+_curses_panel_traverse(PyObject *m, visitproc visit, void *arg)
+{
+ Py_VISIT(_curses_panelstate(m)->PyCursesError);
+ return 0;
+}
+
+static void
+_curses_panel_free(void *m)
+{
+ _curses_panel_clear((PyObject *) m);
+}
+
+static struct PyModuleDef _curses_panelmodule;
+#define _curses_panelstate_global \
+((_curses_panelstate *) PyModule_GetState(PyState_FindModule(&_curses_panelmodule)))
/* Utility Functions */
@@ -34,9 +64,9 @@ PyCursesCheckERR(int code, char *fname)
return Py_None;
} else {
if (fname == NULL) {
- PyErr_SetString(PyCursesError, catchall_ERR);
+ PyErr_SetString(_curses_panelstate_global->PyCursesError, catchall_ERR);
} else {
- PyErr_Format(PyCursesError, "%s() returned ERR", fname);
+ PyErr_Format(_curses_panelstate_global->PyCursesError, "%s() returned ERR", fname);
}
return NULL;
}
@@ -280,7 +310,7 @@ PyCursesPanel_replace_panel(PyCursesPanelObject *self, PyObject *args)
rtn = replace_panel(self->pan, temp->win);
if (rtn == ERR) {
- PyErr_SetString(PyCursesError, "replace_panel() returned ERR");
+ PyErr_SetString(_curses_panelstate_global->PyCursesError, "replace_panel() returned ERR");
return NULL;
}
Py_DECREF(po->wo);
@@ -305,7 +335,7 @@ PyCursesPanel_userptr(PyCursesPanelObject *self)
PyCursesInitialised;
obj = (PyObject *) panel_userptr(self->pan);
if (obj == NULL) {
- PyErr_SetString(PyCursesError, "no userptr set");
+ PyErr_SetString(_curses_panelstate_global->PyCursesError, "no userptr set");
return NULL;
}
@@ -405,7 +435,7 @@ PyCurses_new_panel(PyObject *self, PyObject *args)
return NULL;
pan = new_panel(win->win);
if (pan == NULL) {
- PyErr_SetString(PyCursesError, catchall_NULL);
+ PyErr_SetString(_curses_panelstate_global->PyCursesError, catchall_NULL);
return NULL;
}
return (PyObject *)PyCursesPanel_New(pan, win);
@@ -467,12 +497,12 @@ static struct PyModuleDef _curses_panelmodule = {
PyModuleDef_HEAD_INIT,
"_curses_panel",
NULL,
- -1,
+ sizeof(_curses_panelstate),
PyCurses_methods,
NULL,
- NULL,
- NULL,
- NULL
+ _curses_panel_traverse,
+ _curses_panel_clear,
+ _curses_panel_free
};
PyMODINIT_FUNC
@@ -493,8 +523,8 @@ PyInit__curses_panel(void)
d = PyModule_GetDict(m);
/* For exception _curses_panel.error */
- PyCursesError = PyErr_NewException("_curses_panel.error", NULL, NULL);
- PyDict_SetItemString(d, "error", PyCursesError);
+ _curses_panelstate(m)->PyCursesError = PyErr_NewException("_curses_panel.error", NULL, NULL);
+ PyDict_SetItemString(d, "error", _curses_panelstate(m)->PyCursesError);
/* Make the version available */
v = PyUnicode_FromString(PyCursesVersion);