From: "Daniel Shahaf" <d.s@daniel.shahaf.name>
To: zsh-workers <zsh-workers@zsh.org>
Cc: "Carl Agrell" <caagr98@gmail.com>
Subject: Re: [Bug] $jobstates does not work in $()
Date: Wed, 02 Mar 2022 09:44:02 +0000 [thread overview]
Message-ID: <18fc86e5-467d-4753-9f82-6a3073874334@www.fastmail.com> (raw)
In-Reply-To: <1912988517.1110378.1646131250968@mail2.virginmedia.com>
Peter Stephenson wrote on Tue, 01 Mar 2022 10:40 +00:00:
>> On 01 March 2022 at 00:46 Carl Agrell <caagr98@gmail.com> wrote:
>>
>>
>> It appears that zsh/parameter's $jobstates is always empty inside $(),
>> probably because it's a subshell of some sort. `jobs` still works
>> however, making it rather incongruous. Having access to $jobstates
>> would be useful for prompts for example, rather than having to parse
>> the output of `jobs`.
>>
>> To reproduce:
>> ❯ sleep 1000 &
>> [1] 210460
>> ❯ jobs
>> [1] + running sleep 1000
>> ❯ echo $jobstates
>> running:+:210460=running
>> ❯ echo $(jobs)
>> [1] + running sleep 1000
>> ❯ echo $(echo $jobstates)
>> (empty)
>
> Yes, we store the old job table for use with the builtin, but not with
> parameters, which is inconsistent.
>
> What is probably worse is that some parameters (not, as it happens,
> jobstates) call getjob(), which does have the logic to switch to the old
> table, but then make no attempt to switch to the right table for the
> remainder of the processing, which could result in undefined behaviour.
>
> This fixes it up with a function selectjobtab() used to query job states
> in the parameter functions as well as getjob().
>
Is this testable? Sorry, haven't got time to write a test myself right now.
Cheers,
Daniel
> --- a/Src/Modules/parameter.c
> +++ b/Src/Modules/parameter.c
> @@ -1244,19 +1244,19 @@ histwgetfn(UNUSED(Param pm))
> @@ -1269,22 +1269,25 @@ static HashNode
> @@ -1297,22 +1300,25 @@ static void
> @@ -1323,7 +1329,7 @@ scanpmjobtexts(UNUSED(HashTable ht), ScanFunc
> @@ -1335,14 +1341,14 @@ pmjobstate(int job)
> @@ -1371,21 +1377,24 @@ static HashNode
> @@ -1398,22 +1407,25 @@ static void
> @@ -1424,11 +1436,11 @@ scanpmjobstates(UNUSED(HashTable ht), ScanFunc
> @@ -1437,21 +1449,24 @@ static HashNode
> @@ -1464,22 +1479,25 @@ static void
> --- a/Src/jobs.c
> +++ b/Src/jobs.c
> @@ -98,10 +98,12 @@ mod_export int jobtabsize;
> @@ -1894,6 +1896,26 @@ setcurjob(void)
> @@ -1904,13 +1926,7 @@ getjob(const char *s, const char *prog)
next prev parent reply other threads:[~2022-03-02 9:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-01 0:46 Carl Agrell
2022-03-01 10:40 ` Peter Stephenson
2022-03-02 9:44 ` Daniel Shahaf [this message]
2022-03-02 20:18 ` Peter Stephenson
2022-03-03 22:04 ` Vin Shelton
2022-03-03 23:07 ` Bart Schaefer
2022-03-04 2:14 ` Jun T
2022-03-04 13:04 ` Daniel Shahaf
2022-03-04 13:13 ` Vin Shelton
2022-03-06 4:18 ` Jun T
2022-03-07 14:22 ` Daniel Shahaf
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=18fc86e5-467d-4753-9f82-6a3073874334@www.fastmail.com \
--to=d.s@daniel.shahaf.name \
--cc=caagr98@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).