Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 340eb88

Browse files
committed
On MacOSX StackSpace() may lie because it doesn't know about the stack rlimit. For now we set a hard limit of 256K (default rlimit is 512K).
1 parent f8cdb5c commit 340eb88

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

Mac/Python/macglue.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ extern pascal unsigned char *PLstrrchr(unsigned char *, unsigned char);
100100
#endif
101101
#endif
102102

103+
#if TARGET_API_MAC_CARBON
104+
/*
105+
** On MacOSX StackSpace() lies: it gives the distance from heap end to stack pointer,
106+
** but the stack cannot grow that far due to rlimit values. We cannot get at this value
107+
** from Carbon, so we set a maximum to the stack here that is based on the default
108+
** stack limit of 512K.
109+
*/
110+
#define MAXIMUM_STACK_SIZE (256*1024)
111+
#endif
112+
103113
/*
104114
** We have to be careful, since we can't handle
105115
** things like updates (and they'll keep coming back if we don't
@@ -429,8 +439,15 @@ PyOS_CheckStack()
429439
static char *sentinel = 0;
430440
static PyThreadState *thread_for_sentinel = 0;
431441

432-
if ( sentinel == 0 ) {
433-
sentinel = &here - StackSpace() + MINIMUM_STACK_SIZE;
442+
if ( sentinel == 0 ) {
443+
unsigned long stackspace = StackSpace();
444+
445+
#ifdef MAXIMUM_STACK_SIZE
446+
/* See the comment at the definition */
447+
if ( stackspace > MAXIMUM_STACK_SIZE )
448+
stackspace = MAXIMUM_STACK_SIZE;
449+
#endif
450+
sentinel = &here - stackspace + MINIMUM_STACK_SIZE;
434451
}
435452
if ( thread_for_sentinel == 0 ) {
436453
thread_for_sentinel = PyThreadState_Get();

0 commit comments

Comments
 (0)