Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b82d34f

Browse files
committed
Convert METH_OLDARGS -> METH_VARARGS: also PyArg_Parse -> PyArg_ParseTuple
Please review for correctness.
1 parent ba3a16c commit b82d34f

3 files changed

Lines changed: 34 additions & 47 deletions

File tree

Modules/bsddbmodule.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -470,18 +470,16 @@ bsddb_has_key(bsddbobject *dp, PyObject *args)
470470
recno_t recno;
471471

472472
if (dp->di_type == DB_RECNO) {
473-
if (!PyArg_Parse(args, "i", &recno)) {
474-
PyErr_SetString(PyExc_TypeError,
475-
"key type must be integer");
473+
if (!PyArg_ParseTuple(args, "i;key type must be integer",
474+
&recno)) {
476475
return NULL;
477476
}
478477
krec.data = &recno;
479478
krec.size = sizeof(recno);
480479
}
481480
else {
482-
if (!PyArg_Parse(args, "s#", &data, &size)) {
483-
PyErr_SetString(PyExc_TypeError,
484-
"key type must be string");
481+
if (!PyArg_ParseTuple(args, "s#;key type must be string",
482+
&data, &size)) {
485483
return NULL;
486484
}
487485
krec.data = data;
@@ -511,18 +509,16 @@ bsddb_set_location(bsddbobject *dp, PyObject *key)
511509
recno_t recno;
512510

513511
if (dp->di_type == DB_RECNO) {
514-
if (!PyArg_Parse(key, "i", &recno)) {
515-
PyErr_SetString(PyExc_TypeError,
516-
"key type must be integer");
512+
if (!PyArg_ParseTuple(key, "i;key type must be integer",
513+
&recno)) {
517514
return NULL;
518515
}
519516
krec.data = &recno;
520517
krec.size = sizeof(recno);
521518
}
522519
else {
523-
if (!PyArg_Parse(key, "s#", &data, &size)) {
524-
PyErr_SetString(PyExc_TypeError,
525-
"key type must be string");
520+
if (!PyArg_ParseTuple(key, "s#;key type must be string",
521+
&data, &size)) {
526522
return NULL;
527523
}
528524
krec.data = data;
@@ -644,8 +640,8 @@ bsddb_sync(bsddbobject *dp)
644640
static PyMethodDef bsddb_methods[] = {
645641
{"close", (PyCFunction)bsddb_close, METH_NOARGS},
646642
{"keys", (PyCFunction)bsddb_keys, METH_NOARGS},
647-
{"has_key", (PyCFunction)bsddb_has_key, METH_OLDARGS},
648-
{"set_location", (PyCFunction)bsddb_set_location, METH_OLDARGS},
643+
{"has_key", (PyCFunction)bsddb_has_key, METH_VARARGS},
644+
{"set_location", (PyCFunction)bsddb_set_location, METH_VARARGS},
649645
{"next", (PyCFunction)bsddb_next, METH_NOARGS},
650646
{"previous", (PyCFunction)bsddb_previous, METH_NOARGS},
651647
{"first", (PyCFunction)bsddb_first, METH_NOARGS},

Modules/dlmodule.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ dl_dealloc(dlobject *xp)
3939
}
4040

4141
static PyObject *
42-
dl_close(dlobject *xp, PyObject *args)
42+
dl_close(dlobject *xp)
4343
{
44-
if (!PyArg_Parse(args, ""))
45-
return NULL;
4644
if (xp->dl_handle != NULL) {
4745
dlclose(xp->dl_handle);
4846
xp->dl_handle = NULL;
@@ -56,8 +54,13 @@ dl_sym(dlobject *xp, PyObject *args)
5654
{
5755
char *name;
5856
PyUnivPtr *func;
59-
if (!PyArg_Parse(args, "s", &name))
57+
if (PyString_Check(args)) {
58+
name = PyString_AS_STRING(args);
59+
} else {
60+
PyErr_Format(PyExc_TypeError, "expected string, found %.200s",
61+
args->ob_type->tp_name);
6062
return NULL;
63+
}
6164
func = dlsym(xp->dl_handle, name);
6265
if (func == NULL) {
6366
Py_INCREF(Py_None);
@@ -121,8 +124,8 @@ dl_call(dlobject *xp, PyObject *args)
121124

122125
static PyMethodDef dlobject_methods[] = {
123126
{"call", (PyCFunction)dl_call, METH_VARARGS},
124-
{"sym", (PyCFunction)dl_sym, METH_OLDARGS},
125-
{"close", (PyCFunction)dl_close, METH_OLDARGS},
127+
{"sym", (PyCFunction)dl_sym, METH_O},
128+
{"close", (PyCFunction)dl_close, METH_NOARGS},
126129
{NULL, NULL} /* Sentinel */
127130
};
128131

@@ -165,11 +168,11 @@ dl_open(PyObject *self, PyObject *args)
165168
return NULL;
166169
}
167170

168-
if (PyArg_Parse(args, "z", &name))
171+
if (PyArg_ParseTuple(args, "z:open", &name))
169172
mode = RTLD_LAZY;
170173
else {
171174
PyErr_Clear();
172-
if (!PyArg_Parse(args, "(zi)", &name, &mode))
175+
if (!PyArg_ParseTuple(args, "zi:open", &name, &mode))
173176
return NULL;
174177
#ifndef RTLD_NOW
175178
if (mode != RTLD_LAZY) {
@@ -187,7 +190,7 @@ dl_open(PyObject *self, PyObject *args)
187190
}
188191

189192
static PyMethodDef dl_methods[] = {
190-
{"open", dl_open, METH_OLDARGS},
193+
{"open", dl_open, METH_VARARGS},
191194
{NULL, NULL} /* sentinel */
192195
};
193196

Modules/imgfile.c

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ imgfile_ttob(PyObject *self, PyObject *args)
7575
int newval;
7676
PyObject *rv;
7777

78-
if (!PyArg_Parse(args, "i", &newval))
78+
if (!PyArg_ParseTuple(args, "i:ttob", &newval))
7979
return NULL;
8080
rv = PyInt_FromLong(top_to_bottom);
8181
top_to_bottom = newval;
@@ -95,7 +95,7 @@ imgfile_read(PyObject *self, PyObject *args)
9595
IMAGE *image;
9696
int yfirst, ylast, ystep;
9797

98-
if ( !PyArg_Parse(args, "s", &fname) )
98+
if ( !PyArg_ParseTuple(args, "s:read", &fname) )
9999
return NULL;
100100

101101
if ( (image = imgfile_open(fname)) == NULL )
@@ -250,10 +250,9 @@ imgfile_readscaled(PyObject *self, PyObject *args)
250250
int x, y;
251251
int xwtd, ywtd, xorig, yorig;
252252
float xfac, yfac;
253-
int cnt;
254253
IMAGE *image;
255254
char *filter;
256-
double blur;
255+
double blur = 1.0;
257256
int extended;
258257
int fmode = 0;
259258
int yfirst, ylast, ystep;
@@ -263,20 +262,9 @@ imgfile_readscaled(PyObject *self, PyObject *args)
263262
** (filter name and blur factor). Also, 4 or 5 arguments indicates
264263
** extended scale algorithm in stead of simple-minded pixel drop/dup.
265264
*/
266-
extended = 0;
267-
cnt = PyTuple_Size(args);
268-
if ( cnt == 5 ) {
269-
extended = 1;
270-
if ( !PyArg_Parse(args, "(siisd)",
271-
&fname, &xwtd, &ywtd, &filter, &blur) )
272-
return NULL;
273-
} else if ( cnt == 4 ) {
274-
extended = 1;
275-
if ( !PyArg_Parse(args, "(siis)",
276-
&fname, &xwtd, &ywtd, &filter) )
277-
return NULL;
278-
blur = 1.0;
279-
} else if ( !PyArg_Parse(args, "(sii)", &fname, &xwtd, &ywtd) )
265+
extended = PyTuple_Size(args) >= 4;
266+
if ( !PyArg_ParseTuple(args, "sii|sd",
267+
&fname, &xwtd, &ywtd, &filter, &blur) )
280268
return NULL;
281269

282270
/*
@@ -391,7 +379,7 @@ imgfile_getsizes(PyObject *self, PyObject *args)
391379
PyObject *rv;
392380
IMAGE *image;
393381

394-
if ( !PyArg_Parse(args, "s", &fname) )
382+
if ( !PyArg_ParseTuple(args, "s:getsizes", &fname) )
395383
return NULL;
396384

397385
if ( (image = imgfile_open(fname)) == NULL )
@@ -416,7 +404,7 @@ imgfile_write(PyObject *self, PyObject *args)
416404
int yfirst, ylast, ystep;
417405

418406

419-
if ( !PyArg_Parse(args, "(ss#iii)",
407+
if ( !PyArg_ParseTuple(args, "ss#iii:write",
420408
&fname, &cdatap, &len, &xsize, &ysize, &zsize) )
421409
return NULL;
422410

@@ -490,11 +478,11 @@ imgfile_write(PyObject *self, PyObject *args)
490478

491479

492480
static PyMethodDef imgfile_methods[] = {
493-
{ "getsizes", imgfile_getsizes, METH_OLDARGS },
494-
{ "read", imgfile_read, METH_OLDARGS },
481+
{ "getsizes", imgfile_getsizes, METH_VARARGS },
482+
{ "read", imgfile_read, METH_VARARGS },
495483
{ "readscaled", imgfile_readscaled, METH_VARARGS},
496-
{ "write", imgfile_write, METH_OLDARGS },
497-
{ "ttob", imgfile_ttob, METH_OLDARGS },
484+
{ "write", imgfile_write, METH_VARARGS },
485+
{ "ttob", imgfile_ttob, METH_VARARGS },
498486
{ NULL, NULL } /* Sentinel */
499487
};
500488

0 commit comments

Comments
 (0)