[Libguestfs] [PATCH nbdkit 1/2] include: Fix NBDKIT_HANDLE_NOT_NEEDED for C90 compilers.

Eric Blake eblake at redhat.com
Fri Jan 18 14:36:07 UTC 2019


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20190118/67ac4295/attachment.sig>


More information about the Libguestfs mailing list