Skip to contentSkip to conversation

w32: Add new directory hierarchy for MinGW extensions

PATCH In review Stefan Weil 3 participants 9 messages Feb 27, 2011 – Mar 6, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 w32: Add new directory hierarchy for MinGW extensions

This is a first step which will reduce the number
of conditional compilations caused by MinGW.

Include files will be added to hosts/w32/include.

---
 configure        |    1 +
 hosts/w32/README |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 hosts/w32/README
configure +1 -0
index 3036faf..47779b6 100755
@@ -474,6 +474,7 @@ if test "$mingw32" = "yes" ; then
   QEMU_CFLAGS="-DWIN32_LEAN_AND_MEAN -DWINVER=0x501 $QEMU_CFLAGS"
   # enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later)
   QEMU_CFLAGS="-D__USE_MINGW_ANSI_STDIO=1 $QEMU_CFLAGS"
+  QEMU_CFLAGS="-I\$(SRC_PATH)/hosts/w32/include $QEMU_CFLAGS"
   LIBS="-lwinmm -lws2_32 -liberty -liphlpapi $LIBS"
   prefix="c:/Program Files/Qemu"
   mandir="\${prefix}"
hosts/w32/README new file +1 -0
new file mode 100644
index 0000000..d5aafe9
@@ -0,0 +1 @@
+This directory contains extensions of MinGW which are needed by QEMU.
Signature · 1 line
1.7.2.3
#1 lore raw

PATCH 2/3 w32: Add macro timersub to sys/time.h

timersub is needed by the latest vnc code.

---
 hosts/w32/include/sys/time.h |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)
 create mode 100644 hosts/w32/include/sys/time.h
hosts/w32/include/sys/time.h new file +24 -0
new file mode 100644
index 0000000..94056ff
@@ -0,0 +1,24 @@
+/*
+ * Extensions of MinGW sys/time.h
+ *
+ * Copyright (C) 2011 Stefan Weil
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include_next <sys/time.h>
+
+#ifndef timersub
+/* This is a copy from GNU C Library (GNU LGPL 2.1), sys/time.h. */
+# define timersub(a, b, result)                                               \
+  do {                                                                        \
+    (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;                             \
+    (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;                          \
+    if ((result)->tv_usec < 0) {                                              \
+      --(result)->tv_sec;                                                     \
+      (result)->tv_usec += 1000000;                                           \
+    }                                                                         \
+  } while (0)
+#endif
Signature · 1 line
1.7.2.3
#2 lore raw

Re: [Qemu-devel] [PATCH 2/3] w32: Add macro timersub to sys/time.h

hosts/w32/include/sys/time.h

Quoted 13 lines · Stefan Weil

timersub is needed by the latest vnc code.

---
 hosts/w32/include/sys/time.h |   24 ++++++++++++++++++++++++

 1 files changed, 24 insertions(+), 0 deletions(-)

 create mode 100644 hosts/w32/include/sys/time.h

hosts/w32/include/sys/time.h new file +0 -0
new file mode 100644
index 0000000..94056ff

Nack. The QEMU way of handling host peculiarities is to add wrappers, for example qemu_timersub in this case, and converting all callers.

hosts/w32/include/sys/time.h line 11

Quoted 12 lines
hosts/w32/include/sys/time.h new file +11 -0
@@ -0,0 +1,24 @@
+/*
+ * Extensions of MinGW sys/time.h
+ *
+ * Copyright (C) 2011 Stefan Weil
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include_next <sys/time.h>

Isn't include_next an extension by GCC?

Quoted 18 lines
hosts/w32/include/sys/time.h new file +13 -1
+
+#ifndef timersub
+/* This is a copy from GNU C Library (GNU LGPL 2.1), sys/time.h. */
+# define timersub(a, b, result)                                               \
+  do {                                                                        \
+    (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;                             \
+    (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;                          \
+    if ((result)->tv_usec < 0) {                                              \
+      --(result)->tv_sec;                                                     \
+      (result)->tv_usec += 1000000;                                           \
+    }                                                                         \
+  } while (0)
+#endif
--

1.7.2.3

#3 lore raw

Re: [Qemu-devel] [PATCH 2/3] w32: Add macro timersub to sys/time.h

Quoted 4 lines · Blue Swirl
Quoted 1 line · Stefan Weil

+#include_next <sys/time.h>

Isn't include_next an extension by GCC?

Are gcc extensions forbidden? We already have plenty of code that uses gcc-specific syntax or gcc extensions...

-- PMM

#4 lore raw

Re: [Qemu-devel] [PATCH 2/3] w32: Add macro timersub to sys/time.h

Quoted 8 lines · Peter Maydell
Quoted 4 lines · Blue Swirl
Quoted 1 line · Stefan Weil

+#include_next <sys/time.h>

Isn't include_next an extension by GCC?

Are gcc extensions forbidden? We already have plenty of code that uses gcc-specific syntax or gcc extensions...

No, but relying on them is not OK. For example gcc attributes are wrapped in macros to allow other implementations.

#5 lore raw

Re: [Qemu-devel] [PATCH 2/3] w32: Add macro timersub to sys/time.h

Quoted 5 lines · Blue Swirl
Quoted 4 lines · Peter Maydell
Quoted 3 lines · Blue Swirl
Quoted 1 line · Stefan Weil

+#include_next <sys/time.h>

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Isn't include_next an extension by GCC?

Are gcc extensions forbidden? We already have plenty of code that uses gcc-specific syntax or gcc extensions...

No, but relying on them is not OK. For example gcc attributes are wrapped in macros to allow other implementations.

Three random counter-examples:

vl.c:

    machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */

That use of ?: is a gcc extension.

target-i386/cpu.h:
register struct CPUX86State *env asm(AREG0);

Explicit register variables are a gcc extension.

qemu-timer-common.c:
static void __attribute__((constructor)) init_get_clock(void)

gcc-specific attribute not hidden by a macro.

-- PMM

#6 lore raw

Re: [Qemu-devel] [PATCH 2/3] w32: Add macro timersub to sys/time.h

Quoted 14 lines · Peter Maydell
Quoted 5 lines · Blue Swirl
Quoted 4 lines · Peter Maydell
Quoted 3 lines · Blue Swirl
Quoted 1 line · Stefan Weil

+#include_next <sys/time.h>

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Isn't include_next an extension by GCC?

Are gcc extensions forbidden? We already have plenty of code that uses gcc-specific syntax or gcc extensions...

No, but relying on them is not OK. For example gcc attributes are wrapped in macros to allow other implementations.

Quoted 6 lines

Three random counter-examples:

vl.c:
   machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */

That use of ?: is a gcc extension.

There's no need to use that, so those should be removed.

Quoted 4 lines

target-i386/cpu.h:
register struct CPUX86State *env asm(AREG0);

Explicit register variables are a gcc extension.

Is there any other way?

Quoted 4 lines

qemu-timer-common.c:
static void __attribute__((constructor)) init_get_clock(void)

gcc-specific attribute not hidden by a macro.

Probably should be wrapped, but I don't think we can avoid constructors.

#7 lore raw

Re: [Qemu-devel] [PATCH 2/3] w32: Add macro timersub to sys/time.h

In reply to Blue Swirl

Am 05.03.2011 10:34, schrieb Blue Swirl:

Quoted 9 lines · Stefan Weil
Quoted 8 lines

timersub is needed by the latest vnc code.

---
 hosts/w32/include/sys/time.h |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)
 create mode 100644 hosts/w32/include/sys/time.h
Quoted 8 lines

hosts/w32/include/sys/time.h

Quoted 5 lines
hosts/w32/include/sys/time.h new file +0 -0
new file mode 100644
index 0000000..94056ff

Nack. The QEMU way of handling host peculiarities is to add wrappers, for example qemu_timersub in this case, and converting all callers.

That's one way how things can be handled.

I know at least one QEMU maintainer who does not like those workarounds, especially if they are needed because of w32/w64 operating systems, so I decided to choose a different approach here. My approach also can be easily removed as soon as MinGW is improved (I'm sure it will be improved).

There is another QEMU way of handling host peculiarities:
conditional compilation. Most of this kind of handling could be eliminated by my approach.

Quoted 16 lines
Quoted 12 lines
hosts/w32/include/sys/time.h new file +6 -0
@@ -0,0 +1,24 @@
+/*
+ * Extensions of MinGW sys/time.h
+ *
+ * Copyright (C) 2011 Stefan Weil
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 

2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */

hosts/w32/include/sys/time.h line 11

Quoted 2 lines
hosts/w32/include/sys/time.h new file +2 -0
+
+#include_next <sys/time.h>

Isn't include_next an extension by GCC?

It is, but that's not critical given the fact that QEMU does not work without gcc.

If needed, this dependency can be fixed easily by renaming the intermediate include files (and including the renamed files).

I don't think that those intermediate files will be needed forever, so a clean and cheap solution like the one which I implemented seems to be more important to me.

Quoted 16 lines
Quoted 16 lines
hosts/w32/include/sys/time.h new file +9 -0
+
+#ifndef timersub
+/* This is a copy from GNU C Library (GNU LGPL 2.1), sys/time.h. */
+# define timersub(a, b, result)                                     
          \
+  do {                                                               
         \
+    (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;                   
          \
+    (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;                 
         \
+    if ((result)->tv_usec < 0) {                                     
         \
+      --(result)->tv_sec;                                           
          \
Quoted 8 lines
Quoted 8 lines
hosts/w32/include/sys/time.h new file +4 -1
+      (result)->tv_usec += 1000000;                                 
          \
+    }                                                               
          \
+  } while (0)
+#endif
--

1.7.2.3

By the way: it's not possible to add timersub to existing files like oslib-win32.c or os-win32.c (another way to handle the problem) because of incompatible licenses.

Regards,
Stefan W.

#8 lore raw

PATCH 3/3 osdep: Remove conditional compilation (fixes w32 compilation)

In reply to Stefan Weil

sys/time.h also exists for MinGW, and it is needed because it declares struct timeval (needed by latest vnc code).

---
 osdep.h |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
osdep.h +0 -2
index 27eedcf..5a667b4 100644
@@ -8,9 +8,7 @@
 #include <sys/signal.h>
 #endif
 
-#ifndef _WIN32
 #include <sys/time.h>
-#endif
 
 #ifndef glue
 #define xglue(x, y) x ## y
Signature · 1 line
1.7.2.3