[Toybox] [PATCH] id: various fixes.
enh
enh at google.com
Tue Nov 5 17:25:01 PST 2019
On Tue, Nov 5, 2019 at 5:15 PM Rob Landley <rob at landley.net> wrote:
>
>
>
> On 11/4/19 10:56 PM, enh wrote:
> > On Mon, Nov 4, 2019 at 8:12 PM Rob Landley <rob at landley.net> wrote:
> >>
> >>
> >>
> >> On 11/4/19 12:43 PM, enh via Toybox wrote:
> >>> Handle unknown groups (fixes #117).
> >>>
> >>> Fix -G to show *all* groups, not just all supplementary groups.
> >>>
> >>> Fix -Z output to not include "context=".
> >>
> >> Sigh:
> >>
> >> - if (!FLAG(Z)) {
> >> + if (!(toys.optflags&(FLAG_g|FLAG_Z))) {
> >>
> >> I need some kind of FLAGS(Z,g) syntax, but have no idea how to get the
> >> preprocessor to do that. Hmmm...
> >
> > funnily enough, in this specific case we can rearrange the code a bit
> > and remove these completely. i'll send you a patch.
>
> Ok, I _do_ know how to do FLAG2(a,b) FLAG3(a,b,c) FLAG4(a,b,c,d) if it's worth
> going there... (I keep thinking there should be something clever I can do with
> varargs and recursive evaluation but it doesn't evaluate recursively.)
>
> Sigh, FLAG() macro is kinda borderline at the best of times, it adds a _little_
> convenience and readability, but the recent "FLAG(o) isn't using the local
> variable o" confusion points out a downside, and FLAG(a) expanding to
> (toys.optflags&FLAG_a) isn't a huge lift...
>
> I've been doing FLAG(a)|FLAG(b)|FLAG(c) but that's long and awkward, and might
> produce worse code depending on what the optimizer does (haven't checked, afraid
> of what I'd find).
i actually rewrote all of bionic's <ctype.h> the other week because
the optimizer now does a _better_ job with the obvious readable code
`(c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')` than with any of
the tricky stuff or a table lookup. but strictly that was for
arm/arm64, so...
...yeah, x86-64 is turning `FLAG(a) || FLAG(b) || FLAG(c) || FLAG(d)`
into just a single test and a conditional jump, as you'd expect.
(x86/x86-64 have the advantage that they can represent any constant,
so you don't even need the compiler to do anything clever like with
arm/arm64.)
> The hard calls are always the small/close ones, never the big ones.
>
> >> + if (groups[i] != egid) {
> >> + if ((grp=getgrgid(groups[i]))) showid(",", grp->gr_gid, grp->gr_name);
> >> + else printf(",%u", groups[i]);
> >>
> >> Does this mean if the first group you show is unknown, it'll have a comma before it?
> >
> > no. there's an unconditional call to showid for the primary group
> > above the loop, so there's alway been something printed.
>
> Oh right, groups stored in 2 batches.
>
> Rob
More information about the Toybox
mailing list