[pypy-commit] pypy default: tentative checkin to fix a bug which originates in SVN rev 74676, the merge of the py131 branch.

antocuni noreply at buildbot.pypy.org
Fri Mar 16 12:46:36 CET 2012


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r53715:a8f6a9147d27
Date: 2012-03-16 12:46 +0100
http://bitbucket.org/pypy/pypy/changeset/a8f6a9147d27/

Log:	tentative checkin to fix a bug which originates in SVN rev 74676,
	the merge of the py131 branch.

	The problem comes when we call gateway.applevel(...,
	filename=__file__), which happens e.g. in pyopcode.py. In this case,
	we overwrote the content of linecache.cache[filename], with the
	result that inspect.getsource() no longer worked (and e.g. pdb++ was
	unable to show the source code). The problem got somehow unnoticed
	because most of the time __filename__ points to the pyc file, so the
	linecache of the source .py file was not overwritten. However, the
	problem appears whenever we modify one of these files which contains
	a call to applevel(..., filename=__file__).

	Fix it by modifying linecache only if the filename is "fake". I'm
	not sure whether it's useful at all, but at least it's harmless. The
	comment says that it's needed to show tracebacks, but I didn't find
	any case in which one of these tracebacks from applevel() code is
	shown.

	Comments welcome :-)

diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -901,15 +901,16 @@
 
     def __init__(self, source, filename=None, modname='__builtin__'):
         # HAAACK (but a good one)
+        self.filename = filename
+        self.source = str(py.code.Source(source).deindent())
+        self.modname = modname
         if filename is None:
             f = sys._getframe(1)
             filename = '<%s:%d>' % (f.f_code.co_filename, f.f_lineno)
+            # make source code available for tracebacks
+            lines = [x + "\n" for x in source.split("\n")]
+            py.std.linecache.cache[filename] = (1, None, lines, filename)
         self.filename = filename
-        self.source = str(py.code.Source(source).deindent())
-        self.modname = modname
-        # make source code available for tracebacks
-        lines = [x + "\n" for x in source.split("\n")]
-        py.std.linecache.cache[filename] = (1, None, lines, filename)
 
     def __repr__(self):
         return "<ApplevelClass filename=%r>" % (self.filename,)


More information about the pypy-commit mailing list