On 1/14/19 6:15 AM, Richard W.M. Jones wrote:
When an ANSI/C90 plugin compiled with ‘-pedantic’ uses
NBDKIT_HANDLE_NOT_NEEDED it gets the error:
ISO C forbids conversion of function pointer to object pointer type
While POSIX requires it to work. But such is life.
This is because the existing macro worked by returning a function
pointer but in C90 function pointers cannot be cast to data pointers
since on some ancient architectures code and data pointers were
incompatible.
We only need a convenient global data pointer here, and the address of
‘errno’ should be fine.
errno is often implemented as a dereference of a function call in order
to get thread-safe semantics; for example, your patch produces
'&(*__errno_location())' on glibc. That should be okay (especially
since it silenced the warning).
Another option, instead of referencing an actual variable, could be
writing ((void*)(intptr_t)1).
Either way, this patch makes sense.
@@ -78,7 +79,7 @@ extern char *nbdkit_realpath (const char *path);
/* A static non-NULL pointer which can be used when you don't need a
* per-connection handle.
*/
-#define NBDKIT_HANDLE_NOT_NEEDED ((void *) &nbdkit_error)
+#define NBDKIT_HANDLE_NOT_NEEDED (&errno)
#ifdef __cplusplus
}
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization:
qemu.org |
libvirt.org