From 8b9eb964d904c1dab33ed819497fb997f25e473b Mon Sep 17 00:00:00 2001 From: Boris Staletic Date: Sat, 11 Jul 2020 17:20:22 +0200 Subject: [PATCH] Check for NULL in raw_str on Python3 (#2290) --- include/pybind11/pytypes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index b2180fd3e..6e7666b87 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -933,8 +933,8 @@ private: /// Return string representation -- always returns a new reference, even if already a str static PyObject *raw_str(PyObject *op) { PyObject *str_value = PyObject_Str(op); -#if PY_MAJOR_VERSION < 3 if (!str_value) throw error_already_set(); +#if PY_MAJOR_VERSION < 3 PyObject *unicode = PyUnicode_FromEncodedObject(str_value, "utf-8", nullptr); Py_XDECREF(str_value); str_value = unicode; #endif