[Python-checkins] r46128 - in python/trunk: Include/frameobject.h Misc/NEWS Objects/frameobject.c Python/ceval.c

Neal Norwitz nnorwitz at gmail.com
Wed May 24 08:59:10 CEST 2006


On 5/23/06, richard.jones <python-checkins at python.org> wrote:
> Author: richard.jones
> Date: Tue May 23 20:28:17 2006
> New Revision: 46128
>
> Log:
> Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects.

Richard,

You can get rid of one more int, f_restricted if you make it a
PyGetSetDef, it's a pretty trivial change.  Most of the patch is
below, but since I cut and pasted, it would have to be applied
manually.   (Plus it's missing one removal of setting f_restricted in
Frame_New.)

n
--

Index: Python/ceval.c
===================================================================
--- Python/ceval.c      (revision 42560)
+++ Python/ceval.c      (working copy)
@@ -3357,7 +3357,7 @@
 PyEval_GetRestricted(void)
 {
        PyFrameObject *current_frame = PyEval_GetFrame();
-       return current_frame == NULL ? 0 : current_frame->f_restricted;
+       return current_frame == NULL ? 0 : PyFrame_IsRestricted(current_frame);
 }

 int
Index: Include/frameobject.h
===================================================================
--- Include/frameobject.h       (revision 42560)
+++ Include/frameobject.h       (working copy)
@@ -32,15 +32,13 @@
     /* As of 2.3 f_lineno is only valid when tracing is active (i.e. when
        f_trace is set) -- at other times use PyCode_Addr2Line instead. */
     int f_lineno;              /* Current line number */
-    int f_restricted;          /* Flag set if restricted operations
-                                  in this scope */
     int f_iblock;              /* index in f_blockstack */
@@ -49,6 +44,8 @@
 PyAPI_DATA(PyTypeObject) PyFrame_Type;

 #define PyFrame_Check(op) ((op)->ob_type == &PyFrame_Type)
+#define PyFrame_IsRestricted(f) \
+       ((f)->f_builtins != (f)->f_tstate->interp->builtins)

 PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
                                        PyObject *, PyObject *);
Index: Objects/frameobject.c
===================================================================
--- Objects/frameobject.c       (revision 42560)
+++ Objects/frameobject.c       (working copy)
@@ -15,13 +15,14 @@
        {"f_builtins",  T_OBJECT,       OFF(f_builtins),RO},
        {"f_globals",   T_OBJECT,       OFF(f_globals), RO},
        {"f_lasti",     T_INT,          OFF(f_lasti),   RO},
-       {"f_restricted",T_INT,          OFF(f_restricted),RO},
        {"f_exc_type",  T_OBJECT,       OFF(f_exc_type)},
        {"f_exc_value", T_OBJECT,       OFF(f_exc_value)},
        {"f_exc_traceback", T_OBJECT,   OFF(f_exc_traceback)},
@@ -342,11 +343,18 @@
        return 0;
 }

+static PyObject *
+frame_getrestricted(PyFrameObject *f, void *closure)
+{
+       return PyBool_FromLong(PyFrame_IsRestricted(f));
+}
+
 static PyGetSetDef frame_getsetlist[] = {
        {"f_locals",    (getter)frame_getlocals, NULL, NULL},
        {"f_lineno",    (getter)frame_getlineno,
                        (setter)frame_setlineno, NULL},
        {"f_trace",     (getter)frame_gettrace, (setter)frame_settrace, NULL},
+       {"f_restricted",(getter)frame_getrestricted, NULL, NULL},
        {0}
 };


More information about the Python-checkins mailing list