Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Fix up zsh/ksh93 for named reference changes
- X-seq: zsh-workers 52725
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Fix up zsh/ksh93 for named reference changes
- Date: Sat, 9 Mar 2024 21:53:53 -0800
- Archived-at: <https://zsh.org/workers/52725>
- List-id: <zsh-workers.zsh.org>
Several recent changes to named references, particularly the fixing of
reference targets at the scope of declaration, have made it impossible
to use the module PARAMDEF() macro to create named references at
module load that refer to locals at expansion time.
The attached patch removes the global partab namerefs affected by
this, and instead explicitly creates them as locals in the
ksh93_wrapper() callback, so that they come and go in the appropriate
scopes.
This is mildly unsatisfying because it leaves a couple of specials at
global scope, mostly for ease of instantiation, that really should
also be locals. Might revisit that later.
diff --git a/Src/Modules/ksh93.c b/Src/Modules/ksh93.c
index 6760cbca0..8d10317dc 100644
--- a/Src/Modules/ksh93.c
+++ b/Src/Modules/ksh93.c
@@ -113,18 +113,17 @@ static char sh_edmode[2];
* obviously includes those commented out here.
*/
static struct paramdef partab[] = {
- PARAMDEF(".sh.command", PM_NAMEREF|PM_READONLY, "ZSH_DEBUG_CMD", &constant_gsu),
- PARAMDEF(".sh.edchar", PM_SCALAR|PM_SPECIAL, &sh_edchar, &sh_edchar_gsu),
- PARAMDEF(".sh.edcol", PM_NAMEREF|PM_READONLY, "CURSOR", &constant_gsu),
- PARAMDEF(".sh.edmode", PM_SCALAR|PM_READONLY|PM_SPECIAL, &sh_edmode, &sh_edmode_gsu),
- PARAMDEF(".sh.edtext", PM_NAMEREF|PM_READONLY, "BUFFER", &constant_gsu),
+ PARAMDEF(".sh.edchar", PM_SCALAR|PM_SPECIAL,
+ &sh_edchar, &sh_edchar_gsu),
+ PARAMDEF(".sh.edmode", PM_SCALAR|PM_READONLY|PM_SPECIAL,
+ &sh_edmode, &sh_edmode_gsu),
PARAMDEF(".sh.file", PM_NAMEREF|PM_READONLY, "ZSH_SCRIPT", &constant_gsu),
- /* PARAMDEF(".sh.fun", PM_SCALAR|PM_UNSET, NULL, &constant_gsu), */
- /* PARAMDEF(".sh.level", PM_INTEGER|PM_UNSET, NULL, &constant_gsu), */
PARAMDEF(".sh.lineno", PM_NAMEREF|PM_READONLY, "LINENO", &constant_gsu),
PARAMDEF(".sh.match", PM_ARRAY|PM_READONLY, NULL, &sh_match_gsu),
- PARAMDEF(".sh.name", PM_SCALAR|PM_READONLY|PM_SPECIAL, &sh_name, &sh_name_gsu),
- PARAMDEF(".sh.subscript", PM_SCALAR|PM_READONLY|PM_SPECIAL, &sh_subscript, &sh_subscript_gsu),
+ PARAMDEF(".sh.name", PM_SCALAR|PM_READONLY|PM_SPECIAL,
+ &sh_name, &sh_name_gsu),
+ PARAMDEF(".sh.subscript", PM_SCALAR|PM_READONLY|PM_SPECIAL,
+ &sh_subscript, &sh_subscript_gsu),
PARAMDEF(".sh.subshell", PM_NAMEREF|PM_READONLY, "ZSH_SUBSHELL", &constant_gsu),
/* SPECIALPMDEF(".sh.value", 0, NULL, NULL, NULL), */
PARAMDEF(".sh.version", PM_NAMEREF|PM_READONLY, "ZSH_PATCHLEVEL", &constant_gsu)
@@ -156,15 +155,35 @@ ksh93_wrapper(Eprog prog, FuncWrap w, char *name)
queue_signals();
++locallevel; /* Make these local */
- if ((pm = createparam(".sh.level", PM_LOCAL|PM_UNSET))) {
+#define LOCAL_NAMEREF (PM_LOCAL|PM_UNSET|PM_NAMEREF)
+ if ((pm = createparam(".sh.command", LOCAL_NAMEREF))) {
pm->level = locallevel; /* Why is this necessary? */
- setiparam(".sh.level", num);
+ /* Force scoping by assignent hack */
+ setloopvar(".sh.command", "ZSH_DEBUG_CMD");
+ pm->node.flags |= PM_READONLY;
}
+ /* .sh.edchar is in partab and below */
+ if (zleactive && (pm = createparam(".sh.edcol", LOCAL_NAMEREF))) {
+ pm->level = locallevel;
+ setloopvar(".sh.edcol", "CURSOR");
+ pm->node.flags |= (PM_NAMEREF|PM_READONLY);
+ }
+ /* .sh.edmode is in partab and below */
+ if (zleactive && (pm = createparam(".sh.edtext", LOCAL_NAMEREF))) {
+ pm->level = locallevel;
+ setloopvar(".sh.edtext", "BUFFER");
+ pm->node.flags |= PM_READONLY;
+ }
+
if ((pm = createparam(".sh.fun", PM_LOCAL|PM_UNSET))) {
pm->level = locallevel;
setsparam(".sh.fun", ztrdup(name));
pm->node.flags |= PM_READONLY;
}
+ if ((pm = createparam(".sh.level", PM_LOCAL|PM_UNSET))) {
+ pm->level = locallevel;
+ setiparam(".sh.level", num);
+ }
if (zleactive) {
extern mod_import_variable char *curkeymapname; /* XXX */
extern mod_import_variable char *varedarg; /* XXX */
@@ -186,9 +205,10 @@ ksh93_wrapper(Eprog prog, FuncWrap w, char *name)
*--ie = '\0';
} else
sh_subscript = NULL;
- if ((pm = createparam(".sh.value", PM_LOCAL|PM_NAMEREF|PM_UNSET))) {
+ if ((pm = createparam(".sh.value", LOCAL_NAMEREF))) {
pm->level = locallevel;
setloopvar(".sh.value", "BUFFER"); /* Hack */
+ pm->node.flags |= PM_READONLY;
}
} else
sh_name = sh_subscript = NULL;
Messages sorted by:
Reverse Date,
Date,
Thread,
Author