Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit ae7db35

Browse files
author
Anselm Kruis
committed
Stackless issue #183: use a volatile pointer to call slp_switch()
Prevent inlining slp_switch() more reliably. C standard guarantees to read the value of a volatile variable from memory on each access. Therefore the compiler does not know the called function and can't inline. (cherry picked from commit 78f6b66)
1 parent a8cf08d commit ae7db35

9 files changed

+13
-73
lines changed

Stackless/core/slp_transfer.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ slp_transfer(PyCStackObject **cstprev, PyCStackObject *cst,
117117
{
118118
PyThreadState *ts = PyThreadState_GET();
119119
int result;
120+
/* Use a volatile pointer to prevent inlining of slp_switch().
121+
* See Stackless issue 183
122+
*/
123+
static int (*volatile slp_switch_ptr)(void) = slp_switch;
120124

121125
/* since we change the stack we must assure that the protocol was met */
122126
STACKLESS_ASSERT();
@@ -148,7 +152,7 @@ slp_transfer(PyCStackObject **cstprev, PyCStackObject *cst,
148152
_cstprev = cstprev;
149153
_cst = cst;
150154
_prev = prev;
151-
result = slp_switch();
155+
result = slp_switch_ptr();
152156
SLP_ASSERT_FRAME_IN_TRANSFER(ts);
153157
if (!result) {
154158
if (_cst) {

Stackless/platf/switch_amd64_unix.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,7 @@
9494
"xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15"
9595
#endif
9696

97-
/*
98-
* You may want to make the function static enable optimizations.
99-
* However, the ABI SPEC does not apply to static functions. Therefore
100-
* I make slp_switch a regular global function.
101-
*/
102-
#if 0
103-
static
104-
#endif
105-
int
97+
static int
10698
slp_switch(void)
10799
{
108100
register long *stackref, stsizediff;

Stackless/platf/switch_arm32_gcc.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,7 @@
2727
#define STACK_MAGIC 0
2828
#define REGS_TO_SAVE /*"r1", "r2", "r3", "r4",*/ "r5", "r6", "fp", "ip", "lr"
2929

30-
/*
31-
* You may want to make the function static enable optimizations.
32-
* However, the ABI SPEC does not apply to static functions. Therefore
33-
* I make slp_switch a regular global function.
34-
*/
35-
#if 0
36-
static
37-
#endif
38-
int
30+
static int
3931
slp_switch(void)
4032
{
4133
register int *stackref, stsizediff;

Stackless/platf/switch_mips_unix.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,7 @@
2020
"$23", "$30"
2121
#endif
2222
__asm__ volatile ("" : : : REGS_TO_SAVE);
23-
/*
24-
* You may want to make the function static enable optimizations.
25-
* However, the ABI SPEC does not apply to static functions. Therefore
26-
* I make slp_switch a regular global function.
27-
*/
28-
#if 0
29-
static
30-
#endif
31-
int
23+
static int
3224
slp_switch(void)
3325
{
3426
register int *stackref, stsizediff;

Stackless/platf/switch_ppc_macosx.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,7 @@
4242
"cr2", "cr3", "cr4"
4343
#endif
4444

45-
/*
46-
* You may want to make the function static enable optimizations.
47-
* However, the ABI SPEC does not apply to static functions. Therefore
48-
* I make slp_switch a regular global function.
49-
*/
50-
#if 0
51-
static
52-
#endif
53-
int
45+
static int
5446
slp_switch(void)
5547
{
5648
static int x = 0;

Stackless/platf/switch_ppc_unix.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,7 @@
3737
#define REGS_TO_SAVE "r13", "r14", "r15", "r16", "r17", "r18", "r19", "r20", \
3838
"r21", "r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29", "r31", \
3939
"cr2", "cr3", "cr4"
40-
/*
41-
* You may want to make the function static enable optimizations.
42-
* However, the ABI SPEC does not apply to static functions. Therefore
43-
* I make slp_switch a regular global function.
44-
*/
45-
#if 0
46-
static
47-
#endif
48-
int
40+
static int
4941
slp_switch(void)
5042
{
5143
register int *stackref, stsizediff;

Stackless/platf/switch_s390_unix.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,7 @@
2121
"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
2222
"f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15"
2323

24-
/*
25-
* You may want to make the function static enable optimizations.
26-
* However, the ABI SPEC does not apply to static functions. Therefore
27-
* I make slp_switch a regular global function.
28-
*/
29-
#if 0
30-
static
31-
#endif
32-
int
24+
static int
3325
slp_switch(void)
3426
{
3527
register int *stackref, stsizediff;

Stackless/platf/switch_sparc_sun_gcc.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,7 @@
2323

2424
#define STACK_MAGIC 0
2525

26-
/*
27-
* You may want to make the function static enable optimizations.
28-
* However, the ABI SPEC does not apply to static functions. Therefore
29-
* I make slp_switch a regular global function.
30-
*/
31-
#if 0
32-
static
33-
#endif
34-
int
26+
static int
3527
slp_switch(void)
3628
{
3729
register int *stackref, stsizediff;

Stackless/platf/switch_x86_unix.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,7 @@
6666
/* Registers marked as clobbered, minimum set according to the ABI spec. */
6767
#define REGS_CLOBBERED "ebx", "edi", "esi"
6868

69-
/*
70-
* You may want to make the function static enable optimizations.
71-
* However, the ABI SPEC does not apply to static functions. Therefore
72-
* I make slp_switch a regular global function.
73-
*/
74-
#if 0
75-
static
76-
#endif
77-
int
69+
static int
7870
slp_switch(void)
7971
{
8072
register int *stackref, stsizediff;

0 commit comments

Comments
 (0)