Skip to content

Commit 1bd113a

Browse files
author
nnorwitz
committed
Remove METH_OLDARGS:
Convert METH_OLDARGS -> METH_VARARGS: also PyArg_Parse -> PyArg_ParseTuple Convert METH_OLDARGS -> METH_NOARGS: remove args parameter Please review. All tests pass, but some modules don't have tests. I spot checked various functions to try to make sure nothing broke. git-svn-id: http://svn.python.org/projects/python/trunk@26071 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent f17a86b commit 1bd113a

11 files changed

Lines changed: 85 additions & 164 deletions

Modules/cryptmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static PyObject *crypt_crypt(PyObject *self, PyObject *args)
1414
char *word, *salt;
1515
extern char * crypt(const char *, const char *);
1616

17-
if (!PyArg_Parse(args, "(ss)", &word, &salt)) {
17+
if (!PyArg_ParseTuple(args, "ss:crypt", &word, &salt)) {
1818
return NULL;
1919
}
2020
return PyString_FromString( crypt( word, salt ) );
@@ -31,7 +31,7 @@ the same alphabet as the salt.";
3131

3232

3333
static PyMethodDef crypt_methods[] = {
34-
{"crypt", crypt_crypt, METH_OLDARGS, crypt_crypt__doc__},
34+
{"crypt", crypt_crypt, METH_VARARGS, crypt_crypt__doc__},
3535
{NULL, NULL} /* sentinel */
3636
};
3737

Modules/md5module.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ md5_update(md5object *self, PyObject *args)
5252
unsigned char *cp;
5353
int len;
5454

55-
if (!PyArg_Parse(args, "s#", &cp, &len))
55+
if (!PyArg_ParseTuple(args, "s#:update", &cp, &len))
5656
return NULL;
5757

5858
MD5Update(&self->md5, cp, len);
@@ -142,7 +142,7 @@ Return a copy (``clone'') of the md5 object.";
142142

143143

144144
static PyMethodDef md5_methods[] = {
145-
{"update", (PyCFunction)md5_update, METH_OLDARGS, update_doc},
145+
{"update", (PyCFunction)md5_update, METH_VARARGS, update_doc},
146146
{"digest", (PyCFunction)md5_digest, METH_NOARGS, digest_doc},
147147
{"hexdigest", (PyCFunction)md5_hexdigest, METH_NOARGS, hexdigest_doc},
148148
{"copy", (PyCFunction)md5_copy, METH_NOARGS, copy_doc},

Modules/mpzmodule.c

Lines changed: 7 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,23 +1242,12 @@ MPZ_divm(PyObject *self, PyObject *args)
12421242
} /* MPZ_divm() */
12431243

12441244

1245-
/* MPZ methods-as-attributes */
1246-
#ifdef MPZ_CONVERSIONS_AS_METHODS
1247-
static PyObject *
1248-
mpz_int(mpzobject *self, PyObject *args)
1249-
#else /* def MPZ_CONVERSIONS_AS_METHODS */
12501245
static PyObject *
12511246
mpz_int(mpzobject *self)
1252-
#endif /* def MPZ_CONVERSIONS_AS_METHODS else */
12531247
{
12541248
long sli;
12551249

12561250

1257-
#ifdef MPZ_CONVERSIONS_AS_METHODS
1258-
if (!PyArg_NoArgs(args))
1259-
return NULL;
1260-
#endif /* def MPZ_CONVERSIONS_AS_METHODS */
1261-
12621251
if (mpz_size(&self->mpz) > 1
12631252
|| (sli = (long)mpz_get_ui(&self->mpz)) < (long)0 ) {
12641253
PyErr_SetString(PyExc_ValueError,
@@ -1273,11 +1262,7 @@ mpz_int(mpzobject *self)
12731262
} /* mpz_int() */
12741263

12751264
static PyObject *
1276-
#ifdef MPZ_CONVERSIONS_AS_METHODS
1277-
mpz_long(mpzobject *self, PyObject *args)
1278-
#else /* def MPZ_CONVERSIONS_AS_METHODS */
12791265
mpz_long(mpzobject *self)
1280-
#endif /* def MPZ_CONVERSIONS_AS_METHODS else */
12811266
{
12821267
int i, isnegative;
12831268
unsigned long int uli;
@@ -1287,11 +1272,6 @@ mpz_long(mpzobject *self)
12871272
MP_INT mpzscratch;
12881273

12891274

1290-
#ifdef MPZ_CONVERSIONS_AS_METHODS
1291-
if (!PyArg_NoArgs(args))
1292-
return NULL;
1293-
#endif /* def MPZ_CONVERSIONS_AS_METHODS */
1294-
12951275
/* determine length of python-long to be allocated */
12961276
if ((longobjp = _PyLong_New(i = (int)
12971277
((mpz_size(&self->mpz) * BITS_PER_MP_LIMB
@@ -1352,25 +1332,15 @@ mpz_long(mpzobject *self)
13521332
/* I would have avoided pow() anyways, so ... */
13531333
static const double multiplier = 256.0 * 256.0 * 256.0 * 256.0;
13541334

1355-
#ifdef MPZ_CONVERSIONS_AS_METHODS
1356-
static PyObject *
1357-
mpz_float(mpzobject *self, PyObject *args)
1358-
#else /* def MPZ_CONVERSIONS_AS_METHODS */
13591335
static PyObject *
13601336
mpz_float(mpzobject *self)
1361-
#endif /* def MPZ_CONVERSIONS_AS_METHODS else */
13621337
{
13631338
int i, isnegative;
13641339
double x;
13651340
double mulstate;
13661341
MP_INT mpzscratch;
13671342

13681343

1369-
#ifdef MPZ_CONVERSIONS_AS_METHODS
1370-
if (!PyArg_NoArgs(args))
1371-
return NULL;
1372-
#endif /* def MPZ_CONVERSIONS_AS_METHODS */
1373-
13741344
i = (int)mpz_size(&self->mpz);
13751345

13761346
/* determine sign, and copy abs(self) to scratch var */
@@ -1406,50 +1376,27 @@ mpz_float(mpzobject *self)
14061376

14071377
} /* mpz_float() */
14081378

1409-
#ifdef MPZ_CONVERSIONS_AS_METHODS
1410-
static PyObject *
1411-
mpz_hex(mpzobject *self, PyObject *args)
1412-
#else /* def MPZ_CONVERSIONS_AS_METHODS */
14131379
static PyObject *
14141380
mpz_hex(mpzobject *self)
1415-
#endif /* def MPZ_CONVERSIONS_AS_METHODS else */
14161381
{
1417-
#ifdef MPZ_CONVERSIONS_AS_METHODS
1418-
if (!PyArg_NoArgs(args))
1419-
return NULL;
1420-
#endif /* def MPZ_CONVERSIONS_AS_METHODS */
1421-
14221382
return mpz_format((PyObject *)self, 16, (unsigned char)1);
14231383
} /* mpz_hex() */
14241384

1425-
#ifdef MPZ_CONVERSIONS_AS_METHODS
1426-
static PyObject *
1427-
mpz_oct(mpzobject *self, PyObject *args)
1428-
#else /* def MPZ_CONVERSIONS_AS_METHODS */
14291385
static PyObject *
14301386
mpz_oct(mpzobject *self)
1431-
#endif /* def MPZ_CONVERSIONS_AS_METHODS else */
14321387
{
1433-
#ifdef MPZ_CONVERSIONS_AS_METHODS
1434-
if (!PyArg_NoArgs(args))
1435-
return NULL;
1436-
#endif /* def MPZ_CONVERSIONS_AS_METHODS */
1437-
14381388
return mpz_format((PyObject *)self, 8, (unsigned char)1);
14391389
} /* mpz_oct() */
14401390

14411391
static PyObject *
1442-
mpz_binary(mpzobject *self, PyObject *args)
1392+
mpz_binary(mpzobject *self)
14431393
{
14441394
int size;
14451395
PyStringObject *strobjp;
14461396
char *cp;
14471397
MP_INT mp;
14481398
unsigned long ldigit;
14491399

1450-
if (!PyArg_NoArgs(args))
1451-
return NULL;
1452-
14531400
if (mpz_cmp_ui(&self->mpz, (unsigned long int)0) < 0) {
14541401
PyErr_SetString(PyExc_ValueError,
14551402
"mpz.binary() arg must be >= 0");
@@ -1493,13 +1440,13 @@ mpz_binary(mpzobject *self, PyObject *args)
14931440

14941441
static PyMethodDef mpz_methods[] = {
14951442
#ifdef MPZ_CONVERSIONS_AS_METHODS
1496-
{"int", mpz_int},
1497-
{"long", mpz_long},
1498-
{"float", mpz_float},
1499-
{"hex", mpz_hex},
1500-
{"oct", mpz_oct},
1443+
{"int", mpz_int, METH_NOARGS},
1444+
{"long", mpz_long, METH_NOARGS},
1445+
{"float", mpz_float, METH_NOARGS},
1446+
{"hex", mpz_hex, METH_NOARGS},
1447+
{"oct", mpz_oct, METH_NOARGS},
15011448
#endif /* def MPZ_CONVERSIONS_AS_METHODS */
1502-
{"binary", (PyCFunction)mpz_binary},
1449+
{"binary", (PyCFunction)mpz_binary, METH_NOARGS},
15031450
{NULL, NULL} /* sentinel */
15041451
};
15051452

Modules/nismodule.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ nis_match (PyObject *self, PyObject *args)
120120
PyObject *res;
121121
int fix;
122122

123-
if (!PyArg_Parse(args, "(t#s)", &key, &keylen, &map))
123+
if (!PyArg_ParseTuple(args, "t#s:match", &key, &keylen, &map))
124124
return NULL;
125125
if ((err = yp_get_default_domain(&domain)) != 0)
126126
return nis_error(err);
@@ -149,7 +149,7 @@ nis_cat (PyObject *self, PyObject *args)
149149
PyObject *dict;
150150
int err;
151151

152-
if (!PyArg_Parse(args, "s", &map))
152+
if (!PyArg_ParseTuple(args, "s:cat", &map))
153153
return NULL;
154154
if ((err = yp_get_default_domain(&domain)) != 0)
155155
return nis_error(err);
@@ -338,13 +338,11 @@ nis_maplist (void)
338338
}
339339

340340
static PyObject *
341-
nis_maps (PyObject *self, PyObject *args)
341+
nis_maps (PyObject *self)
342342
{
343343
nismaplist *maps;
344344
PyObject *list;
345345

346-
if (!PyArg_NoArgs(args))
347-
return NULL;
348346
if ((maps = nis_maplist ()) == NULL)
349347
return NULL;
350348
if ((list = PyList_New(0)) == NULL)
@@ -364,9 +362,9 @@ nis_maps (PyObject *self, PyObject *args)
364362
}
365363

366364
static PyMethodDef nis_methods[] = {
367-
{"match", nis_match, METH_OLDARGS},
368-
{"cat", nis_cat, METH_OLDARGS},
369-
{"maps", nis_maps, METH_OLDARGS},
365+
{"match", nis_match, METH_VARARGS},
366+
{"cat", nis_cat, METH_VARARGS},
367+
{"maps", (PyCFunction)nis_maps, METH_NOARGS},
370368
{NULL, NULL} /* Sentinel */
371369
};
372370

Modules/pwdmodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pwd_getpwuid(PyObject *self, PyObject *args)
8484
{
8585
int uid;
8686
struct passwd *p;
87-
if (!PyArg_Parse(args, "i", &uid))
87+
if (!PyArg_ParseTuple(args, "i:getpwuid", &uid))
8888
return NULL;
8989
if ((p = getpwuid(uid)) == NULL) {
9090
PyErr_SetString(PyExc_KeyError, "getpwuid(): uid not found");
@@ -103,7 +103,7 @@ pwd_getpwnam(PyObject *self, PyObject *args)
103103
{
104104
char *name;
105105
struct passwd *p;
106-
if (!PyArg_Parse(args, "s", &name))
106+
if (!PyArg_ParseTuple(args, "s:getpwnam", &name))
107107
return NULL;
108108
if ((p = getpwnam(name)) == NULL) {
109109
PyErr_SetString(PyExc_KeyError, "getpwnam(): name not found");
@@ -146,8 +146,8 @@ pwd_getpwall(PyObject *self)
146146
#endif
147147

148148
static PyMethodDef pwd_methods[] = {
149-
{"getpwuid", pwd_getpwuid, METH_OLDARGS, pwd_getpwuid__doc__},
150-
{"getpwnam", pwd_getpwnam, METH_OLDARGS, pwd_getpwnam__doc__},
149+
{"getpwuid", pwd_getpwuid, METH_VARARGS, pwd_getpwuid__doc__},
150+
{"getpwnam", pwd_getpwnam, METH_VARARGS, pwd_getpwnam__doc__},
151151
#ifdef HAVE_GETPWENT
152152
{"getpwall", (PyCFunction)pwd_getpwall,
153153
METH_NOARGS, pwd_getpwall__doc__},

Modules/regexmodule.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ regex_match(PyObject *self, PyObject *args)
583583
PyObject *pat, *string;
584584
PyObject *tuple, *v;
585585

586-
if (!PyArg_Parse(args, "(SS)", &pat, &string))
586+
if (!PyArg_ParseTuple(args, "SS:match", &pat, &string))
587587
return NULL;
588588
if (update_cache(pat) < 0)
589589
return NULL;
@@ -601,7 +601,7 @@ regex_search(PyObject *self, PyObject *args)
601601
PyObject *pat, *string;
602602
PyObject *tuple, *v;
603603

604-
if (!PyArg_Parse(args, "(SS)", &pat, &string))
604+
if (!PyArg_ParseTuple(args, "SS:search", &pat, &string))
605605
return NULL;
606606
if (update_cache(pat) < 0)
607607
return NULL;
@@ -617,7 +617,7 @@ static PyObject *
617617
regex_set_syntax(PyObject *self, PyObject *args)
618618
{
619619
int syntax;
620-
if (!PyArg_Parse(args, "i", &syntax))
620+
if (!PyArg_ParseTuple(args, "i:set_syntax", &syntax))
621621
return NULL;
622622
syntax = re_set_syntax(syntax);
623623
/* wipe the global pattern cache */
@@ -629,21 +629,19 @@ regex_set_syntax(PyObject *self, PyObject *args)
629629
}
630630

631631
static PyObject *
632-
regex_get_syntax(PyObject *self, PyObject *args)
632+
regex_get_syntax(PyObject *self)
633633
{
634-
if (!PyArg_Parse(args, ""))
635-
return NULL;
636634
return PyInt_FromLong((long)re_syntax);
637635
}
638636

639637

640638
static struct PyMethodDef regex_global_methods[] = {
641639
{"compile", regex_compile, METH_VARARGS},
642640
{"symcomp", regex_symcomp, METH_VARARGS},
643-
{"match", regex_match, METH_OLDARGS},
644-
{"search", regex_search, METH_OLDARGS},
645-
{"set_syntax", regex_set_syntax, METH_OLDARGS},
646-
{"get_syntax", regex_get_syntax, METH_OLDARGS},
641+
{"match", regex_match, METH_VARARGS},
642+
{"search", regex_search, METH_VARARGS},
643+
{"set_syntax", regex_set_syntax, METH_VARARGS},
644+
{"get_syntax", (PyCFunction)regex_get_syntax, METH_NOARGS},
647645
{NULL, NULL} /* sentinel */
648646
};
649647

Modules/rgbimgmodule.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ sizeofimage(PyObject *self, PyObject *args)
236236
IMAGE image;
237237
FILE *inf;
238238

239-
if (!PyArg_Parse(args, "s", &name))
239+
if (!PyArg_ParseTuple(args, "s:sizeofimage", &name))
240240
return NULL;
241241

242242
inf = fopen(name, "rb");
@@ -275,7 +275,7 @@ longimagedata(PyObject *self, PyObject *args)
275275
int rlebuflen;
276276
PyObject *rv = NULL;
277277

278-
if (!PyArg_Parse(args, "s", &name))
278+
if (!PyArg_ParseTuple(args, "s:longimagedata", &name))
279279
return NULL;
280280

281281
inf = fopen(name,"rb");
@@ -570,8 +570,8 @@ longstoimage(PyObject *self, PyObject *args)
570570
int rlebuflen, goodwrite;
571571
PyObject *retval = NULL;
572572

573-
if (!PyArg_Parse(args, "(s#iiis)", &lptr, &len, &xsize, &ysize, &zsize,
574-
&name))
573+
if (!PyArg_ParseTuple(args, "s#iiis:longstoimage", &lptr, &len,
574+
&xsize, &ysize, &zsize, &name))
575575
return NULL;
576576

577577
goodwrite = 1;
@@ -734,7 +734,7 @@ ttob(PyObject *self, PyObject *args)
734734
{
735735
int order, oldorder;
736736

737-
if (!PyArg_Parse(args, "i", &order))
737+
if (!PyArg_ParseTuple(args, "i:ttob", &order))
738738
return NULL;
739739
oldorder = reverse_order;
740740
reverse_order = order;
@@ -743,10 +743,10 @@ ttob(PyObject *self, PyObject *args)
743743

744744
static PyMethodDef
745745
rgbimg_methods[] = {
746-
{"sizeofimage", sizeofimage, METH_OLDARGS},
747-
{"longimagedata", longimagedata, METH_OLDARGS},
748-
{"longstoimage", longstoimage, METH_OLDARGS},
749-
{"ttob", ttob, METH_OLDARGS},
746+
{"sizeofimage", sizeofimage, METH_VARARGS},
747+
{"longimagedata", longimagedata, METH_VARARGS},
748+
{"longstoimage", longstoimage, METH_VARARGS},
749+
{"ttob", ttob, METH_VARARGS},
750750
{NULL, NULL} /* sentinel */
751751
};
752752

0 commit comments

Comments
 (0)