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

Rob Landley rob at landley.net
Mon Jun 10 15:34:22 PDT 2019


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



More information about the Toybox mailing list