File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -388,6 +388,19 @@ inline py_ref capture_if_not_null(PyObject *o)
388
388
// return py_ref(o, true);
389
389
}
390
390
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
+
391
404
// RAII class to acquire GIL.
392
405
class with_gil {
393
406
PyGILState_STATE m_gstate;
You can’t perform that action at this time.
0 commit comments