[pypy-commit] jitviewer default: Two changes trying a bit randomly to fix stuff:

arigo noreply at buildbot.pypy.org
Fri Mar 29 22:46:55 CET 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r227:1fadd37bdea6
Date: 2013-03-29 22:46 +0100
http://bitbucket.org/pypy/jitviewer/changeset/1fadd37bdea6/

Log:	Two changes trying a bit randomly to fix stuff:

	 * don't just crash when line numbers are out of range

	 * attempt to fix the case of "<module>" code objects that don't
	have any code on their line 1.

diff --git a/_jitviewer/app.py b/_jitviewer/app.py
--- a/_jitviewer/app.py
+++ b/_jitviewer/app.py
@@ -161,11 +161,14 @@
             try:
                 code = self.storage.load_code(loop.filename)[(loop.startlineno,
                                                               loop.name)]
-                if code.co_name == '<module>' and code.co_firstlineno == 1:
+                if code.co_name == '<module>':
                     with open(code.co_filename) as f:
-                        source = CodeRepr(f.read(), code, loop)
+                        source = f.readlines()
+                    striplines = max(code.co_firstlineno - 1, 0)
+                    source = ''.join(source[striplines:])
                 else:
-                    source = CodeRepr(inspect.getsource(code), code, loop)
+                    source = inspect.getsource(code)
+                source = CodeRepr(source, code, loop)
             except (IOError, OSError):
                 source = CodeReprNoFile(loop)
         d = {'html': flask.render_template('loop.html',
diff --git a/_jitviewer/display.py b/_jitviewer/display.py
--- a/_jitviewer/display.py
+++ b/_jitviewer/display.py
@@ -49,4 +49,9 @@
                     last_lineno = no
             else:
                 no = last_lineno
-            self.lines[no - self.firstlineno].chunks.append(chunk)
+            i = no - self.firstlineno
+            if i < 0:
+                i = 0
+            while len(self.lines) <= i:
+                self.lines.append(LineRepr('# missing line', False))
+            self.lines[i].chunks.append(chunk)


More information about the pypy-commit mailing list