@@ -1515,12 +1515,6 @@ eval_frame(PyFrameObject *f)
15151515 why = WHY_RETURN ;
15161516 break ;
15171517
1518- case RETURN_NONE :
1519- retval = Py_None ;
1520- Py_INCREF (retval );
1521- why = WHY_RETURN ;
1522- break ;
1523-
15241518 case YIELD_VALUE :
15251519 retval = POP ();
15261520 f -> f_stacktop = stack_pointer ;
@@ -2880,9 +2874,8 @@ maybe_call_line_trace(int opcode, Py_tracefunc func, PyObject *obj,
28802874 This is all fairly simple. Digging the information out of
28812875 co_lnotab takes some work, but is conceptually clear.
28822876
2883- Somewhat harder to explain is why we don't call the line
2884- trace function when executing a POP_TOP or RETURN_NONE
2885- opcodes. An example probably serves best.
2877+ Somewhat harder to explain is why we don't *always* call the
2878+ line trace function when the above test fails.
28862879
28872880 Consider this code:
28882881
@@ -2907,64 +2900,57 @@ maybe_call_line_trace(int opcode, Py_tracefunc func, PyObject *obj,
29072900 5 16 LOAD_CONST 2 (2)
29082901 19 PRINT_ITEM
29092902 20 PRINT_NEWLINE
2910- >> 21 RETURN_NONE
2903+ >> 21 LOAD_CONST 0 (None)
2904+ 24 RETURN_VALUE
29112905
29122906 If a is false, execution will jump to instruction at offset
29132907 15 and the co_lnotab will claim that execution has moved to
29142908 line 3. This is at best misleading. In this case we could
29152909 associate the POP_TOP with line 4, but that doesn't make
29162910 sense in all cases (I think).
29172911
2918- On the other hand, if a is true, execution will jump from
2919- instruction offset 12 to offset 21. Then the co_lnotab would
2920- imply that execution has moved to line 5, which is again
2921- misleading.
2922-
2923- This is why it is important that RETURN_NONE is *only* used
2924- for the "falling off the end of the function" form of
2925- returning None -- using it for code like
2926-
2927- 1: def f():
2928- 2: return
2912+ What we do is only call the line trace function if the co_lnotab
2913+ indicates we have jumped to the *start* of a line, i.e. if the
2914+ current instruction offset matches the offset given for the
2915+ start of a line by the co_lnotab.
29292916
2930- would, once again, lead to misleading tracing behaviour.
2931-
2932- It is also worth mentioning that getting tracing behaviour
2933- right is the *entire* motivation for adding the RETURN_NONE
2934- opcode.
2917+ This also takes care of the situation where a is true.
2918+ Execution will jump from instruction offset 12 to offset 21.
2919+ Then the co_lnotab would imply that execution has moved to line
2920+ 5, which is again misleading.
29352921 */
29362922
2937- if (opcode != POP_TOP && opcode != RETURN_NONE &&
2938- (frame -> f_lasti < * instr_lb || frame -> f_lasti > * instr_ub )) {
2923+ if ((frame -> f_lasti < * instr_lb || frame -> f_lasti >= * instr_ub )) {
29392924 PyCodeObject * co = frame -> f_code ;
29402925 int size , addr ;
29412926 unsigned char * p ;
29422927
2943- call_trace (func , obj , frame , PyTrace_LINE , Py_None );
2928+ size = PyString_GET_SIZE (co -> co_lnotab ) / 2 ;
2929+ p = (unsigned char * )PyString_AS_STRING (co -> co_lnotab );
29442930
2945- size = PyString_Size (co -> co_lnotab ) / 2 ;
2946- p = (unsigned char * )PyString_AsString (co -> co_lnotab );
2931+ addr = 0 ;
29472932
29482933 /* possible optimization: if f->f_lasti == instr_ub
29492934 (likely to be a common case) then we already know
29502935 instr_lb -- if we stored the matching value of p
29512936 somwhere we could skip the first while loop. */
29522937
2953- addr = 0 ;
2954-
29552938 /* see comments in compile.c for the description of
29562939 co_lnotab. A point to remember: increments to p
29572940 should come in pairs -- although we don't care about
29582941 the line increments here, treating them as byte
29592942 increments gets confusing, to say the least. */
29602943
2961- while (size >= 0 ) {
2944+ while (size > 0 ) {
29622945 if (addr + * p > frame -> f_lasti )
29632946 break ;
29642947 addr += * p ++ ;
29652948 p ++ ;
29662949 -- size ;
29672950 }
2951+ if (addr == frame -> f_lasti )
2952+ call_trace (func , obj , frame ,
2953+ PyTrace_LINE , Py_None );
29682954 * instr_lb = addr ;
29692955 if (size > 0 ) {
29702956 while (-- size >= 0 ) {
0 commit comments