diff options
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/lib/libdis.tex | 27 | ||||
-rw-r--r-- | Doc/lib/libtraceback.tex | 8 | ||||
-rw-r--r-- | Doc/tut/tut.tex | 11 | ||||
-rw-r--r-- | Doc/whatsnew/whatsnew23.tex | 30 |
4 files changed, 52 insertions, 24 deletions
diff --git a/Doc/lib/libdis.tex b/Doc/lib/libdis.tex index 16b692d..567c0ee 100644 --- a/Doc/lib/libdis.tex +++ b/Doc/lib/libdis.tex @@ -23,17 +23,15 @@ the following command can be used to get the disassembly of \begin{verbatim} >>> dis.dis(myfunc) - 0 SET_LINENO 1 - - 3 SET_LINENO 2 - 6 LOAD_GLOBAL 0 (len) - 9 LOAD_FAST 0 (alist) - 12 CALL_FUNCTION 1 - 15 RETURN_VALUE - 16 LOAD_CONST 0 (None) - 19 RETURN_VALUE + 2 0 LOAD_GLOBAL 0 (len) + 3 LOAD_FAST 0 (alist) + 6 CALL_FUNCTION 1 + 9 RETURN_VALUE + 10 RETURN_NONE \end{verbatim} +(The ``2'' is a line number). + The \module{dis} module defines the following functions and constants: \begin{funcdesc}{dis}{\optional{bytesource}} @@ -56,6 +54,7 @@ Disassembles a code object, indicating the last instruction if \var{lasti} was provided. The output is divided in the following columns: \begin{enumerate} +\item the line number, for the first instruction of each line \item the current instruction, indicated as \samp{-->}, \item a labelled instruction, indicated with \samp{>\code{>}}, \item the address of the instruction, @@ -402,6 +401,14 @@ is evaluated, the locals are passed to the class definition. Returns with TOS to the caller of the function. \end{opcodedesc} +\begin{opcodedesc}{RETURN_NONE}{} +Returns \constant{None} to the caller of the function. This opcode is +generated as the last opcode of every function and only then, for +reasons to do with tracing support. See the comments in the function +\cfunction{maybe_call_line_trace} in \file{Python/ceval.c} for the +gory details. \versionadded{2.3}. +\end{opcodedesc} + \begin{opcodedesc}{YIELD_VALUE}{} Pops \code{TOS} and yields it from a generator. \end{opcodedesc} @@ -621,7 +628,7 @@ free variable storage. \end{opcodedesc} \begin{opcodedesc}{SET_LINENO}{lineno} -Sets the current line number to \var{lineno}. +This opcode is obsolete. \end{opcodedesc} \begin{opcodedesc}{RAISE_VARARGS}{argc} diff --git a/Doc/lib/libtraceback.tex b/Doc/lib/libtraceback.tex index 2b20b0c..a74613b 100644 --- a/Doc/lib/libtraceback.tex +++ b/Doc/lib/libtraceback.tex @@ -118,10 +118,10 @@ A shorthand for \code{format_list(extract_stack(\var{f}, \var{limit}))}. \begin{funcdesc}{tb_lineno}{tb} This function returns the current line number set in the traceback -object. This is normally the same as the \code{\var{tb}.tb_lineno} -field of the object, but when optimization is used (the -O flag) this -field is not updated correctly; this function calculates the correct -value. +object. This function was necessary because in versions of Python +prior to 2.3 when the \programopt{O} flag was passed to Python the +\code{\var{tb}.tb_lineno} was not updated correctly. This function +has no use in versions past 2.3. \end{funcdesc} diff --git a/Doc/tut/tut.tex b/Doc/tut/tut.tex index c6081c6..4bc571a 100644 --- a/Doc/tut/tut.tex +++ b/Doc/tut/tut.tex @@ -2340,12 +2340,11 @@ Some tips for experts: \item When the Python interpreter is invoked with the \programopt{-O} flag, -optimized code is generated and stored in \file{.pyo} files. -The optimizer currently doesn't help much; it only removes -\keyword{assert} statements and \code{SET_LINENO} instructions. -When \programopt{-O} is used, \emph{all} bytecode is optimized; -\code{.pyc} files are ignored and \code{.py} files are compiled to -optimized bytecode. +optimized code is generated and stored in \file{.pyo} files. The +optimizer currently doesn't help much; it only removes +\keyword{assert} statements. When \programopt{-O} is used, \emph{all} +bytecode is optimized; \code{.pyc} files are ignored and \code{.py} +files are compiled to optimized bytecode. \item Passing two \programopt{-O} flags to the Python interpreter diff --git a/Doc/whatsnew/whatsnew23.tex b/Doc/whatsnew/whatsnew23.tex index 0d7d774..f919d7e 100644 --- a/Doc/whatsnew/whatsnew23.tex +++ b/Doc/whatsnew/whatsnew23.tex @@ -658,7 +658,6 @@ In 2.3, you get this: \end{itemize} - %====================================================================== \section{New and Improved Modules} @@ -987,9 +986,9 @@ allocate objects, and \cfunction{PyObject_GC_Del} to deallocate them. when running Python's \file{configure} script. (Contributed by Ondrej Palkovsky.) -\item The \csimplemacro{DL_EXPORT} and \csimplemacro{DL_IMPORT} macros are now -deprecated. Initialization functions for Python extension modules -should now be declared using the new macro +\item The \csimplemacro{DL_EXPORT} and \csimplemacro{DL_IMPORT} macros +are now deprecated. Initialization functions for Python extension +modules should now be declared using the new macro \csimplemacro{PyMODINIT_FUNC}, while the Python core will generally use the \csimplemacro{PyAPI_FUNC} and \csimplemacro{PyAPI_DATA} macros. @@ -1076,6 +1075,29 @@ Finally, there are various miscellaneous fixes: \item The tools used to build the documentation now work under Cygwin as well as \UNIX. +\item The \code{SET_LINENO} opcode has been removed. Back in the +mists of time, this opcode was needed to produce line numbers in +tracebacks and support trace functions (for, e.g., \module{pdb}). +Since Python 1.5, the line numbers in tracebacks have been computed +using a different mechanism that works with ``python -O''. For Python +2.3 Michael Hudson implemented a similar scheme to determine when to +call the trace function, removing the need for \code{SET_LINENO} +entirely. + +Python code will be hard pushed to notice a difference from this +change, apart from a slight speed up when python is run without +\programopt{-O}. + +C extensions that access the \member{f_lineno} field of frame objects +should instead call \code{PyCode_Addr2Line(f->f_code, f->f_lasti)}. +This will have the added effect of making the code work as desired +under ``python -O'' in earlier versions of Python. + +To make tracing work as expected, it was found necessary to add a new +opcode, \cdata{RETURN_NONE}, to the VM. If you want to know why, read +the comments in the function \cfunction{maybe_call_line_trace} in +\file{Python/ceval.c}. + \end{itemize} |