[Python-checkins] python/dist/src/Lib dis.py,1.41,1.42 inspect.py,1.37,1.38 pdb.py,1.54,1.55 traceback.py,1.27,1.28

mwh@users.sourceforge.net mwh@users.sourceforge.net
Thu, 15 Aug 2002 07:59:03 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv10908/Lib

Modified Files:
	dis.py inspect.py pdb.py traceback.py 
Log Message:
This is my patch

[ 587993 ] SET_LINENO killer

Remove SET_LINENO.  Tracing is now supported by inspecting co_lnotab.

Many sundry changes to document and adapt to this change.


Index: dis.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/dis.py,v
retrieving revision 1.41
retrieving revision 1.42
diff -C2 -d -r1.41 -r1.42
*** dis.py	13 Jun 2002 17:59:51 -0000	1.41
--- dis.py	15 Aug 2002 14:59:00 -0000	1.42
***************
*** 56,59 ****
--- 56,73 ----
      """Disassemble a code object."""
      code = co.co_code
+ 
+     byte_increments = [ord(c) for c in co.co_lnotab[0::2]]
+     line_increments = [ord(c) for c in co.co_lnotab[1::2]]
+     table_length = len(byte_increments) # == len(line_increments)
+ 
+     lineno = co.co_firstlineno
+     table_index = 0
+     while (table_index < table_length
+            and byte_increments[table_index] == 0):
+         lineno += line_increments[table_index]
+         table_index += 1
+     addr = 0
+     line_incr = 0
+     
      labels = findlabels(code)
      n = len(code)
***************
*** 64,68 ****
          c = code[i]
          op = ord(c)
!         if op == SET_LINENO and i > 0: print # Extra blank line
          if i == lasti: print '-->',
          else: print '   ',
--- 78,98 ----
          c = code[i]
          op = ord(c)
! 
!         if i >= addr:
!             lineno += line_incr
!             while table_index < table_length:
!                 addr += byte_increments[table_index]
!                 line_incr = line_increments[table_index]
!                 table_index += 1
!                 if line_incr:
!                     break
!             else:
!                 addr = sys.maxint
!             if i > 0:
!                 print
!             print "%3d"%lineno,
!         else:
!             print '   ',
! 
          if i == lasti: print '-->',
          else: print '   ',
***************
*** 225,228 ****
--- 255,259 ----
  def_op('BREAK_LOOP', 80)
  
+ def_op('RETURN_NONE', 81)
  def_op('LOAD_LOCALS', 82)
  def_op('RETURN_VALUE', 83)
***************
*** 277,283 ****
  def_op('DELETE_FAST', 126)      # Local variable number
  haslocal.append(126)
- 
- def_op('SET_LINENO', 127)       # Current line number
- SET_LINENO = 127
  
  def_op('RAISE_VARARGS', 130)    # Number of raise arguments (1, 2, or 3)
--- 308,311 ----

Index: inspect.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/inspect.py,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** inspect.py	4 Aug 2002 17:22:59 -0000	1.37
--- inspect.py	15 Aug 2002 14:59:00 -0000	1.38
***************
*** 712,716 ****
  
      filename = getsourcefile(frame) or getfile(frame)
!     lineno = getlineno(frame)
      if context > 0:
          start = lineno - 1 - context//2
--- 712,716 ----
  
      filename = getsourcefile(frame) or getfile(frame)
!     lineno = frame.f_lineno
      if context > 0:
          start = lineno - 1 - context//2
***************
*** 731,746 ****
  def getlineno(frame):
      """Get the line number from a frame object, allowing for optimization."""
!     # Written by Marc-André Lemburg; revised by Jim Hugunin and Fredrik Lundh.
!     lineno = frame.f_lineno
!     code = frame.f_code
!     if hasattr(code, 'co_lnotab'):
!         table = code.co_lnotab
!         lineno = code.co_firstlineno
!         addr = 0
!         for i in range(0, len(table), 2):
!             addr = addr + ord(table[i])
!             if addr > frame.f_lasti: break
!             lineno = lineno + ord(table[i+1])
!     return lineno
  
  def getouterframes(frame, context=1):
--- 731,736 ----
  def getlineno(frame):
      """Get the line number from a frame object, allowing for optimization."""
!     # FrameType.f_lineno is now a descriptor that grovels co_lnotab
!     return frame.f_lineno
  
  def getouterframes(frame, context=1):

Index: pdb.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pdb.py,v
retrieving revision 1.54
retrieving revision 1.55
diff -C2 -d -r1.54 -r1.55
*** pdb.py	12 Jul 2002 13:10:53 -0000	1.54
--- pdb.py	15 Aug 2002 14:59:00 -0000	1.55
***************
*** 106,110 ****
                      self.onecmd(line)
  
!     # Override Bdb methods (except user_call, for now)
  
      def user_line(self, frame):
--- 106,116 ----
                      self.onecmd(line)
  
!     # Override Bdb methods 
! 
!     def user_call(self, frame, argument_list):
!         """This method is called when there is the remote possibility
!         that we ever need to stop in this function."""
!         print '--Call--'
!         self.interaction(frame, None)
  
      def user_line(self, frame):

Index: traceback.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/traceback.py,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** traceback.py	2 Jun 2002 03:04:51 -0000	1.27
--- traceback.py	15 Aug 2002 14:59:00 -0000	1.28
***************
*** 60,64 ****
      while tb is not None and (limit is None or n < limit):
          f = tb.tb_frame
!         lineno = tb_lineno(tb)
          co = f.f_code
          filename = co.co_filename
--- 60,64 ----
      while tb is not None and (limit is None or n < limit):
          f = tb.tb_frame
!         lineno = tb.tb_lineno
          co = f.f_code
          filename = co.co_filename
***************
*** 93,97 ****
      while tb is not None and (limit is None or n < limit):
          f = tb.tb_frame
!         lineno = tb_lineno(tb)
          co = f.f_code
          filename = co.co_filename
--- 93,97 ----
      while tb is not None and (limit is None or n < limit):
          f = tb.tb_frame
!         lineno = tb.tb_lineno
          co = f.f_code
          filename = co.co_filename
***************
*** 264,268 ****
      n = 0
      while f is not None and (limit is None or n < limit):
!         lineno = f.f_lineno     # XXX Too bad if -O is used
          co = f.f_code
          filename = co.co_filename
--- 264,268 ----
      n = 0
      while f is not None and (limit is None or n < limit):
!         lineno = f.f_lineno
          co = f.f_code
          filename = co.co_filename
***************
*** 280,301 ****
      """Calculate correct line number of traceback given in tb.
  
!     Even works with -O on.
      """
!     # Coded by Marc-Andre Lemburg from the example of PyCode_Addr2Line()
!     # in compile.c.
!     # Revised version by Jim Hugunin to work with JPython too.
! 
!     c = tb.tb_frame.f_code
!     if not hasattr(c, 'co_lnotab'):
!         return tb.tb_lineno
! 
!     tab = c.co_lnotab
!     line = c.co_firstlineno
!     stopat = tb.tb_lasti
!     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
--- 280,284 ----
      """Calculate correct line number of traceback given in tb.
  
!     Obsolete in 2.3.
      """
!     return tb.tb_lineno