Skip to content

Commit f4cf539

Browse files
committed
Move handle before check
1 parent 76d9e10 commit f4cf539

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

include/pybind11/warnings.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@ new_warning_type(handle scope, const char *name, handle base = PyExc_RuntimeWarn
4545
+ std::string(name) + "\" exists already.");
4646
}
4747
std::string full_name = scope.attr("__name__").cast<std::string>() + std::string(".") + name;
48-
auto *new_ex = PyErr_NewException(const_cast<char *>(full_name.c_str()), base.ptr(), nullptr);
49-
if (!new_ex) {
48+
handle h(PyErr_NewException(full_name.c_str(), base.ptr(), nullptr));
49+
if (!h) {
5050
raise_from(PyExc_SystemError,
5151
"pybind11::warnings::new_warning_type(): PyErr_NewException() call failed.");
5252
throw error_already_set();
5353
}
54-
handle h(new_ex);
5554
auto obj = reinterpret_steal<object>(h);
5655
scope.attr(name) = obj;
5756
return obj;

0 commit comments

Comments
 (0)