[libvirt] mingw64 + gnulib time.h / pthread.h / gmtime_r incompatibility

Eric Blake eblake at redhat.com
Thu Jan 23 03:14:46 UTC 2014


On 01/22/2014 09:27 AM, Daniel P. Berrange wrote:
> I'm attempting to make libvirt capable of building with mingw64 toolchain's
> pthread.h, instead of directly using Windows thread primitives.
> 

> When attempting to build though I see failures
> 
>   CC       util/libvirt_util_la-virerror.lo
> In file included from /usr/i686-w64-mingw32/sys-root/mingw/include/sys/time.h:10:0,
>                  from ../gnulib/lib/sys/time.h:39,
>                  from ../gnulib/lib/sys/select.h:117,
>                  from util/virutil.h:31,
>                  from util/virerror.c:35:
> ../gnulib/lib/time.h:468:21: error: expected identifier or '(' before '{' token
>  _GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
>                      ^

> 
> The problem appears to be that mingw64's pthread.h has the following
> craziness:
> 
> 
> /* Recursive API emulation.  */
> #undef localtime_r
> #define localtime_r(_Time, _Tm) ({ struct tm *___tmp_tm;                \

Yep, that's broken.  But new enough mingw now provides 'struct timespec'
via <time.h> (or rather, mingw + winpthreads provides pthread_time.h
which gets included by both <time.h> and <pthread.h>), whereas the
broken localtime_r is only provided by <pthread.h>.

I think the time.h checks are just fine, and what we really need to do
is to provide a wrapper <pthread.h> header that undoes the damage
directly when pthread.h is included, rather than indirectly via time.h.
 Now that I've reproduced the problem myself, I hope to come up with a
solution soon.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140122/82f4b4f0/attachment-0001.sig>


More information about the libvir-list mailing list