Commit c0e1671c authored by Martin v. Löwis's avatar Martin v. Löwis

Patch #477752: Drop old-style getargs from curses.

parent ac6dd0a8
......@@ -68,10 +68,6 @@ static void **PyCurses_API;
static char *catchall_ERR = "curses function returned ERR";
static char *catchall_NULL = "curses function returned NULL";
/* Utility macros */
#define ARG_COUNT(X) \
(((X) == NULL) ? 0 : (PyTuple_Check(X) ? PyTuple_Size(X) : 1))
/* Function Prototype Macros - They are ugly but very, very useful. ;-)
X - function name
......@@ -81,10 +77,9 @@ static char *catchall_NULL = "curses function returned NULL";
*/
#define NoArgNoReturnFunction(X) \
static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
static PyObject *PyCurses_ ## X (PyObject *self) \
{ \
PyCursesInitialised \
if (!PyArg_NoArgs(args)) return NULL; \
return PyCursesCheckERR(X(), # X); }
#define NoArgOrFlagNoReturnFunction(X) \
......@@ -92,11 +87,11 @@ static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
{ \
int flag = 0; \
PyCursesInitialised \
switch(ARG_COUNT(args)) { \
switch(PyTuple_Size(args)) { \
case 0: \
return PyCursesCheckERR(X(), # X); \
case 1: \
if (!PyArg_Parse(args, "i;True(1) or False(0)", &flag)) return NULL; \
if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; \
if (flag) return PyCursesCheckERR(X(), # X); \
else return PyCursesCheckERR(no ## X (), # X); \
default: \
......@@ -104,25 +99,22 @@ static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
return NULL; } }
#define NoArgReturnIntFunction(X) \
static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
static PyObject *PyCurses_ ## X (PyObject *self) \
{ \
PyCursesInitialised \
if (!PyArg_NoArgs(args)) return NULL; \
return PyInt_FromLong((long) X()); }
#define NoArgReturnStringFunction(X) \
static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
static PyObject *PyCurses_ ## X (PyObject *self) \
{ \
PyCursesInitialised \
if (!PyArg_NoArgs(args)) return NULL; \
return PyString_FromString(X()); }
#define NoArgTrueFalseFunction(X) \
static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
static PyObject *PyCurses_ ## X (PyObject *self) \
{ \
PyCursesInitialised \
if (!PyArg_NoArgs(args)) return NULL; \
if (X () == FALSE) { \
Py_INCREF(Py_False); \
return Py_False; \
......@@ -131,10 +123,9 @@ static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
return Py_True; }
#define NoArgNoReturnVoidFunction(X) \
static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
static PyObject *PyCurses_ ## X (PyObject *self) \
{ \
PyCursesInitialised \
if (!PyArg_NoArgs(args)) return NULL; \
X(); \
Py_INCREF(Py_None); \
return Py_None; }
......
......@@ -141,14 +141,12 @@ find_po(PANEL *pan)
PARSESTR - format string for argument parsing */
#define Panel_NoArgNoReturnFunction(X) \
static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self, PyObject *args) \
{ if (!PyArg_NoArgs(args)) return NULL; \
return PyCursesCheckERR(X(self->pan), # X); }
static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self) \
{ return PyCursesCheckERR(X(self->pan), # X); }
#define Panel_NoArgTrueFalseFunction(X) \
static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self, PyObject *args) \
static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self) \
{ \
if (!PyArg_NoArgs(args)) return NULL; \
if (X (self->pan) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
else { Py_INCREF(Py_True); return Py_True; } }
......@@ -156,7 +154,7 @@ static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self, PyObject *args) \
static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self, PyObject *args) \
{ \
TYPE arg1, arg2; \
if (!PyArg_Parse(args,PARSESTR, &arg1, &arg2)) return NULL; \
if (!PyArg_ParseTuple(args, PARSESTR, &arg1, &arg2)) return NULL; \
return PyCursesCheckERR(X(self->pan, arg1, arg2), # X); }
/* ------------- PANEL routines --------------- */
......@@ -166,7 +164,7 @@ Panel_NoArgNoReturnFunction(hide_panel)
Panel_NoArgNoReturnFunction(show_panel)
Panel_NoArgNoReturnFunction(top_panel)
Panel_NoArgTrueFalseFunction(panel_hidden)
Panel_TwoArgNoReturnFunction(move_panel, int, "(ii);y,x")
Panel_TwoArgNoReturnFunction(move_panel, int, "ii;y,x")
/* Allocation and deallocation of Panel Objects */
......@@ -199,13 +197,11 @@ PyCursesPanel_Dealloc(PyCursesPanelObject *po)
/* panel_above(NULL) returns the bottom panel in the stack. To get
this behaviour we use curses.panel.bottom_panel(). */
static PyObject *
PyCursesPanel_above(PyCursesPanelObject *self, PyObject *args)
PyCursesPanel_above(PyCursesPanelObject *self)
{
PANEL *pan;
PyCursesPanelObject *po;
if (!PyArg_NoArgs(args)) return NULL;
pan = panel_above(self->pan);
if (pan == NULL) { /* valid output, it means the calling panel
......@@ -226,13 +222,11 @@ PyCursesPanel_above(PyCursesPanelObject *self, PyObject *args)
/* panel_below(NULL) returns the top panel in the stack. To get
this behaviour we use curses.panel.top_panel(). */
static PyObject *
PyCursesPanel_below(PyCursesPanelObject *self, PyObject *args)
PyCursesPanel_below(PyCursesPanelObject *self)
{
PANEL *pan;
PyCursesPanelObject *po;
if (!PyArg_NoArgs(args)) return NULL;
pan = panel_below(self->pan);
if (pan == NULL) { /* valid output, it means the calling panel
......@@ -251,10 +245,8 @@ PyCursesPanel_below(PyCursesPanelObject *self, PyObject *args)
}
static PyObject *
PyCursesPanel_window(PyCursesPanelObject *self, PyObject *args)
PyCursesPanel_window(PyCursesPanelObject *self)
{
if (!PyArg_NoArgs(args)) return NULL;
Py_INCREF(self->wo);
return (PyObject *)self->wo;
}
......@@ -266,7 +258,7 @@ PyCursesPanel_replace_panel(PyCursesPanelObject *self, PyObject *args)
PyCursesWindowObject *temp;
int rtn;
if (ARG_COUNT(args) != 1) {
if (PyTuple_Size(args) != 1) {
PyErr_SetString(PyExc_TypeError, "replace requires one argument");
return NULL;
}
......@@ -294,27 +286,18 @@ PyCursesPanel_replace_panel(PyCursesPanelObject *self, PyObject *args)
}
static PyObject *
PyCursesPanel_set_panel_userptr(PyCursesPanelObject *self, PyObject *args)
PyCursesPanel_set_panel_userptr(PyCursesPanelObject *self, PyObject *obj)
{
PyObject *obj;
if (ARG_COUNT(args) != 1) {
PyErr_SetString(PyExc_TypeError, "set_userptr requires one argument");
return NULL;
}
obj = PyTuple_GetItem(args, 0);
Py_INCREF(obj);
return PyCursesCheckERR(set_panel_userptr(self->pan, (void*)obj),
"set_panel_userptr");
}
static PyObject *PyCursesPanel_userptr
(PyCursesPanelObject *self, PyObject *args)
static PyObject *
PyCursesPanel_userptr(PyCursesPanelObject *self)
{
PyObject *obj;
PyCursesInitialised;
if (!PyArg_NoArgs(args))
return NULL;
obj = (PyObject *) panel_userptr(self->pan);
Py_INCREF(obj);
return obj;
......@@ -324,20 +307,19 @@ static PyObject *PyCursesPanel_userptr
/* Module interface */
static PyMethodDef PyCursesPanel_Methods[] = {
{"above", (PyCFunction)PyCursesPanel_above},
{"below", (PyCFunction)PyCursesPanel_below},
{"bottom", (PyCFunction)PyCursesPanel_bottom_panel},
{"hidden", (PyCFunction)PyCursesPanel_panel_hidden},
{"hide", (PyCFunction)PyCursesPanel_hide_panel},
{"move", (PyCFunction)PyCursesPanel_move_panel},
{"above", (PyCFunction)PyCursesPanel_above, METH_NOARGS},
{"below", (PyCFunction)PyCursesPanel_below, METH_NOARGS},
{"bottom", (PyCFunction)PyCursesPanel_bottom_panel, METH_NOARGS},
{"hidden", (PyCFunction)PyCursesPanel_panel_hidden, METH_NOARGS},
{"hide", (PyCFunction)PyCursesPanel_hide_panel, METH_NOARGS},
{"move", (PyCFunction)PyCursesPanel_move_panel, METH_VARARGS},
{"replace", (PyCFunction)PyCursesPanel_replace_panel,
METH_VARARGS},
{"set_userptr", (PyCFunction)PyCursesPanel_set_panel_userptr,
METH_VARARGS},
{"show", (PyCFunction)PyCursesPanel_show_panel},
{"top", (PyCFunction)PyCursesPanel_top_panel},
{"userptr", (PyCFunction)PyCursesPanel_userptr},
{"window", (PyCFunction)PyCursesPanel_window},
{"set_userptr", (PyCFunction)PyCursesPanel_set_panel_userptr, METH_O},
{"show", (PyCFunction)PyCursesPanel_show_panel, METH_NOARGS},
{"top", (PyCFunction)PyCursesPanel_top_panel, METH_NOARGS},
{"userptr", (PyCFunction)PyCursesPanel_userptr, METH_NOARGS},
{"window", (PyCFunction)PyCursesPanel_window, METH_NOARGS},
{NULL, NULL} /* sentinel */
};
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment