Skip to content

Commit 2a15b79

Browse files
author
loewis
committed
Patch #477752: Drop old-style getargs from curses.
git-svn-id: http://svn.python.org/projects/python/trunk@25116 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 098b1ca commit 2a15b79

3 files changed

Lines changed: 316 additions & 388 deletions

File tree

Include/py_curses.h

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ static void **PyCurses_API;
6868
static char *catchall_ERR = "curses function returned ERR";
6969
static char *catchall_NULL = "curses function returned NULL";
7070

71-
/* Utility macros */
72-
#define ARG_COUNT(X) \
73-
(((X) == NULL) ? 0 : (PyTuple_Check(X) ? PyTuple_Size(X) : 1))
74-
7571
/* Function Prototype Macros - They are ugly but very, very useful. ;-)
7672
7773
X - function name
@@ -81,48 +77,44 @@ static char *catchall_NULL = "curses function returned NULL";
8177
*/
8278

8379
#define NoArgNoReturnFunction(X) \
84-
static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
80+
static PyObject *PyCurses_ ## X (PyObject *self) \
8581
{ \
8682
PyCursesInitialised \
87-
if (!PyArg_NoArgs(args)) return NULL; \
8883
return PyCursesCheckERR(X(), # X); }
8984

9085
#define NoArgOrFlagNoReturnFunction(X) \
9186
static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
9287
{ \
9388
int flag = 0; \
9489
PyCursesInitialised \
95-
switch(ARG_COUNT(args)) { \
90+
switch(PyTuple_Size(args)) { \
9691
case 0: \
9792
return PyCursesCheckERR(X(), # X); \
9893
case 1: \
99-
if (!PyArg_Parse(args, "i;True(1) or False(0)", &flag)) return NULL; \
94+
if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; \
10095
if (flag) return PyCursesCheckERR(X(), # X); \
10196
else return PyCursesCheckERR(no ## X (), # X); \
10297
default: \
10398
PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \
10499
return NULL; } }
105100

106101
#define NoArgReturnIntFunction(X) \
107-
static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
102+
static PyObject *PyCurses_ ## X (PyObject *self) \
108103
{ \
109104
PyCursesInitialised \
110-
if (!PyArg_NoArgs(args)) return NULL; \
111105
return PyInt_FromLong((long) X()); }
112106

113107

114108
#define NoArgReturnStringFunction(X) \
115-
static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
109+
static PyObject *PyCurses_ ## X (PyObject *self) \
116110
{ \
117111
PyCursesInitialised \
118-
if (!PyArg_NoArgs(args)) return NULL; \
119112
return PyString_FromString(X()); }
120113

121114
#define NoArgTrueFalseFunction(X) \
122-
static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
115+
static PyObject *PyCurses_ ## X (PyObject *self) \
123116
{ \
124117
PyCursesInitialised \
125-
if (!PyArg_NoArgs(args)) return NULL; \
126118
if (X () == FALSE) { \
127119
Py_INCREF(Py_False); \
128120
return Py_False; \
@@ -131,10 +123,9 @@ static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
131123
return Py_True; }
132124

133125
#define NoArgNoReturnVoidFunction(X) \
134-
static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
126+
static PyObject *PyCurses_ ## X (PyObject *self) \
135127
{ \
136128
PyCursesInitialised \
137-
if (!PyArg_NoArgs(args)) return NULL; \
138129
X(); \
139130
Py_INCREF(Py_None); \
140131
return Py_None; }

Modules/_curses_panel.c

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,20 @@ find_po(PANEL *pan)
141141
PARSESTR - format string for argument parsing */
142142

143143
#define Panel_NoArgNoReturnFunction(X) \
144-
static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self, PyObject *args) \
145-
{ if (!PyArg_NoArgs(args)) return NULL; \
146-
return PyCursesCheckERR(X(self->pan), # X); }
144+
static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self) \
145+
{ return PyCursesCheckERR(X(self->pan), # X); }
147146

148147
#define Panel_NoArgTrueFalseFunction(X) \
149-
static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self, PyObject *args) \
148+
static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self) \
150149
{ \
151-
if (!PyArg_NoArgs(args)) return NULL; \
152150
if (X (self->pan) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
153151
else { Py_INCREF(Py_True); return Py_True; } }
154152

155153
#define Panel_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
156154
static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self, PyObject *args) \
157155
{ \
158156
TYPE arg1, arg2; \
159-
if (!PyArg_Parse(args,PARSESTR, &arg1, &arg2)) return NULL; \
157+
if (!PyArg_ParseTuple(args, PARSESTR, &arg1, &arg2)) return NULL; \
160158
return PyCursesCheckERR(X(self->pan, arg1, arg2), # X); }
161159

162160
/* ------------- PANEL routines --------------- */
@@ -166,7 +164,7 @@ Panel_NoArgNoReturnFunction(hide_panel)
166164
Panel_NoArgNoReturnFunction(show_panel)
167165
Panel_NoArgNoReturnFunction(top_panel)
168166
Panel_NoArgTrueFalseFunction(panel_hidden)
169-
Panel_TwoArgNoReturnFunction(move_panel, int, "(ii);y,x")
167+
Panel_TwoArgNoReturnFunction(move_panel, int, "ii;y,x")
170168

171169
/* Allocation and deallocation of Panel Objects */
172170

@@ -199,13 +197,11 @@ PyCursesPanel_Dealloc(PyCursesPanelObject *po)
199197
/* panel_above(NULL) returns the bottom panel in the stack. To get
200198
this behaviour we use curses.panel.bottom_panel(). */
201199
static PyObject *
202-
PyCursesPanel_above(PyCursesPanelObject *self, PyObject *args)
200+
PyCursesPanel_above(PyCursesPanelObject *self)
203201
{
204202
PANEL *pan;
205203
PyCursesPanelObject *po;
206204

207-
if (!PyArg_NoArgs(args)) return NULL;
208-
209205
pan = panel_above(self->pan);
210206

211207
if (pan == NULL) { /* valid output, it means the calling panel
@@ -226,13 +222,11 @@ PyCursesPanel_above(PyCursesPanelObject *self, PyObject *args)
226222
/* panel_below(NULL) returns the top panel in the stack. To get
227223
this behaviour we use curses.panel.top_panel(). */
228224
static PyObject *
229-
PyCursesPanel_below(PyCursesPanelObject *self, PyObject *args)
225+
PyCursesPanel_below(PyCursesPanelObject *self)
230226
{
231227
PANEL *pan;
232228
PyCursesPanelObject *po;
233229

234-
if (!PyArg_NoArgs(args)) return NULL;
235-
236230
pan = panel_below(self->pan);
237231

238232
if (pan == NULL) { /* valid output, it means the calling panel
@@ -251,10 +245,8 @@ PyCursesPanel_below(PyCursesPanelObject *self, PyObject *args)
251245
}
252246

253247
static PyObject *
254-
PyCursesPanel_window(PyCursesPanelObject *self, PyObject *args)
248+
PyCursesPanel_window(PyCursesPanelObject *self)
255249
{
256-
if (!PyArg_NoArgs(args)) return NULL;
257-
258250
Py_INCREF(self->wo);
259251
return (PyObject *)self->wo;
260252
}
@@ -266,7 +258,7 @@ PyCursesPanel_replace_panel(PyCursesPanelObject *self, PyObject *args)
266258
PyCursesWindowObject *temp;
267259
int rtn;
268260

269-
if (ARG_COUNT(args) != 1) {
261+
if (PyTuple_Size(args) != 1) {
270262
PyErr_SetString(PyExc_TypeError, "replace requires one argument");
271263
return NULL;
272264
}
@@ -294,27 +286,18 @@ PyCursesPanel_replace_panel(PyCursesPanelObject *self, PyObject *args)
294286
}
295287

296288
static PyObject *
297-
PyCursesPanel_set_panel_userptr(PyCursesPanelObject *self, PyObject *args)
289+
PyCursesPanel_set_panel_userptr(PyCursesPanelObject *self, PyObject *obj)
298290
{
299-
PyObject *obj;
300-
301-
if (ARG_COUNT(args) != 1) {
302-
PyErr_SetString(PyExc_TypeError, "set_userptr requires one argument");
303-
return NULL;
304-
}
305-
obj = PyTuple_GetItem(args, 0);
306291
Py_INCREF(obj);
307292
return PyCursesCheckERR(set_panel_userptr(self->pan, (void*)obj),
308293
"set_panel_userptr");
309294
}
310295

311-
static PyObject *PyCursesPanel_userptr
312-
(PyCursesPanelObject *self, PyObject *args)
296+
static PyObject *
297+
PyCursesPanel_userptr(PyCursesPanelObject *self)
313298
{
314299
PyObject *obj;
315300
PyCursesInitialised;
316-
if (!PyArg_NoArgs(args))
317-
return NULL;
318301
obj = (PyObject *) panel_userptr(self->pan);
319302
Py_INCREF(obj);
320303
return obj;
@@ -324,20 +307,19 @@ static PyObject *PyCursesPanel_userptr
324307
/* Module interface */
325308

326309
static PyMethodDef PyCursesPanel_Methods[] = {
327-
{"above", (PyCFunction)PyCursesPanel_above},
328-
{"below", (PyCFunction)PyCursesPanel_below},
329-
{"bottom", (PyCFunction)PyCursesPanel_bottom_panel},
330-
{"hidden", (PyCFunction)PyCursesPanel_panel_hidden},
331-
{"hide", (PyCFunction)PyCursesPanel_hide_panel},
332-
{"move", (PyCFunction)PyCursesPanel_move_panel},
310+
{"above", (PyCFunction)PyCursesPanel_above, METH_NOARGS},
311+
{"below", (PyCFunction)PyCursesPanel_below, METH_NOARGS},
312+
{"bottom", (PyCFunction)PyCursesPanel_bottom_panel, METH_NOARGS},
313+
{"hidden", (PyCFunction)PyCursesPanel_panel_hidden, METH_NOARGS},
314+
{"hide", (PyCFunction)PyCursesPanel_hide_panel, METH_NOARGS},
315+
{"move", (PyCFunction)PyCursesPanel_move_panel, METH_VARARGS},
333316
{"replace", (PyCFunction)PyCursesPanel_replace_panel,
334317
METH_VARARGS},
335-
{"set_userptr", (PyCFunction)PyCursesPanel_set_panel_userptr,
336-
METH_VARARGS},
337-
{"show", (PyCFunction)PyCursesPanel_show_panel},
338-
{"top", (PyCFunction)PyCursesPanel_top_panel},
339-
{"userptr", (PyCFunction)PyCursesPanel_userptr},
340-
{"window", (PyCFunction)PyCursesPanel_window},
318+
{"set_userptr", (PyCFunction)PyCursesPanel_set_panel_userptr, METH_O},
319+
{"show", (PyCFunction)PyCursesPanel_show_panel, METH_NOARGS},
320+
{"top", (PyCFunction)PyCursesPanel_top_panel, METH_NOARGS},
321+
{"userptr", (PyCFunction)PyCursesPanel_userptr, METH_NOARGS},
322+
{"window", (PyCFunction)PyCursesPanel_window, METH_NOARGS},
341323
{NULL, NULL} /* sentinel */
342324
};
343325

0 commit comments

Comments
 (0)