]> granicus.if.org Git - python/commitdiff
PyFrameObject: rename f_stackbottom to f_stacktop, since it points to
authorTim Peters <tim.peters@gmail.com>
Sat, 23 Jun 2001 05:26:56 +0000 (05:26 +0000)
committerTim Peters <tim.peters@gmail.com>
Sat, 23 Jun 2001 05:26:56 +0000 (05:26 +0000)
the next free valuestack slot, not to the base (in America, stacks push
and pop at the top -- they mutate at the bottom in Australia <winK>).
eval_frame():  assert that f_stacktop isn't NULL upon entry.
frame_delloc():  avoid ordered pointer comparisons involving f_stacktop
when f_stacktop is NULL.

Include/frameobject.h
Objects/frameobject.c
Python/ceval.c

index b620f7652fa052df53f743d759301764cda4e4ec..e2bf7a1ef609674ccc330c5bb09b8ff5e1af05d2 100644 (file)
@@ -21,8 +21,10 @@ typedef struct _frame {
     PyObject *f_globals;       /* global symbol table (PyDictObject) */
     PyObject *f_locals;                /* local symbol table (PyDictObject) */
     PyObject **f_valuestack;   /* points after the last local */
-    PyObject **f_stackbottom;   /* points to the last item on the stack if
-                                  frame has yielded. */
+    /* Next free slot in f_valuestack.  Frame creation sets to f_valuestack.
+       Frame evaluation usually NULLs it, but a frame that yields sets it
+       to the current stack top. */
+    PyObject **f_stacktop;
     PyObject *f_trace;         /* Trace function */
     PyObject *f_exc_type, *f_exc_value, *f_exc_traceback;
     PyThreadState *f_tstate;
index c38c5fbc2508452fe000c253d2f02f42554ac521..6af4e6e88ad75b68438bca53371d457927a65eb5 100644 (file)
@@ -78,9 +78,11 @@ frame_dealloc(PyFrameObject *f)
        }
 
        /* Free stack */
-       for (p = f->f_valuestack; p < f->f_stackbottom; p++) {
-               Py_XDECREF(*p);
+       if (f->f_stacktop != NULL) {
+               for (p = f->f_valuestack; p < f->f_stacktop; p++)
+                       Py_XDECREF(*p);
        }
+       
        Py_XDECREF(f->f_back);
        Py_XDECREF(f->f_code);
        Py_XDECREF(f->f_builtins);
@@ -226,7 +228,7 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals,
                f->f_localsplus[extras] = NULL;
 
        f->f_valuestack = f->f_localsplus + (f->f_nlocals + ncells + nfrees);
-       f->f_stackbottom = f->f_valuestack;
+       f->f_stacktop = f->f_valuestack;
 
        return f;
 }
index fcb8fc3e058512ec671a4630ba44225cff8b37de..d6b61d5b42fc122973b5496b0e42077b4380fb4c 100644 (file)
@@ -147,9 +147,8 @@ gen_iternext(genobject *gen)
                                "generator already executing");
                return NULL;
        }
-       if (f->f_stackbottom == NULL) {
+       if (f->f_stacktop == NULL)
                return NULL;
-       }
 
        /* Generators always return to their most recent caller, not
         * necessarily their creator. */
@@ -584,8 +583,9 @@ eval_frame(PyFrameObject *f)
        freevars = f->f_localsplus + f->f_nlocals;
        _PyCode_GETCODEPTR(co, &first_instr);
        next_instr = first_instr + f->f_lasti;
-       stack_pointer = f->f_stackbottom;
-       f->f_stackbottom = NULL;
+       stack_pointer = f->f_stacktop;
+       assert(stack_pointer != NULL);
+       f->f_stacktop = NULL;
 
 #ifdef LLTRACE
        lltrace = PyDict_GetItemString(f->f_globals,"__lltrace__") != NULL;
@@ -1371,7 +1371,7 @@ eval_frame(PyFrameObject *f)
 
                case YIELD_VALUE:
                        retval = POP();
-                       f->f_stackbottom = stack_pointer;
+                       f->f_stacktop = stack_pointer;
                        f->f_lasti = INSTR_OFFSET();
                        why = WHY_YIELD;
                        break;