check_config: validate INI datatypes (numeric / enum / duplicate) before comparison#4181
check_config: validate INI datatypes (numeric / enum / duplicate) before comparison#4181tzuohann wants to merge 1 commit into
Conversation
The [JOINT_n]/[AXIS_L] limit check compares values with Tcl > / <,
which silently falls back to *string* comparison when a value isn't a
valid number (e.g. an inline "# comment" left on the line). Equal
numeric limits could then spuriously fail, with a misleading message,
and the outcome depended on trailing whitespace rather than the numbers.
Add assert_ini_datatypes(), run once right after parse_ini, before any
comparison. For each [JOINT_n]/[AXIS_L] item it:
- flags duplicate (multi-valued) keys as an error;
- requires numeric items (limits, vels, accels, scales, PID terms,
home vels, ...) to pass `string is double` (accepts ints and reals);
- requires enum items to match a fixed set, case-insensitively, to
mirror LinuxCNC's own caseless parsers:
TYPE -> {LINEAR ANGULAR} (IniFile::mapJointType)
bools -> {TRUE YES 1 ON FALSE NO 0 OFF} (IniFile::convertBool)
- leaves unknown items untouched.
Each error names the [SECTION]ITEM and the offending value, so a stray
comment is reported as such instead of a phantom limit violation.
Duplicate [JOINT_]/[AXIS_] keys are now an error; this supersedes the
warn-only warn_for_multiple_ini_values, which is removed.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Thanks for digging into this, and welcome to LinuxCNC. The inline MDI_COMMAND_MACRO0 = G0 Z2;X0 Y0;Z0, Goto\nUser\nZeroThe Also worth knowing: the datatype, enum, and duplicate-key checks here already exist in Given the above, I tend toward closing this, but happy to hear if I am missing something. |
|
The lib/hallib/check_config.tcl script has been superseded by emc/ini/linuxcnc_check_ini.py. Any changes to the Tcl script are in vain. |
|
@BsAtHome if |
|
There were some doubts when I wrote the new checker so I left it hanging around unused. There have been no complaints, so better remove the old Tcl script. |
Problem
check_config.tclcompares[JOINT_n]/[AXIS_L]limits with Tcl>/<.Tcl compares numerically only when both operands are valid numbers; otherwise
it silently does a string comparison. So a limit line carrying stray text —
e.g. an inline
# comment— gets compared as a string.With equal limits like:
3600000 == 3600000, yet check_config reports[JOINT_4]MAX_LIMIT < [AXIS_A]MAX_LIMIT— because the strings (comments +differing whitespace) compare unequal. Pass/fail flips on trailing spaces, and
the error points at the wrong thing.
Fix
Add
assert_ini_datatypes, run once right afterparse_ini, before anycomparison. For each
[JOINT_n]/[AXIS_L]item:string is double -strict(ints and reals);LinuxCNC's caseless maps:
TYPE→{LINEAR ANGULAR}(IniFile::mapJointType){TRUE YES 1 ON FALSE NO 0 OFF}(IniFile::convertBool)Errors name the
[SECTION]ITEMand the offending value.Behavior change
Duplicate
[JOINT_]/[AXIS_]keys are now an error, replacing the warn-onlywarn_for_multiple_ini_values(removed; same scope, now fatal).Testing
Patched checker vs a working 5-joint INI and corrupted copies:
TYPE=angular, all eight boolean spellings.abc,1,000,1.2.3,TYPE=LINER,HOME_USE_INDEX=MAYBE, duplicate key.Note
I'm not a software developer by trade, and this is my first day using LinuxCNC,
so I'd genuinely welcome feedback on the approach, the Tcl style, or the
numeric/enum item lists — happy to revise.