comparison src/emacs.c @ 20412:31468445f518

(main): Fix the stack-limit code to calculate the ratio for re_max_failures accurately and leave some extra slack.
author Karl Heuer <kwzh@gnu.org>
date Thu, 04 Dec 1997 05:53:41 +0000
parents a4042bd1c038
children 35972a1f8f1b
comparison
equal deleted inserted replaced
20411:089ca3e66e6d 20412:31468445f518
593 #endif 593 #endif
594 && !getrlimit (RLIMIT_STACK, &rlim)) 594 && !getrlimit (RLIMIT_STACK, &rlim))
595 { 595 {
596 long newlim; 596 long newlim;
597 extern int re_max_failures; 597 extern int re_max_failures;
598 /* Approximate the amount regex.c needs, plus some more. */ 598 /* Approximate the amount regex.c needs per unit of re_max_failures. */
599 newlim = re_max_failures * 2 * 20 * sizeof (char *); 599 int ratio = 20 * sizeof (char *);
600 /* Then add 33% to cover the size of the smaller stacks that regex.c
601 successively allocates and discards, on its way to the maximum. */
602 ratio += ratio / 3;
603 /* Add in some extra to cover
604 what we're likely to use for other reasons. */
605 newlim = re_max_failures * ratio + 200000;
600 #ifdef __NetBSD__ 606 #ifdef __NetBSD__
601 /* NetBSD (at least NetBSD 1.2G and former) has a bug in its 607 /* NetBSD (at least NetBSD 1.2G and former) has a bug in its
602 stack allocation routine for new process that the allocation 608 stack allocation routine for new process that the allocation
603 fails if stack limit is not on page boundary. So, round up the 609 fails if stack limit is not on page boundary. So, round up the
604 new limit to page boundary. */ 610 new limit to page boundary. */
605 newlim = (newlim + getpagesize () - 1) / getpagesize () * getpagesize(); 611 newlim = (newlim + getpagesize () - 1) / getpagesize () * getpagesize();
606 #endif 612 #endif
607 if (newlim > rlim.rlim_max) 613 if (newlim > rlim.rlim_max)
608 { 614 {
609 newlim = rlim.rlim_max; 615 newlim = rlim.rlim_max;
610 /* Don't let regex.c overflow the stack. */ 616 /* Don't let regex.c overflow the stack we have. */
611 re_max_failures = newlim / (2 * 20 * sizeof (char *)); 617 re_max_failures = (newlim - 200000) / ratio;
612 } 618 }
613 if (rlim.rlim_cur < newlim) 619 if (rlim.rlim_cur < newlim)
614 rlim.rlim_cur = newlim; 620 rlim.rlim_cur = newlim;
615 621
616 setrlimit (RLIMIT_STACK, &rlim); 622 setrlimit (RLIMIT_STACK, &rlim);