Skip to content

Commit 3480759

Browse files
Addressed PR feedback re: definition of benchmark_wrapper_t
See #237 (comment)
1 parent 88cb632 commit 3480759

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

python/src/py_nvbench.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,29 @@ struct PyObjectDeleter
7373
struct 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

0 commit comments

Comments
 (0)