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