Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r97377:6ef693fdb897 Date: 2019-09-05 15:23 +0200 http://bitbucket.org/pypy/pypy/changeset/6ef693fdb897/
Log: Simplify again sys._current_frames() from d48eaa036796. I *think* that by now it's not needed any more, and some basic testing seems to confirm that. diff --git a/pypy/module/sys/currentframes.py b/pypy/module/sys/currentframes.py --- a/pypy/module/sys/currentframes.py +++ b/pypy/module/sys/currentframes.py @@ -1,76 +1,27 @@ """ Implementation of the 'sys._current_frames()' routine. """ -from pypy.interpreter import gateway -app = gateway.applevel(''' -"NOT_RPYTHON" -import __builtin__ - -class fake_code(object): - co_name = "?" - co_filename = "?" - co_firstlineno = 0 - -class fake_frame(object): - f_back = None - f_builtins = __builtin__.__dict__ - f_code = fake_code() - f_exc_traceback = None - f_exc_type = None - f_exc_value = None - f_globals = {} - f_lasti = -1 - f_lineno = 0 - f_locals = {} - f_restricted = False - f_trace = None - - def __init__(self, f): - if f is not None: - for name in ["f_builtins", "f_code", "f_globals", "f_lasti", - "f_lineno"]: - setattr(self, name, getattr(f, name)) -''') def _current_frames(space): """_current_frames() -> dictionary Return a dictionary mapping each current thread T's thread id to T's - current stack "frame". Functions in the traceback module can build the + current stack frame. Functions in the traceback module can build the call stack given such a frame. - Note that in PyPy this returns fake frame objects, to avoid a runtime - penalty everywhere with the JIT. (So far these fake frames can be - completely uninformative depending on the JIT state; we could return - more with more efforts.) + Note that in PyPy with the JIT, calling this function causes a runtime + penalty in all threads, depending on the internal JIT state. In each + thread, the penalty should only be noticeable if this call was done + while in the middle of a long-running function. This function should be used for specialized purposes only.""" w_result = space.newdict() - w_fake_frame = app.wget(space, "fake_frame") ecs = space.threadlocals.getallvalues() for thread_ident, ec in ecs.items(): - vref = ec.topframeref - frames = [] - while not vref.virtual: - f = vref() - if f is None: - break - frames.append(f) - vref = f.f_backref - else: - frames.append(None) - - w_topframe = space.w_None - w_prevframe = None - for f in frames: - w_nextframe = space.call_function(w_fake_frame, space.wrap_none(f)) - if w_prevframe is None: - w_topframe = w_nextframe - else: - space.setattr(w_prevframe, space.newtext('f_back'), w_nextframe) - w_prevframe = w_nextframe - + w_topframe = ec.gettopframe_nohidden() + if w_topframe is None: + continue space.setitem(w_result, space.newint(thread_ident), w_topframe) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit