From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Mikael Magnusson <mikachu@gmail.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>,
Marlon Richert <marlon.richert@gmail.com>
Subject: Re: Feature Patch: Use completion to view parameter values
Date: Wed, 31 Mar 2021 22:55:14 +0000 [thread overview]
Message-ID: <20210331225514.GA16838@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <CAHYJk3Tfb0xqP_QoAGoTOd3RKOqDLW9o8Zs7MepkCtkEv-8MJw@mail.gmail.com>
Mikael Magnusson wrote on Tue, Mar 30, 2021 at 07:41:05 +0200:
> On 3/29/21, Daniel Shahaf <d.s@daniel.shahaf.name> 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 <d.s@daniel.shahaf.name>
> >> 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<TAB><TAB>
> > 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
next prev parent reply other threads:[~2021-03-31 22:55 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-28 20:53 Marlon Richert
2021-03-29 7:39 ` Daniel Shahaf
2021-03-29 11:55 ` Marlon Richert
2021-03-29 17:11 ` Daniel Shahaf
2021-03-29 17:20 ` Bart Schaefer
2021-03-29 18:14 ` Daniel Shahaf
2021-03-29 20:00 ` Marlon Richert
2021-03-29 20:05 ` Daniel Shahaf
2021-03-29 20:35 ` Marlon Richert
2021-04-01 4:28 ` Marlon Richert
2021-04-01 18:40 ` Daniel Shahaf
2021-04-02 0:50 ` Oliver Kiddle
2021-04-10 20:20 ` Lawrence Velázquez
2021-04-11 20:06 ` Marlon Richert
2021-04-11 21:24 ` Patch bumping (was Re: Feature Patch: Use completion to view parameter values) Bart Schaefer
2021-04-12 8:18 ` Marlon
2021-04-13 12:32 ` Daniel Shahaf
2021-04-13 18:08 ` Lawrence Velázquez
2021-04-15 9:39 ` [META] Tone of voice / Writing style in patch reviews (was Re: Patch bumping) Marlon
2021-04-15 10:33 ` zeurkous
2021-04-13 13:35 ` Patch bumping (was Re: Feature Patch: Use completion to view parameter values) Daniel Shahaf
2021-04-13 21:31 ` Lawrence Velázquez
2021-04-13 21:50 ` Bart Schaefer
2021-04-14 12:52 ` Daniel Shahaf
2021-04-13 2:47 ` Lawrence Velázquez
2021-04-12 20:22 ` Feature Patch: Use completion to view parameter values Marlon
2021-04-12 21:49 ` Bart Schaefer
2021-04-13 4:50 ` Marlon Richert
2021-03-30 5:41 ` Mikael Magnusson
2021-03-31 22:55 ` Daniel Shahaf [this message]
2021-03-31 23:03 ` Daniel Shahaf
2021-03-29 20:10 ` Peter Stephenson
2021-03-29 11:48 ` Mikael Magnusson
2021-03-29 12:06 ` Marlon Richert
2021-03-29 12:07 ` Marlon Richert
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=20210331225514.GA16838@tarpaulin.shahaf.local2 \
--to=d.s@daniel.shahaf.name \
--cc=marlon.richert@gmail.com \
--cc=mikachu@gmail.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).