Skip to content

halmodule: fix inverted float to bool, unterminated RTType table, missing PyErr_Format argument - #4568

Merged
BsAtHome merged 1 commit into
LinuxCNC:masterfrom
grandixximo:halmodule-fixes
Sep 19, 2026
Merged

BsAtHome merged 1 commit into
LinuxCNC:masterfrom
grandixximo:halmodule-fixes

Conversation

@grandixximo

Copy link
Copy Markdown
Contributor

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 *) tested 0.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 a PyErr_Format with 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-get now 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 with 0.0 True / 1.0 False.

…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.
@rene-dev

Copy link
Copy Markdown
Member

all this would not be a problem with the new pybind11 bindings ;)

@BsAtHome

Copy link
Copy Markdown
Contributor

all this would not be a problem with the new pybind11 bindings ;)

And nothing would be any problem ever when the universe had both strong typing and type checked its creation.
And rust will save us from the world crumbling and falling apart.
And NoCode will be the future of programming.
...

Really?

@grandixximo

Copy link
Copy Markdown
Contributor Author

We actually have to be careful promoting pybind11 mostly on any hot path see
#4481 (comment)
I also did some local testing, and my own results match up, so it has a lot to like, but it is not the holy grail, performance will suffer and needs to be kept in mind.

@BsAtHome
BsAtHome merged commit 260f61e into LinuxCNC:master Sep 19, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants