diff --git a/make/pre-make.r3 b/make/pre-make.r3 index 21a7aff9f0..e3d810ac77 100644 --- a/make/pre-make.r3 +++ b/make/pre-make.r3 @@ -112,6 +112,7 @@ target: any [spec/target spec/os-target spec/configuration] os-base: 'win32 product: any [spec/product 'Core] configs: unique any [spec/config copy []] +stack-size: any [spec/stack-size 1048576] ;default 1MiB unless target [ diff --git a/make/rebol3.nest b/make/rebol3.nest index bd8d918cae..24c5e8a375 100644 --- a/make/rebol3.nest +++ b/make/rebol3.nest @@ -16,7 +16,7 @@ include: %src/include/ temp: %make/tmp/ ;output: %build/ -stack-size: 4194304 +stack-size: 4194304 ;= 4MB (4 * 1024 * 1024) optimize: 2 version: 3.5.5 @@ -296,6 +296,7 @@ config: [ ;- this is list of configuration (optional) defines ;SERIES_LABELS ; used for special debug purposes ;SHOW_SIZEOFS ; for debugging ports to some new systems + ;SHOW_EXPAND_STACK ; will print info when stack expands ;NDEBUG ; removes some asserts ;TEST_SCAN ;_DEBUG diff --git a/make/tools/make-boot.reb b/make/tools/make-boot.reb index 1827400dfc..5cec389c95 100644 --- a/make/tools/make-boot.reb +++ b/make/tools/make-boot.reb @@ -1178,6 +1178,9 @@ emit-head "Build configuration" %config.h emit {^/#ifndef REBOL_OPTIONS_H^/} +if stack-size [ + emit ajoin ["#define STACK_SIZE " stack-size lf lf] +] foreach def configs [ emit ajoin ["#define " def lf] ] diff --git a/src/core/c-do.c b/src/core/c-do.c index ec20b84583..267bc3f2a5 100644 --- a/src/core/c-do.c +++ b/src/core/c-do.c @@ -105,7 +105,9 @@ static REBVAL *Func_Word(REBINT dsf) } Extend_Series(DS_Series, amount); DS_Base = BLK_HEAD(DS_Series); +#ifdef SHOW_EXPAND_STACK Debug_Fmt(BOOT_STR(RS_STACK, 0), DSP, SERIES_REST(DS_Series)); +#endif } @@ -861,7 +863,7 @@ x*/ static REBINT Do_Args_Light(REBVAL *func, REBVAL *path, REBSER *block, REBCN //CHECK_MEMORY(1); CHECK_STACK(&value); - if ((DSP + 20) > (REBINT)SERIES_REST(DS_Series)) Expand_Stack(STACK_MIN); //Trap0(RE_STACK_OVERFLOW); + if ((DSP + 200) > (REBINT)SERIES_REST(DS_Series)) Expand_Stack(STACK_MIN); //Trap0(RE_STACK_OVERFLOW); if (--Eval_Count <= 0 || Eval_Signals) Do_Signals(); value = BLK_SKIP(block, index); diff --git a/src/include/sys-core.h b/src/include/sys-core.h index dc3dfe41d8..cb42ffd5bb 100644 --- a/src/include/sys-core.h +++ b/src/include/sys-core.h @@ -39,6 +39,9 @@ //#define MUNGWALL // memory allocation bounds checking #define STACK_MIN 4000 // data stack increment size #define STACK_LIMIT 400000 // data stack max (6.4MB) +#ifndef STACK_SIZE +#define STACK_SIZE (1 * 1024 * 1024) // Default MSVS stack size is 1MiB +#endif #define MIN_COMMON 10000 // min size of common buffer #define MAX_COMMON 100000 // max size of common buffer (shrink trigger) #define MAX_NUM_LEN 64 // As many numeric digits we will accept on input @@ -354,8 +357,9 @@ enum { #else #define CHECK_STACK(v) if ((REBUPT)(v) <= Stack_Limit) Trap_Stack(); #endif -#define STACK_BOUNDS (4*1024*1000) // note: need a better way to set it !! -// Also: made somewhat smaller than linker setting to allow trapping it +#define STACK_BOUNDS (STACK_SIZE - (24 * 1024)) // made somewhat smaller than linker setting to allow trapping it +//NOTE: in VS Debug build the stack overflow is detected before trying to expand the data stack! +// So use Relase build to test the stack expansion. /***********************************************************************