zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Fix up zsh/ksh93 for named reference changes
Date: Sat, 9 Mar 2024 21:53:53 -0800	[thread overview]
Message-ID: <CAH+w=7YLxmctgu=NiLMyo6XviFxfdFfcmPp-TK9M_zTg2N_r7A@mail.gmail.com> (raw)

[-- 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;

                 reply	other threads:[~2024-03-10  5:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7YLxmctgu=NiLMyo6XviFxfdFfcmPp-TK9M_zTg2N_r7A@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).