From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 19264 invoked from network); 31 Mar 2021 22:55:43 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 31 Mar 2021 22:55:43 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1617231343; b=J+jgDjEdo4fiQ+7w1wHV9nJ4bSP+GEvx1n7FRMkaonnBs1++KwKoWvY3iGaZ0fpnUAR4sS/116 2fUOat0Bi6JUGrIyIJzDbZA9fF+ApYLQ50kJoHCh+UCQsAd5i+l0c3muc/VxHpx/Ap7CLi9U5v BgAWOX3VBtFHq8NeF0piOdzhHw6FErGc61JmWObgO5ReEWS42fJp/6RMo9J0j7ABokLQXl2sNq NwAUPTMqbR/DwEmjZvw1CWvp/Mfib/kMHtW7UvugLWpG3ojmipJtiH6GXUx1Xt9UdgOHOTsCnB YoIoNSSy+IDwv8DXdADoEp09X3xDge9Z7ef72vMx3Tj23w==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (out3-smtp.messagingengine.com) smtp.remote-ip=66.111.4.27; dkim=pass header.d=daniel.shahaf.name header.s=fm3 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm2 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1617231343; bh=t3Sn2yA5NMNe7Mf/DLYKTRwT8B1D2+mCUKrX8uw18+c=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:DKIM-Signature: DKIM-Signature:DKIM-Signature; b=divANHuGhWfdvpKcRNMKk7HaneoLT/lUSmVEzBnNIN5dwEyPofLhkgpjVXwcLInaOLDV2eI5q6 BJSzuen+/m99tWb9+1/NRnFdRGfaO0YKg5xwrawOkiMdKWcxIqhGHGmLOyeWn/SQuN+a8WpXfG LIIq05B8tt2bmNuWN4MgCHl57BUxp47siozafT6rl+RVNHc0pd5haLBAD9A1C9Q2m3JU7qzx+H w5qJ/0XVJHiGmW0Uf7NEJ3SVVnLlLVm8o5vrHymyxAj1RLmYLAVYZeNKGLtX6C7++Ra+alMTyL /8Deu9iSzuuO82NwEdId8GykmfC02+U6aeCP5gPhQqDgwA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=/cm7pvGZgwMQpQx3rbf4UCiS6GJbSXUVnL+XLsqVljc=; b=i4XM3Zwk7duSEuwMKhjhU8lxwP AxafzegUIq+vTOz5UfahIcFVBUb1P/ggmyPb3khbLMc5saAh2DHmWzsIhEF8d5rqKoQjzYpLMX9Ho HQ0IuPMn5iIP1ydYX/cYtT5vq2fpmJMGhyy4kq6M7YzTk00/XUqyDVvBVJ6kumz4k2Uqky8qAdLp4 bO2AKdqV4ZZ6YHZc2Q0osRMl3ztyEJkCr7mhcY9hZHtfQL07Lv272h3SLYoxBXNyRRwVb2TqzB8P4 +sMLP3aGlfAvFll1ZiP21Q88w4XfqQSlwG9nqL3UmQUDdoSGwN67LQ3mwpPhjWrip5r7LTWZ9EhhM LWzb3D0w==; Received: from authenticated user by zero.zsh.org with local id 1lRjkP-000AjT-Hd; Wed, 31 Mar 2021 22:55:37 +0000 Authentication-Results: zsh.org; iprev=pass (out3-smtp.messagingengine.com) smtp.remote-ip=66.111.4.27; dkim=pass header.d=daniel.shahaf.name header.s=fm3 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm2 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none Received: from out3-smtp.messagingengine.com ([66.111.4.27]:50685) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1lRjk7-000AZg-Dd; Wed, 31 Mar 2021 22:55:20 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 64DA15C0109; Wed, 31 Mar 2021 18:55:18 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Wed, 31 Mar 2021 18:55:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:cc:subject:message-id :references:mime-version:content-type:content-transfer-encoding :in-reply-to; s=fm3; bh=/cm7pvGZgwMQpQx3rbf4UCiS6GJbSXUVnL+XLsqV ljc=; b=j11sRZm43sLkQgPidCH/lp/5yZPLbORWvP6UqwVe0iFAot0fvKvtunnu fCpS2nHNdCze0bu2YXB38Zc0wRRZhLlWzwE0F4DuTtkjDboAEdUrDdp6DtTN4stb jVuoUiwh2+ZjxcViwc1lktrVKoBahRKjx0132BY9bviHnEWvbvYnruueJSCytLkP fJKL9CVyJ/6eEmwbhEyA0C79K32VRJlsrAZLHvnCakkNfn5j3e3jkLKXH/Xvenr9 elXQLTZoEM0U6GLm3Mlua8Tb6yBw0x6bLMVwjn9VYuDma9aASNyiXingTwE1yg5V RTuReXdnn50kDR0gZGcGus/Ygp9wnw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=/cm7pvGZgwMQpQx3rbf4UCiS6GJbSXUVnL+XLsqVl jc=; b=ipmbDn7L15+J85G2sk9Qq998f1+mxwl3iWlK7j9Afpdq6wyVkVIOhXQTG MJsKAxP+AsuWBQ4V1/qtga9qPZymdv/iLTEo/vhx384gypuqX1wFI3enjiVunH3R 6Iqwa6UD2v3CsmXkwHwboS5iKj5V6MQVvQrXikmd9RBSdMhtJxVKhMT9zVQ5AkCg PFP5t0aaQTI+csMCy1IIfw4jgtqzUrwYN+9ExMVCCu4WzMuTQvrgv8GjBp8Hj1xE EESu/wB7pBnNOrhb0VXpsq27giqhUyUI8yjwS1ULE7HGuVFOLM6ym8XhF/HmQrFj cLb1jCAdr2a0/MaL4CAk3+ivuYz7w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudeifedgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtugfgjggfsehtkedttddtreejnecuhfhrohhmpeffrghn ihgvlhcuufhhrghhrghfuceougdrshesuggrnhhivghlrdhshhgrhhgrfhdrnhgrmhgvqe enucggtffrrghtthgvrhhnpefgkefgfeejgfdvvdfguddtleelkedvfeetiedtudfhveev veduhfdvveeffedvueenucfkphepjeelrddukedvrdefiedrudekudenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegurdhssegurghnihgvlhdr shhhrghhrghfrdhnrghmvg X-ME-Proxy: Received: from tarpaulin.shahaf.local2 (bzq-79-182-36-181.red.bezeqint.net [79.182.36.181]) by mail.messagingengine.com (Postfix) with ESMTPA id 021F01080057; Wed, 31 Mar 2021 18:55:18 -0400 (EDT) Received: by tarpaulin.shahaf.local2 (Postfix, from userid 1005) id 4F9hVB6njGz3W3; Wed, 31 Mar 2021 22:55:14 +0000 (UTC) Date: Wed, 31 Mar 2021 22:55:14 +0000 From: Daniel Shahaf To: Mikael Magnusson Cc: Zsh hackers list , Marlon Richert Subject: Re: Feature Patch: Use completion to view parameter values Message-ID: <20210331225514.GA16838@tarpaulin.shahaf.local2> References: <20210329073913.GP18178@tarpaulin.shahaf.local2> <20210329171120.GA6044@tarpaulin.shahaf.local2> <20210329181452.GB6044@tarpaulin.shahaf.local2> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Seq: 48358 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: Mikael Magnusson wrote on Tue, Mar 30, 2021 at 07:41:05 +0200: > On 3/29/21, Daniel Shahaf wrote: > > Bart Schaefer wrote on Mon, Mar 29, 2021 at 10:20:08 -0700: > >> On Mon, Mar 29, 2021 at 10:11 AM Daniel Shahaf > >> wrote: > >> > > >> > I think that's right. -workers@: Is it possible for a non-PM_SPECIAL > >> > parameter have a custom getfn? > >> > >> Only with the zsh/param/private module, I think, and in that case the > >> getfn is just a wrapper around the default and doesn't add any > >> side-effects. > > > > Thanks, Bart. > > > > And as to $AUTOINCREMENT, this isn't the first time I mentioned it as > > a hypothetical, so I'm going to go ahead and post it here. I suspect > > people from the future will use this for something-or-other. > > > > Works as you'd expect: > > . > > % echo $AUTOINCREMENT $AUTOINCREMENT > > 0 1 > > % > > > > And in Marlon's patch with the ${(t)…*special*} exclusion bypassed: > > . > > % zstyle \* extra-verbose yes > > % AUTOFOO=42 > > % echo $AUTO > > AUTOFOO -- 42 AUTOINCREMENT -- 2 > > AUTOFOO -- 42 AUTOINCREMENT -- 4 > > > > Yes, it does actually increment the variable twice, probably because the > > _parameters patch uses both ${(t)${(P)}} and then ${(P)}, and the former > > does an increment too: > > . > > % echo $AUTOINCREMENT ${(tP)AUTOINCREMENT} $AUTOINCREMENT > > 0 array-special 2 > > % > > > > I'm not proposing to commit $AUTOINCREMENT. > > > > Cheers, > > > > Daniel > > > > P.S. Another similar example is Perl's magic flip-flop variable: > > «perl -E 'say --$| for (1..10)'» > > > > > > diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c > > index ef9148d7b..179ac068e 100644 > > --- a/Src/Modules/parameter.c > > +++ b/Src/Modules/parameter.c > > @@ -2136,6 +2136,24 @@ scanpmusergroups(UNUSED(HashTable ht), ScanFunc func, > > int flags) > > } > > > > > > +/* Functions for the AUTOINCREMENT special parameter. */ > > + > > +static zlong autoincrement = 0; > > + > > +static zlong > > +autoincrementgetfn(UNUSED(Param pm)) > > +{ > > + return autoincrement++; > > +} > > + > > +static void > > +autoincrementsetfn(UNUSED(Param pm), zlong value) > > +{ > > + autoincrement = value; > > +} > > If someone hypothetically wanted to use this, this (eg, the static > zlong autoincrement variable) should either be a zulong, or > autoincrementgetfn should check for wrapping, otherwise this is > undefined behavior (hypothetically) (unless we use -fwrapv, but I > don't think we do). Thanks, Mikael. Completely forgot about this. The signatures in gsu_integer specify signed and I don't want to deal with signed/unsigned differences, so: diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c index 179ac068e..638ccc886 100644 --- a/Src/Modules/parameter.c +++ b/Src/Modules/parameter.c @@ -2143,6 +2143,10 @@ static zlong autoincrement = 0; static zlong autoincrementgetfn(UNUSED(Param pm)) { + if (autoincrement == ZLONG_MAX) { + autoincrement = ZLONG_MIN; + return ZLONG_MAX; + } return autoincrement++; } diff --git a/Src/zsh.h b/Src/zsh.h index 6cf1b4186..536d728c5 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -38,12 +38,15 @@ typedef ZSH_64_BIT_TYPE zlong; #if defined(ZLONG_IS_LONG_LONG) && defined(LLONG_MAX) #define ZLONG_MAX LLONG_MAX +#define ZLONG_MIN LLONG_MIN #else #ifdef ZLONG_IS_LONG_64 #define ZLONG_MAX LONG_MAX +#define ZLONG_MIN LONG_MIN #else /* umm... */ #define ZLONG_MAX ((zlong)9223372036854775807) +#define ZLONG_MIN ((zlong)-9223372036854775808) #endif #endif #ifdef ZSH_64_BIT_UTYPE @@ -55,6 +58,7 @@ typedef unsigned zlong zulong; typedef long zlong; typedef unsigned long zulong; #define ZLONG_MAX LONG_MAX +#define ZLONG_MIN LONG_MIN #endif /* diff --git a/Test/V06parameter.ztst b/Test/V06parameter.ztst index 27d587852..610422abd 100644 --- a/Test/V06parameter.ztst +++ b/Test/V06parameter.ztst @@ -92,6 +92,37 @@ >foo >bar + repeat 3 echo $AUTOINCREMENT + : + AUTOINCREMENT=42; + repeat 3 echo $AUTOINCREMENT + : + AUTOINCREMENT=2147483647 + repeat 3 echo $AUTOINCREMENT + : + AUTOINCREMENT=4294967295 + repeat 3 echo $AUTOINCREMENT + : + AUTOINCREMENT=9223372036854775807 + repeat 3 echo $AUTOINCREMENT +0:$AUTOINCREMENT unit test +>0 +>1 +>2 +>42 +>43 +>44 +>2147483647 +>2147483648 +>2147483649 +>4294967295 +>4294967296 +>4294967297 +>9223372036854775807 +*>(-9223372036854775808|9223372036854775809) +*>(-9223372036854775807|9223372036854775810) +F:This test assumes zlong is at least a 64-bit type. + %clean rm -f autofn functrace.zsh rocky3.zsh sourcedfile myfunc Cheers, Daniel