Skip to content

halcompile: warn about, and reject colliding, mangled HAL names - #4298

Open
tzuohann wants to merge 1 commit into
LinuxCNC:masterfrom
tzuohann:halcompile-halname-upstream
Open

halcompile: warn about, and reject colliding, mangled HAL names#4298
tzuohann wants to merge 1 commit into
LinuxCNC:masterfrom
tzuohann:halcompile-halname-upstream

Conversation

@tzuohann

@tzuohann tzuohann commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

pin in float my_input is exported as component.N.my-input — underscores become dashes (comp.adoc, HALNAME).

A component that declares both x_y and x_y_ exports both as x-y. halcompile accepts it; the module then fails at loadrt:

HAL: ERROR: duplicate variable 'collide.0.x-y'
collide: rtapi_app_main: Invalid argument (-22)

check_name_ok() only compares declared names. check_hal_name() errors on the collision at the offending line, and a once-per-file warning lists names whose HAL identifier differs. -N suppresses the warning only, never the error; the in-tree rules pass it so build output is unchanged.

Docs: NAMES section in the halcompile man page, note under the HALNAME table in comp.adoc. Tests: tests/halcompile/halname. All 133 in-tree .comp files preprocess with no new error.

Backport for 2.9: #4299.

🤖 Generated with Claude Code

@BsAtHome

Copy link
Copy Markdown
Contributor

Name collisions are bad by default and fail to compile. Why is there an option for this? You should be able to check this much easier using a parallel name array for target names (which you apparently do) without complex regexes or lambdas by using a simple if name in array construct. Also note that functions have a different HAL namespace than pins/params.

Your second PR seems to be a duplicate and changes a generated (man) file that is not part of the repository. Why is this submitted twice?

@grandixximo

Copy link
Copy Markdown
Contributor

Your second PR seems to be a duplicate and changes a generated (man) file that is not part of the repository. Why is this submitted twice?

It's a 2.9 backport, no .adoc there, also threw me off...

@tzuohann

Copy link
Copy Markdown
Contributor Author

thanks. help me understand here. is this is a problem that can throw some people (amateurs using AI) off? if so and a little fix can help, I'll try to sharpen the solution. but if its not even an issue, i'll close the PR.

A name declared in a .comp file is a C identifier, but it is exported
under a mangled HAL identifier: underscores become dashes and a trailing
dash or period is removed (comp.adoc, HALNAME). Nothing said so at
compile time, so "pin in float my_input" silently became
component.N.my-input.

Worse, check_name_ok() compares only declared names. Two declarations
that mangle to the same HAL name -- x_y and x_y_, the two rows of the
HALNAME table that share a HAL identifier -- therefore compiled cleanly
and failed much later, at load time:

    HAL: ERROR: duplicate variable 'collide.0.x-y'
    collide: rtapi_app_main: Invalid argument (-22)

Add check_hal_name(), which rejects that collision at the offending
line, and a once-per-file warning listing the names whose HAL identifier
differs from the declaration. Both messages point at the HALNAME
documentation. The warning is suppressed by -N (--no-name-warnings),
which the in-tree component rules pass, since those names are deliberate.

All 133 in-tree .comp files preprocess with no new error, and silently
under -N. tests/halcompile/halname covers the warning, -N, and the
rejected collision.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@tzuohann
tzuohann force-pushed the halcompile-halname-upstream branch from e1db816 to 1188057 Compare July 31, 2026 01:12
@grandixximo

grandixximo commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Name collisions are bad by default and fail to compile.

But they actually don't, I tested the claimed x_y + x_y_ on master, compiles fine, fails on loadrt...

Edit:
Unless you mean name collisions should always fail to compile, in the PR context, then agreed...

@tzuohann

Copy link
Copy Markdown
Contributor Author

-N silences the warning only; a collision is always an error. The comment in initialize() said that badly — fixed.

Simplified as you suggested: two dicts (pins+params, functions) and if hal_name in seen; the regex and lambda are gone. Pins and params share one dict because hal_lib.c does — hal_pin_newf() rejects a duplicate pin and complains about an overlapping param, hal_param_newf() mirrors it.

Also fixed while checking this: array names were listed as mangled even without an underscore, since to_hal() expands ## to %02d.

#4299 is the 2.9 backport, not a duplicate. docs/man/man1/halcompile.1 is the tracked source on 2.9 — 101 troff pages there, no adoc for halcompile, nothing generates them. Master has none of that tree. Happy to close it if 2.9 is off-limits.

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