halmodule: fix inverted float to bool, unterminated RTType table, missing PyErr_Format argument - #4568
Merged
Conversation
…sing PyErr_Format argument
from_python(PyObject *, bool *) set the bool to true when the float was 0.0 and false otherwise, so writing 1.0 to a bool pin or param cleared it and writing 0.0 set it. The comment above it already stated the intended rule; the comparison is now "!= 0.0".
halenum_rt_members[] had no empty terminator, so halenum_build("RTType", ...) kept reading past the end of the array until it found a NULL name in whatever followed in .rodata. Whether the enum built correctly depended on the memory layout of the build.
check_port() passed two arguments to a format with three conversions, so the "Pin type not HAL_PORT" message printed the type where the pin name belongs and read garbage for the type.
tests/halmodule/comp-set-get now writes floats and ints into a bool param and checks what comes back.
Member
|
all this would not be a problem with the new pybind11 bindings ;) |
Contributor
And nothing would be any problem ever when the universe had both strong typing and type checked its creation. Really? |
Contributor
Author
|
We actually have to be careful promoting pybind11 mostly on any hot path see |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three pre-existing bugs in
src/hal/halmodule.cc, found while reviewing #4565. None of the lines are touched by that PR, so there is no conflict.from_python(PyObject *, bool *)tested0.0 == v, so a float 1.0 written to a bool pin or param cleared it and 0.0 set it. The comment above already said "false only when it is 0.0"; the comparison now matches it.halenum_rt_members[]had no{}terminator.halenum_build("RTType", ...)walks the table until it finds a NULL name, so it read past the array into whatever followed in.rodata. It worked by luck of the memory layout.check_port()passed two arguments to aPyErr_Formatwith three conversions, so the "Pin type not HAL_PORT" message printed the type in the pin name slot and read garbage for the type.tests/halmodule/comp-set-getnow writes 0.0, 1.0, -0.5, 0 and 2 into a bool param and checks what comes back; with the first fix reverted it fails with0.0 True/1.0 False.