From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19417 invoked by alias); 26 Nov 2015 00:33:44 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 37217 Received: (qmail 18710 invoked from network); 26 Nov 2015 00:33:41 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:to:subject:mime-version:content-type; bh=aTm4Kpukvv8AOhfxmwrblHnrfqi5ep1h8XuXCmIJ2go=; b=yDJxwtx/sgVbuOk+Bu/c9CWdGewQg/Ej8n0heZEUMZcH+IvLP9k8wovqeW48vg/2NB pEb5bF223eBv3f+pUucOMmAnc8N/gOrqDcEhCnUgjJfDb7zqgYNG2I/d5ccBqaYgxVb4 sHC3Uz8Q3/iiWJ6n7DctbC2ZhyoZMMhbCx+nqovZaRhsaqq8TGGWjLNX54NVmzrbRUNA KAivvniwKXw7TwKN5m2jOlD4k0HZl8qiJNhZ/Igd6q8ewDUcG0trVn5Kj4R+oPAbVD54 hbW9YGa51bkdvl8decC8t4lwcp8YroN0/mZ3wCf8GlONBHednkF3SA3qUF9FpmYeViNS fyKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:to:subject:mime-version :content-type; bh=aTm4Kpukvv8AOhfxmwrblHnrfqi5ep1h8XuXCmIJ2go=; b=WsJmU5fB8nOZ1wO3wqflBgOBQvwhtlemljKODi4hlPHxnLVxgsqGMhYR/BnfnDYdbu zbNDu/WHP5RDYb6vAUiKLFcJxu6OOkLnRQ2H1x1iYCU/os6L3tnMHfGx8RQU3RacBsYz 85F3EetMQyA9LmFm0uLzMR9sFY1cZBN4RpqCPONG1t5Sm2uwW+rkVXjs6/8V4y29nNZD 2vNoPInTSzCXxBqehypoE1SGgYHm/5juYv0o1M4DNU5KGdUMXEfMa1zwoZmMrLQczA8M PWcLWp+G6oFQ5Aq5VAsN2K39JMmZ9jc75eRwPGFj8ZHx4j7V/Jc8j5tNofJST4kSn31W VpvA== X-Gm-Message-State: ALoCoQmN6di1DJsdXRaS+DIgeZSWF9OpT6ycpN2PCZayRbUQWbuLC7thsv2uuWP41Axr7bmh49gd X-Received: by 10.66.136.40 with SMTP id px8mr56460429pab.75.1448498018181; Wed, 25 Nov 2015 16:33:38 -0800 (PST) From: Bart Schaefer Message-Id: <151125163351.ZM5279@torch.brasslantern.com> Date: Wed, 25 Nov 2015 16:33:51 -0800 X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: POSIX_BUILTINS and readonly parameters, again MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii This concerns the discussion that started in 34991, specifically the patch 34992 and the thread leading to 35004 where things dropped without further resolution. Part of the patch in 34992 is this: @@ -874,10 +874,14 @@ createparam(char *name, int flags) DPUTS(oldpm && oldpm->level > locallevel, "BUG: old local parameter not deleted"); if (oldpm && (oldpm->level == locallevel || !(flags & PM_LOCAL))) { + if (isset(POSIXBUILTINS) && (oldpm->node.flags & PM_READONLY)) { + zerr("read-only variable: %s", name); + return NULL; + } Short question: Why does that test POSIXBUILTINS as well as PM_READONLY ? Long explanation: The isset(POSIXBUILTINS) there seems to be covering a really strange edge case. If POSIXBUILTINS is not set, it's impossible to create a readonly variable that is unset: torch% () { readonly foo; print ${foo+foo is set}; unset foo } foo is set (anon): read-only variable: foo torch% () { readonly foo; print ${foo+foo is set}; foo=oopsie } foo is set (anon): read-only variable: foo [That first error is coming from unsetparam_pm() and the second from assignsparam(). Neither is from the createparam() patch above, the variable is set so createparam() never called.] Conversely if POSIXBUILTINS is set, readonly variables are unset unless assigned in the declaration [good thing we fixed array assignment there]: torch% () { setopt localoptions posixbuiltins readonly foo; print ${foo-foo is NOT set}; unset foo } foo is NOT set (anon):1: read-only variable: foo torch% () { setopt localoptions posixbuiltins readonly foo; print ${foo-foo is NOT set}; foo=oopsie } foo is NOT set (anon):1: read-only variable: foo [Note we still get the error for attempting to unset an already unset parameter. Probably wrong. The first error is from unsetparam_pm() and the second one is from createparam(), assignment is never tried.] So the only reason for testing isset(POSIXBUILTINS) in createparam() is the case where POSIXBUILTINS *changes* between time of declaration and time of assignment: torch% () { setopt localoptions posixbuiltins readonly foo; print ${foo-foo is NOT set}; unsetopt posixbuiltins; foo=oopsie; print ${foo-foo is NOT set} } foo is NOT set oopsie This seems a little twitchy. Having gone to the trouble of creating a parameter that we know is both readonly and unset, we allow it to be clobbered anyway? Could this respect PM_READONLY unconditionally? -- Barton E. Schaefer