summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2001-10-27 06:16:31 (GMT)
committerFred Drake <fdrake@acm.org>2001-10-27 06:16:31 (GMT)
commitb92cf067c63e3ed809f30ae51fdafc18c1db0c37 (patch)
tree9f0eed56fc99cc9e4b557cf03fc132e9d74833d8
parent0af4916ad42f0a5eec08b81adf9971e3b8e4a629 (diff)
downloadcpython-b92cf067c63e3ed809f30ae51fdafc18c1db0c37.zip
cpython-b92cf067c63e3ed809f30ae51fdafc18c1db0c37.tar.gz
cpython-b92cf067c63e3ed809f30ae51fdafc18c1db0c37.tar.bz2
PyObject_CallFunction(), PyObject_CallMethod(): Make sure we do not touch
the va_list until we are sure we have a format string and need to use it; this avoid premature initialization and having to finalize it several different places because of error returns.
-rw-r--r--Objects/abstract.c29
1 files changed, 11 insertions, 18 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 003c9a3..8f77120 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -1670,20 +1670,18 @@ PyObject_CallFunction(PyObject *callable, char *format, ...)
{
va_list va;
PyObject *args, *retval;
- va_start(va, format);
- if (callable == NULL) {
- va_end(va);
+ if (callable == NULL)
return null_error();
- }
- if (format)
+ if (format && *format) {
+ va_start(va, format);
args = Py_VaBuildValue(format, va);
+ va_end(va);
+ }
else
args = PyTuple_New(0);
- va_end(va);
-
if (args == NULL)
return NULL;
@@ -1709,32 +1707,27 @@ PyObject_CallMethod(PyObject *o, char *name, char *format, ...)
{
va_list va;
PyObject *args, *func = 0, *retval;
- va_start(va, format);
- if (o == NULL || name == NULL) {
- va_end(va);
+ if (o == NULL || name == NULL)
return null_error();
- }
func = PyObject_GetAttrString(o, name);
if (func == NULL) {
- va_end(va);
PyErr_SetString(PyExc_AttributeError, name);
return 0;
}
- if (!PyCallable_Check(func)) {
- va_end(va);
+ if (!PyCallable_Check(func))
return type_error("call of non-callable attribute");
- }
- if (format && *format)
+ if (format && *format) {
+ va_start(va, format);
args = Py_VaBuildValue(format, va);
+ va_end(va);
+ }
else
args = PyTuple_New(0);
- va_end(va);
-
if (!args)
return NULL;