Kaydet (Commit) 0d1a7993 authored tarafından Victor Stinner's avatar Victor Stinner

Avoid call_function_tail() for empty format str

Issue #27128, PyObject_CallFunction(), _PyObject_FastCall() and callmethod():
if the format string of parameters is empty, avoid the creation of an empty
tuple: call _PyObject_FastCall() without parameters.
üst 71aea8e9
...@@ -2324,14 +2324,13 @@ PyObject_CallFunction(PyObject *callable, const char *format, ...) ...@@ -2324,14 +2324,13 @@ PyObject_CallFunction(PyObject *callable, const char *format, ...)
return null_error(); return null_error();
} }
if (format && *format) { if (!format || !*format) {
va_start(va, format); return _PyObject_FastCall(callable, NULL, 0, NULL);
args = Py_VaBuildValue(format, va);
va_end(va);
}
else {
args = PyTuple_New(0);
} }
va_start(va, format);
args = Py_VaBuildValue(format, va);
va_end(va);
if (args == NULL) { if (args == NULL) {
return NULL; return NULL;
} }
...@@ -2351,14 +2350,13 @@ _PyObject_CallFunction_SizeT(PyObject *callable, const char *format, ...) ...@@ -2351,14 +2350,13 @@ _PyObject_CallFunction_SizeT(PyObject *callable, const char *format, ...)
return null_error(); return null_error();
} }
if (format && *format) { if (!format || !*format) {
va_start(va, format); return _PyObject_FastCall(callable, NULL, 0, NULL);
args = _Py_VaBuildValue_SizeT(format, va);
va_end(va);
}
else {
args = PyTuple_New(0);
} }
va_start(va, format);
args = _Py_VaBuildValue_SizeT(format, va);
va_end(va);
if (args == NULL) { if (args == NULL) {
return NULL; return NULL;
} }
...@@ -2380,14 +2378,15 @@ callmethod(PyObject* func, const char *format, va_list va, int is_size_t) ...@@ -2380,14 +2378,15 @@ callmethod(PyObject* func, const char *format, va_list va, int is_size_t)
return NULL; return NULL;
} }
if (format && *format) { if (!format || !*format) {
if (is_size_t) return _PyObject_FastCall(func, NULL, 0, NULL);
args = _Py_VaBuildValue_SizeT(format, va); }
else
args = Py_VaBuildValue(format, va); if (is_size_t) {
args = _Py_VaBuildValue_SizeT(format, va);
} }
else { else {
args = PyTuple_New(0); args = Py_VaBuildValue(format, va);
} }
if (args == NULL) { if (args == NULL) {
return NULL; return NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment