Skip to content

hal: hold the query enum types as py::handle - #4853

Merged
BsAtHome merged 1 commit into
LinuxCNC:masterfrom
grandixximo:hal-query-static-handles
Nov 16, 2026
Merged

BsAtHome merged 1 commit into
LinuxCNC:masterfrom
grandixximo:hal-query-static-handles

Conversation

@grandixximo

Copy link
Copy Markdown
Contributor

Fixes #4849.

halquery.cc kept the _hal Type, Dir and CompType enums in static py::object variables. The inc_ref() stopped them from being freed, but the static destructors still ran dec_ref() at process exit, after the interpreter had finalized. pybind11 3.x checks the GIL there and aborts, so on Fedora 45 LinuxCNC and python3 -c 'import hal' crash on exit.

I hold them as py::handle, which has no destructor, and keep the reference with release().

halquery.o registers three exit-time destructors before and none after. tests/halmodule passes.

@NTULINUX, could you test this on Fedora 45?

LinuxCNC aborts on exit on Fedora 45, and so does python3 -c 'import hal' (issue LinuxCNC#4849). halquery.cc kept the _hal Type, Dir and CompType enums in static py::object variables. The extra inc_ref() stopped the enums from being freed, but the static destructors still ran dec_ref() at process exit, after the interpreter had finalized. pybind11 3.x checks that the GIL is held in dec_ref() and terminates.

Store them as py::handle, which has no destructor, and keep the reference with release(). Nothing runs at exit any more: the object file registers no exit-time destructors (three before).

Fixes LinuxCNC#4849
@NTULINUX

Copy link
Copy Markdown
Contributor

Can confirm, all is well now, thank you!

@BsAtHome
BsAtHome merged commit 69f3439 into LinuxCNC:master Nov 16, 2026
19 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.

LinuxCNC crashes on exit with Fedora 45

3 participants