fix: hide KEYBOARD_HACK with PM_UNSET instead of removing it#10
fix: hide KEYBOARD_HACK with PM_UNSET instead of removing it#10HaleTom wants to merge 4 commits into
Conversation
This fixes issue zdharma-continuum#9 by not polluting the environment with KEYBOARD_HACK when the SUN_KEYBOARD_HACK option is used with an empty/NULL value. The change only affects the SUN_KEYBOARD_HACK option handler in options.c:826. When value is NULL/empty, we no longer set keyboardhackchar, preventing the unnecessary legacy variable from being exported. The internal keyboardhackchar variable is still used by input.c (input processing) and builtin.c (emulate save/restore), but keyboardhackgetfn/keyboardhacksetfn functions are no longer referenced through the GSU struct since the KEYBOARD_HACK parameter registration remains for backward compatibility.
KEYBOARD_HACK is a legacy Sun keyboard workaround that serves no purpose on modern systems. Removing the IPDEF2 registration prevents it from polluting the environment in every Zsh session. Closes zdharma-continuum#9
Re-engineer the fix for issue zdharma-continuum#9: instead of deleting the special parameter entirely, keep KEYBOARD_HACK registered but start it hidden via PM_UNSET. The setter toggles PM_UNSET based on value — non-empty clears it (visible), empty or unset sets it (hidden). The SUN_KEYBOARD_HACK option continues to work independently by setting keyboardhackchar directly. Also fixes a pre-existing memory leak on the ASCII validation error path.
The c88e600 change prevented keyboardhackchar from being cleared when unsetting SUN_KEYBOARD_HACK, which meant the hack remained active after disabling the option. With the PM_UNSET approach, the IPDEF2 flags already handle hiding the parameter — the option handler should behave correctly (set on enable, clear on disable).
Production readiness review — diff to
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates the KEYBOARD_HACK special parameter handling so its unset/set state is tracked consistently via PM_UNSET.
Changes:
- Initialize
KEYBOARD_HACKwithPM_UNSETin the parameter definition. - Update
keyboardhacksetfnto togglePM_UNSETbased on whether the resulting value is empty/unset. - Fix memory management in the non-ASCII validation path by freeing the incoming value before returning.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Issues found and addressed during development: 1. Options handler bug (commit
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
Src/params.c:1
keyboardhacksetfnsilently ignores all but the first character (x[0]). IfKEYBOARD_HACKis intended to be a single ASCII character, it would be clearer to validatelen <= 1and warn/reject when extra characters are provided (or explicitly document that only the first character is used). This avoids confusing behavior likeKEYBOARD_HACK=abcbeing treated asawithout any feedback.
/*
|
Re: Copilot review #4361918200 — suppressed low-confidence observation about multi-character values: The concern is already addressed. At if (len > 1) {
len = 1;
zwarn("Only one KEYBOARD_HACK character can be defined");
}When |
Issue for this PR
Closes #9
Type of change
What does this PR do?
Hides the
KEYBOARD_HACKspecial parameter fromtypeset/echolistings when empty or unset, instead of removing it entirely. The approach usesPM_UNSET:IPDEF2("KEYBOARD_HACK", ...)registered withPM_DONTIMPORT | PM_UNSET— starts hidden by defaultkeyboardhacksetfntogglesPM_UNSETbased on value:pm->node.flags &= ~PM_UNSET(visible)pm->node.flags |= PM_UNSET(hidden)stdunsetfn) →pm->node.flags |= PM_UNSET(hidden)The
SUN_KEYBOARD_HACKoption andkeyboardhackcharvariable continue working independently — the option handler sets the hack character directly without touching the parameter's visibility.Also fixes a pre-existing memory leak:
keyboardhacksetfnwas missingfree(x)on the ASCII validation error return path.How did you verify your code works?
Code review and production-readiness adversarial review — see
REVIEW-2026-05-25T18:54:46+07:00.md.Changes in
Src/params.c:IPDEF2flags:PM_DONTIMPORT→PM_DONTIMPORT | PM_UNSET(1 insertion)keyboardhacksetfn: added PM_UNSET toggling + memory leak fix (9 insertions, 3 deletions)Related
Checklist