On Fri, Jan 18, 2019 at 08:36:07AM -0600, Eric Blake wrote:
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).
Yeah, I was aware of this and looking for some other global variable
but couldn't think of one at the time.
Hmm, how about optind?
Rich.
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
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v