Skip to content

Commit 937ea32

Browse files
committed
Remove stack manipulation macros
1 parent ba530f6 commit 937ea32

File tree

5 files changed

+23
-3215
lines changed

5 files changed

+23
-3215
lines changed

Python/bytecodes.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ dummy_func(
11231123
_PyStackRef temp = PyStackRef_MakeHeapSafe(retval);
11241124
DEAD(retval);
11251125
SAVE_STACK();
1126-
assert(EMPTY());
1126+
assert(STACK_LEVEL() == 0);
11271127
_Py_LeaveRecursiveCallPy(tstate);
11281128
// GH-99729: We need to unlink the frame *before* clearing it:
11291129
_PyInterpreterFrame *dying = frame;
@@ -4815,7 +4815,7 @@ dummy_func(
48154815
PyFunctionObject *func = (PyFunctionObject *)PyStackRef_AsPyObjectBorrow(frame->f_funcobj);
48164816
PyGenObject *gen = (PyGenObject *)_Py_MakeCoro(func);
48174817
ERROR_IF(gen == NULL, error);
4818-
assert(EMPTY());
4818+
assert(STACK_LEVEL() == 0);
48194819
SAVE_STACK();
48204820
_PyInterpreterFrame *gen_frame = &gen->gi_iframe;
48214821
frame->instr_ptr++;
@@ -5224,22 +5224,26 @@ dummy_func(
52245224
}
52255225

52265226
label(pop_4_error) {
5227-
STACK_SHRINK(4);
5227+
stack_pointer -= 4;
5228+
assert(WITHIN_STACK_BOUNDS());
52285229
goto error;
52295230
}
52305231

52315232
label(pop_3_error) {
5232-
STACK_SHRINK(3);
5233+
stack_pointer -= 3;
5234+
assert(WITHIN_STACK_BOUNDS());
52335235
goto error;
52345236
}
52355237

52365238
label(pop_2_error) {
5237-
STACK_SHRINK(2);
5239+
stack_pointer -= 2;
5240+
assert(WITHIN_STACK_BOUNDS());
52385241
goto error;
52395242
}
52405243

52415244
label(pop_1_error) {
5242-
STACK_SHRINK(1);
5245+
stack_pointer -= 1;
5246+
assert(WITHIN_STACK_BOUNDS());
52435247
goto error;
52445248
}
52455249

Python/ceval_macros.h

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -194,48 +194,8 @@ GETITEM(PyObject *v, Py_ssize_t i) {
194194
#define JUMPBY(x) (next_instr += (x))
195195
#define SKIP_OVER(x) (next_instr += (x))
196196

197-
198-
/* Stack manipulation macros */
199-
200-
/* The stack can grow at most MAXINT deep, as co_nlocals and
201-
co_stacksize are ints. */
202197
#define STACK_LEVEL() ((int)(stack_pointer - _PyFrame_Stackbase(frame)))
203198
#define STACK_SIZE() (_PyFrame_GetCode(frame)->co_stacksize)
204-
#define EMPTY() (STACK_LEVEL() == 0)
205-
#define TOP() (stack_pointer[-1])
206-
#define SECOND() (stack_pointer[-2])
207-
#define THIRD() (stack_pointer[-3])
208-
#define FOURTH() (stack_pointer[-4])
209-
#define PEEK(n) (stack_pointer[-(n)])
210-
#define POKE(n, v) (stack_pointer[-(n)] = (v))
211-
#define SET_TOP(v) (stack_pointer[-1] = (v))
212-
#define SET_SECOND(v) (stack_pointer[-2] = (v))
213-
#define BASIC_STACKADJ(n) (stack_pointer += n)
214-
#define BASIC_PUSH(v) (*stack_pointer++ = (v))
215-
#define BASIC_POP() (*--stack_pointer)
216-
217-
#ifdef Py_DEBUG
218-
#define PUSH(v) do { \
219-
BASIC_PUSH(v); \
220-
assert(STACK_LEVEL() <= STACK_SIZE()); \
221-
} while (0)
222-
#define POP() (assert(STACK_LEVEL() > 0), BASIC_POP())
223-
#define STACK_GROW(n) do { \
224-
assert(n >= 0); \
225-
BASIC_STACKADJ(n); \
226-
assert(STACK_LEVEL() <= STACK_SIZE()); \
227-
} while (0)
228-
#define STACK_SHRINK(n) do { \
229-
assert(n >= 0); \
230-
assert(STACK_LEVEL() >= n); \
231-
BASIC_STACKADJ(-(n)); \
232-
} while (0)
233-
#else
234-
#define PUSH(v) BASIC_PUSH(v)
235-
#define POP() BASIC_POP()
236-
#define STACK_GROW(n) BASIC_STACKADJ(n)
237-
#define STACK_SHRINK(n) BASIC_STACKADJ(-(n))
238-
#endif
239199

240200
#define WITHIN_STACK_BOUNDS() \
241201
(frame->owner == FRAME_OWNED_BY_INTERPRETER || (STACK_LEVEL() >= 0 && STACK_LEVEL() <= STACK_SIZE()))

0 commit comments

Comments
 (0)