Issue #14936: curses_panel was converted to PEP 3121 API.

Patch by Robin Schreiber.
This commit is contained in:
Martin v. Löwis 2012-06-14 16:00:24 +02:00
parent 474eb23b7f
commit c838ec1f82
2 changed files with 45 additions and 12 deletions

View File

@ -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

View File

@ -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);