[Toybox] [PATCH] Improve signal name<->number conversions.

enh enh at google.com
Tue Jun 11 15:04:36 PDT 2019


okay, i've attached take two, which moves the signal stuff into
portability instead...

works for me on macOS and Linux.

On Mon, Jun 10, 2019 at 3:33 PM Rob Landley <rob at landley.net> wrote:
>
> On 6/10/19 3:56 PM, enh wrote:
> > thanks.
> >
> > much lower priority for me (and i'm volunteering to fix it), but...
> > what should i do about the mac here?
>
> Sigh, sounds like signames[] needs to move to portability.c.
>
> > #if around the
> > linux-only/mac-only signals (SIGPOLL is linux-only, SIGEMT is
> > mac-only, for example).
>
> Remember that horrible trick the kernel guys used to turn an #ifdef into a macro
> returning 0 or 1? Maybe that can be used to provide a default value of 0 (in
> which case it wouldn't need to be moved to portability.c).
>
> Dig dig... it's include/linux/kconfig.h:
>
> #define __ARG_PLACEHOLDER_1 0,
> #define __take_second_arg(__ignored, val, ...) val
> /*
>  * Getting something that works in C and CPP for an arg that may or may
>  * not be defined is tricky.  Here, if we have "#define CONFIG_BOOGER 1"
>  * we match on the placeholder define, insert the "0," for arg1 and generate
>  * the triplet (0, 1, 0).  Then the last step cherry picks the 2nd arg (a one).
>  * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when
>  * the last step cherry picks the 2nd arg, we get a zero.
>  */
> #define __is_defined(x)                 ___is_defined(x)
> #define ___is_defined(val)              ____is_defined(__ARG_PLACEHOLDER_##val)
> #define ____is_defined(arg1_or_junk)    __take_second_arg(arg1_or_junk 1, 0)
>
> #define IS_BUILTIN(option) __is_defined(option)
>
> That's ugly, #if __APPLE__ sections in portability.c may be less ugly...
>
> > also -- something i didn't know until just now -- it turns out that
> > the mac doesn't have real-time signals.
>
> Well of course.
>
> > i've attached a patch, but it
> > adds #ifs to lib.c which doesn't currently have them, so i don't know
> > if you'd prefer me to move those bits to portability.c?
>
> If we can do it without #ifs it can stay where it is. If we need #ifs, they
> should go in portability.c.
>
> > (i also didn't
> > know whether you'd prefer big "linux" vs "macOS" #ifs or per-constant
> > #ifs, but assumed the former given the complaints i've heard about GNU
> > code...)
>
> You assumed correctly, fewer #ifs is better.
>
> Rob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Move-sig_to_num-and-num_to_sig-into-portability.c.patch
Type: application/octet-stream
Size: 8109 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20190611/4a917fcf/attachment-0003.obj>


More information about the Toybox mailing list