From e71ab8f455dc374aeb719f500bc9300db9207687 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Sat, 8 Oct 2016 15:30:00 +0200 Subject: [PATCH] unpacking_collector: allow nullptr-valued kwargs argument This fixes an issue that can arise when forwarding (*args, **kwargs) captured from a pybind11-bound function call to another Python function. When the initial function call includes no keyword arguments, the py::kwargs field is set to nullptr and causes a crash later on. --- include/pybind11/cast.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index d1f6b250..00c29aca 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -1218,9 +1218,8 @@ private: } void process(list &args_list, detail::args_proxy ap) { - for (const auto &a : ap) { + for (const auto &a : ap) args_list.append(a); - } } void process(list &/*args_list*/, arg_v a) { @@ -1242,6 +1241,8 @@ private: } void process(list &/*args_list*/, detail::kwargs_proxy kp) { + if (!kp) + return; for (const auto &k : dict(kp, true)) { if (m_kwargs.contains(k.first)) { #if defined(NDEBUG)