Feature Requests item #1654367, was opened at 2007-02-07 17:12 Message generated for change (Comment added) made by arigo You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1654367&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Python Interpreter Core Group: Python 2.6 Status: Open Resolution: None Priority: 5 Private: No Submitted By: Fabio Zadrozny (fabioz) Assigned to: Nobody/Anonymous (nobody) Summary: [PATCH] Debuggers need a way to change the locals of a frame Initial Comment: Debuggers need a way to change the local variables in a given frame... currently, this works only if this change is done in the topmost frame (and under certain circumstances), but it should work for any frame. Initial discussion at: http://mail.python.org/pipermail/python-dev/2007-February/070884.html Apparently, the problem is the order in which PyFrame_LocalsToFast / PyFrame_FastToLocals is called. The proposed solution to this is having a savelocals() method in the frame object and have it reflect the changes in its returned dict into its locals. It will simply enable users to call PyFrame_LocalsToFast externally after a change, to be sure that it will not be changed (and it must be done before another call to PyFrame_LocalsToFast -- which I don't see as a large problem, because it is of restrict use -- mainly for debuggers). --------- frameobject.c Patch part 1: ----------------- static PyObject * PyFrame_SaveLocals(PyFrameObject *f) { PyFrame_LocalsToFast(f, 0); Py_INCREF(Py_None); return Py_None; } static PyMethodDef frame_methodlist[] = { {"savelocals", (PyCFunction)PyFrame_SaveLocals, METH_NOARGS, "After a change in f_locals, this method should be called to save the changes internally." }, {NULL} /* Sentinel */ }; ---------- frameobject.c Patch part 2: --------------- Add to PyTypeObject PyFrame_Type: frame_methodlist,/* tp_methods */ ------------------ end patch ------------------------- I'm sorry that this is not in an actual patch format... but as I didn't get it from the cvs, it is easier for me to explain it (as it is a rather small patch). Attached is a test-case for this patch. Thanks, Fabio ---------------------------------------------------------------------- >Comment By: Armin Rigo (arigo) Date: 2007-02-10 20:16 Message: Logged In: YES user_id=4771 Originator: NO A point of detail probably, but I suppose that instead of introducing a new method on frame objects, we could allow f_locals to be a writeable attribute. Setting it to a dictionary would update the value of the local variables. It's a bit of a hack, but so is the need for an explicit savelocals() method. A cleaner solution is to have f_locals return a dict-like object instead of a real dict when appropriate, but it takes more efforts to implement. ---------------------------------------------------------------------- Comment By: Martin v. Löwis (loewis) Date: 2007-02-08 08:38 Message: Logged In: YES user_id=21627 Originator: NO Why don't you set the clear parameter to 1? Please do submit a patch, you can use 'diff -ur' to create a recursive unified diff between source trees. Please also try to come up with a patch to the documentation. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1654367&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com