diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-11-29 17:47:56 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-11-29 17:47:56 (GMT) |
commit | ebea9988e0808cab8736f100fc480d536e68f930 (patch) | |
tree | f667dc2778eb2a3041c965aba94f2bfa99146c9f /Objects | |
parent | 356ae170ef47af5561d0c39be56ef32b76d704a0 (diff) | |
download | cpython-ebea9988e0808cab8736f100fc480d536e68f930.zip cpython-ebea9988e0808cab8736f100fc480d536e68f930.tar.gz cpython-ebea9988e0808cab8736f100fc480d536e68f930.tar.bz2 |
Uniformize argument names of "call" functions
* Callable object: callable, o, callable_object => func
* Object for method calls: o => obj
* Method name: name or nameid => method
Cleanup also the C code:
* Don't initialize variables to NULL if they are not used before their first
assignement
* Add braces for readability
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/abstract.c | 122 | ||||
-rw-r--r-- | Objects/typeobject.c | 17 |
2 files changed, 71 insertions, 68 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c index beb12c9..1a83e93 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -2173,9 +2173,9 @@ PyMapping_Values(PyObject *o) /* XXX PyCallable_Check() is in object.c */ PyObject * -PyObject_CallObject(PyObject *o, PyObject *a) +PyObject_CallObject(PyObject *func, PyObject *args) { - return PyEval_CallObjectWithKeywords(o, a, NULL); + return PyEval_CallObjectWithKeywords(func, args, NULL); } PyObject* @@ -2331,10 +2331,10 @@ exit: return result; } -/* Positional arguments are obj followed args. */ +/* Positional arguments are arg0 followed args: [arg0, *args]. */ PyObject * _PyObject_Call_Prepend(PyObject *func, - PyObject *obj, PyObject *args, PyObject *kwargs) + PyObject *arg0, PyObject *args, PyObject *kwargs) { PyObject *small_stack[8]; PyObject **stack; @@ -2356,7 +2356,7 @@ _PyObject_Call_Prepend(PyObject *func, } /* use borrowed references */ - stack[0] = obj; + stack[0] = arg0; memcpy(&stack[1], &PyTuple_GET_ITEM(args, 0), argcount * sizeof(PyObject *)); @@ -2489,34 +2489,34 @@ _PyObject_FastCallKeywords(PyObject *func, PyObject **stack, Py_ssize_t nargs, } static PyObject* -call_function_tail(PyObject *callable, PyObject *args) +call_function_tail(PyObject *func, PyObject *args) { PyObject *result; assert(args != NULL); if (!PyTuple_Check(args)) { - result = _PyObject_CallArg1(callable, args); + result = _PyObject_CallArg1(func, args); } else { - result = PyObject_Call(callable, args, NULL); + result = PyObject_Call(func, args, NULL); } return result; } PyObject * -PyObject_CallFunction(PyObject *callable, const char *format, ...) +PyObject_CallFunction(PyObject *func, const char *format, ...) { va_list va; PyObject *args, *result; - if (callable == NULL) { + if (func == NULL) { return null_error(); } if (!format || !*format) { - return _PyObject_CallNoArg(callable); + return _PyObject_CallNoArg(func); } va_start(va, format); @@ -2526,23 +2526,23 @@ PyObject_CallFunction(PyObject *callable, const char *format, ...) return NULL; } - result = call_function_tail(callable, args); + result = call_function_tail(func, args); Py_DECREF(args); return result; } PyObject * -_PyObject_CallFunction_SizeT(PyObject *callable, const char *format, ...) +_PyObject_CallFunction_SizeT(PyObject *func, const char *format, ...) { va_list va; PyObject *args, *result; - if (callable == NULL) { + if (func == NULL) { return null_error(); } if (!format || !*format) { - return _PyObject_CallNoArg(callable); + return _PyObject_CallNoArg(func); } va_start(va, format); @@ -2552,7 +2552,7 @@ _PyObject_CallFunction_SizeT(PyObject *callable, const char *format, ...) return NULL; } - result = call_function_tail(callable, args); + result = call_function_tail(func, args); Py_DECREF(args); return result; } @@ -2589,19 +2589,20 @@ callmethod(PyObject* func, const char *format, va_list va, int is_size_t) } PyObject * -PyObject_CallMethod(PyObject *o, const char *name, const char *format, ...) +PyObject_CallMethod(PyObject *obj, const char *method, const char *format, ...) { va_list va; PyObject *func = NULL; PyObject *retval = NULL; - if (o == NULL || name == NULL) { + if (obj == NULL || method == NULL) { return null_error(); } - func = PyObject_GetAttrString(o, name); - if (func == NULL) + func = PyObject_GetAttrString(obj, method); + if (func == NULL) { return NULL; + } va_start(va, format); retval = callmethod(func, format, va, 0); @@ -2611,20 +2612,20 @@ PyObject_CallMethod(PyObject *o, const char *name, const char *format, ...) } PyObject * -_PyObject_CallMethodId(PyObject *o, _Py_Identifier *name, +_PyObject_CallMethodId(PyObject *obj, _Py_Identifier *method, const char *format, ...) { va_list va; - PyObject *func = NULL; - PyObject *retval = NULL; + PyObject *func, *retval; - if (o == NULL || name == NULL) { + if (obj == NULL || method == NULL) { return null_error(); } - func = _PyObject_GetAttrId(o, name); - if (func == NULL) + func = _PyObject_GetAttrId(obj, method); + if (func == NULL) { return NULL; + } va_start(va, format); retval = callmethod(func, format, va, 0); @@ -2634,20 +2635,21 @@ _PyObject_CallMethodId(PyObject *o, _Py_Identifier *name, } PyObject * -_PyObject_CallMethod_SizeT(PyObject *o, const char *name, +_PyObject_CallMethod_SizeT(PyObject *obj, const char *method, const char *format, ...) { va_list va; - PyObject *func = NULL; - PyObject *retval; + PyObject *func, *retval; - if (o == NULL || name == NULL) { + if (obj == NULL || method == NULL) { return null_error(); } - func = PyObject_GetAttrString(o, name); - if (func == NULL) + func = PyObject_GetAttrString(obj, method); + if (func == NULL) { return NULL; + } + va_start(va, format); retval = callmethod(func, format, va, 1); va_end(va); @@ -2656,21 +2658,21 @@ _PyObject_CallMethod_SizeT(PyObject *o, const char *name, } PyObject * -_PyObject_CallMethodId_SizeT(PyObject *o, _Py_Identifier *name, +_PyObject_CallMethodId_SizeT(PyObject *obj, _Py_Identifier *method, const char *format, ...) { va_list va; - PyObject *func = NULL; - PyObject *retval; + PyObject *func, *retval; - if (o == NULL || name == NULL) { + if (obj == NULL || method == NULL) { return null_error(); } - func = _PyObject_GetAttrId(o, name); + func = _PyObject_GetAttrId(obj, method); if (func == NULL) { return NULL; } + va_start(va, format); retval = callmethod(func, format, va, 1); va_end(va); @@ -2720,34 +2722,34 @@ objargs_mkstack(PyObject **small_stack, Py_ssize_t small_stack_size, } PyObject * -PyObject_CallMethodObjArgs(PyObject *callable, PyObject *name, ...) +PyObject_CallMethodObjArgs(PyObject *obj, PyObject *method, ...) { PyObject *small_stack[5]; PyObject **stack; Py_ssize_t nargs; - PyObject *result; + PyObject *func, *result; va_list vargs; - if (callable == NULL || name == NULL) { + if (obj == NULL || method == NULL) { return null_error(); } - callable = PyObject_GetAttr(callable, name); - if (callable == NULL) + func = PyObject_GetAttr(obj, method); + if (func == NULL) return NULL; /* count the args */ - va_start(vargs, name); + va_start(vargs, method); stack = objargs_mkstack(small_stack, Py_ARRAY_LENGTH(small_stack), vargs, &nargs); va_end(vargs); if (stack == NULL) { - Py_DECREF(callable); + Py_DECREF(func); return NULL; } - result = _PyObject_FastCall(callable, stack, nargs); - Py_DECREF(callable); + result = _PyObject_FastCall(func, stack, nargs); + Py_DECREF(func); if (stack != small_stack) { PyMem_Free(stack); } @@ -2756,35 +2758,35 @@ PyObject_CallMethodObjArgs(PyObject *callable, PyObject *name, ...) } PyObject * -_PyObject_CallMethodIdObjArgs(PyObject *callable, - struct _Py_Identifier *name, ...) +_PyObject_CallMethodIdObjArgs(PyObject *obj, + struct _Py_Identifier *method, ...) { PyObject *small_stack[5]; PyObject **stack; Py_ssize_t nargs; - PyObject *result; + PyObject *func, *result; va_list vargs; - if (callable == NULL || name == NULL) { + if (obj == NULL || method == NULL) { return null_error(); } - callable = _PyObject_GetAttrId(callable, name); - if (callable == NULL) + func = _PyObject_GetAttrId(obj, method); + if (func == NULL) return NULL; /* count the args */ - va_start(vargs, name); + va_start(vargs, method); stack = objargs_mkstack(small_stack, Py_ARRAY_LENGTH(small_stack), vargs, &nargs); va_end(vargs); if (stack == NULL) { - Py_DECREF(callable); + Py_DECREF(func); return NULL; } - result = _PyObject_FastCall(callable, stack, nargs); - Py_DECREF(callable); + result = _PyObject_FastCall(func, stack, nargs); + Py_DECREF(func); if (stack != small_stack) { PyMem_Free(stack); } @@ -2793,7 +2795,7 @@ _PyObject_CallMethodIdObjArgs(PyObject *callable, } PyObject * -PyObject_CallFunctionObjArgs(PyObject *callable, ...) +PyObject_CallFunctionObjArgs(PyObject *func, ...) { PyObject *small_stack[5]; PyObject **stack; @@ -2801,12 +2803,12 @@ PyObject_CallFunctionObjArgs(PyObject *callable, ...) PyObject *result; va_list vargs; - if (callable == NULL) { + if (func == NULL) { return null_error(); } /* count the args */ - va_start(vargs, callable); + va_start(vargs, func); stack = objargs_mkstack(small_stack, Py_ARRAY_LENGTH(small_stack), vargs, &nargs); va_end(vargs); @@ -2814,7 +2816,7 @@ PyObject_CallFunctionObjArgs(PyObject *callable, ...) return NULL; } - result = _PyObject_FastCall(callable, stack, nargs); + result = _PyObject_FastCall(func, stack, nargs); if (stack != small_stack) { PyMem_Free(stack); } diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 186c570..3cff904 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -1425,15 +1425,16 @@ _PyObject_LookupSpecial(PyObject *self, _Py_Identifier *attrid) as lookup_method to cache the interned name string object. */ static PyObject * -call_method(PyObject *o, _Py_Identifier *nameid, const char *format, ...) +call_method(PyObject *obj, _Py_Identifier *method, const char *format, ...) { va_list va; - PyObject *func = NULL, *retval; + PyObject *func, *retval; - func = lookup_maybe(o, nameid); + func = lookup_maybe(obj, method); if (func == NULL) { - if (!PyErr_Occurred()) - PyErr_SetObject(PyExc_AttributeError, nameid->object); + if (!PyErr_Occurred()) { + PyErr_SetObject(PyExc_AttributeError, method->object); + } return NULL; } @@ -1465,12 +1466,12 @@ call_method(PyObject *o, _Py_Identifier *nameid, const char *format, ...) /* Clone of call_method() that returns NotImplemented when the lookup fails. */ static PyObject * -call_maybe(PyObject *o, _Py_Identifier *nameid, const char *format, ...) +call_maybe(PyObject *obj, _Py_Identifier *method, const char *format, ...) { va_list va; - PyObject *func = NULL, *retval; + PyObject *func, *retval; - func = lookup_maybe(o, nameid); + func = lookup_maybe(obj, method); if (func == NULL) { if (!PyErr_Occurred()) Py_RETURN_NOTIMPLEMENTED; |