Skip to content

Commit 97c65bf

Browse files
committed
fix: regression in #662 causing segfaults
1 parent 724b0b2 commit 97c65bf

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

include/bh_python/register_histogram.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,17 @@ auto register_histogram(py::module& m, const char* name, const char* desc) {
190190

191191
.def("reduce",
192192
[](const histogram_t& self, py::args args) {
193+
auto commands
194+
= py::cast<std::vector<bh::algorithm::reduce_command>>(args);
193195
py::gil_scoped_release release;
194-
return bh::algorithm::reduce(
195-
self, py::cast<std::vector<bh::algorithm::reduce_command>>(args));
196+
return bh::algorithm::reduce(self, commands);
196197
})
197198

198199
.def("project",
199200
[](const histogram_t& self, py::args values) {
201+
auto cpp_values = py::cast<std::vector<unsigned>>(values);
200202
py::gil_scoped_release release;
201-
return bh::algorithm::project(self,
202-
py::cast<std::vector<unsigned>>(values));
203+
return bh::algorithm::project(self, cpp_values);
203204
})
204205

205206
.def("fill", &fill<histogram_t>)

tests/test_histogram.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,12 @@ def test_project():
589589
with pytest.raises(ValueError):
590590
h.project(2, 1)
591591

592+
with pytest.raises(ValueError):
593+
h.project(9)
594+
595+
with pytest.raises(ValueError):
596+
h.project(-1)
597+
592598

593599
def test_shrink_1d():
594600
h = bh.Histogram(bh.axis.Regular(20, 1, 5))

0 commit comments

Comments
 (0)