--- libgnumeric.c.~1.209.~	Mon Jun 30 12:25:34 2003
+++ libgnumeric.c	Sat Jul 12 22:00:34 2003
@@ -45,6 +45,7 @@
 #include "hlink.h"
 #include "gnumeric-paths.h"
 #include <goffice/graph/lib.h>
+#include <sys/resource.h>
 
 #include <locale.h>
 #ifdef WITH_BONOBO
@@ -103,6 +104,31 @@
 }
 #endif
 
+static void
+gnm_expand_stack (void)
+{
+	struct rlimit limit;
+	/* We want 16MB on 32-bit machines, 32MB on 64-bit machines.  */
+	const rlim_t stacklim = (4 << 20) * sizeof (int);
+
+	if (getrlimit (RLIMIT_STACK, &limit) != 0) {
+		g_warning ("getrlimit failed: %s", g_strerror (errno));
+		return;
+	}
+
+	if (limit.rlim_cur == RLIM_INFINITY ||
+	    limit.rlim_cur >= stacklim ||
+	    limit.rlim_cur == limit.rlim_max)
+		return;
+
+	limit.rlim_cur = (limit.rlim_max == RLIM_INFINITY)
+		? stacklim
+		: MIN (stacklim, limit.rlim_max);
+	if (setrlimit (RLIMIT_STACK, &limit) != 0) {
+		g_warning ("setrlimit failed: %s", g_strerror (errno));
+	}	
+}
+
 extern void libgoffice_init (void);
 extern char *gnumeric_data_dir;
 /*
@@ -112,6 +138,7 @@
 void
 gnm_common_init (void)
 {
+	gnm_expand_stack ();
 	mathfunc_init ();
 	g_object_new (GNUMERIC_APPLICATION_TYPE, NULL);
 	plugin_services_init ();
