[pypy-commit] pypy jitlog-exact-source-lines: deduplicate offset2lineno, moved comment to rpython/tool/error.py (pypyjit)

plan_rich pypy.commits at gmail.com
Mon Aug 1 13:11:20 EDT 2016


Author: Richard Plangger <planrichi at gmail.com>
Branch: jitlog-exact-source-lines
Changeset: r85963:3654fa52664d
Date: 2016-08-01 19:09 +0200
http://bitbucket.org/pypy/pypy/changeset/3654fa52664d/

Log:	deduplicate offset2lineno, moved comment to rpython/tool/error.py
	(pypyjit)

diff --git a/pypy/module/pypyjit/interp_jit.py b/pypy/module/pypyjit/interp_jit.py
--- a/pypy/module/pypyjit/interp_jit.py
+++ b/pypy/module/pypyjit/interp_jit.py
@@ -42,26 +42,11 @@
     from rpython.rlib import rvmprof
     return rvmprof.get_unique_id(bytecode)
 
- at jit.elidable
-def offset2lineno(bytecode, stopat):
-    # see dis.findlinestarts for an explanation. This function is copied from
-    # rpython/tool/error.py
-    # lnotab is a list of [byte inc, line inc, ...]
-    # even position denote byte increments, odd line increments...
-    tab = bytecode.co_lnotab
-    line = bytecode.co_firstlineno
-    addr = 0
-    for i in range(0, len(tab), 2):
-        addr = addr + ord(tab[i])
-        if addr > stopat:
-            break
-        line = line + ord(tab[i+1])
-    return line
-
 @jl.returns(jl.MP_FILENAME, jl.MP_LINENO,
             jl.MP_SCOPE, jl.MP_INDEX, jl.MP_OPCODE)
 def get_location(next_instr, is_being_profiled, bytecode):
     from pypy.tool.stdlib_opcode import opcode_method_names
+    from pypy.tool.error import offset2lineno
     bcindex = ord(bytecode.co_code[next_instr])
     opname = ""
     if 0 <= bcindex < len(opcode_method_names):
diff --git a/rpython/tool/error.py b/rpython/tool/error.py
--- a/rpython/tool/error.py
+++ b/rpython/tool/error.py
@@ -158,6 +158,8 @@
 
 @jit.elidable
 def offset2lineno(c, stopat):
+    # even position in lnotab denote byte increments, odd line increments.
+    # see dis.findlinestarts in the python std. library for more details
     tab = c.co_lnotab
     line = c.co_firstlineno
     addr = 0


More information about the pypy-commit mailing list