Skip to content

Commit af77722

Browse files
committed
FEAT: better deal with stack size definition while compilation
1 parent f1b74c7 commit af77722

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

make/pre-make.r3

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ target: any [spec/target spec/os-target spec/configuration]
112112
os-base: 'win32
113113
product: any [spec/product 'Core]
114114
configs: unique any [spec/config copy []]
115+
stack-size: any [spec/stack-size 1048576] ;default 1MiB
115116

116117

117118
unless target [

make/rebol3.nest

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ include: %src/include/
1616
temp: %make/tmp/
1717
;output: %build/
1818

19-
stack-size: 4194304
19+
stack-size: 4194304 ;= 4MB (4 * 1024 * 1024)
2020
optimize: 2
2121

2222
version: 3.5.5
@@ -296,6 +296,7 @@ config: [ ;- this is list of configuration (optional) defines
296296

297297
;SERIES_LABELS ; used for special debug purposes
298298
;SHOW_SIZEOFS ; for debugging ports to some new systems
299+
;SHOW_EXPAND_STACK ; will print info when stack expands
299300
;NDEBUG ; removes some asserts
300301
;TEST_SCAN
301302
;_DEBUG

make/tools/make-boot.reb

+3
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,9 @@ emit-head "Build configuration" %config.h
11781178

11791179
emit {^/#ifndef REBOL_OPTIONS_H^/}
11801180

1181+
if stack-size [
1182+
emit ajoin ["#define STACK_SIZE " stack-size lf lf]
1183+
]
11811184
foreach def configs [
11821185
emit ajoin ["#define " def lf]
11831186
]

src/core/c-do.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ static REBVAL *Func_Word(REBINT dsf)
105105
}
106106
Extend_Series(DS_Series, amount);
107107
DS_Base = BLK_HEAD(DS_Series);
108+
#ifdef SHOW_EXPAND_STACK
108109
Debug_Fmt(BOOT_STR(RS_STACK, 0), DSP, SERIES_REST(DS_Series));
110+
#endif
109111
}
110112

111113

@@ -861,7 +863,7 @@ x*/ static REBINT Do_Args_Light(REBVAL *func, REBVAL *path, REBSER *block, REBCN
861863

862864
//CHECK_MEMORY(1);
863865
CHECK_STACK(&value);
864-
if ((DSP + 20) > (REBINT)SERIES_REST(DS_Series)) Expand_Stack(STACK_MIN); //Trap0(RE_STACK_OVERFLOW);
866+
if ((DSP + 200) > (REBINT)SERIES_REST(DS_Series)) Expand_Stack(STACK_MIN); //Trap0(RE_STACK_OVERFLOW);
865867
if (--Eval_Count <= 0 || Eval_Signals) Do_Signals();
866868

867869
value = BLK_SKIP(block, index);

src/include/sys-core.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
//#define MUNGWALL // memory allocation bounds checking
4040
#define STACK_MIN 4000 // data stack increment size
4141
#define STACK_LIMIT 400000 // data stack max (6.4MB)
42+
#ifndef STACK_SIZE
43+
#define STACK_SIZE (1 * 1024 * 1024) // Default MSVS stack size is 1MiB
44+
#endif
4245
#define MIN_COMMON 10000 // min size of common buffer
4346
#define MAX_COMMON 100000 // max size of common buffer (shrink trigger)
4447
#define MAX_NUM_LEN 64 // As many numeric digits we will accept on input
@@ -354,8 +357,9 @@ enum {
354357
#else
355358
#define CHECK_STACK(v) if ((REBUPT)(v) <= Stack_Limit) Trap_Stack();
356359
#endif
357-
#define STACK_BOUNDS (4*1024*1000) // note: need a better way to set it !!
358-
// Also: made somewhat smaller than linker setting to allow trapping it
360+
#define STACK_BOUNDS (STACK_SIZE - (24 * 1024)) // made somewhat smaller than linker setting to allow trapping it
361+
//NOTE: in VS Debug build the stack overflow is detected before trying to expand the data stack!
362+
// So use Relase build to test the stack expansion.
359363

360364

361365
/***********************************************************************

0 commit comments

Comments
 (0)