Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0d1a799

Browse files
committed
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.
1 parent 71aea8e commit 0d1a799

1 file changed

Lines changed: 19 additions & 20 deletions

File tree

Objects/abstract.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,14 +2324,13 @@ PyObject_CallFunction(PyObject *callable, const char *format, ...)
23242324
return null_error();
23252325
}
23262326

2327-
if (format && *format) {
2328-
va_start(va, format);
2329-
args = Py_VaBuildValue(format, va);
2330-
va_end(va);
2331-
}
2332-
else {
2333-
args = PyTuple_New(0);
2327+
if (!format || !*format) {
2328+
return _PyObject_FastCall(callable, NULL, 0, NULL);
23342329
}
2330+
2331+
va_start(va, format);
2332+
args = Py_VaBuildValue(format, va);
2333+
va_end(va);
23352334
if (args == NULL) {
23362335
return NULL;
23372336
}
@@ -2351,14 +2350,13 @@ _PyObject_CallFunction_SizeT(PyObject *callable, const char *format, ...)
23512350
return null_error();
23522351
}
23532352

2354-
if (format && *format) {
2355-
va_start(va, format);
2356-
args = _Py_VaBuildValue_SizeT(format, va);
2357-
va_end(va);
2358-
}
2359-
else {
2360-
args = PyTuple_New(0);
2353+
if (!format || !*format) {
2354+
return _PyObject_FastCall(callable, NULL, 0, NULL);
23612355
}
2356+
2357+
va_start(va, format);
2358+
args = _Py_VaBuildValue_SizeT(format, va);
2359+
va_end(va);
23622360
if (args == NULL) {
23632361
return NULL;
23642362
}
@@ -2380,14 +2378,15 @@ callmethod(PyObject* func, const char *format, va_list va, int is_size_t)
23802378
return NULL;
23812379
}
23822380

2383-
if (format && *format) {
2384-
if (is_size_t)
2385-
args = _Py_VaBuildValue_SizeT(format, va);
2386-
else
2387-
args = Py_VaBuildValue(format, va);
2381+
if (!format || !*format) {
2382+
return _PyObject_FastCall(func, NULL, 0, NULL);
2383+
}
2384+
2385+
if (is_size_t) {
2386+
args = _Py_VaBuildValue_SizeT(format, va);
23882387
}
23892388
else {
2390-
args = PyTuple_New(0);
2389+
args = Py_VaBuildValue(format, va);
23912390
}
23922391
if (args == NULL) {
23932392
return NULL;

0 commit comments

Comments
 (0)