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.
This commit is contained in:
Fred Drake 2001-10-27 06:16:31 +00:00
parent 0af4916ad4
commit b92cf067c6
1 changed files with 11 additions and 18 deletions

View File

@ -1670,20 +1670,18 @@ PyObject_CallFunction(PyObject *callable, char *format, ...)
{ {
va_list va; va_list va;
PyObject *args, *retval; PyObject *args, *retval;
va_start(va, format);
if (callable == NULL) { if (callable == NULL)
va_end(va);
return null_error(); return null_error();
}
if (format) if (format && *format) {
va_start(va, format);
args = Py_VaBuildValue(format, va); args = Py_VaBuildValue(format, va);
va_end(va);
}
else else
args = PyTuple_New(0); args = PyTuple_New(0);
va_end(va);
if (args == NULL) if (args == NULL)
return NULL; return NULL;
@ -1709,32 +1707,27 @@ PyObject_CallMethod(PyObject *o, char *name, char *format, ...)
{ {
va_list va; va_list va;
PyObject *args, *func = 0, *retval; PyObject *args, *func = 0, *retval;
va_start(va, format);
if (o == NULL || name == NULL) { if (o == NULL || name == NULL)
va_end(va);
return null_error(); return null_error();
}
func = PyObject_GetAttrString(o, name); func = PyObject_GetAttrString(o, name);
if (func == NULL) { if (func == NULL) {
va_end(va);
PyErr_SetString(PyExc_AttributeError, name); PyErr_SetString(PyExc_AttributeError, name);
return 0; return 0;
} }
if (!PyCallable_Check(func)) { if (!PyCallable_Check(func))
va_end(va);
return type_error("call of non-callable attribute"); return type_error("call of non-callable attribute");
}
if (format && *format) if (format && *format) {
va_start(va, format);
args = Py_VaBuildValue(format, va); args = Py_VaBuildValue(format, va);
va_end(va);
}
else else
args = PyTuple_New(0); args = PyTuple_New(0);
va_end(va);
if (!args) if (!args)
return NULL; return NULL;