[Spice-devel] [PATCH 4/8] common: mem.h add alloca definition

Marc-André Lureau marcandre.lureau at redhat.com
Tue May 3 07:37:41 PDT 2011


We don't support the autoconf ALLOCA/C_ALLOC fallback. If one day,
someone cares for a weird platform, he can fix it.
---
 common/mem.h |   30 ++++++++++++++++++++++++++++++
 configure.ac |    1 +
 2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/common/mem.h b/common/mem.h
index 8ba6586..980ea13 100644
--- a/common/mem.h
+++ b/common/mem.h
@@ -22,10 +22,40 @@
 #include <stdlib.h>
 #include <spice/macros.h>
 
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+#  include <stdlib.h>
+# endif
+#endif
+#ifdef HAVE_ALLOCA_H
+# include <alloca.h>
+#elif defined __GNUC__
+# define alloca __builtin_alloca
+#elif defined _AIX
+# define alloca __alloca
+#elif defined _MSC_VER
+# include <malloc.h>
+# define alloca _alloca
+#else
+# ifndef HAVE_ALLOCA
+#  ifdef  __cplusplus
+extern "C"
+#  endif
+void *alloca (size_t);
+# endif
+#endif
+
 typedef struct SpiceChunk {
     uint8_t *data;
     uint32_t len;
diff --git a/configure.ac b/configure.ac
index 9a303c9..bf585f9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,6 +28,7 @@ AC_C_BIGENDIAN
 AC_PATH_PROGS(PYTHON, python2 python)
 
 AC_CHECK_HEADERS([sys/time.h])
+AC_FUNC_ALLOCA
 
 SPICE_LT_VERSION=m4_format("%d:%d:%d", 1, 0, 2)
 AC_SUBST(SPICE_LT_VERSION)
-- 
1.7.4



More information about the Spice-devel mailing list