Skip to content
Discussion options

You must be logged in to vote

The root bug is this loop:

for(uint i; i < m.getLength(); ++i)

i is never initialized. In C++, a local variable like uint i; has an indeterminate value. If that value happens to be greater than or equal to m.getLength(), the loop body never runs and the returned vector stays empty

Adding std::cerr changes the generated code / stack layout enough to mask the bug in that particular build, which is why it may look like an optimization issue

Fix:

for (uint i = 0; i < m.getLength(); ++i)

That said, if the goal is to return raw bytes to Python, py::bytes is usually the simpler option:

.def("getValue", [](const rav::Msg &m) {
    auto data = m.getValue();
    return py::bytes(reinterpret_cast<const

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rackaracka
Comment options

Answer selected by rackaracka
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants