On 09/28/2018 10:05 PM, enh wrote: > As someone who has a vested interest in having less generated code (because > I'd > like to stop checking in generated files and use toybox in the AOSP > build[1])... > do we even need to do this? How many of these defines are missing on > glibc/musl/bionic? If it's only one or two as I assume, could we just have the > #ifdefs instead? > > Or are there actually a large number of these missing?
Years ago the linux kernel had clever config_enabled(CONFIG_BLAH) macros that did a trick with commas and varargs to turn undefined symbols into a default argument, and I've been meaning to try to extend that into CFG(THINGY) and USE(THINGY, xxx) macros that don't require a preprocessed #include file. Unfortunately they seem to have renamed it (broke my "apply DEVTMPFS_MOUNT to initramfs" patch, that did), lemme see if I can dig that up... it's in include/linux/kconfig.h, and consists of the following 5 macros plus explanation comment: #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) So __is_defined(BLAH) resolves to 0 or 1 depending on whether BLAH is defined to 1 or not, using just macro expansion... (The "need for multiple macros that call each other" is a thing I hit long ago and described at https://landley.net/notes-2007.html#05-12-2007 .) The problem is, we can't guarantee the macro is defined to 1, so I need to invert the logic and have it be "does not resolve exactly to the macro name". And ideally, we want: ISDEFAULT(MACRONAME,default value) Where it resolves to whatever the macro is defined to, else resolves to the second argument... Rob _______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
