qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] build: Work around SIZE_MAX bug in OSX headers
@ 2016-07-12 15:21 Eric Blake
  2016-07-12 18:23 ` Eric Blake
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Blake @ 2016-07-12 15:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, kwolf, qemu-block

C99 requires SIZE_MAX to be declared with the same type as the
integral promotion of size_t, but OSX mistakenly defines it as
an unsigned long long expression even though size_t is only
unsigned long.  Rather than futzing around with whether size_t
is 32- or 64-bits wide, let the compiler get the right type
for us by virtue of integer promotion.

See also https://patchwork.ozlabs.org/patch/542327/ for an
instance where the wrong type trips us up if we don't fix it
for good in osdep.h.

Signed-off-by: Eric Blake <eblake@redhat.com>
---

I can't test this on OSX, but I _did_ test that if I remove the
'#ifdef __APPLE__' conditional (and just blindly do the redefine),
things still compile on Linux (which means I got the type
computation correct).

This is my response to
https://lists.gnu.org/archive/html/qemu-devel/2016-07/msg02276.html

 include/qemu/osdep.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 7361006..9b4b2d3 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -141,6 +141,13 @@ extern int daemon(int, int);
 # error Unknown pointer size
 #endif

+/* Mac OSX has a <stdint.h> bug that incorrectly defines SIZE_MAX with
+ * the wrong type */
+#ifdef __APPLE__
+#undef SIZE_MAX
+#define SIZE_MAX ((sizeof(char)) * -1)
+#endif
+
 #ifndef MIN
 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
 #endif
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-07-13  7:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-12 15:21 [Qemu-devel] [PATCH] build: Work around SIZE_MAX bug in OSX headers Eric Blake
2016-07-12 18:23 ` Eric Blake
2016-07-12 19:35   ` Peter Maydell
2016-07-12 20:22     ` Eric Blake
2016-07-13  7:50     ` Markus Armbruster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).