emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unbinding let-bound built-in variables


From: Stefan Monnier
Subject: Re: Unbinding let-bound built-in variables
Date: Fri, 24 May 2024 10:10:44 -0400
User-agent: Gnus/5.13 (Gnus v5.13)

>> I'd expect that the connection between the ELisp var and the C var is
>> "forever", especially since once the connection is broken there's no way
>> to re-establish it, so I think it's a drastic effect.
> Uninterning the variable's name would also produce such a "drastic
> effect", at least in code loaded after the fact.

Indeed, uninterning symbols from the global obarray is a really
dangerous operation (which is why we changed `unintern` to make its
second argument non-optional).
But that's not specific to variables-with-forwarding.

> IMHO, the meaning of `makunbound' is to revert the effect of the
> operation that established the binding within the current dynamic scope,
> be that a DEFVAR_LISP or a setq.

I guess that can make sense too.  But I'm not sure what it implies w.r.t
the interaction with a dynbound let-binding (should `makunbound` just
undo the last let-binding?).

> But all these are details, and my only wish is to see this decided one
> way or the other, preferably soon.

I suggest a patch like the one below.


        Stefan


diff --git a/src/data.c b/src/data.c
index be7ae023d8d..18e41dce334 100644
--- a/src/data.c
+++ b/src/data.c
@@ -1743,20 +1742,19 @@ set_internal (Lisp_Object symbol, Lisp_Object newval, 
Lisp_Object where,
            set_blv_valcell (blv, tem1);
          }
 
-       /* Store the new value in the cons cell.  */
-       set_blv_value (blv, newval);
-
        if (blv->fwd.fwdptr)
          {
            if (voide)
-             /* If storing void (making the symbol void), forward only through
-                buffer-local indicator, not through Lisp_Objfwd, etc.  */
-             blv->fwd.fwdptr = NULL;
+             error ("This variable cannot be void");
            else
              store_symval_forwarding (blv->fwd, newval,
                                       BUFFERP (where)
                                       ? XBUFFER (where) : current_buffer);
          }
+
+       /* Store the new value in the cons cell.  */
+       set_blv_value (blv, newval);
+
        break;
       }
     case SYMBOL_FORWARDED:
@@ -1780,11 +1778,7 @@ set_internal (Lisp_Object symbol, Lisp_Object newval, 
Lisp_Object where,
          }
 
        if (voide)
-         { /* If storing void (making the symbol void), forward only through
-              buffer-local indicator, not through Lisp_Objfwd, etc.  */
-           sym->u.s.redirect = SYMBOL_PLAINVAL;
-           SET_SYMBOL_VAL (sym, newval);
-         }
+         error ("This variable cannot be void");
        else
          store_symval_forwarding (/* sym, */ innercontents, newval, buf);
        break;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]