[Libguestfs] [nbdkit PATCH 0/2] stdin/out cleanups

Eric Blake eblake at redhat.com
Tue Apr 7 16:21:56 UTC 2020


On 4/7/20 2:55 AM, Richard W.M. Jones wrote:
> On Sat, Apr 04, 2020 at 05:02:37PM -0500, Eric Blake wrote:
>> This is what I've been playing with in response to my earlier question
>> about what to do with 'nbdkit -s sh -'
>> (https://www.redhat.com/archives/libguestfs/2020-April/msg00032.html)
>>
>> I'm still open to ideas on a better name, and/or whether adding
>> <stdbool.h> to our public include files is a good idea (if not,
>> returning int instead of bool is tolerable).
> 
> The answer is: no, we cannot use <stdbool.h>.  This is because we
> advertise that we support using the headers in plugins which are pure
> C90 code.
> 
> We also test this -- see tests/Makefile.am test-ansi-c-plugin.la --
> however it may be that the test doesn't work properly if it didn't
> fail after your change.

Interesting - even with -std=c90 -pedantic, gcc is NOT flagging the use 
of <stdbool.h> as a problem.  Maybe we should open a glibc bug 
requesting that it be taught to make <stdbool.h> error out if compiler 
witness macros indicate it is being sucked in during pedantic c90 
compilation.  But it was easy enough to strengthen the test (now committed):

diff --git c/tests/test-ansi-c-plugin.c w/tests/test-ansi-c-plugin.c
index ff0b34d0..140d29ce 100644
--- c/tests/test-ansi-c-plugin.c
+++ w/tests/test-ansi-c-plugin.c
@@ -36,6 +36,16 @@

  #include <nbdkit-plugin.h>

+/* C90 lacks <stdbool.h>, and even in C99 and later, we are permitted
+ * to use 'bool', 'true', and 'false' however we want if that header
+ * is not included.  Prove that nbdkit did not pollute the namespace.
+ */
+#if __bool_true_false_are_defined
+#error nbdkit polluted namespace with stdbool.h
+#else
+extern int true, false;
+#endif
+
  /* This looks like a 100MB disk with one empty partition. */
  static unsigned char bootsector[512] = {
    0xfa, 0xb8, 0x00, 0x10, 0x8e, 0xd0, 0xbc, 0x00,



Also, the term 'ANSI C' is now ambiguous: newer ANSI has moved to 
include C11 by reference, so you have to be clear when you mean ANSI 
C89/ISO C90. 
https://stackoverflow.com/questions/1608318/is-bool-a-native-c-type


-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




More information about the Libguestfs mailing list