Index: m4/tls.m4
===================================================================
--- m4/tls.m4	(revision 0)
+++ m4/tls.m4	(revision 0)
@@ -0,0 +1,18 @@
+AC_DEFUN([CHECK_TLS], [
+  AC_CACHE_CHECK([whether the target supports thread-local storage],
+		 have_tls, [
+    AC_RUN_IFELSE([__thread int a; int b; int main() { return a = b; }],
+      [dnl If the test case passed with dynamic linking, try again with
+      dnl static linking.  This fails at least with some older Red Hat
+      dnl releases.
+      AC_RUN_IFELSE([__thread int a; int b; int main() { return a = b; }],
+		    [have_tls=yes], [have_tls=no], [])
+      ],
+      [have_tls=no],
+      [AC_COMPILE_IFELSE([__thread int foo;], [have_tls=yes], [have_tls=no])]
+    )])
+  if test "$have_tls" = "yes"; then
+    AC_DEFINE(HAVE_TLS, 1,
+	      [Define to 1 if the target supports thread-local storage.])
+  fi])
+
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 861)
+++ ChangeLog	(working copy)
@@ -1,3 +1,11 @@
+2008-11-02  Philip Van Hoof  <philip@codeminded.be>
+
+	* configure.ac: 
+	* m4/tls.m4: Check for TLS support
+
+	* girepository/ginvoke.c: Store arguments and values in a TLS to avoid
+	a alloca per function call
+
 2008-11-01  Owen Taylor  <otaylor@redhat.com>
 
 	Bug 558848 giparser.py: shared library should be optional
Index: girepository/ginvoke.c
===================================================================
--- girepository/ginvoke.c	(revision 861)
+++ girepository/ginvoke.c	(working copy)
@@ -27,6 +27,7 @@
 #include "gtypelib.h"
 #include "config.h"
 
+
 GQuark
 g_invoke_error_quark (void)
 {
@@ -116,6 +117,11 @@
   return rettype;
 }
 
+#ifdef HAVE_TLS
+static __thread  ffi_type *arg_types[200];
+static __thread  gpointer  arg_values[200];
+#endif
+
 /**
  * g_function_info_invoke:
  * @info: a #GIFunctionInfo describing the function to invoke
@@ -210,9 +216,18 @@
     /* Add an argument for the GError */
     n_invoke_args ++;
 
-  atypes = g_alloca (sizeof (ffi_type*) * n_invoke_args);
-  args = g_alloca (sizeof (gpointer) * n_invoke_args);
-  
+#ifdef HAVE_TLS
+  if (G_LIKELY (n_invoke_args < 200)) {
+     atypes = arg_types;
+     args = arg_values;
+  } else {
+#endif
+     atypes = g_alloca (sizeof (ffi_type*) * n_invoke_args);
+     args = g_alloca (sizeof (gpointer) * n_invoke_args);
+#ifdef HAVE_TLS
+  }
+#endif
+
   if (is_method)
     {
       atypes[0] = &ffi_type_pointer;
Index: configure.ac
===================================================================
--- configure.ac	(revision 861)
+++ configure.ac	(working copy)
@@ -168,6 +168,8 @@
 AC_CHECK_FUNCS([memchr strchr strspn strstr strtol strtoull])
 AC_CHECK_FUNCS([backtrace backtrace_symbols])
 
+CHECK_TLS
+
 # Python
 
 AC_MSG_CHECKING([whether Python support is requested])
