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

Skip to content

Commit 3a6f978

Browse files
committed
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
1 parent 57f8e06 commit 3a6f978

9 files changed

Lines changed: 65 additions & 122 deletions

File tree

Include/Python.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@
118118
#include "abstract.h"
119119

120120
#define PyArg_GetInt(v, a) PyArg_Parse((v), "i", (a))
121+
122+
/* PyArg_NoArgs should not be necessary.
123+
Set ml_flags in the PyMethodDef to METH_NOARGS. */
121124
#define PyArg_NoArgs(v) PyArg_Parse(v, "")
122125

123126
/* Convert a possibly signed character to a nonnegative int */

Modules/_curses_panel.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,12 @@ PyTypeObject PyCursesPanel_Type = {
355355
panel.above() *requires* a panel object in the first place which
356356
may be undesirable. */
357357
static PyObject *
358-
PyCurses_bottom_panel(PyObject *self, PyObject *args)
358+
PyCurses_bottom_panel(PyObject *self)
359359
{
360360
PANEL *pan;
361361
PyCursesPanelObject *po;
362362

363363
PyCursesInitialised;
364-
365-
if (!PyArg_NoArgs(args)) return NULL;
366364

367365
pan = panel_above(NULL);
368366

@@ -403,14 +401,12 @@ PyCurses_new_panel(PyObject *self, PyObject *args)
403401
*requires* a panel object in the first place which may be
404402
undesirable. */
405403
static PyObject *
406-
PyCurses_top_panel(PyObject *self, PyObject *args)
404+
PyCurses_top_panel(PyObject *self)
407405
{
408406
PANEL *pan;
409407
PyCursesPanelObject *po;
410408

411409
PyCursesInitialised;
412-
413-
if (!PyArg_NoArgs(args)) return NULL;
414410

415411
pan = panel_below(NULL);
416412

@@ -429,10 +425,9 @@ PyCurses_top_panel(PyObject *self, PyObject *args)
429425
return (PyObject *)po;
430426
}
431427

432-
static PyObject *PyCurses_update_panels(PyObject *self, PyObject *args)
428+
static PyObject *PyCurses_update_panels(PyObject *self)
433429
{
434430
PyCursesInitialised;
435-
if (!PyArg_NoArgs(args)) return NULL;
436431
update_panels();
437432
Py_INCREF(Py_None);
438433
return Py_None;
@@ -442,10 +437,10 @@ static PyObject *PyCurses_update_panels(PyObject *self, PyObject *args)
442437
/* List of functions defined in the module */
443438

444439
static PyMethodDef PyCurses_methods[] = {
445-
{"bottom_panel", (PyCFunction)PyCurses_bottom_panel},
446-
{"new_panel", (PyCFunction)PyCurses_new_panel, METH_VARARGS},
447-
{"top_panel", (PyCFunction)PyCurses_top_panel},
448-
{"update_panels", (PyCFunction)PyCurses_update_panels},
440+
{"bottom_panel", (PyCFunction)PyCurses_bottom_panel, METH_NOARGS},
441+
{"new_panel", (PyCFunction)PyCurses_new_panel, METH_VARARGS},
442+
{"top_panel", (PyCFunction)PyCurses_top_panel, METH_NOARGS},
443+
{"update_panels", (PyCFunction)PyCurses_update_panels, METH_NOARGS},
449444
{NULL, NULL} /* sentinel */
450445
};
451446

Modules/_localemodule.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,12 @@ static char localeconv__doc__[] =
245245
;
246246

247247
static PyObject*
248-
PyLocale_localeconv(PyObject* self, PyObject* args)
248+
PyLocale_localeconv(PyObject* self)
249249
{
250250
PyObject* result;
251251
struct lconv *l;
252252
PyObject *x;
253253

254-
if (!PyArg_NoArgs(args))
255-
return NULL;
256-
257254
result = PyDict_New();
258255
if (!result)
259256
return NULL;
@@ -368,14 +365,11 @@ PyLocale_strxfrm(PyObject* self, PyObject* args)
368365

369366
#if defined(MS_WIN32)
370367
static PyObject*
371-
PyLocale_getdefaultlocale(PyObject* self, PyObject* args)
368+
PyLocale_getdefaultlocale(PyObject* self)
372369
{
373370
char encoding[100];
374371
char locale[100];
375372

376-
if (!PyArg_NoArgs(args))
377-
return NULL;
378-
379373
PyOS_snprintf(encoding, sizeof(encoding), "cp%d", GetACP());
380374

381375
if (GetLocaleInfo(LOCALE_USER_DEFAULT,
@@ -408,7 +402,7 @@ PyLocale_getdefaultlocale(PyObject* self, PyObject* args)
408402

409403
#if defined(macintosh)
410404
static PyObject*
411-
PyLocale_getdefaultlocale(PyObject* self, PyObject* args)
405+
PyLocale_getdefaultlocale(PyObject* self)
412406
{
413407
return Py_BuildValue("Os", Py_None, PyMac_getscript());
414408
}
@@ -530,13 +524,13 @@ static struct PyMethodDef PyLocale_Methods[] = {
530524
{"setlocale", (PyCFunction) PyLocale_setlocale,
531525
METH_VARARGS, setlocale__doc__},
532526
{"localeconv", (PyCFunction) PyLocale_localeconv,
533-
0, localeconv__doc__},
527+
METH_NOARGS, localeconv__doc__},
534528
{"strcoll", (PyCFunction) PyLocale_strcoll,
535529
METH_VARARGS, strcoll__doc__},
536530
{"strxfrm", (PyCFunction) PyLocale_strxfrm,
537531
METH_VARARGS, strxfrm__doc__},
538532
#if defined(MS_WIN32) || defined(macintosh)
539-
{"_getdefaultlocale", (PyCFunction) PyLocale_getdefaultlocale, 0},
533+
{"_getdefaultlocale", (PyCFunction) PyLocale_getdefaultlocale, METH_NOARGS},
540534
#endif
541535
#ifdef HAVE_LANGINFO_H
542536
{"nl_langinfo", (PyCFunction) PyLocale_nl_langinfo,

Modules/bsddbmodule.c

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,8 @@ static PyMappingMethods bsddb_as_mapping = {
380380
};
381381

382382
static PyObject *
383-
bsddb_close(bsddbobject *dp, PyObject *args)
383+
bsddb_close(bsddbobject *dp)
384384
{
385-
if (!PyArg_NoArgs(args))
386-
return NULL;
387385
if (dp->di_bsddb != NULL) {
388386
int status;
389387
BSDDB_BGN_SAVE(dp)
@@ -401,16 +399,14 @@ bsddb_close(bsddbobject *dp, PyObject *args)
401399
}
402400

403401
static PyObject *
404-
bsddb_keys(bsddbobject *dp, PyObject *args)
402+
bsddb_keys(bsddbobject *dp)
405403
{
406404
PyObject *list, *item=NULL;
407405
DBT krec, drec;
408406
char *data=NULL,buf[4096];
409407
int status;
410408
int err;
411409

412-
if (!PyArg_NoArgs(args))
413-
return NULL;
414410
check_bsddbobject_open(dp, NULL);
415411
list = PyList_New(0);
416412
if (list == NULL)
@@ -562,17 +558,14 @@ bsddb_set_location(bsddbobject *dp, PyObject *key)
562558
}
563559

564560
static PyObject *
565-
bsddb_seq(bsddbobject *dp, PyObject *args, int sequence_request)
561+
bsddb_seq(bsddbobject *dp, int sequence_request)
566562
{
567563
int status;
568564
DBT krec, drec;
569565
char *kdata=NULL,kbuf[4096];
570566
char *ddata=NULL,dbuf[4096];
571567
PyObject *result;
572568

573-
if (!PyArg_NoArgs(args))
574-
return NULL;
575-
576569
check_bsddbobject_open(dp, NULL);
577570
krec.data = 0;
578571
krec.size = 0;
@@ -598,11 +591,10 @@ bsddb_seq(bsddbobject *dp, PyObject *args, int sequence_request)
598591
if (status < 0)
599592
PyErr_SetFromErrno(BsddbError);
600593
else
601-
PyErr_SetObject(PyExc_KeyError, args);
594+
PyErr_SetString(PyExc_KeyError, "no key/data pairs");
602595
return NULL;
603596
}
604597

605-
606598
if (dp->di_type == DB_RECNO)
607599
result = Py_BuildValue("is#", *((int*)kdata),
608600
ddata, drec.size);
@@ -615,32 +607,30 @@ bsddb_seq(bsddbobject *dp, PyObject *args, int sequence_request)
615607
}
616608

617609
static PyObject *
618-
bsddb_next(bsddbobject *dp, PyObject *key)
610+
bsddb_next(bsddbobject *dp)
619611
{
620-
return bsddb_seq(dp, key, R_NEXT);
612+
return bsddb_seq(dp, R_NEXT);
621613
}
622614
static PyObject *
623-
bsddb_previous(bsddbobject *dp, PyObject *key)
615+
bsddb_previous(bsddbobject *dp)
624616
{
625-
return bsddb_seq(dp, key, R_PREV);
617+
return bsddb_seq(dp, R_PREV);
626618
}
627619
static PyObject *
628-
bsddb_first(bsddbobject *dp, PyObject *key)
620+
bsddb_first(bsddbobject *dp)
629621
{
630-
return bsddb_seq(dp, key, R_FIRST);
622+
return bsddb_seq(dp, R_FIRST);
631623
}
632624
static PyObject *
633-
bsddb_last(bsddbobject *dp, PyObject *key)
625+
bsddb_last(bsddbobject *dp)
634626
{
635-
return bsddb_seq(dp, key, R_LAST);
627+
return bsddb_seq(dp, R_LAST);
636628
}
637629
static PyObject *
638-
bsddb_sync(bsddbobject *dp, PyObject *args)
630+
bsddb_sync(bsddbobject *dp)
639631
{
640632
int status;
641633

642-
if (!PyArg_NoArgs(args))
643-
return NULL;
644634
check_bsddbobject_open(dp, NULL);
645635
BSDDB_BGN_SAVE(dp)
646636
status = (dp->di_bsddb->sync)(dp->di_bsddb, 0);
@@ -652,15 +642,15 @@ bsddb_sync(bsddbobject *dp, PyObject *args)
652642
return PyInt_FromLong(status = 0);
653643
}
654644
static PyMethodDef bsddb_methods[] = {
655-
{"close", (PyCFunction)bsddb_close, METH_OLDARGS},
656-
{"keys", (PyCFunction)bsddb_keys, METH_OLDARGS},
645+
{"close", (PyCFunction)bsddb_close, METH_NOARGS},
646+
{"keys", (PyCFunction)bsddb_keys, METH_NOARGS},
657647
{"has_key", (PyCFunction)bsddb_has_key, METH_OLDARGS},
658648
{"set_location", (PyCFunction)bsddb_set_location, METH_OLDARGS},
659-
{"next", (PyCFunction)bsddb_next, METH_OLDARGS},
660-
{"previous", (PyCFunction)bsddb_previous, METH_OLDARGS},
661-
{"first", (PyCFunction)bsddb_first, METH_OLDARGS},
662-
{"last", (PyCFunction)bsddb_last, METH_OLDARGS},
663-
{"sync", (PyCFunction)bsddb_sync, METH_OLDARGS},
649+
{"next", (PyCFunction)bsddb_next, METH_NOARGS},
650+
{"previous", (PyCFunction)bsddb_previous, METH_NOARGS},
651+
{"first", (PyCFunction)bsddb_first, METH_NOARGS},
652+
{"last", (PyCFunction)bsddb_last, METH_NOARGS},
653+
{"sync", (PyCFunction)bsddb_sync, METH_NOARGS},
664654
{NULL, NULL} /* sentinel */
665655
};
666656

Modules/md5module.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,11 @@ arguments.";
7070

7171

7272
static PyObject *
73-
md5_digest(md5object *self, PyObject *args)
73+
md5_digest(md5object *self)
7474
{
7575
MD5_CTX mdContext;
7676
unsigned char aDigest[16];
7777

78-
if (!PyArg_NoArgs(args))
79-
return NULL;
80-
8178
/* make a temporary copy, and perform the final */
8279
mdContext = self->md5;
8380
MD5Final(aDigest, &mdContext);
@@ -94,16 +91,13 @@ including null bytes.";
9491

9592

9693
static PyObject *
97-
md5_hexdigest(md5object *self, PyObject *args)
94+
md5_hexdigest(md5object *self)
9895
{
9996
MD5_CTX mdContext;
10097
unsigned char digest[16];
10198
unsigned char hexdigest[32];
10299
int i, j;
103100

104-
if (!PyArg_NoArgs(args))
105-
return NULL;
106-
107101
/* make a temporary copy, and perform the final */
108102
mdContext = self->md5;
109103
MD5Final(digest, &mdContext);
@@ -129,13 +123,10 @@ Like digest(), but returns the digest as a string of hexadecimal digits.";
129123

130124

131125
static PyObject *
132-
md5_copy(md5object *self, PyObject *args)
126+
md5_copy(md5object *self)
133127
{
134128
md5object *md5p;
135129

136-
if (!PyArg_NoArgs(args))
137-
return NULL;
138-
139130
if ((md5p = newmd5object()) == NULL)
140131
return NULL;
141132

@@ -152,9 +143,9 @@ Return a copy (``clone'') of the md5 object.";
152143

153144
static PyMethodDef md5_methods[] = {
154145
{"update", (PyCFunction)md5_update, METH_OLDARGS, update_doc},
155-
{"digest", (PyCFunction)md5_digest, METH_OLDARGS, digest_doc},
156-
{"hexdigest", (PyCFunction)md5_hexdigest, METH_OLDARGS, hexdigest_doc},
157-
{"copy", (PyCFunction)md5_copy, METH_OLDARGS, copy_doc},
146+
{"digest", (PyCFunction)md5_digest, METH_NOARGS, digest_doc},
147+
{"hexdigest", (PyCFunction)md5_hexdigest, METH_NOARGS, hexdigest_doc},
148+
{"copy", (PyCFunction)md5_copy, METH_NOARGS, copy_doc},
158149
{NULL, NULL} /* sentinel */
159150
};
160151

Modules/pwdmodule.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,10 @@ in arbitrary order.\n\
120120
See pwd.__doc__ for more on password database entries.";
121121

122122
static PyObject *
123-
pwd_getpwall(PyObject *self, PyObject *args)
123+
pwd_getpwall(PyObject *self)
124124
{
125125
PyObject *d;
126126
struct passwd *p;
127-
if (!PyArg_NoArgs(args))
128-
return NULL;
129127
if ((d = PyList_New(0)) == NULL)
130128
return NULL;
131129
#if defined(PYOS_OS2) && defined(PYCC_GCC)
@@ -151,7 +149,7 @@ static PyMethodDef pwd_methods[] = {
151149
{"getpwuid", pwd_getpwuid, METH_OLDARGS, pwd_getpwuid__doc__},
152150
{"getpwnam", pwd_getpwnam, METH_OLDARGS, pwd_getpwnam__doc__},
153151
#ifdef HAVE_GETPWENT
154-
{"getpwall", pwd_getpwall, METH_OLDARGS, pwd_getpwall__doc__},
152+
{"getpwall", pwd_getpwall, METH_NOARGS, pwd_getpwall__doc__},
155153
#endif
156154
{NULL, NULL} /* sentinel */
157155
};

0 commit comments

Comments
 (0)