File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -73,21 +73,29 @@ struct PyObjectDeleter
7373struct benchmark_wrapper_t
7474{
7575
76- benchmark_wrapper_t ()
77- : m_fn() {};
76+ benchmark_wrapper_t () = default ;
77+
7878 explicit benchmark_wrapper_t (py::object o)
7979 : m_fn{std::shared_ptr<py::object>(new py::object (o), PyObjectDeleter{})}
80- {}
80+ {
81+ if (!PyCallable_Check (m_fn->ptr ()))
82+ {
83+ throw py::value_error (" Argument must be a callable" );
84+ }
85+ }
8186
82- benchmark_wrapper_t (const benchmark_wrapper_t &other)
83- : m_fn{other.m_fn }
84- {}
87+ // Only copy constructor is used, delete copy-assign, and moves
88+ benchmark_wrapper_t (const benchmark_wrapper_t &other) = default ;
8589 benchmark_wrapper_t &operator =(const benchmark_wrapper_t &other) = delete ;
8690 benchmark_wrapper_t (benchmark_wrapper_t &&) noexcept = delete ;
8791 benchmark_wrapper_t &operator =(benchmark_wrapper_t &&) noexcept = delete ;
8892
8993 void operator ()(nvbench::state &state, nvbench::type_list<>)
9094 {
95+ if (!m_fn)
96+ {
97+ throw std::runtime_error (" No function to execute" );
98+ }
9199 // box as Python object, using reference semantics
92100 auto arg = py::cast (std::ref (state), py::return_value_policy::reference);
93101
You can’t perform that action at this time.
0 commit comments