File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -388,6 +388,19 @@ inline py_ref capture_if_not_null(PyObject *o)
388388 // return py_ref(o, true);
389389}
390390
391+ /* Convert to a non-null reference.
392+ * If the input type allows nulls, explicitly check for null and raise an exception.
393+ * If the input type does not allow null, this function is marked as noexcept and
394+ * only checks for via an assert statement in debug builds.
395+ */
396+ template <bool owns_ref, bool not_null>
397+ inline py_ref_tmpl<owns_ref, true > nullcheck (py_ref_tmpl<owns_ref, not_null> &&obj) noexcept (not_null)
398+ {
399+ // Route this through the assignment operator since the semantics are the same.
400+ py_ref_tmpl<owns_ref, true > out = obj;
401+ return out;
402+ }
403+
391404// RAII class to acquire GIL.
392405class with_gil {
393406 PyGILState_STATE m_gstate;
You can’t perform that action at this time.
0 commit comments