zsh-workers
 help / color / mirror / code / Atom feed
* Fix up zsh/ksh93 for named reference changes
@ 2024-03-10  5:53 Bart Schaefer
  0 siblings, 0 replies; only message in thread
From: Bart Schaefer @ 2024-03-10  5:53 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 644 bytes --]

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.

[-- Attachment #2: repair-ksh93.txt --]
[-- Type: text/plain, Size: 3707 bytes --]

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;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-03-10  5:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-10  5:53 Fix up zsh/ksh93 for named reference changes Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).