Skip to content

Commit 3824cd8

Browse files
authored
bpo-29684: Fix regression of PyEval_CallObjectWithKeywords (GH-87)
It should raise TypeError when kwargs is not a dict.
1 parent f518474 commit 3824cd8

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ What's New in Python 3.7.0 alpha 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- bpo-29684: Fix minor regression of PyEval_CallObjectWithKeywords.
14+
It should raise TypeError when kwargs is not a dict. But it might
15+
cause segv when args=NULL and kwargs is not a dict.
16+
1317
- bpo-28598: Support __rmod__ for subclasses of str being called before
1418
str.__mod__. Patch by Martijn Pieters.
1519

Objects/call.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -766,11 +766,7 @@ PyEval_CallObjectWithKeywords(PyObject *callable,
766766
assert(!PyErr_Occurred());
767767
#endif
768768

769-
if (args == NULL) {
770-
return _PyObject_FastCallDict(callable, NULL, 0, kwargs);
771-
}
772-
773-
if (!PyTuple_Check(args)) {
769+
if (args != NULL && !PyTuple_Check(args)) {
774770
PyErr_SetString(PyExc_TypeError,
775771
"argument list must be a tuple");
776772
return NULL;
@@ -782,7 +778,12 @@ PyEval_CallObjectWithKeywords(PyObject *callable,
782778
return NULL;
783779
}
784780

785-
return PyObject_Call(callable, args, kwargs);
781+
if (args == NULL) {
782+
return _PyObject_FastCallDict(callable, NULL, 0, kwargs);
783+
}
784+
else {
785+
return PyObject_Call(callable, args, kwargs);
786+
}
786787
}
787788

788789

0 commit comments

Comments
 (0)