diff --git a/src/emacs.c b/src/emacs.c
index 017c623..89380f5 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -826,68 +826,57 @@ main (int argc, char **argv)
         }
     }
 
+/* *************************************************************************** */
+/* BEGIN FIXME: #27571; 11/19/2016; c61ee94959ba96b2a327df0684593f7e569e30be */
+
 #if defined (HAVE_SETRLIMIT) && defined (RLIMIT_STACK) && !defined (CYGWIN)
+  struct rlimit rlim;
+  size_t re_max_failures = 40000;
   /* Extend the stack space available.  Don't do that if dumping,
      since some systems (e.g. DJGPP) might define a smaller stack
      limit at that time.  And it's not needed on Cygwin, since emacs
      is built with an 8MB stack.  Moreover, the setrlimit call can
      cause problems on Cygwin
      (https://www.cygwin.com/ml/cygwin/2015-07/msg00096.html).  */
-  struct rlimit rlim;
-  if (getrlimit (RLIMIT_STACK, &rlim) == 0
-      && 0 <= rlim.rlim_cur && rlim.rlim_cur <= LONG_MAX)
-    {
-      rlim_t lim = rlim.rlim_cur;
-
-      /* Approximate the amount regex.c needs per unit of
-	 emacs_re_max_failures, then add 33% to cover the size of the
-	 smaller stacks that regex.c successively allocates and
-	 discards on its way to the maximum.  */
-      int min_ratio = 20 * sizeof (char *);
-      int ratio = min_ratio + min_ratio / 3;
-
-      /* Extra space to cover what we're likely to use for other
-         reasons.  For example, a typical GC might take 30K stack
-         frames.  */
-      int extra = (30 * 1000) * 50;
-
-      bool try_to_grow_stack = true;
+  if (1
 #ifndef CANNOT_DUMP
-      try_to_grow_stack = !noninteractive || initialized;
+      && (!noninteractive || initialized)
 #endif
-
-      if (try_to_grow_stack)
+      && !getrlimit (RLIMIT_STACK, &rlim))
+    {
+      long newlim;
+      /* Approximate the amount regex.c needs per unit of re_max_failures.  */
+      int ratio = 20 * sizeof (char *);
+      /* Then add 33% to cover the size of the smaller stacks that regex.c
+	 successively allocates and discards, on its way to the maximum.  */
+      ratio += ratio / 3;
+      /* Add in some extra to cover
+	 what we're likely to use for other reasons.  */
+      newlim = re_max_failures * ratio + 200000;
+#ifdef __NetBSD__
+      /* NetBSD (at least NetBSD 1.2G and former) has a bug in its
+       stack allocation routine for new process that the allocation
+       fails if stack limit is not on page boundary.  So, round up the
+       new limit to page boundary.  */
+      newlim = (newlim + getpagesize () - 1) / getpagesize () * getpagesize ();
+#endif
+      if (newlim > rlim.rlim_max)
 	{
-	  rlim_t newlim = emacs_re_max_failures * ratio + extra;
-
-	  /* Round the new limit to a page boundary; this is needed
-	     for Darwin kernel 15.4.0 (see Bug#23622) and perhaps
-	     other systems.  Do not shrink the stack and do not exceed
-	     rlim_max.  Don't worry about exact values of
-	     RLIM_INFINITY etc. since in practice when they are
-	     nonnegative they are so large that the code does the
-	     right thing anyway.  */
-	  long pagesize = getpagesize ();
-	  newlim += pagesize - 1;
-	  if (0 <= rlim.rlim_max && rlim.rlim_max < newlim)
-	    newlim = rlim.rlim_max;
-	  newlim -= newlim % pagesize;
-
-	  if (pagesize <= newlim - lim)
-	    {
-	      rlim.rlim_cur = newlim;
-	      if (setrlimit (RLIMIT_STACK, &rlim) == 0)
-		lim = newlim;
-	    }
+	  newlim = rlim.rlim_max;
+	  /* Don't let regex.c overflow the stack we have.  */
+	  re_max_failures = (newlim - 200000) / ratio;
 	}
-      /* If the stack is big enough, let regex.c more of it before
-         falling back to heap allocation.  */
-      emacs_re_safe_alloca = max
-        (min (lim - extra, SIZE_MAX) * (min_ratio / ratio),
-         MAX_ALLOCA);
+      if (rlim.rlim_cur < newlim)
+	rlim.rlim_cur = newlim;
+
+      setrlimit (RLIMIT_STACK, &rlim);
     }
 #endif /* HAVE_SETRLIMIT and RLIMIT_STACK and not CYGWIN */
 
+/* END FIXME: #27571; 11/19/2016; c61ee94959ba96b2a327df0684593f7e569e30be */
+/* *************************************************************************** */
+
+
   clearerr_unlocked (stdin);
 
   emacs_backtrace (-1);
