Skip to content

Commit

Permalink
FEAT: better deal with stack size definition while compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Jul 24, 2021
1 parent f1b74c7 commit af77722
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions make/pre-make.r3
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
3 changes: 2 additions & 1 deletion make/rebol3.nest
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions make/tools/make-boot.reb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
]
Expand Down
4 changes: 3 additions & 1 deletion src/core/c-do.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


Expand Down Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions src/include/sys-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.


/***********************************************************************
Expand Down

0 comments on commit af77722

Please # to comment.