From 68a001dd59e2f0c00cb703200e801d0e6be63546 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 6 Feb 2017 10:41:46 +0200 Subject: Issue #29460: _PyArg_NoKeywords(), _PyArg_NoStackKeywords() and _PyArg_NoPositional() now are macros. --- Include/modsupport.h | 7 +++++++ Modules/_operator.c | 6 +++--- Objects/setobject.c | 5 ++--- Python/getargs.c | 4 ++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Include/modsupport.h b/Include/modsupport.h index 7f4160e..853860f 100644 --- a/Include/modsupport.h +++ b/Include/modsupport.h @@ -62,6 +62,13 @@ PyAPI_FUNC(int) _PyArg_UnpackStack( PyAPI_FUNC(int) _PyArg_NoKeywords(const char *funcname, PyObject *kwargs); PyAPI_FUNC(int) _PyArg_NoStackKeywords(const char *funcname, PyObject *kwnames); PyAPI_FUNC(int) _PyArg_NoPositional(const char *funcname, PyObject *args); +#define _PyArg_NoKeywords(funcname, kwargs) \ + ((kwargs) == NULL || _PyArg_NoKeywords((funcname), (kwargs))) +#define _PyArg_NoStackKeywords(funcname, kwnames) \ + ((kwnames) == NULL || _PyArg_NoStackKeywords((funcname), (kwnames))) +#define _PyArg_NoPositional(funcname, args) \ + ((args) == NULL || _PyArg_NoPositional((funcname), (args))) + #endif PyAPI_FUNC(PyObject *) Py_VaBuildValue(const char *, va_list); diff --git a/Modules/_operator.c b/Modules/_operator.c index 9374b8e..10d7874 100644 --- a/Modules/_operator.c +++ b/Modules/_operator.c @@ -993,7 +993,7 @@ itemgetter_call(itemgetterobject *ig, PyObject *args, PyObject *kw) PyObject *obj, *result; Py_ssize_t i, nitems=ig->nitems; - if (kw != NULL && !_PyArg_NoKeywords("itemgetter", kw)) + if (!_PyArg_NoKeywords("itemgetter", kw)) return NULL; if (!PyArg_UnpackTuple(args, "itemgetter", 1, 1, &obj)) return NULL; @@ -1283,7 +1283,7 @@ attrgetter_call(attrgetterobject *ag, PyObject *args, PyObject *kw) PyObject *obj, *result; Py_ssize_t i, nattrs=ag->nattrs; - if (kw != NULL && !_PyArg_NoKeywords("attrgetter", kw)) + if (!_PyArg_NoKeywords("attrgetter", kw)) return NULL; if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &obj)) return NULL; @@ -1527,7 +1527,7 @@ methodcaller_call(methodcallerobject *mc, PyObject *args, PyObject *kw) { PyObject *method, *obj, *result; - if (kw != NULL && !_PyArg_NoKeywords("methodcaller", kw)) + if (!_PyArg_NoKeywords("methodcaller", kw)) return NULL; if (!PyArg_UnpackTuple(args, "methodcaller", 1, 1, &obj)) return NULL; diff --git a/Objects/setobject.c b/Objects/setobject.c index 4f04f49..2ccf183 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -1084,8 +1084,7 @@ frozenset_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *iterable = NULL, *result; - if (kwds != NULL && type == &PyFrozenSet_Type - && !_PyArg_NoKeywords("frozenset()", kwds)) + if (type == &PyFrozenSet_Type && !_PyArg_NoKeywords("frozenset()", kwds)) return NULL; if (!PyArg_UnpackTuple(args, type->tp_name, 0, 1, &iterable)) @@ -2002,7 +2001,7 @@ set_init(PySetObject *self, PyObject *args, PyObject *kwds) { PyObject *iterable = NULL; - if (kwds != NULL && !_PyArg_NoKeywords("set()", kwds)) + if (!_PyArg_NoKeywords("set()", kwds)) return -1; if (!PyArg_UnpackTuple(args, Py_TYPE(self)->tp_name, 0, 1, &iterable)) return -1; diff --git a/Python/getargs.c b/Python/getargs.c index 952a662..8cb672d 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -2446,6 +2446,10 @@ _PyArg_UnpackStack(PyObject **args, Py_ssize_t nargs, const char *name, } +#undef _PyArg_NoKeywords +#undef _PyArg_NoStackKeywords +#undef _PyArg_NoPositional + /* For type constructors that don't take keyword args * * Sets a TypeError and returns 0 if the args/kwargs is -- cgit v0.12