From aab9d46c83c2ad03abb0a2dc000167e552de2c29 Mon Sep 17 00:00:00 2001 From: Stefan Israelsson Tampe Date: Wed, 12 Dec 2012 17:37:44 +0100 Subject: [PATCH] add GUILE_STACK_SIZE environment variable * libguile/vm.c (initialize_default_stack_size): New helper. (scm_bootstrap_vm): Call initialize_default_stack_size. * doc/ref/guile-invoke.texi (Environment Variables): Add docs. Based on a patch by Stefan Israelsson Tampe. --- doc/ref/guile-invoke.texi | 12 ++++++++++++ libguile/vm.c | 18 ++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/doc/ref/guile-invoke.texi b/doc/ref/guile-invoke.texi index 7cf4c9f88..397bc47e4 100644 --- a/doc/ref/guile-invoke.texi +++ b/doc/ref/guile-invoke.texi @@ -307,6 +307,18 @@ characters. However, for compatibility with previous Guile 2.0 releases, this option is off by default. The next stable release series of Guile (the 2.2 series) will install locales by default. +@item GUILE_STACK_SIZE +@vindex GUILE_STACK_SIZE +Guile currently has a limited stack size for Scheme computations. +Attempting to call too many nested functions will signal an error. This +is good to detect infinite recursion, but sometimes the limit is reached +for normal computations. This environment variable, if set to a +positive integer, specifies the number of Scheme value slots to allocate +for the stack. + +In the future we will implement stacks that can grow and shrink, but for +now this hack will have to do. + @item GUILE_LOAD_COMPILED_PATH @vindex GUILE_LOAD_COMPILED_PATH This variable may be used to augment the path that is searched for diff --git a/libguile/vm.c b/libguile/vm.c index 5dec106a5..6a4ecd8e4 100644 --- a/libguile/vm.c +++ b/libguile/vm.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. +/* Copyright (C) 2001, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -37,6 +37,8 @@ #include "programs.h" #include "vm.h" +#include "private-gc.h" /* scm_getenv_int */ + static int vm_default_engine = SCM_VM_REGULAR_ENGINE; /* Unfortunately we can't snarf these: snarfed things are only loaded up from @@ -633,7 +635,17 @@ resolve_variable (SCM what, SCM program_module) } } +#define VM_MIN_STACK_SIZE (1024) #define VM_DEFAULT_STACK_SIZE (64 * 1024) +static size_t vm_stack_size = VM_DEFAULT_STACK_SIZE; + +static void +initialize_default_stack_size (void) +{ + int size = scm_getenv_int ("GUILE_STACK_SIZE", vm_stack_size); + if (size >= VM_MIN_STACK_SIZE) + vm_stack_size = size; +} #define VM_NAME vm_regular_engine #define FUNC_NAME "vm-regular-engine" @@ -670,7 +682,7 @@ make_vm (void) vp = scm_gc_malloc (sizeof (struct scm_vm), "vm"); - vp->stack_size = VM_DEFAULT_STACK_SIZE; + vp->stack_size= vm_stack_size; #ifdef VM_ENABLE_PRECISE_STACK_GC_SCAN vp->stack_base = (SCM *) @@ -1086,6 +1098,8 @@ scm_bootstrap_vm (void) "scm_init_vm", (scm_t_extension_init_func)scm_init_vm, NULL); + initialize_default_stack_size (); + sym_vm_run = scm_from_latin1_symbol ("vm-run"); sym_vm_error = scm_from_latin1_symbol ("vm-error"); sym_keyword_argument_error = scm_from_latin1_symbol ("keyword-argument-error");