2001-10-12 16:01:43 -03:00
|
|
|
\chapter{Initialization, Finalization, and Threads
|
|
|
|
\label{initialization}}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{void}{Py_Initialize}{}
|
|
|
|
Initialize the Python interpreter. In an application embedding
|
|
|
|
Python, this should be called before using any other Python/C API
|
|
|
|
functions; with the exception of
|
|
|
|
\cfunction{Py_SetProgramName()}\ttindex{Py_SetProgramName()},
|
|
|
|
\cfunction{PyEval_InitThreads()}\ttindex{PyEval_InitThreads()},
|
|
|
|
\cfunction{PyEval_ReleaseLock()}\ttindex{PyEval_ReleaseLock()},
|
|
|
|
and \cfunction{PyEval_AcquireLock()}\ttindex{PyEval_AcquireLock()}.
|
|
|
|
This initializes the table of loaded modules (\code{sys.modules}),
|
|
|
|
and\withsubitem{(in module sys)}{\ttindex{modules}\ttindex{path}}
|
|
|
|
creates the fundamental modules
|
|
|
|
\module{__builtin__}\refbimodindex{__builtin__},
|
|
|
|
\module{__main__}\refbimodindex{__main__} and
|
|
|
|
\module{sys}\refbimodindex{sys}. It also initializes the module
|
|
|
|
search\indexiii{module}{search}{path} path (\code{sys.path}).
|
|
|
|
It does not set \code{sys.argv}; use
|
|
|
|
\cfunction{PySys_SetArgv()}\ttindex{PySys_SetArgv()} for that. This
|
|
|
|
is a no-op when called for a second time (without calling
|
|
|
|
\cfunction{Py_Finalize()}\ttindex{Py_Finalize()} first). There is
|
|
|
|
no return value; it is a fatal error if the initialization fails.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
2004-08-19 08:31:58 -03:00
|
|
|
\begin{cfuncdesc}{void}{Py_InitializeEx}{int initsigs}
|
2004-10-10 23:40:51 -03:00
|
|
|
This function works like \cfunction{Py_Initialize()} if
|
2004-08-19 08:31:58 -03:00
|
|
|
\var{initsigs} is 1. If \var{initsigs} is 0, it skips
|
|
|
|
initialization registration of signal handlers, which
|
|
|
|
might be useful when Python is embedded. \versionadded{2.4}
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
2001-10-12 16:01:43 -03:00
|
|
|
\begin{cfuncdesc}{int}{Py_IsInitialized}{}
|
|
|
|
Return true (nonzero) when the Python interpreter has been
|
|
|
|
initialized, false (zero) if not. After \cfunction{Py_Finalize()}
|
|
|
|
is called, this returns false until \cfunction{Py_Initialize()} is
|
|
|
|
called again.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{void}{Py_Finalize}{}
|
|
|
|
Undo all initializations made by \cfunction{Py_Initialize()} and
|
|
|
|
subsequent use of Python/C API functions, and destroy all
|
|
|
|
sub-interpreters (see \cfunction{Py_NewInterpreter()} below) that
|
|
|
|
were created and not yet destroyed since the last call to
|
|
|
|
\cfunction{Py_Initialize()}. Ideally, this frees all memory
|
|
|
|
allocated by the Python interpreter. This is a no-op when called
|
|
|
|
for a second time (without calling \cfunction{Py_Initialize()} again
|
|
|
|
first). There is no return value; errors during finalization are
|
|
|
|
ignored.
|
|
|
|
|
|
|
|
This function is provided for a number of reasons. An embedding
|
|
|
|
application might want to restart Python without having to restart
|
|
|
|
the application itself. An application that has loaded the Python
|
|
|
|
interpreter from a dynamically loadable library (or DLL) might want
|
|
|
|
to free all memory allocated by Python before unloading the
|
|
|
|
DLL. During a hunt for memory leaks in an application a developer
|
|
|
|
might want to free all memory allocated by Python before exiting
|
|
|
|
from the application.
|
|
|
|
|
|
|
|
\strong{Bugs and caveats:} The destruction of modules and objects in
|
|
|
|
modules is done in random order; this may cause destructors
|
|
|
|
(\method{__del__()} methods) to fail when they depend on other
|
|
|
|
objects (even functions) or modules. Dynamically loaded extension
|
|
|
|
modules loaded by Python are not unloaded. Small amounts of memory
|
|
|
|
allocated by the Python interpreter may not be freed (if you find a
|
|
|
|
leak, please report it). Memory tied up in circular references
|
|
|
|
between objects is not freed. Some memory allocated by extension
|
2003-02-10 15:12:42 -04:00
|
|
|
modules may not be freed. Some extensions may not work properly if
|
2001-10-12 16:01:43 -03:00
|
|
|
their initialization routine is called more than once; this can
|
2003-02-10 15:12:42 -04:00
|
|
|
happen if an application calls \cfunction{Py_Initialize()} and
|
2001-10-12 16:01:43 -03:00
|
|
|
\cfunction{Py_Finalize()} more than once.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{PyThreadState*}{Py_NewInterpreter}{}
|
|
|
|
Create a new sub-interpreter. This is an (almost) totally separate
|
|
|
|
environment for the execution of Python code. In particular, the
|
|
|
|
new interpreter has separate, independent versions of all imported
|
|
|
|
modules, including the fundamental modules
|
|
|
|
\module{__builtin__}\refbimodindex{__builtin__},
|
|
|
|
\module{__main__}\refbimodindex{__main__} and
|
|
|
|
\module{sys}\refbimodindex{sys}. The table of loaded modules
|
|
|
|
(\code{sys.modules}) and the module search path (\code{sys.path})
|
|
|
|
are also separate. The new environment has no \code{sys.argv}
|
|
|
|
variable. It has new standard I/O stream file objects
|
|
|
|
\code{sys.stdin}, \code{sys.stdout} and \code{sys.stderr} (however
|
|
|
|
these refer to the same underlying \ctype{FILE} structures in the C
|
|
|
|
library).
|
|
|
|
\withsubitem{(in module sys)}{
|
|
|
|
\ttindex{stdout}\ttindex{stderr}\ttindex{stdin}}
|
|
|
|
|
|
|
|
The return value points to the first thread state created in the new
|
2004-03-17 21:38:11 -04:00
|
|
|
sub-interpreter. This thread state is made in the current thread
|
2001-10-12 16:01:43 -03:00
|
|
|
state. Note that no actual thread is created; see the discussion of
|
|
|
|
thread states below. If creation of the new interpreter is
|
|
|
|
unsuccessful, \NULL{} is returned; no exception is set since the
|
|
|
|
exception state is stored in the current thread state and there may
|
|
|
|
not be a current thread state. (Like all other Python/C API
|
|
|
|
functions, the global interpreter lock must be held before calling
|
|
|
|
this function and is still held when it returns; however, unlike
|
|
|
|
most other Python/C API functions, there needn't be a current thread
|
|
|
|
state on entry.)
|
|
|
|
|
|
|
|
Extension modules are shared between (sub-)interpreters as follows:
|
|
|
|
the first time a particular extension is imported, it is initialized
|
|
|
|
normally, and a (shallow) copy of its module's dictionary is
|
|
|
|
squirreled away. When the same extension is imported by another
|
|
|
|
(sub-)interpreter, a new module is initialized and filled with the
|
|
|
|
contents of this copy; the extension's \code{init} function is not
|
|
|
|
called. Note that this is different from what happens when an
|
|
|
|
extension is imported after the interpreter has been completely
|
|
|
|
re-initialized by calling
|
|
|
|
\cfunction{Py_Finalize()}\ttindex{Py_Finalize()} and
|
|
|
|
\cfunction{Py_Initialize()}\ttindex{Py_Initialize()}; in that case,
|
|
|
|
the extension's \code{init\var{module}} function \emph{is} called
|
|
|
|
again.
|
|
|
|
|
|
|
|
\strong{Bugs and caveats:} Because sub-interpreters (and the main
|
|
|
|
interpreter) are part of the same process, the insulation between
|
|
|
|
them isn't perfect --- for example, using low-level file operations
|
|
|
|
like \withsubitem{(in module os)}{\ttindex{close()}}
|
|
|
|
\function{os.close()} they can (accidentally or maliciously) affect
|
|
|
|
each other's open files. Because of the way extensions are shared
|
|
|
|
between (sub-)interpreters, some extensions may not work properly;
|
|
|
|
this is especially likely when the extension makes use of (static)
|
|
|
|
global variables, or when the extension manipulates its module's
|
|
|
|
dictionary after its initialization. It is possible to insert
|
|
|
|
objects created in one sub-interpreter into a namespace of another
|
|
|
|
sub-interpreter; this should be done with great care to avoid
|
|
|
|
sharing user-defined functions, methods, instances or classes
|
|
|
|
between sub-interpreters, since import operations executed by such
|
|
|
|
objects may affect the wrong (sub-)interpreter's dictionary of
|
|
|
|
loaded modules. (XXX This is a hard-to-fix bug that will be
|
|
|
|
addressed in a future release.)
|
2005-06-20 13:37:03 -03:00
|
|
|
|
|
|
|
Also note that the use of this functionality is incompatible with
|
|
|
|
extension modules such as PyObjC and ctypes that use the
|
|
|
|
\cfunction{PyGILState_*} APIs (and this is inherent in the way the
|
|
|
|
\cfunction{PyGILState_*} functions work). Simple things may work,
|
|
|
|
but confusing behavior will always be near.
|
2001-10-12 16:01:43 -03:00
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{void}{Py_EndInterpreter}{PyThreadState *tstate}
|
|
|
|
Destroy the (sub-)interpreter represented by the given thread state.
|
|
|
|
The given thread state must be the current thread state. See the
|
|
|
|
discussion of thread states below. When the call returns, the
|
|
|
|
current thread state is \NULL. All thread states associated with
|
2004-03-17 20:49:01 -04:00
|
|
|
this interpreter are destroyed. (The global interpreter lock must
|
2001-10-12 16:01:43 -03:00
|
|
|
be held before calling this function and is still held when it
|
|
|
|
returns.) \cfunction{Py_Finalize()}\ttindex{Py_Finalize()} will
|
|
|
|
destroy all sub-interpreters that haven't been explicitly destroyed
|
|
|
|
at that point.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{void}{Py_SetProgramName}{char *name}
|
|
|
|
This function should be called before
|
|
|
|
\cfunction{Py_Initialize()}\ttindex{Py_Initialize()} is called
|
|
|
|
for the first time, if it is called at all. It tells the
|
|
|
|
interpreter the value of the \code{argv[0]} argument to the
|
|
|
|
\cfunction{main()}\ttindex{main()} function of the program. This is
|
|
|
|
used by \cfunction{Py_GetPath()}\ttindex{Py_GetPath()} and some
|
|
|
|
other functions below to find the Python run-time libraries relative
|
|
|
|
to the interpreter executable. The default value is
|
|
|
|
\code{'python'}. The argument should point to a zero-terminated
|
|
|
|
character string in static storage whose contents will not change
|
|
|
|
for the duration of the program's execution. No code in the Python
|
|
|
|
interpreter will change the contents of this storage.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{char*}{Py_GetProgramName}{}
|
|
|
|
Return the program name set with
|
|
|
|
\cfunction{Py_SetProgramName()}\ttindex{Py_SetProgramName()}, or the
|
|
|
|
default. The returned string points into static storage; the caller
|
|
|
|
should not modify its value.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{char*}{Py_GetPrefix}{}
|
|
|
|
Return the \emph{prefix} for installed platform-independent files.
|
|
|
|
This is derived through a number of complicated rules from the
|
|
|
|
program name set with \cfunction{Py_SetProgramName()} and some
|
|
|
|
environment variables; for example, if the program name is
|
|
|
|
\code{'/usr/local/bin/python'}, the prefix is \code{'/usr/local'}.
|
|
|
|
The returned string points into static storage; the caller should
|
|
|
|
not modify its value. This corresponds to the \makevar{prefix}
|
|
|
|
variable in the top-level \file{Makefile} and the
|
|
|
|
\longprogramopt{prefix} argument to the \program{configure} script
|
|
|
|
at build time. The value is available to Python code as
|
2006-03-01 12:37:55 -04:00
|
|
|
\code{sys.prefix}. It is only useful on \UNIX{}. See also the next
|
2001-10-12 16:01:43 -03:00
|
|
|
function.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{char*}{Py_GetExecPrefix}{}
|
|
|
|
Return the \emph{exec-prefix} for installed
|
|
|
|
platform-\emph{de}pendent files. This is derived through a number
|
|
|
|
of complicated rules from the program name set with
|
|
|
|
\cfunction{Py_SetProgramName()} and some environment variables; for
|
|
|
|
example, if the program name is \code{'/usr/local/bin/python'}, the
|
|
|
|
exec-prefix is \code{'/usr/local'}. The returned string points into
|
|
|
|
static storage; the caller should not modify its value. This
|
|
|
|
corresponds to the \makevar{exec_prefix} variable in the top-level
|
|
|
|
\file{Makefile} and the \longprogramopt{exec-prefix} argument to the
|
|
|
|
\program{configure} script at build time. The value is available
|
|
|
|
to Python code as \code{sys.exec_prefix}. It is only useful on
|
|
|
|
\UNIX.
|
|
|
|
|
|
|
|
Background: The exec-prefix differs from the prefix when platform
|
|
|
|
dependent files (such as executables and shared libraries) are
|
|
|
|
installed in a different directory tree. In a typical installation,
|
|
|
|
platform dependent files may be installed in the
|
|
|
|
\file{/usr/local/plat} subtree while platform independent may be
|
|
|
|
installed in \file{/usr/local}.
|
|
|
|
|
|
|
|
Generally speaking, a platform is a combination of hardware and
|
|
|
|
software families, e.g. Sparc machines running the Solaris 2.x
|
|
|
|
operating system are considered the same platform, but Intel
|
|
|
|
machines running Solaris 2.x are another platform, and Intel
|
|
|
|
machines running Linux are yet another platform. Different major
|
|
|
|
revisions of the same operating system generally also form different
|
|
|
|
platforms. Non-\UNIX{} operating systems are a different story; the
|
|
|
|
installation strategies on those systems are so different that the
|
|
|
|
prefix and exec-prefix are meaningless, and set to the empty string.
|
|
|
|
Note that compiled Python bytecode files are platform independent
|
|
|
|
(but not independent from the Python version by which they were
|
|
|
|
compiled!).
|
|
|
|
|
|
|
|
System administrators will know how to configure the \program{mount}
|
|
|
|
or \program{automount} programs to share \file{/usr/local} between
|
|
|
|
platforms while having \file{/usr/local/plat} be a different
|
|
|
|
filesystem for each platform.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{char*}{Py_GetProgramFullPath}{}
|
|
|
|
Return the full program name of the Python executable; this is
|
|
|
|
computed as a side-effect of deriving the default module search path
|
|
|
|
from the program name (set by
|
|
|
|
\cfunction{Py_SetProgramName()}\ttindex{Py_SetProgramName()} above).
|
|
|
|
The returned string points into static storage; the caller should
|
|
|
|
not modify its value. The value is available to Python code as
|
|
|
|
\code{sys.executable}.
|
|
|
|
\withsubitem{(in module sys)}{\ttindex{executable}}
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{char*}{Py_GetPath}{}
|
|
|
|
\indexiii{module}{search}{path}
|
|
|
|
Return the default module search path; this is computed from the
|
|
|
|
program name (set by \cfunction{Py_SetProgramName()} above) and some
|
|
|
|
environment variables. The returned string consists of a series of
|
|
|
|
directory names separated by a platform dependent delimiter
|
2005-02-13 18:50:04 -04:00
|
|
|
character. The delimiter character is \character{:} on \UNIX and Mac OS X,
|
|
|
|
\character{;} on Windows. The returned string points into
|
2001-10-12 16:01:43 -03:00
|
|
|
static storage; the caller should not modify its value. The value
|
|
|
|
is available to Python code as the list
|
|
|
|
\code{sys.path}\withsubitem{(in module sys)}{\ttindex{path}}, which
|
|
|
|
may be modified to change the future search path for loaded
|
|
|
|
modules.
|
|
|
|
|
|
|
|
% XXX should give the exact rules
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{const char*}{Py_GetVersion}{}
|
|
|
|
Return the version of this Python interpreter. This is a string
|
|
|
|
that looks something like
|
|
|
|
|
|
|
|
\begin{verbatim}
|
|
|
|
"1.5 (#67, Dec 31 1997, 22:34:28) [GCC 2.7.2.2]"
|
|
|
|
\end{verbatim}
|
|
|
|
|
|
|
|
The first word (up to the first space character) is the current
|
|
|
|
Python version; the first three characters are the major and minor
|
|
|
|
version separated by a period. The returned string points into
|
|
|
|
static storage; the caller should not modify its value. The value
|
2003-02-10 15:12:42 -04:00
|
|
|
is available to Python code as \code{sys.version}.
|
2001-10-12 16:01:43 -03:00
|
|
|
\withsubitem{(in module sys)}{\ttindex{version}}
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
2005-12-17 21:27:35 -04:00
|
|
|
\begin{cfuncdesc}{const char*}{Py_GetBuildNumber}{}
|
|
|
|
Return a string representing the Subversion revision that this Python
|
|
|
|
executable was built from. This number is a string because it may contain a
|
|
|
|
trailing 'M' if Python was built from a mixed revision source tree.
|
2005-12-17 21:36:44 -04:00
|
|
|
\versionadded{2.5}
|
2005-12-17 21:27:35 -04:00
|
|
|
\end{cfuncdesc}
|
|
|
|
|
2001-10-12 16:01:43 -03:00
|
|
|
\begin{cfuncdesc}{const char*}{Py_GetPlatform}{}
|
|
|
|
Return the platform identifier for the current platform. On \UNIX,
|
|
|
|
this is formed from the ``official'' name of the operating system,
|
|
|
|
converted to lower case, followed by the major revision number;
|
|
|
|
e.g., for Solaris 2.x, which is also known as SunOS 5.x, the value
|
2005-02-13 18:50:04 -04:00
|
|
|
is \code{'sunos5'}. On Mac OS X, it is \code{'darwin'}. On Windows,
|
2001-10-12 16:01:43 -03:00
|
|
|
it is \code{'win'}. The returned string points into static storage;
|
|
|
|
the caller should not modify its value. The value is available to
|
|
|
|
Python code as \code{sys.platform}.
|
|
|
|
\withsubitem{(in module sys)}{\ttindex{platform}}
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{const char*}{Py_GetCopyright}{}
|
|
|
|
Return the official copyright string for the current Python version,
|
|
|
|
for example
|
|
|
|
|
|
|
|
\code{'Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam'}
|
|
|
|
|
|
|
|
The returned string points into static storage; the caller should
|
2003-02-10 15:12:42 -04:00
|
|
|
not modify its value. The value is available to Python code as
|
|
|
|
\code{sys.copyright}.
|
2001-10-12 16:01:43 -03:00
|
|
|
\withsubitem{(in module sys)}{\ttindex{copyright}}
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{const char*}{Py_GetCompiler}{}
|
|
|
|
Return an indication of the compiler used to build the current
|
|
|
|
Python version, in square brackets, for example:
|
|
|
|
|
|
|
|
\begin{verbatim}
|
|
|
|
"[GCC 2.7.2.2]"
|
|
|
|
\end{verbatim}
|
|
|
|
|
|
|
|
The returned string points into static storage; the caller should
|
|
|
|
not modify its value. The value is available to Python code as part
|
|
|
|
of the variable \code{sys.version}.
|
|
|
|
\withsubitem{(in module sys)}{\ttindex{version}}
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{const char*}{Py_GetBuildInfo}{}
|
|
|
|
Return information about the sequence number and build date and time
|
|
|
|
of the current Python interpreter instance, for example
|
|
|
|
|
|
|
|
\begin{verbatim}
|
|
|
|
"#67, Aug 1 1997, 22:34:28"
|
|
|
|
\end{verbatim}
|
|
|
|
|
|
|
|
The returned string points into static storage; the caller should
|
|
|
|
not modify its value. The value is available to Python code as part
|
|
|
|
of the variable \code{sys.version}.
|
|
|
|
\withsubitem{(in module sys)}{\ttindex{version}}
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
2006-03-01 01:16:03 -04:00
|
|
|
\begin{cfuncdesc}{void}{PySys_SetArgv}{int argc, char **argv}
|
2001-10-12 16:01:43 -03:00
|
|
|
Set \code{sys.argv} based on \var{argc} and \var{argv}. These
|
|
|
|
parameters are similar to those passed to the program's
|
|
|
|
\cfunction{main()}\ttindex{main()} function with the difference that
|
|
|
|
the first entry should refer to the script file to be executed
|
|
|
|
rather than the executable hosting the Python interpreter. If there
|
|
|
|
isn't a script that will be run, the first entry in \var{argv} can
|
|
|
|
be an empty string. If this function fails to initialize
|
|
|
|
\code{sys.argv}, a fatal condition is signalled using
|
|
|
|
\cfunction{Py_FatalError()}\ttindex{Py_FatalError()}.
|
|
|
|
\withsubitem{(in module sys)}{\ttindex{argv}}
|
|
|
|
% XXX impl. doesn't seem consistent in allowing 0/NULL for the params;
|
|
|
|
% check w/ Guido.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
% XXX Other PySys thingies (doesn't really belong in this chapter)
|
|
|
|
|
|
|
|
\section{Thread State and the Global Interpreter Lock
|
|
|
|
\label{threads}}
|
|
|
|
|
|
|
|
\index{global interpreter lock}
|
|
|
|
\index{interpreter lock}
|
|
|
|
\index{lock, interpreter}
|
|
|
|
|
|
|
|
The Python interpreter is not fully thread safe. In order to support
|
|
|
|
multi-threaded Python programs, there's a global lock that must be
|
|
|
|
held by the current thread before it can safely access Python objects.
|
|
|
|
Without the lock, even the simplest operations could cause problems in
|
|
|
|
a multi-threaded program: for example, when two threads simultaneously
|
|
|
|
increment the reference count of the same object, the reference count
|
|
|
|
could end up being incremented only once instead of twice.
|
|
|
|
|
|
|
|
Therefore, the rule exists that only the thread that has acquired the
|
|
|
|
global interpreter lock may operate on Python objects or call Python/C
|
|
|
|
API functions. In order to support multi-threaded Python programs,
|
|
|
|
the interpreter regularly releases and reacquires the lock --- by
|
2003-07-02 18:38:34 -03:00
|
|
|
default, every 100 bytecode instructions (this can be changed with
|
2001-10-12 16:01:43 -03:00
|
|
|
\withsubitem{(in module sys)}{\ttindex{setcheckinterval()}}
|
|
|
|
\function{sys.setcheckinterval()}). The lock is also released and
|
|
|
|
reacquired around potentially blocking I/O operations like reading or
|
|
|
|
writing a file, so that other threads can run while the thread that
|
|
|
|
requests the I/O is waiting for the I/O operation to complete.
|
|
|
|
|
|
|
|
The Python interpreter needs to keep some bookkeeping information
|
|
|
|
separate per thread --- for this it uses a data structure called
|
2004-07-10 10:48:54 -03:00
|
|
|
\ctype{PyThreadState}\ttindex{PyThreadState}. There's one global
|
|
|
|
variable, however: the pointer to the current
|
2001-10-12 16:01:43 -03:00
|
|
|
\ctype{PyThreadState}\ttindex{PyThreadState} structure. While most
|
|
|
|
thread packages have a way to store ``per-thread global data,''
|
|
|
|
Python's internal platform independent thread abstraction doesn't
|
|
|
|
support this yet. Therefore, the current thread state must be
|
|
|
|
manipulated explicitly.
|
|
|
|
|
|
|
|
This is easy enough in most cases. Most code manipulating the global
|
|
|
|
interpreter lock has the following simple structure:
|
|
|
|
|
|
|
|
\begin{verbatim}
|
|
|
|
Save the thread state in a local variable.
|
|
|
|
Release the interpreter lock.
|
|
|
|
...Do some blocking I/O operation...
|
|
|
|
Reacquire the interpreter lock.
|
|
|
|
Restore the thread state from the local variable.
|
|
|
|
\end{verbatim}
|
|
|
|
|
|
|
|
This is so common that a pair of macros exists to simplify it:
|
|
|
|
|
|
|
|
\begin{verbatim}
|
|
|
|
Py_BEGIN_ALLOW_THREADS
|
|
|
|
...Do some blocking I/O operation...
|
|
|
|
Py_END_ALLOW_THREADS
|
|
|
|
\end{verbatim}
|
|
|
|
|
2002-04-09 18:09:42 -03:00
|
|
|
The
|
|
|
|
\csimplemacro{Py_BEGIN_ALLOW_THREADS}\ttindex{Py_BEGIN_ALLOW_THREADS}
|
|
|
|
macro opens a new block and declares a hidden local variable; the
|
|
|
|
\csimplemacro{Py_END_ALLOW_THREADS}\ttindex{Py_END_ALLOW_THREADS}
|
|
|
|
macro closes the block. Another advantage of using these two macros
|
|
|
|
is that when Python is compiled without thread support, they are
|
|
|
|
defined empty, thus saving the thread state and lock manipulations.
|
2001-10-12 16:01:43 -03:00
|
|
|
|
|
|
|
When thread support is enabled, the block above expands to the
|
|
|
|
following code:
|
|
|
|
|
|
|
|
\begin{verbatim}
|
|
|
|
PyThreadState *_save;
|
|
|
|
|
|
|
|
_save = PyEval_SaveThread();
|
|
|
|
...Do some blocking I/O operation...
|
|
|
|
PyEval_RestoreThread(_save);
|
|
|
|
\end{verbatim}
|
|
|
|
|
|
|
|
Using even lower level primitives, we can get roughly the same effect
|
|
|
|
as follows:
|
|
|
|
|
|
|
|
\begin{verbatim}
|
|
|
|
PyThreadState *_save;
|
|
|
|
|
|
|
|
_save = PyThreadState_Swap(NULL);
|
|
|
|
PyEval_ReleaseLock();
|
|
|
|
...Do some blocking I/O operation...
|
|
|
|
PyEval_AcquireLock();
|
|
|
|
PyThreadState_Swap(_save);
|
|
|
|
\end{verbatim}
|
|
|
|
|
|
|
|
There are some subtle differences; in particular,
|
|
|
|
\cfunction{PyEval_RestoreThread()}\ttindex{PyEval_RestoreThread()} saves
|
|
|
|
and restores the value of the global variable
|
|
|
|
\cdata{errno}\ttindex{errno}, since the lock manipulation does not
|
|
|
|
guarantee that \cdata{errno} is left alone. Also, when thread support
|
|
|
|
is disabled,
|
|
|
|
\cfunction{PyEval_SaveThread()}\ttindex{PyEval_SaveThread()} and
|
|
|
|
\cfunction{PyEval_RestoreThread()} don't manipulate the lock; in this
|
|
|
|
case, \cfunction{PyEval_ReleaseLock()}\ttindex{PyEval_ReleaseLock()} and
|
|
|
|
\cfunction{PyEval_AcquireLock()}\ttindex{PyEval_AcquireLock()} are not
|
|
|
|
available. This is done so that dynamically loaded extensions
|
|
|
|
compiled with thread support enabled can be loaded by an interpreter
|
|
|
|
that was compiled with disabled thread support.
|
|
|
|
|
|
|
|
The global interpreter lock is used to protect the pointer to the
|
|
|
|
current thread state. When releasing the lock and saving the thread
|
|
|
|
state, the current thread state pointer must be retrieved before the
|
|
|
|
lock is released (since another thread could immediately acquire the
|
|
|
|
lock and store its own thread state in the global variable).
|
|
|
|
Conversely, when acquiring the lock and restoring the thread state,
|
|
|
|
the lock must be acquired before storing the thread state pointer.
|
|
|
|
|
|
|
|
Why am I going on with so much detail about this? Because when
|
|
|
|
threads are created from C, they don't have the global interpreter
|
|
|
|
lock, nor is there a thread state data structure for them. Such
|
|
|
|
threads must bootstrap themselves into existence, by first creating a
|
|
|
|
thread state data structure, then acquiring the lock, and finally
|
|
|
|
storing their thread state pointer, before they can start using the
|
|
|
|
Python/C API. When they are done, they should reset the thread state
|
|
|
|
pointer, release the lock, and finally free their thread state data
|
|
|
|
structure.
|
|
|
|
|
2005-01-19 00:18:39 -04:00
|
|
|
Beginning with version 2.3, threads can now take advantage of the
|
|
|
|
\cfunction{PyGILState_*()} functions to do all of the above
|
|
|
|
automatically. The typical idiom for calling into Python from a C
|
|
|
|
thread is now:
|
2003-03-02 09:17:20 -04:00
|
|
|
|
|
|
|
\begin{verbatim}
|
2004-07-10 10:42:52 -03:00
|
|
|
PyGILState_STATE gstate;
|
|
|
|
gstate = PyGILState_Ensure();
|
2003-03-02 09:17:20 -04:00
|
|
|
|
|
|
|
/* Perform Python actions here. */
|
|
|
|
result = CallSomeFunction();
|
|
|
|
/* evaluate result */
|
|
|
|
|
|
|
|
/* Release the thread. No Python API allowed beyond this point. */
|
2004-07-10 10:42:52 -03:00
|
|
|
PyGILState_Release(gstate);
|
2003-03-02 09:17:20 -04:00
|
|
|
\end{verbatim}
|
2001-10-12 16:01:43 -03:00
|
|
|
|
2005-06-20 09:12:45 -03:00
|
|
|
Note that the \cfunction{PyGILState_*()} functions assume there is
|
|
|
|
only one global interpreter (created automatically by
|
2005-01-19 00:18:39 -04:00
|
|
|
\cfunction{Py_Initialize()}). Python still supports the creation of
|
2005-06-20 09:12:45 -03:00
|
|
|
additional interpreters (using \cfunction{Py_NewInterpreter()}), but
|
2005-01-19 00:18:39 -04:00
|
|
|
mixing multiple interpreters and the \cfunction{PyGILState_*()} API is
|
|
|
|
unsupported.
|
|
|
|
|
2001-10-12 16:01:43 -03:00
|
|
|
\begin{ctypedesc}{PyInterpreterState}
|
|
|
|
This data structure represents the state shared by a number of
|
|
|
|
cooperating threads. Threads belonging to the same interpreter
|
|
|
|
share their module administration and a few other internal items.
|
|
|
|
There are no public members in this structure.
|
|
|
|
|
|
|
|
Threads belonging to different interpreters initially share nothing,
|
|
|
|
except process state like available memory, open file descriptors
|
|
|
|
and such. The global interpreter lock is also shared by all
|
|
|
|
threads, regardless of to which interpreter they belong.
|
|
|
|
\end{ctypedesc}
|
|
|
|
|
|
|
|
\begin{ctypedesc}{PyThreadState}
|
|
|
|
This data structure represents the state of a single thread. The
|
|
|
|
only public data member is \ctype{PyInterpreterState
|
|
|
|
*}\member{interp}, which points to this thread's interpreter state.
|
|
|
|
\end{ctypedesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{void}{PyEval_InitThreads}{}
|
|
|
|
Initialize and acquire the global interpreter lock. It should be
|
|
|
|
called in the main thread before creating a second thread or
|
|
|
|
engaging in any other thread operations such as
|
|
|
|
\cfunction{PyEval_ReleaseLock()}\ttindex{PyEval_ReleaseLock()} or
|
|
|
|
\code{PyEval_ReleaseThread(\var{tstate})}\ttindex{PyEval_ReleaseThread()}.
|
|
|
|
It is not needed before calling
|
|
|
|
\cfunction{PyEval_SaveThread()}\ttindex{PyEval_SaveThread()} or
|
|
|
|
\cfunction{PyEval_RestoreThread()}\ttindex{PyEval_RestoreThread()}.
|
|
|
|
|
|
|
|
This is a no-op when called for a second time. It is safe to call
|
|
|
|
this function before calling
|
|
|
|
\cfunction{Py_Initialize()}\ttindex{Py_Initialize()}.
|
|
|
|
|
|
|
|
When only the main thread exists, no lock operations are needed.
|
|
|
|
This is a common situation (most Python programs do not use
|
|
|
|
threads), and the lock operations slow the interpreter down a bit.
|
|
|
|
Therefore, the lock is not created initially. This situation is
|
2004-10-10 23:40:51 -03:00
|
|
|
equivalent to having acquired the lock: when there is only a single
|
2001-10-12 16:01:43 -03:00
|
|
|
thread, all object accesses are safe. Therefore, when this function
|
|
|
|
initializes the lock, it also acquires it. Before the Python
|
|
|
|
\module{thread}\refbimodindex{thread} module creates a new thread,
|
|
|
|
knowing that either it has the lock or the lock hasn't been created
|
|
|
|
yet, it calls \cfunction{PyEval_InitThreads()}. When this call
|
2004-10-10 23:40:51 -03:00
|
|
|
returns, it is guaranteed that the lock has been created and that the
|
|
|
|
calling thread has acquired it.
|
2001-10-12 16:01:43 -03:00
|
|
|
|
|
|
|
It is \strong{not} safe to call this function when it is unknown
|
|
|
|
which thread (if any) currently has the global interpreter lock.
|
|
|
|
|
|
|
|
This function is not available when thread support is disabled at
|
|
|
|
compile time.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
2004-10-10 23:40:51 -03:00
|
|
|
\begin{cfuncdesc}{int}{PyEval_ThreadsInitialized}{}
|
|
|
|
Returns a non-zero value if \cfunction{PyEval_InitThreads()} has been
|
|
|
|
called. This function can be called without holding the lock, and
|
|
|
|
therefore can be used to avoid calls to the locking API when running
|
|
|
|
single-threaded. This function is not available when thread support
|
|
|
|
is disabled at compile time. \versionadded{2.4}
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
2001-10-12 16:01:43 -03:00
|
|
|
\begin{cfuncdesc}{void}{PyEval_AcquireLock}{}
|
|
|
|
Acquire the global interpreter lock. The lock must have been
|
|
|
|
created earlier. If this thread already has the lock, a deadlock
|
|
|
|
ensues. This function is not available when thread support is
|
|
|
|
disabled at compile time.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{void}{PyEval_ReleaseLock}{}
|
|
|
|
Release the global interpreter lock. The lock must have been
|
|
|
|
created earlier. This function is not available when thread support
|
|
|
|
is disabled at compile time.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{void}{PyEval_AcquireThread}{PyThreadState *tstate}
|
2004-03-17 21:38:11 -04:00
|
|
|
Acquire the global interpreter lock and set the current thread
|
2001-10-12 16:01:43 -03:00
|
|
|
state to \var{tstate}, which should not be \NULL. The lock must
|
|
|
|
have been created earlier. If this thread already has the lock,
|
|
|
|
deadlock ensues. This function is not available when thread support
|
|
|
|
is disabled at compile time.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{void}{PyEval_ReleaseThread}{PyThreadState *tstate}
|
|
|
|
Reset the current thread state to \NULL{} and release the global
|
|
|
|
interpreter lock. The lock must have been created earlier and must
|
|
|
|
be held by the current thread. The \var{tstate} argument, which
|
|
|
|
must not be \NULL, is only used to check that it represents the
|
|
|
|
current thread state --- if it isn't, a fatal error is reported.
|
|
|
|
This function is not available when thread support is disabled at
|
|
|
|
compile time.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{PyThreadState*}{PyEval_SaveThread}{}
|
|
|
|
Release the interpreter lock (if it has been created and thread
|
|
|
|
support is enabled) and reset the thread state to \NULL, returning
|
|
|
|
the previous thread state (which is not \NULL). If the lock has
|
|
|
|
been created, the current thread must have acquired it. (This
|
|
|
|
function is available even when thread support is disabled at
|
|
|
|
compile time.)
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{void}{PyEval_RestoreThread}{PyThreadState *tstate}
|
|
|
|
Acquire the interpreter lock (if it has been created and thread
|
|
|
|
support is enabled) and set the thread state to \var{tstate}, which
|
|
|
|
must not be \NULL. If the lock has been created, the current thread
|
|
|
|
must not have acquired it, otherwise deadlock ensues. (This
|
|
|
|
function is available even when thread support is disabled at
|
|
|
|
compile time.)
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
The following macros are normally used without a trailing semicolon;
|
|
|
|
look for example usage in the Python source distribution.
|
|
|
|
|
|
|
|
\begin{csimplemacrodesc}{Py_BEGIN_ALLOW_THREADS}
|
|
|
|
This macro expands to
|
|
|
|
\samp{\{ PyThreadState *_save; _save = PyEval_SaveThread();}.
|
|
|
|
Note that it contains an opening brace; it must be matched with a
|
2002-04-09 18:09:42 -03:00
|
|
|
following \csimplemacro{Py_END_ALLOW_THREADS} macro. See above for
|
|
|
|
further discussion of this macro. It is a no-op when thread support
|
|
|
|
is disabled at compile time.
|
2001-10-12 16:01:43 -03:00
|
|
|
\end{csimplemacrodesc}
|
|
|
|
|
|
|
|
\begin{csimplemacrodesc}{Py_END_ALLOW_THREADS}
|
|
|
|
This macro expands to \samp{PyEval_RestoreThread(_save); \}}.
|
|
|
|
Note that it contains a closing brace; it must be matched with an
|
2002-04-09 18:09:42 -03:00
|
|
|
earlier \csimplemacro{Py_BEGIN_ALLOW_THREADS} macro. See above for
|
|
|
|
further discussion of this macro. It is a no-op when thread support
|
|
|
|
is disabled at compile time.
|
2001-10-12 16:01:43 -03:00
|
|
|
\end{csimplemacrodesc}
|
|
|
|
|
|
|
|
\begin{csimplemacrodesc}{Py_BLOCK_THREADS}
|
|
|
|
This macro expands to \samp{PyEval_RestoreThread(_save);}: it is
|
2002-04-09 18:09:42 -03:00
|
|
|
equivalent to \csimplemacro{Py_END_ALLOW_THREADS} without the
|
|
|
|
closing brace. It is a no-op when thread support is disabled at
|
|
|
|
compile time.
|
2001-10-12 16:01:43 -03:00
|
|
|
\end{csimplemacrodesc}
|
|
|
|
|
|
|
|
\begin{csimplemacrodesc}{Py_UNBLOCK_THREADS}
|
|
|
|
This macro expands to \samp{_save = PyEval_SaveThread();}: it is
|
2002-04-09 18:09:42 -03:00
|
|
|
equivalent to \csimplemacro{Py_BEGIN_ALLOW_THREADS} without the
|
|
|
|
opening brace and variable declaration. It is a no-op when thread
|
|
|
|
support is disabled at compile time.
|
2001-10-12 16:01:43 -03:00
|
|
|
\end{csimplemacrodesc}
|
|
|
|
|
|
|
|
All of the following functions are only available when thread support
|
|
|
|
is enabled at compile time, and must be called only when the
|
|
|
|
interpreter lock has been created.
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{PyInterpreterState*}{PyInterpreterState_New}{}
|
|
|
|
Create a new interpreter state object. The interpreter lock need
|
|
|
|
not be held, but may be held if it is necessary to serialize calls
|
|
|
|
to this function.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{void}{PyInterpreterState_Clear}{PyInterpreterState *interp}
|
|
|
|
Reset all information in an interpreter state object. The
|
|
|
|
interpreter lock must be held.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{void}{PyInterpreterState_Delete}{PyInterpreterState *interp}
|
|
|
|
Destroy an interpreter state object. The interpreter lock need not
|
|
|
|
be held. The interpreter state must have been reset with a previous
|
|
|
|
call to \cfunction{PyInterpreterState_Clear()}.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{PyThreadState*}{PyThreadState_New}{PyInterpreterState *interp}
|
|
|
|
Create a new thread state object belonging to the given interpreter
|
|
|
|
object. The interpreter lock need not be held, but may be held if
|
|
|
|
it is necessary to serialize calls to this function.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{void}{PyThreadState_Clear}{PyThreadState *tstate}
|
|
|
|
Reset all information in a thread state object. The interpreter lock
|
|
|
|
must be held.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{void}{PyThreadState_Delete}{PyThreadState *tstate}
|
|
|
|
Destroy a thread state object. The interpreter lock need not be
|
|
|
|
held. The thread state must have been reset with a previous call to
|
|
|
|
\cfunction{PyThreadState_Clear()}.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{PyThreadState*}{PyThreadState_Get}{}
|
|
|
|
Return the current thread state. The interpreter lock must be
|
|
|
|
held. When the current thread state is \NULL, this issues a fatal
|
|
|
|
error (so that the caller needn't check for \NULL).
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{PyThreadState*}{PyThreadState_Swap}{PyThreadState *tstate}
|
|
|
|
Swap the current thread state with the thread state given by the
|
|
|
|
argument \var{tstate}, which may be \NULL. The interpreter lock
|
|
|
|
must be held.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{PyObject*}{PyThreadState_GetDict}{}
|
|
|
|
Return a dictionary in which extensions can store thread-specific
|
|
|
|
state information. Each extension should use a unique key to use to
|
2003-04-15 12:12:39 -03:00
|
|
|
store state in the dictionary. It is okay to call this function
|
|
|
|
when no current thread state is available.
|
|
|
|
If this function returns \NULL, no exception has been raised and the
|
|
|
|
caller should assume no current thread state is available.
|
|
|
|
\versionchanged[Previously this could only be called when a current
|
2003-09-06 23:32:55 -03:00
|
|
|
thread is active, and \NULL{} meant that an exception was raised]{2.3}
|
2001-10-12 16:01:43 -03:00
|
|
|
\end{cfuncdesc}
|
|
|
|
|
2003-06-28 23:14:31 -03:00
|
|
|
\begin{cfuncdesc}{int}{PyThreadState_SetAsyncExc}{long id, PyObject *exc}
|
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
which unfortunately means the errors from the bytes type change somewhat:
bytes([300]) still raises a ValueError, but bytes([10**100]) now raises a
TypeError (either that, or bytes(1.0) also raises a ValueError --
PyNumber_AsSsize_t() can only raise one type of exception.)
Merged revisions 51188-51433 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r51189 | kurt.kaiser | 2006-08-10 19:11:09 +0200 (Thu, 10 Aug 2006) | 4 lines
Retrieval of previous shell command was not always preserving indentation
since 1.2a1) Patch 1528468 Tal Einat.
........
r51190 | guido.van.rossum | 2006-08-10 19:41:07 +0200 (Thu, 10 Aug 2006) | 3 lines
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
SF bug #1112549.
........
r51191 | guido.van.rossum | 2006-08-10 19:42:50 +0200 (Thu, 10 Aug 2006) | 2 lines
News item for SF bug 1112549.
........
r51192 | guido.van.rossum | 2006-08-10 20:09:25 +0200 (Thu, 10 Aug 2006) | 2 lines
Fix title -- it's rc1, not beta3.
........
r51194 | martin.v.loewis | 2006-08-10 21:04:00 +0200 (Thu, 10 Aug 2006) | 3 lines
Update dangling references to the 3.2 database to
mention that this is UCD 4.1 now.
........
r51195 | tim.peters | 2006-08-11 00:45:34 +0200 (Fri, 11 Aug 2006) | 6 lines
Followup to bug #1069160.
PyThreadState_SetAsyncExc(): internal correctness changes wrt
refcount safety and deadlock avoidance. Also added a basic test
case (relying on ctypes) and repaired the docs.
........
r51196 | tim.peters | 2006-08-11 00:48:45 +0200 (Fri, 11 Aug 2006) | 2 lines
Whitespace normalization.
........
r51197 | tim.peters | 2006-08-11 01:22:13 +0200 (Fri, 11 Aug 2006) | 5 lines
Whitespace normalization broke test_cgi, because a line
of quoted test data relied on preserving a single trailing
blank. Changed the string from raw to regular, and forced
in the trailing blank via an explicit \x20 escape.
........
r51198 | tim.peters | 2006-08-11 02:49:01 +0200 (Fri, 11 Aug 2006) | 10 lines
test_PyThreadState_SetAsyncExc(): This is failing on some
64-bit boxes. I have no idea what the ctypes docs mean
by "integers", and blind-guessing here that it intended to
mean the signed C "int" type, in which case perhaps I can
repair this by feeding the thread id argument to type
ctypes.c_long().
Also made the worker thread daemonic, so it doesn't hang
Python shutdown if the test continues to fail.
........
r51199 | tim.peters | 2006-08-11 05:49:10 +0200 (Fri, 11 Aug 2006) | 6 lines
force_test_exit(): This has been completely ineffective
at stopping test_signal from hanging forever on the Tru64
buildbot. That could be because there's no such thing as
signal.SIGALARM. Changed to the idiotic (but standard)
signal.SIGALRM instead, and added some more debug output.
........
r51202 | neal.norwitz | 2006-08-11 08:09:41 +0200 (Fri, 11 Aug 2006) | 6 lines
Fix the failures on cygwin (2006-08-10 fixed the actual locking issue).
The first hunk changes the colon to an ! like other Windows variants.
We need to always wait on the child so the lock gets released and
no other tests fail. This is the try/finally in the second hunk.
........
r51205 | georg.brandl | 2006-08-11 09:15:38 +0200 (Fri, 11 Aug 2006) | 3 lines
Add Chris McDonough (latest cgi.py patch)
........
r51206 | georg.brandl | 2006-08-11 09:26:10 +0200 (Fri, 11 Aug 2006) | 3 lines
logging's atexit hook now runs even if the rest of the module has
already been cleaned up.
........
r51212 | thomas.wouters | 2006-08-11 17:02:39 +0200 (Fri, 11 Aug 2006) | 4 lines
Add ignore of *.pyc and *.pyo to Lib/xml/etree/.
........
r51215 | thomas.heller | 2006-08-11 21:55:35 +0200 (Fri, 11 Aug 2006) | 7 lines
When a ctypes C callback function is called, zero out the result
storage before converting the result to C data. See the comment in
the code for details.
Provide a better context for errors when the conversion of a callback
function's result cannot be converted.
........
r51218 | neal.norwitz | 2006-08-12 03:43:40 +0200 (Sat, 12 Aug 2006) | 6 lines
Klocwork made another run and found a bunch more problems.
This is the first batch of fixes that should be easy to verify based on context.
This fixes problem numbers: 220 (ast), 323-324 (symtable),
321-322 (structseq), 215 (array), 210 (hotshot), 182 (codecs), 209 (etree).
........
r51219 | neal.norwitz | 2006-08-12 03:45:47 +0200 (Sat, 12 Aug 2006) | 9 lines
Even though _Py_Mangle() isn't truly public anyone can call it and
there was no verification that privateobj was a PyString. If it wasn't
a string, this could have allowed a NULL pointer to creep in below and crash.
I wonder if this should be PyString_CheckExact? Must identifiers be strings
or can they be subclasses?
Klocwork #275
........
r51220 | neal.norwitz | 2006-08-12 03:46:42 +0200 (Sat, 12 Aug 2006) | 5 lines
It's highly unlikely, though possible for PyEval_Get*() to return NULLs.
So be safe and do an XINCREF.
Klocwork # 221-222.
........
r51221 | neal.norwitz | 2006-08-12 03:47:59 +0200 (Sat, 12 Aug 2006) | 7 lines
This code is actually not used unless WITHOUT_COMPLEX is defined.
However, there was no error checking that PyFloat_FromDouble returned
a valid pointer. I believe this change is correct as it seemed
to follow other code in the area.
Klocwork # 292.
........
r51222 | neal.norwitz | 2006-08-12 03:49:12 +0200 (Sat, 12 Aug 2006) | 5 lines
Handle NULL nodes while parsing. I'm not entirely sure this is correct.
There might be something else that needs to be done to setup the error.
Klocwork #295.
........
r51223 | neal.norwitz | 2006-08-12 03:50:38 +0200 (Sat, 12 Aug 2006) | 6 lines
If _stat_float_times is false, we will try to INCREF ival which could be NULL.
Return early in that case. The caller checks for PyErr_Occurred so this
should be ok.
Klocwork #297
........
r51224 | neal.norwitz | 2006-08-12 03:51:12 +0200 (Sat, 12 Aug 2006) | 3 lines
Move the assert which checks for a NULL pointer first.
Klocwork #274.
........
r51225 | neal.norwitz | 2006-08-12 03:53:28 +0200 (Sat, 12 Aug 2006) | 5 lines
Try to handle a malloc failure. I'm not entirely sure this is correct.
There might be something else we need to do to handle the exception.
Klocwork # 212-213
........
r51226 | neal.norwitz | 2006-08-12 03:57:47 +0200 (Sat, 12 Aug 2006) | 6 lines
I'm not sure why this code allocates this string for the error message.
I think it would be better to always use snprintf and have the format
limit the size of the name appropriately (like %.200s).
Klocwork #340
........
r51227 | neal.norwitz | 2006-08-12 04:06:34 +0200 (Sat, 12 Aug 2006) | 3 lines
Check returned pointer is valid.
Klocwork #233
........
r51228 | neal.norwitz | 2006-08-12 04:12:30 +0200 (Sat, 12 Aug 2006) | 1 line
Whoops, how did that get in there. :-) Revert all the parts of 51227 that were not supposed to go it. Only Modules/_ctypes/cfields.c was supposed to be changed
........
r51229 | neal.norwitz | 2006-08-12 04:33:36 +0200 (Sat, 12 Aug 2006) | 4 lines
Don't deref v if it's NULL.
Klocwork #214
........
r51230 | neal.norwitz | 2006-08-12 05:16:54 +0200 (Sat, 12 Aug 2006) | 5 lines
Check return of PyMem_MALLOC (garbage) is non-NULL.
Check seq in both portions of if/else.
Klocwork #289-290.
........
r51231 | neal.norwitz | 2006-08-12 05:17:41 +0200 (Sat, 12 Aug 2006) | 4 lines
PyModule_GetDict() can fail, produce fatal errors if this happens on startup.
Klocwork #298-299.
........
r51232 | neal.norwitz | 2006-08-12 05:18:50 +0200 (Sat, 12 Aug 2006) | 5 lines
Verify verdat which is returned from malloc is not NULL.
Ensure we don't pass NULL to free.
Klocwork #306 (at least the first part, checking malloc)
........
r51233 | tim.peters | 2006-08-12 06:42:47 +0200 (Sat, 12 Aug 2006) | 35 lines
test_signal: Signal handling on the Tru64 buildbot
appears to be utterly insane. Plug some theoretical
insecurities in the test script:
- Verify that the SIGALRM handler was actually installed.
- Don't call alarm() before the handler is installed.
- Move everything that can fail inside the try/finally,
so the test cleans up after itself more often.
- Try sending all the expected signals in
force_test_exit(), not just SIGALRM. Since that was
fixed to actually send SIGALRM (instead of invisibly
dying with an AttributeError), we've seen that sending
SIGALRM alone does not stop this from hanging.
- Move the "kill the child" business into the finally
clause, so the child doesn't survive test failure
to send SIGALRM to other tests later (there are also
baffling SIGALRM-related failures in test_socket).
- Cancel the alarm in the finally clause -- if the
test dies early, we again don't want SIGALRM showing
up to confuse a later test.
Alas, this still relies on timing luck wrt the spawned
script that sends the test signals, but it's hard to see
how waiting for seconds can so often be so unlucky.
test_threadedsignals: curiously, this test never fails
on Tru64, but doesn't normally signal SIGALRM. Anyway,
fixed an obvious (but probably inconsequential) logic
error.
........
r51234 | tim.peters | 2006-08-12 07:17:41 +0200 (Sat, 12 Aug 2006) | 8 lines
Ah, fudge. One of the prints here actually "shouldn't be"
protected by "if verbose:", which caused the test to fail on
all non-Windows boxes.
Note that I deliberately didn't convert this to unittest yet,
because I expect it would be even harder to debug this on Tru64
after conversion.
........
r51235 | georg.brandl | 2006-08-12 10:32:02 +0200 (Sat, 12 Aug 2006) | 3 lines
Repair logging test spew caused by rev. 51206.
........
r51236 | neal.norwitz | 2006-08-12 19:03:09 +0200 (Sat, 12 Aug 2006) | 8 lines
Patch #1538606, Patch to fix __index__() clipping.
I modified this patch some by fixing style, some error checking, and adding
XXX comments. This patch requires review and some changes are to be expected.
I'm checking in now to get the greatest possible review and establish a
baseline for moving forward. I don't want this to hold up release if possible.
........
r51238 | neal.norwitz | 2006-08-12 20:44:06 +0200 (Sat, 12 Aug 2006) | 10 lines
Fix a couple of bugs exposed by the new __index__ code. The 64-bit buildbots
were failing due to inappropriate clipping of numbers larger than 2**31
with new-style classes. (typeobject.c) In reviewing the code for classic
classes, there were 2 problems. Any negative value return could be returned.
Always return -1 if there was an error. Also make the checks similar
with the new-style classes. I believe this is correct for 32 and 64 bit
boxes, including Windows64.
Add a test of classic classes too.
........
r51240 | neal.norwitz | 2006-08-13 02:20:49 +0200 (Sun, 13 Aug 2006) | 1 line
SF bug #1539336, distutils example code missing
........
r51245 | neal.norwitz | 2006-08-13 20:10:10 +0200 (Sun, 13 Aug 2006) | 6 lines
Move/copy assert for tstate != NULL before first use.
Verify that PyEval_Get{Globals,Locals} returned valid pointers.
Klocwork 231-232
........
r51246 | neal.norwitz | 2006-08-13 20:10:28 +0200 (Sun, 13 Aug 2006) | 5 lines
Handle a whole lot of failures from PyString_FromInternedString().
Should fix most of Klocwork 234-272.
........
r51247 | neal.norwitz | 2006-08-13 20:10:47 +0200 (Sun, 13 Aug 2006) | 8 lines
cpathname could be NULL if it was longer than MAXPATHLEN. Don't try
to write the .pyc to NULL.
Check results of PyList_GetItem() and PyModule_GetDict() are not NULL.
Klocwork 282, 283, 285
........
r51248 | neal.norwitz | 2006-08-13 20:11:08 +0200 (Sun, 13 Aug 2006) | 6 lines
Fix segfault when doing string formatting on subclasses of long if
__oct__, __hex__ don't return a string.
Klocwork 308
........
r51250 | neal.norwitz | 2006-08-13 20:11:27 +0200 (Sun, 13 Aug 2006) | 5 lines
Check return result of PyModule_GetDict().
Fix a bunch of refleaks in the init of the module. This would only be found
when running python -v.
........
r51251 | neal.norwitz | 2006-08-13 20:11:43 +0200 (Sun, 13 Aug 2006) | 5 lines
Handle malloc and fopen failures more gracefully.
Klocwork 180-181
........
r51252 | neal.norwitz | 2006-08-13 20:12:03 +0200 (Sun, 13 Aug 2006) | 7 lines
It's very unlikely, though possible that source is not a string. Verify
that PyString_AsString() returns a valid pointer. (The problem can
arise when zlib.decompress doesn't return a string.)
Klocwork 346
........
r51253 | neal.norwitz | 2006-08-13 20:12:26 +0200 (Sun, 13 Aug 2006) | 5 lines
Handle failures from lookup.
Klocwork 341-342
........
r51254 | neal.norwitz | 2006-08-13 20:12:45 +0200 (Sun, 13 Aug 2006) | 6 lines
Handle failure from PyModule_GetDict() (Klocwork 208).
Fix a bunch of refleaks in the init of the module. This would only be found
when running python -v.
........
r51255 | neal.norwitz | 2006-08-13 20:13:02 +0200 (Sun, 13 Aug 2006) | 4 lines
Really address the issue of where to place the assert for leftblock.
(Followup of Klocwork 274)
........
r51256 | neal.norwitz | 2006-08-13 20:13:36 +0200 (Sun, 13 Aug 2006) | 4 lines
Handle malloc failure.
Klocwork 281
........
r51258 | neal.norwitz | 2006-08-13 20:40:39 +0200 (Sun, 13 Aug 2006) | 4 lines
Handle alloca failures.
Klocwork 225-228
........
r51259 | neal.norwitz | 2006-08-13 20:41:15 +0200 (Sun, 13 Aug 2006) | 1 line
Get rid of compiler warning
........
r51261 | neal.norwitz | 2006-08-14 02:51:15 +0200 (Mon, 14 Aug 2006) | 1 line
Ignore pgen.exe and kill_python.exe for cygwin
........
r51262 | neal.norwitz | 2006-08-14 02:59:03 +0200 (Mon, 14 Aug 2006) | 4 lines
Can't return NULL from a void function. If there is a memory error,
about the best we can do is call PyErr_WriteUnraisable and go on.
We won't be able to do the call below either, so verify delstr is valid.
........
r51263 | neal.norwitz | 2006-08-14 03:49:54 +0200 (Mon, 14 Aug 2006) | 1 line
Update purify doc some.
........
r51264 | thomas.heller | 2006-08-14 09:13:05 +0200 (Mon, 14 Aug 2006) | 2 lines
Remove unused, buggy test function.
Fixes klockwork issue #207.
........
r51265 | thomas.heller | 2006-08-14 09:14:09 +0200 (Mon, 14 Aug 2006) | 2 lines
Check for NULL return value from new_CArgObject().
Fixes klockwork issues #183, #184, #185.
........
r51266 | thomas.heller | 2006-08-14 09:50:14 +0200 (Mon, 14 Aug 2006) | 2 lines
Check for NULL return value of GenericCData_new().
Fixes klockwork issues #188, #189.
........
r51274 | thomas.heller | 2006-08-14 12:02:24 +0200 (Mon, 14 Aug 2006) | 2 lines
Revert the change that tries to zero out a closure's result storage
area because the size if unknown in source/callproc.c.
........
r51276 | marc-andre.lemburg | 2006-08-14 12:55:19 +0200 (Mon, 14 Aug 2006) | 11 lines
Slightly revised version of patch #1538956:
Replace UnicodeDecodeErrors raised during == and !=
compares of Unicode and other objects with a new
UnicodeWarning.
All other comparisons continue to raise exceptions.
Exceptions other than UnicodeDecodeErrors are also left
untouched.
........
r51277 | thomas.heller | 2006-08-14 13:17:48 +0200 (Mon, 14 Aug 2006) | 13 lines
Apply the patch #1532975 plus ideas from the patch #1533481.
ctypes instances no longer have the internal and undocumented
'_as_parameter_' attribute which was used to adapt them to foreign
function calls; this mechanism is replaced by a function pointer in
the type's stgdict.
In the 'from_param' class methods, try the _as_parameter_ attribute if
other conversions are not possible.
This makes the documented _as_parameter_ mechanism work as intended.
Change the ctypes version number to 1.0.1.
........
r51278 | marc-andre.lemburg | 2006-08-14 13:44:34 +0200 (Mon, 14 Aug 2006) | 3 lines
Readd NEWS items that were accidentally removed by r51276.
........
r51279 | georg.brandl | 2006-08-14 14:36:06 +0200 (Mon, 14 Aug 2006) | 3 lines
Improve markup in PyUnicode_RichCompare.
........
r51280 | marc-andre.lemburg | 2006-08-14 14:57:27 +0200 (Mon, 14 Aug 2006) | 3 lines
Correct an accidentally removed previous patch.
........
r51281 | thomas.heller | 2006-08-14 18:17:41 +0200 (Mon, 14 Aug 2006) | 3 lines
Patch #1536908: Add support for AMD64 / OpenBSD.
Remove the -no-stack-protector compiler flag for OpenBSD
as it has been reported to be unneeded.
........
r51282 | thomas.heller | 2006-08-14 18:20:04 +0200 (Mon, 14 Aug 2006) | 1 line
News item for rev 51281.
........
r51283 | georg.brandl | 2006-08-14 22:25:39 +0200 (Mon, 14 Aug 2006) | 3 lines
Fix refleak introduced in rev. 51248.
........
r51284 | georg.brandl | 2006-08-14 23:34:08 +0200 (Mon, 14 Aug 2006) | 5 lines
Make tabnanny recognize IndentationErrors raised by tokenize.
Add a test to test_inspect to make sure indented source
is recognized correctly. (fixes #1224621)
........
r51285 | georg.brandl | 2006-08-14 23:42:55 +0200 (Mon, 14 Aug 2006) | 3 lines
Patch #1535500: fix segfault in BZ2File.writelines and make sure it
raises the correct exceptions.
........
r51287 | georg.brandl | 2006-08-14 23:45:32 +0200 (Mon, 14 Aug 2006) | 3 lines
Add an additional test: BZ2File write methods should raise IOError
when file is read-only.
........
r51289 | georg.brandl | 2006-08-14 23:55:28 +0200 (Mon, 14 Aug 2006) | 3 lines
Patch #1536071: trace.py should now find the full module name of a
file correctly even on Windows.
........
r51290 | georg.brandl | 2006-08-15 00:01:24 +0200 (Tue, 15 Aug 2006) | 3 lines
Cookie.py shouldn't "bogusly" use string._idmap.
........
r51291 | georg.brandl | 2006-08-15 00:10:24 +0200 (Tue, 15 Aug 2006) | 3 lines
Patch #1511317: don't crash on invalid hostname info
........
r51292 | tim.peters | 2006-08-15 02:25:04 +0200 (Tue, 15 Aug 2006) | 2 lines
Whitespace normalization.
........
r51293 | neal.norwitz | 2006-08-15 06:14:57 +0200 (Tue, 15 Aug 2006) | 3 lines
Georg fixed one of my bugs, so I'll repay him with 2 NEWS entries.
Now we're even. :-)
........
r51295 | neal.norwitz | 2006-08-15 06:58:28 +0200 (Tue, 15 Aug 2006) | 8 lines
Fix the test for SocketServer so it should pass on cygwin and not fail
sporadically on other platforms. This is really a band-aid that doesn't
fix the underlying issue in SocketServer. It's not clear if it's worth
it to fix SocketServer, however, I opened a bug to track it:
http://python.org/sf/1540386
........
r51296 | neal.norwitz | 2006-08-15 06:59:30 +0200 (Tue, 15 Aug 2006) | 3 lines
Update the docstring to use a version a little newer than 1999. This was
taken from a Debian patch. Should we update the version for each release?
........
r51298 | neal.norwitz | 2006-08-15 08:29:03 +0200 (Tue, 15 Aug 2006) | 2 lines
Subclasses of int/long are allowed to define an __index__.
........
r51300 | thomas.heller | 2006-08-15 15:07:21 +0200 (Tue, 15 Aug 2006) | 1 line
Check for NULL return value from new_CArgObject calls.
........
r51303 | kurt.kaiser | 2006-08-16 05:15:26 +0200 (Wed, 16 Aug 2006) | 2 lines
The 'with' statement is now a Code Context block opener
........
r51304 | anthony.baxter | 2006-08-16 05:42:26 +0200 (Wed, 16 Aug 2006) | 1 line
preparing for 2.5c1
........
r51305 | anthony.baxter | 2006-08-16 05:58:37 +0200 (Wed, 16 Aug 2006) | 1 line
preparing for 2.5c1 - no, really this time
........
r51306 | kurt.kaiser | 2006-08-16 07:01:42 +0200 (Wed, 16 Aug 2006) | 9 lines
Patch #1540892: site.py Quitter() class attempts to close sys.stdin
before raising SystemExit, allowing IDLE to honor quit() and exit().
M Lib/site.py
M Lib/idlelib/PyShell.py
M Lib/idlelib/CREDITS.txt
M Lib/idlelib/NEWS.txt
M Misc/NEWS
........
r51307 | ka-ping.yee | 2006-08-16 09:02:50 +0200 (Wed, 16 Aug 2006) | 6 lines
Update code and tests to support the 'bytes_le' attribute (for
little-endian byte order on Windows), and to work around clocks
with low resolution yielding duplicate UUIDs.
Anthony Baxter has approved this change.
........
r51308 | kurt.kaiser | 2006-08-16 09:04:17 +0200 (Wed, 16 Aug 2006) | 2 lines
Get quit() and exit() to work cleanly when not using subprocess.
........
r51309 | marc-andre.lemburg | 2006-08-16 10:13:26 +0200 (Wed, 16 Aug 2006) | 2 lines
Revert to having static version numbers again.
........
r51310 | martin.v.loewis | 2006-08-16 14:55:10 +0200 (Wed, 16 Aug 2006) | 2 lines
Build _hashlib on Windows. Build OpenSSL with masm assembler code.
Fixes #1535502.
........
r51311 | thomas.heller | 2006-08-16 15:03:11 +0200 (Wed, 16 Aug 2006) | 6 lines
Add commented assert statements to check that the result of
PyObject_stgdict() and PyType_stgdict() calls are non-NULL before
dereferencing the result. Hopefully this fixes what klocwork is
complaining about.
Fix a few other nits as well.
........
r51312 | anthony.baxter | 2006-08-16 15:08:25 +0200 (Wed, 16 Aug 2006) | 1 line
news entry for 51307
........
r51313 | andrew.kuchling | 2006-08-16 15:22:20 +0200 (Wed, 16 Aug 2006) | 1 line
Add UnicodeWarning
........
r51314 | andrew.kuchling | 2006-08-16 15:41:52 +0200 (Wed, 16 Aug 2006) | 1 line
Bump document version to 1.0; remove pystone paragraph
........
r51315 | andrew.kuchling | 2006-08-16 15:51:32 +0200 (Wed, 16 Aug 2006) | 1 line
Link to docs; remove an XXX comment
........
r51316 | martin.v.loewis | 2006-08-16 15:58:51 +0200 (Wed, 16 Aug 2006) | 1 line
Make cl build step compile-only (/c). Remove libs from source list.
........
r51317 | thomas.heller | 2006-08-16 16:07:44 +0200 (Wed, 16 Aug 2006) | 5 lines
The __repr__ method of a NULL py_object does no longer raise an
exception. Remove a stray '?' character from the exception text
when the value is retrieved of such an object.
Includes tests.
........
r51318 | andrew.kuchling | 2006-08-16 16:18:23 +0200 (Wed, 16 Aug 2006) | 1 line
Update bug/patch counts
........
r51319 | andrew.kuchling | 2006-08-16 16:21:14 +0200 (Wed, 16 Aug 2006) | 1 line
Wording/typo fixes
........
r51320 | thomas.heller | 2006-08-16 17:10:12 +0200 (Wed, 16 Aug 2006) | 9 lines
Remove the special casing of Py_None when converting the return value
of the Python part of a callback function to C. If it cannot be
converted, call PyErr_WriteUnraisable with the exception we got.
Before, arbitrary data has been passed to the calling C code in this
case.
(I'm not really sure the NEWS entry is understandable, but I cannot
find better words)
........
r51321 | marc-andre.lemburg | 2006-08-16 18:11:01 +0200 (Wed, 16 Aug 2006) | 2 lines
Add NEWS item mentioning the reverted distutils version number patch.
........
r51322 | fredrik.lundh | 2006-08-16 18:47:07 +0200 (Wed, 16 Aug 2006) | 5 lines
SF#1534630
ignore data that arrives before the opening start tag
........
r51324 | andrew.kuchling | 2006-08-16 19:11:18 +0200 (Wed, 16 Aug 2006) | 1 line
Grammar fix
........
r51328 | thomas.heller | 2006-08-16 20:02:11 +0200 (Wed, 16 Aug 2006) | 12 lines
Tutorial:
Clarify somewhat how parameters are passed to functions
(especially explain what integer means).
Correct the table - Python integers and longs can both be used.
Further clarification to the table comparing ctypes types, Python
types, and C types.
Reference:
Replace integer by C ``int`` where it makes sense.
........
r51329 | kurt.kaiser | 2006-08-16 23:45:59 +0200 (Wed, 16 Aug 2006) | 8 lines
File menu hotkeys: there were three 'p' assignments. Reassign the
'Save Copy As' and 'Print' hotkeys to 'y' and 't'. Change the
Shell menu hotkey from 's' to 'l'.
M Bindings.py
M PyShell.py
M NEWS.txt
........
r51330 | neil.schemenauer | 2006-08-17 01:38:05 +0200 (Thu, 17 Aug 2006) | 3 lines
Fix a bug in the ``compiler`` package that caused invalid code to be
generated for generator expressions.
........
r51342 | martin.v.loewis | 2006-08-17 21:19:32 +0200 (Thu, 17 Aug 2006) | 3 lines
Merge 51340 and 51341 from 2.5 branch:
Leave tk build directory to restore original path.
Invoke debug mk1mf.pl after running Configure.
........
r51354 | martin.v.loewis | 2006-08-18 05:47:18 +0200 (Fri, 18 Aug 2006) | 3 lines
Bug #1541863: uuid.uuid1 failed to generate unique identifiers
on systems with low clock resolution.
........
r51355 | neal.norwitz | 2006-08-18 05:57:54 +0200 (Fri, 18 Aug 2006) | 1 line
Add template for 2.6 on HEAD
........
r51356 | neal.norwitz | 2006-08-18 06:01:38 +0200 (Fri, 18 Aug 2006) | 1 line
More post-release wibble
........
r51357 | neal.norwitz | 2006-08-18 06:58:33 +0200 (Fri, 18 Aug 2006) | 1 line
Try to get Windows bots working again
........
r51358 | neal.norwitz | 2006-08-18 07:10:00 +0200 (Fri, 18 Aug 2006) | 1 line
Try to get Windows bots working again. Take 2
........
r51359 | neal.norwitz | 2006-08-18 07:39:20 +0200 (Fri, 18 Aug 2006) | 1 line
Try to get Unix bots install working again.
........
r51360 | neal.norwitz | 2006-08-18 07:41:46 +0200 (Fri, 18 Aug 2006) | 1 line
Set version to 2.6a0, seems more consistent.
........
r51362 | neal.norwitz | 2006-08-18 08:14:52 +0200 (Fri, 18 Aug 2006) | 1 line
More version wibble
........
r51364 | georg.brandl | 2006-08-18 09:27:59 +0200 (Fri, 18 Aug 2006) | 4 lines
Bug #1541682: Fix example in the "Refcount details" API docs.
Additionally, remove a faulty example showing PySequence_SetItem applied
to a newly created list object and add notes that this isn't a good idea.
........
r51366 | anthony.baxter | 2006-08-18 09:29:02 +0200 (Fri, 18 Aug 2006) | 3 lines
Updating IDLE's version number to match Python's (as per python-dev
discussion).
........
r51367 | anthony.baxter | 2006-08-18 09:30:07 +0200 (Fri, 18 Aug 2006) | 1 line
RPM specfile updates
........
r51368 | georg.brandl | 2006-08-18 09:35:47 +0200 (Fri, 18 Aug 2006) | 2 lines
Typo in tp_clear docs.
........
r51378 | andrew.kuchling | 2006-08-18 15:57:13 +0200 (Fri, 18 Aug 2006) | 1 line
Minor edits
........
r51379 | thomas.heller | 2006-08-18 16:38:46 +0200 (Fri, 18 Aug 2006) | 6 lines
Add asserts to check for 'impossible' NULL values, with comments.
In one place where I'n not 1000% sure about the non-NULL, raise
a RuntimeError for safety.
This should fix the klocwork issues that Neal sent me. If so,
it should be applied to the release25-maint branch also.
........
r51400 | neal.norwitz | 2006-08-19 06:22:33 +0200 (Sat, 19 Aug 2006) | 5 lines
Move initialization of interned strings to before allocating the
object so we don't leak op. (Fixes an earlier patch to this code)
Klockwork #350
........
r51401 | neal.norwitz | 2006-08-19 06:23:04 +0200 (Sat, 19 Aug 2006) | 4 lines
Move assert to after NULL check, otherwise we deref NULL in the assert.
Klocwork #307
........
r51402 | neal.norwitz | 2006-08-19 06:25:29 +0200 (Sat, 19 Aug 2006) | 2 lines
SF #1542693: Remove semi-colon at end of PyImport_ImportModuleEx macro
........
r51403 | neal.norwitz | 2006-08-19 06:28:55 +0200 (Sat, 19 Aug 2006) | 6 lines
Move initialization to after the asserts for non-NULL values.
Klocwork 286-287.
(I'm not backporting this, but if someone wants to, feel free.)
........
r51404 | neal.norwitz | 2006-08-19 06:52:03 +0200 (Sat, 19 Aug 2006) | 6 lines
Handle PyString_FromInternedString() failing (unlikely, but possible).
Klocwork #325
(I'm not backporting this, but if someone wants to, feel free.)
........
r51416 | georg.brandl | 2006-08-20 15:15:39 +0200 (Sun, 20 Aug 2006) | 2 lines
Patch #1542948: fix urllib2 header casing issue. With new test.
........
r51428 | jeremy.hylton | 2006-08-21 18:19:37 +0200 (Mon, 21 Aug 2006) | 3 lines
Move peephole optimizer to separate file.
........
r51429 | jeremy.hylton | 2006-08-21 18:20:29 +0200 (Mon, 21 Aug 2006) | 2 lines
Move peephole optimizer to separate file. (Forgot .h in previous checkin.)
........
r51432 | neal.norwitz | 2006-08-21 19:59:46 +0200 (Mon, 21 Aug 2006) | 5 lines
Fix bug #1543303, tarfile adds padding that breaks gunzip.
Patch # 1543897.
Will backport to 2.5
........
r51433 | neal.norwitz | 2006-08-21 20:01:30 +0200 (Mon, 21 Aug 2006) | 2 lines
Add assert to make Klocwork happy (#276)
........
2006-08-21 16:07:27 -03:00
|
|
|
Asynchronously raise an exception in a thread.
|
2003-06-28 23:14:31 -03:00
|
|
|
The \var{id} argument is the thread id of the target thread;
|
|
|
|
\var{exc} is the exception object to be raised.
|
|
|
|
This function does not steal any references to \var{exc}.
|
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
which unfortunately means the errors from the bytes type change somewhat:
bytes([300]) still raises a ValueError, but bytes([10**100]) now raises a
TypeError (either that, or bytes(1.0) also raises a ValueError --
PyNumber_AsSsize_t() can only raise one type of exception.)
Merged revisions 51188-51433 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r51189 | kurt.kaiser | 2006-08-10 19:11:09 +0200 (Thu, 10 Aug 2006) | 4 lines
Retrieval of previous shell command was not always preserving indentation
since 1.2a1) Patch 1528468 Tal Einat.
........
r51190 | guido.van.rossum | 2006-08-10 19:41:07 +0200 (Thu, 10 Aug 2006) | 3 lines
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
SF bug #1112549.
........
r51191 | guido.van.rossum | 2006-08-10 19:42:50 +0200 (Thu, 10 Aug 2006) | 2 lines
News item for SF bug 1112549.
........
r51192 | guido.van.rossum | 2006-08-10 20:09:25 +0200 (Thu, 10 Aug 2006) | 2 lines
Fix title -- it's rc1, not beta3.
........
r51194 | martin.v.loewis | 2006-08-10 21:04:00 +0200 (Thu, 10 Aug 2006) | 3 lines
Update dangling references to the 3.2 database to
mention that this is UCD 4.1 now.
........
r51195 | tim.peters | 2006-08-11 00:45:34 +0200 (Fri, 11 Aug 2006) | 6 lines
Followup to bug #1069160.
PyThreadState_SetAsyncExc(): internal correctness changes wrt
refcount safety and deadlock avoidance. Also added a basic test
case (relying on ctypes) and repaired the docs.
........
r51196 | tim.peters | 2006-08-11 00:48:45 +0200 (Fri, 11 Aug 2006) | 2 lines
Whitespace normalization.
........
r51197 | tim.peters | 2006-08-11 01:22:13 +0200 (Fri, 11 Aug 2006) | 5 lines
Whitespace normalization broke test_cgi, because a line
of quoted test data relied on preserving a single trailing
blank. Changed the string from raw to regular, and forced
in the trailing blank via an explicit \x20 escape.
........
r51198 | tim.peters | 2006-08-11 02:49:01 +0200 (Fri, 11 Aug 2006) | 10 lines
test_PyThreadState_SetAsyncExc(): This is failing on some
64-bit boxes. I have no idea what the ctypes docs mean
by "integers", and blind-guessing here that it intended to
mean the signed C "int" type, in which case perhaps I can
repair this by feeding the thread id argument to type
ctypes.c_long().
Also made the worker thread daemonic, so it doesn't hang
Python shutdown if the test continues to fail.
........
r51199 | tim.peters | 2006-08-11 05:49:10 +0200 (Fri, 11 Aug 2006) | 6 lines
force_test_exit(): This has been completely ineffective
at stopping test_signal from hanging forever on the Tru64
buildbot. That could be because there's no such thing as
signal.SIGALARM. Changed to the idiotic (but standard)
signal.SIGALRM instead, and added some more debug output.
........
r51202 | neal.norwitz | 2006-08-11 08:09:41 +0200 (Fri, 11 Aug 2006) | 6 lines
Fix the failures on cygwin (2006-08-10 fixed the actual locking issue).
The first hunk changes the colon to an ! like other Windows variants.
We need to always wait on the child so the lock gets released and
no other tests fail. This is the try/finally in the second hunk.
........
r51205 | georg.brandl | 2006-08-11 09:15:38 +0200 (Fri, 11 Aug 2006) | 3 lines
Add Chris McDonough (latest cgi.py patch)
........
r51206 | georg.brandl | 2006-08-11 09:26:10 +0200 (Fri, 11 Aug 2006) | 3 lines
logging's atexit hook now runs even if the rest of the module has
already been cleaned up.
........
r51212 | thomas.wouters | 2006-08-11 17:02:39 +0200 (Fri, 11 Aug 2006) | 4 lines
Add ignore of *.pyc and *.pyo to Lib/xml/etree/.
........
r51215 | thomas.heller | 2006-08-11 21:55:35 +0200 (Fri, 11 Aug 2006) | 7 lines
When a ctypes C callback function is called, zero out the result
storage before converting the result to C data. See the comment in
the code for details.
Provide a better context for errors when the conversion of a callback
function's result cannot be converted.
........
r51218 | neal.norwitz | 2006-08-12 03:43:40 +0200 (Sat, 12 Aug 2006) | 6 lines
Klocwork made another run and found a bunch more problems.
This is the first batch of fixes that should be easy to verify based on context.
This fixes problem numbers: 220 (ast), 323-324 (symtable),
321-322 (structseq), 215 (array), 210 (hotshot), 182 (codecs), 209 (etree).
........
r51219 | neal.norwitz | 2006-08-12 03:45:47 +0200 (Sat, 12 Aug 2006) | 9 lines
Even though _Py_Mangle() isn't truly public anyone can call it and
there was no verification that privateobj was a PyString. If it wasn't
a string, this could have allowed a NULL pointer to creep in below and crash.
I wonder if this should be PyString_CheckExact? Must identifiers be strings
or can they be subclasses?
Klocwork #275
........
r51220 | neal.norwitz | 2006-08-12 03:46:42 +0200 (Sat, 12 Aug 2006) | 5 lines
It's highly unlikely, though possible for PyEval_Get*() to return NULLs.
So be safe and do an XINCREF.
Klocwork # 221-222.
........
r51221 | neal.norwitz | 2006-08-12 03:47:59 +0200 (Sat, 12 Aug 2006) | 7 lines
This code is actually not used unless WITHOUT_COMPLEX is defined.
However, there was no error checking that PyFloat_FromDouble returned
a valid pointer. I believe this change is correct as it seemed
to follow other code in the area.
Klocwork # 292.
........
r51222 | neal.norwitz | 2006-08-12 03:49:12 +0200 (Sat, 12 Aug 2006) | 5 lines
Handle NULL nodes while parsing. I'm not entirely sure this is correct.
There might be something else that needs to be done to setup the error.
Klocwork #295.
........
r51223 | neal.norwitz | 2006-08-12 03:50:38 +0200 (Sat, 12 Aug 2006) | 6 lines
If _stat_float_times is false, we will try to INCREF ival which could be NULL.
Return early in that case. The caller checks for PyErr_Occurred so this
should be ok.
Klocwork #297
........
r51224 | neal.norwitz | 2006-08-12 03:51:12 +0200 (Sat, 12 Aug 2006) | 3 lines
Move the assert which checks for a NULL pointer first.
Klocwork #274.
........
r51225 | neal.norwitz | 2006-08-12 03:53:28 +0200 (Sat, 12 Aug 2006) | 5 lines
Try to handle a malloc failure. I'm not entirely sure this is correct.
There might be something else we need to do to handle the exception.
Klocwork # 212-213
........
r51226 | neal.norwitz | 2006-08-12 03:57:47 +0200 (Sat, 12 Aug 2006) | 6 lines
I'm not sure why this code allocates this string for the error message.
I think it would be better to always use snprintf and have the format
limit the size of the name appropriately (like %.200s).
Klocwork #340
........
r51227 | neal.norwitz | 2006-08-12 04:06:34 +0200 (Sat, 12 Aug 2006) | 3 lines
Check returned pointer is valid.
Klocwork #233
........
r51228 | neal.norwitz | 2006-08-12 04:12:30 +0200 (Sat, 12 Aug 2006) | 1 line
Whoops, how did that get in there. :-) Revert all the parts of 51227 that were not supposed to go it. Only Modules/_ctypes/cfields.c was supposed to be changed
........
r51229 | neal.norwitz | 2006-08-12 04:33:36 +0200 (Sat, 12 Aug 2006) | 4 lines
Don't deref v if it's NULL.
Klocwork #214
........
r51230 | neal.norwitz | 2006-08-12 05:16:54 +0200 (Sat, 12 Aug 2006) | 5 lines
Check return of PyMem_MALLOC (garbage) is non-NULL.
Check seq in both portions of if/else.
Klocwork #289-290.
........
r51231 | neal.norwitz | 2006-08-12 05:17:41 +0200 (Sat, 12 Aug 2006) | 4 lines
PyModule_GetDict() can fail, produce fatal errors if this happens on startup.
Klocwork #298-299.
........
r51232 | neal.norwitz | 2006-08-12 05:18:50 +0200 (Sat, 12 Aug 2006) | 5 lines
Verify verdat which is returned from malloc is not NULL.
Ensure we don't pass NULL to free.
Klocwork #306 (at least the first part, checking malloc)
........
r51233 | tim.peters | 2006-08-12 06:42:47 +0200 (Sat, 12 Aug 2006) | 35 lines
test_signal: Signal handling on the Tru64 buildbot
appears to be utterly insane. Plug some theoretical
insecurities in the test script:
- Verify that the SIGALRM handler was actually installed.
- Don't call alarm() before the handler is installed.
- Move everything that can fail inside the try/finally,
so the test cleans up after itself more often.
- Try sending all the expected signals in
force_test_exit(), not just SIGALRM. Since that was
fixed to actually send SIGALRM (instead of invisibly
dying with an AttributeError), we've seen that sending
SIGALRM alone does not stop this from hanging.
- Move the "kill the child" business into the finally
clause, so the child doesn't survive test failure
to send SIGALRM to other tests later (there are also
baffling SIGALRM-related failures in test_socket).
- Cancel the alarm in the finally clause -- if the
test dies early, we again don't want SIGALRM showing
up to confuse a later test.
Alas, this still relies on timing luck wrt the spawned
script that sends the test signals, but it's hard to see
how waiting for seconds can so often be so unlucky.
test_threadedsignals: curiously, this test never fails
on Tru64, but doesn't normally signal SIGALRM. Anyway,
fixed an obvious (but probably inconsequential) logic
error.
........
r51234 | tim.peters | 2006-08-12 07:17:41 +0200 (Sat, 12 Aug 2006) | 8 lines
Ah, fudge. One of the prints here actually "shouldn't be"
protected by "if verbose:", which caused the test to fail on
all non-Windows boxes.
Note that I deliberately didn't convert this to unittest yet,
because I expect it would be even harder to debug this on Tru64
after conversion.
........
r51235 | georg.brandl | 2006-08-12 10:32:02 +0200 (Sat, 12 Aug 2006) | 3 lines
Repair logging test spew caused by rev. 51206.
........
r51236 | neal.norwitz | 2006-08-12 19:03:09 +0200 (Sat, 12 Aug 2006) | 8 lines
Patch #1538606, Patch to fix __index__() clipping.
I modified this patch some by fixing style, some error checking, and adding
XXX comments. This patch requires review and some changes are to be expected.
I'm checking in now to get the greatest possible review and establish a
baseline for moving forward. I don't want this to hold up release if possible.
........
r51238 | neal.norwitz | 2006-08-12 20:44:06 +0200 (Sat, 12 Aug 2006) | 10 lines
Fix a couple of bugs exposed by the new __index__ code. The 64-bit buildbots
were failing due to inappropriate clipping of numbers larger than 2**31
with new-style classes. (typeobject.c) In reviewing the code for classic
classes, there were 2 problems. Any negative value return could be returned.
Always return -1 if there was an error. Also make the checks similar
with the new-style classes. I believe this is correct for 32 and 64 bit
boxes, including Windows64.
Add a test of classic classes too.
........
r51240 | neal.norwitz | 2006-08-13 02:20:49 +0200 (Sun, 13 Aug 2006) | 1 line
SF bug #1539336, distutils example code missing
........
r51245 | neal.norwitz | 2006-08-13 20:10:10 +0200 (Sun, 13 Aug 2006) | 6 lines
Move/copy assert for tstate != NULL before first use.
Verify that PyEval_Get{Globals,Locals} returned valid pointers.
Klocwork 231-232
........
r51246 | neal.norwitz | 2006-08-13 20:10:28 +0200 (Sun, 13 Aug 2006) | 5 lines
Handle a whole lot of failures from PyString_FromInternedString().
Should fix most of Klocwork 234-272.
........
r51247 | neal.norwitz | 2006-08-13 20:10:47 +0200 (Sun, 13 Aug 2006) | 8 lines
cpathname could be NULL if it was longer than MAXPATHLEN. Don't try
to write the .pyc to NULL.
Check results of PyList_GetItem() and PyModule_GetDict() are not NULL.
Klocwork 282, 283, 285
........
r51248 | neal.norwitz | 2006-08-13 20:11:08 +0200 (Sun, 13 Aug 2006) | 6 lines
Fix segfault when doing string formatting on subclasses of long if
__oct__, __hex__ don't return a string.
Klocwork 308
........
r51250 | neal.norwitz | 2006-08-13 20:11:27 +0200 (Sun, 13 Aug 2006) | 5 lines
Check return result of PyModule_GetDict().
Fix a bunch of refleaks in the init of the module. This would only be found
when running python -v.
........
r51251 | neal.norwitz | 2006-08-13 20:11:43 +0200 (Sun, 13 Aug 2006) | 5 lines
Handle malloc and fopen failures more gracefully.
Klocwork 180-181
........
r51252 | neal.norwitz | 2006-08-13 20:12:03 +0200 (Sun, 13 Aug 2006) | 7 lines
It's very unlikely, though possible that source is not a string. Verify
that PyString_AsString() returns a valid pointer. (The problem can
arise when zlib.decompress doesn't return a string.)
Klocwork 346
........
r51253 | neal.norwitz | 2006-08-13 20:12:26 +0200 (Sun, 13 Aug 2006) | 5 lines
Handle failures from lookup.
Klocwork 341-342
........
r51254 | neal.norwitz | 2006-08-13 20:12:45 +0200 (Sun, 13 Aug 2006) | 6 lines
Handle failure from PyModule_GetDict() (Klocwork 208).
Fix a bunch of refleaks in the init of the module. This would only be found
when running python -v.
........
r51255 | neal.norwitz | 2006-08-13 20:13:02 +0200 (Sun, 13 Aug 2006) | 4 lines
Really address the issue of where to place the assert for leftblock.
(Followup of Klocwork 274)
........
r51256 | neal.norwitz | 2006-08-13 20:13:36 +0200 (Sun, 13 Aug 2006) | 4 lines
Handle malloc failure.
Klocwork 281
........
r51258 | neal.norwitz | 2006-08-13 20:40:39 +0200 (Sun, 13 Aug 2006) | 4 lines
Handle alloca failures.
Klocwork 225-228
........
r51259 | neal.norwitz | 2006-08-13 20:41:15 +0200 (Sun, 13 Aug 2006) | 1 line
Get rid of compiler warning
........
r51261 | neal.norwitz | 2006-08-14 02:51:15 +0200 (Mon, 14 Aug 2006) | 1 line
Ignore pgen.exe and kill_python.exe for cygwin
........
r51262 | neal.norwitz | 2006-08-14 02:59:03 +0200 (Mon, 14 Aug 2006) | 4 lines
Can't return NULL from a void function. If there is a memory error,
about the best we can do is call PyErr_WriteUnraisable and go on.
We won't be able to do the call below either, so verify delstr is valid.
........
r51263 | neal.norwitz | 2006-08-14 03:49:54 +0200 (Mon, 14 Aug 2006) | 1 line
Update purify doc some.
........
r51264 | thomas.heller | 2006-08-14 09:13:05 +0200 (Mon, 14 Aug 2006) | 2 lines
Remove unused, buggy test function.
Fixes klockwork issue #207.
........
r51265 | thomas.heller | 2006-08-14 09:14:09 +0200 (Mon, 14 Aug 2006) | 2 lines
Check for NULL return value from new_CArgObject().
Fixes klockwork issues #183, #184, #185.
........
r51266 | thomas.heller | 2006-08-14 09:50:14 +0200 (Mon, 14 Aug 2006) | 2 lines
Check for NULL return value of GenericCData_new().
Fixes klockwork issues #188, #189.
........
r51274 | thomas.heller | 2006-08-14 12:02:24 +0200 (Mon, 14 Aug 2006) | 2 lines
Revert the change that tries to zero out a closure's result storage
area because the size if unknown in source/callproc.c.
........
r51276 | marc-andre.lemburg | 2006-08-14 12:55:19 +0200 (Mon, 14 Aug 2006) | 11 lines
Slightly revised version of patch #1538956:
Replace UnicodeDecodeErrors raised during == and !=
compares of Unicode and other objects with a new
UnicodeWarning.
All other comparisons continue to raise exceptions.
Exceptions other than UnicodeDecodeErrors are also left
untouched.
........
r51277 | thomas.heller | 2006-08-14 13:17:48 +0200 (Mon, 14 Aug 2006) | 13 lines
Apply the patch #1532975 plus ideas from the patch #1533481.
ctypes instances no longer have the internal and undocumented
'_as_parameter_' attribute which was used to adapt them to foreign
function calls; this mechanism is replaced by a function pointer in
the type's stgdict.
In the 'from_param' class methods, try the _as_parameter_ attribute if
other conversions are not possible.
This makes the documented _as_parameter_ mechanism work as intended.
Change the ctypes version number to 1.0.1.
........
r51278 | marc-andre.lemburg | 2006-08-14 13:44:34 +0200 (Mon, 14 Aug 2006) | 3 lines
Readd NEWS items that were accidentally removed by r51276.
........
r51279 | georg.brandl | 2006-08-14 14:36:06 +0200 (Mon, 14 Aug 2006) | 3 lines
Improve markup in PyUnicode_RichCompare.
........
r51280 | marc-andre.lemburg | 2006-08-14 14:57:27 +0200 (Mon, 14 Aug 2006) | 3 lines
Correct an accidentally removed previous patch.
........
r51281 | thomas.heller | 2006-08-14 18:17:41 +0200 (Mon, 14 Aug 2006) | 3 lines
Patch #1536908: Add support for AMD64 / OpenBSD.
Remove the -no-stack-protector compiler flag for OpenBSD
as it has been reported to be unneeded.
........
r51282 | thomas.heller | 2006-08-14 18:20:04 +0200 (Mon, 14 Aug 2006) | 1 line
News item for rev 51281.
........
r51283 | georg.brandl | 2006-08-14 22:25:39 +0200 (Mon, 14 Aug 2006) | 3 lines
Fix refleak introduced in rev. 51248.
........
r51284 | georg.brandl | 2006-08-14 23:34:08 +0200 (Mon, 14 Aug 2006) | 5 lines
Make tabnanny recognize IndentationErrors raised by tokenize.
Add a test to test_inspect to make sure indented source
is recognized correctly. (fixes #1224621)
........
r51285 | georg.brandl | 2006-08-14 23:42:55 +0200 (Mon, 14 Aug 2006) | 3 lines
Patch #1535500: fix segfault in BZ2File.writelines and make sure it
raises the correct exceptions.
........
r51287 | georg.brandl | 2006-08-14 23:45:32 +0200 (Mon, 14 Aug 2006) | 3 lines
Add an additional test: BZ2File write methods should raise IOError
when file is read-only.
........
r51289 | georg.brandl | 2006-08-14 23:55:28 +0200 (Mon, 14 Aug 2006) | 3 lines
Patch #1536071: trace.py should now find the full module name of a
file correctly even on Windows.
........
r51290 | georg.brandl | 2006-08-15 00:01:24 +0200 (Tue, 15 Aug 2006) | 3 lines
Cookie.py shouldn't "bogusly" use string._idmap.
........
r51291 | georg.brandl | 2006-08-15 00:10:24 +0200 (Tue, 15 Aug 2006) | 3 lines
Patch #1511317: don't crash on invalid hostname info
........
r51292 | tim.peters | 2006-08-15 02:25:04 +0200 (Tue, 15 Aug 2006) | 2 lines
Whitespace normalization.
........
r51293 | neal.norwitz | 2006-08-15 06:14:57 +0200 (Tue, 15 Aug 2006) | 3 lines
Georg fixed one of my bugs, so I'll repay him with 2 NEWS entries.
Now we're even. :-)
........
r51295 | neal.norwitz | 2006-08-15 06:58:28 +0200 (Tue, 15 Aug 2006) | 8 lines
Fix the test for SocketServer so it should pass on cygwin and not fail
sporadically on other platforms. This is really a band-aid that doesn't
fix the underlying issue in SocketServer. It's not clear if it's worth
it to fix SocketServer, however, I opened a bug to track it:
http://python.org/sf/1540386
........
r51296 | neal.norwitz | 2006-08-15 06:59:30 +0200 (Tue, 15 Aug 2006) | 3 lines
Update the docstring to use a version a little newer than 1999. This was
taken from a Debian patch. Should we update the version for each release?
........
r51298 | neal.norwitz | 2006-08-15 08:29:03 +0200 (Tue, 15 Aug 2006) | 2 lines
Subclasses of int/long are allowed to define an __index__.
........
r51300 | thomas.heller | 2006-08-15 15:07:21 +0200 (Tue, 15 Aug 2006) | 1 line
Check for NULL return value from new_CArgObject calls.
........
r51303 | kurt.kaiser | 2006-08-16 05:15:26 +0200 (Wed, 16 Aug 2006) | 2 lines
The 'with' statement is now a Code Context block opener
........
r51304 | anthony.baxter | 2006-08-16 05:42:26 +0200 (Wed, 16 Aug 2006) | 1 line
preparing for 2.5c1
........
r51305 | anthony.baxter | 2006-08-16 05:58:37 +0200 (Wed, 16 Aug 2006) | 1 line
preparing for 2.5c1 - no, really this time
........
r51306 | kurt.kaiser | 2006-08-16 07:01:42 +0200 (Wed, 16 Aug 2006) | 9 lines
Patch #1540892: site.py Quitter() class attempts to close sys.stdin
before raising SystemExit, allowing IDLE to honor quit() and exit().
M Lib/site.py
M Lib/idlelib/PyShell.py
M Lib/idlelib/CREDITS.txt
M Lib/idlelib/NEWS.txt
M Misc/NEWS
........
r51307 | ka-ping.yee | 2006-08-16 09:02:50 +0200 (Wed, 16 Aug 2006) | 6 lines
Update code and tests to support the 'bytes_le' attribute (for
little-endian byte order on Windows), and to work around clocks
with low resolution yielding duplicate UUIDs.
Anthony Baxter has approved this change.
........
r51308 | kurt.kaiser | 2006-08-16 09:04:17 +0200 (Wed, 16 Aug 2006) | 2 lines
Get quit() and exit() to work cleanly when not using subprocess.
........
r51309 | marc-andre.lemburg | 2006-08-16 10:13:26 +0200 (Wed, 16 Aug 2006) | 2 lines
Revert to having static version numbers again.
........
r51310 | martin.v.loewis | 2006-08-16 14:55:10 +0200 (Wed, 16 Aug 2006) | 2 lines
Build _hashlib on Windows. Build OpenSSL with masm assembler code.
Fixes #1535502.
........
r51311 | thomas.heller | 2006-08-16 15:03:11 +0200 (Wed, 16 Aug 2006) | 6 lines
Add commented assert statements to check that the result of
PyObject_stgdict() and PyType_stgdict() calls are non-NULL before
dereferencing the result. Hopefully this fixes what klocwork is
complaining about.
Fix a few other nits as well.
........
r51312 | anthony.baxter | 2006-08-16 15:08:25 +0200 (Wed, 16 Aug 2006) | 1 line
news entry for 51307
........
r51313 | andrew.kuchling | 2006-08-16 15:22:20 +0200 (Wed, 16 Aug 2006) | 1 line
Add UnicodeWarning
........
r51314 | andrew.kuchling | 2006-08-16 15:41:52 +0200 (Wed, 16 Aug 2006) | 1 line
Bump document version to 1.0; remove pystone paragraph
........
r51315 | andrew.kuchling | 2006-08-16 15:51:32 +0200 (Wed, 16 Aug 2006) | 1 line
Link to docs; remove an XXX comment
........
r51316 | martin.v.loewis | 2006-08-16 15:58:51 +0200 (Wed, 16 Aug 2006) | 1 line
Make cl build step compile-only (/c). Remove libs from source list.
........
r51317 | thomas.heller | 2006-08-16 16:07:44 +0200 (Wed, 16 Aug 2006) | 5 lines
The __repr__ method of a NULL py_object does no longer raise an
exception. Remove a stray '?' character from the exception text
when the value is retrieved of such an object.
Includes tests.
........
r51318 | andrew.kuchling | 2006-08-16 16:18:23 +0200 (Wed, 16 Aug 2006) | 1 line
Update bug/patch counts
........
r51319 | andrew.kuchling | 2006-08-16 16:21:14 +0200 (Wed, 16 Aug 2006) | 1 line
Wording/typo fixes
........
r51320 | thomas.heller | 2006-08-16 17:10:12 +0200 (Wed, 16 Aug 2006) | 9 lines
Remove the special casing of Py_None when converting the return value
of the Python part of a callback function to C. If it cannot be
converted, call PyErr_WriteUnraisable with the exception we got.
Before, arbitrary data has been passed to the calling C code in this
case.
(I'm not really sure the NEWS entry is understandable, but I cannot
find better words)
........
r51321 | marc-andre.lemburg | 2006-08-16 18:11:01 +0200 (Wed, 16 Aug 2006) | 2 lines
Add NEWS item mentioning the reverted distutils version number patch.
........
r51322 | fredrik.lundh | 2006-08-16 18:47:07 +0200 (Wed, 16 Aug 2006) | 5 lines
SF#1534630
ignore data that arrives before the opening start tag
........
r51324 | andrew.kuchling | 2006-08-16 19:11:18 +0200 (Wed, 16 Aug 2006) | 1 line
Grammar fix
........
r51328 | thomas.heller | 2006-08-16 20:02:11 +0200 (Wed, 16 Aug 2006) | 12 lines
Tutorial:
Clarify somewhat how parameters are passed to functions
(especially explain what integer means).
Correct the table - Python integers and longs can both be used.
Further clarification to the table comparing ctypes types, Python
types, and C types.
Reference:
Replace integer by C ``int`` where it makes sense.
........
r51329 | kurt.kaiser | 2006-08-16 23:45:59 +0200 (Wed, 16 Aug 2006) | 8 lines
File menu hotkeys: there were three 'p' assignments. Reassign the
'Save Copy As' and 'Print' hotkeys to 'y' and 't'. Change the
Shell menu hotkey from 's' to 'l'.
M Bindings.py
M PyShell.py
M NEWS.txt
........
r51330 | neil.schemenauer | 2006-08-17 01:38:05 +0200 (Thu, 17 Aug 2006) | 3 lines
Fix a bug in the ``compiler`` package that caused invalid code to be
generated for generator expressions.
........
r51342 | martin.v.loewis | 2006-08-17 21:19:32 +0200 (Thu, 17 Aug 2006) | 3 lines
Merge 51340 and 51341 from 2.5 branch:
Leave tk build directory to restore original path.
Invoke debug mk1mf.pl after running Configure.
........
r51354 | martin.v.loewis | 2006-08-18 05:47:18 +0200 (Fri, 18 Aug 2006) | 3 lines
Bug #1541863: uuid.uuid1 failed to generate unique identifiers
on systems with low clock resolution.
........
r51355 | neal.norwitz | 2006-08-18 05:57:54 +0200 (Fri, 18 Aug 2006) | 1 line
Add template for 2.6 on HEAD
........
r51356 | neal.norwitz | 2006-08-18 06:01:38 +0200 (Fri, 18 Aug 2006) | 1 line
More post-release wibble
........
r51357 | neal.norwitz | 2006-08-18 06:58:33 +0200 (Fri, 18 Aug 2006) | 1 line
Try to get Windows bots working again
........
r51358 | neal.norwitz | 2006-08-18 07:10:00 +0200 (Fri, 18 Aug 2006) | 1 line
Try to get Windows bots working again. Take 2
........
r51359 | neal.norwitz | 2006-08-18 07:39:20 +0200 (Fri, 18 Aug 2006) | 1 line
Try to get Unix bots install working again.
........
r51360 | neal.norwitz | 2006-08-18 07:41:46 +0200 (Fri, 18 Aug 2006) | 1 line
Set version to 2.6a0, seems more consistent.
........
r51362 | neal.norwitz | 2006-08-18 08:14:52 +0200 (Fri, 18 Aug 2006) | 1 line
More version wibble
........
r51364 | georg.brandl | 2006-08-18 09:27:59 +0200 (Fri, 18 Aug 2006) | 4 lines
Bug #1541682: Fix example in the "Refcount details" API docs.
Additionally, remove a faulty example showing PySequence_SetItem applied
to a newly created list object and add notes that this isn't a good idea.
........
r51366 | anthony.baxter | 2006-08-18 09:29:02 +0200 (Fri, 18 Aug 2006) | 3 lines
Updating IDLE's version number to match Python's (as per python-dev
discussion).
........
r51367 | anthony.baxter | 2006-08-18 09:30:07 +0200 (Fri, 18 Aug 2006) | 1 line
RPM specfile updates
........
r51368 | georg.brandl | 2006-08-18 09:35:47 +0200 (Fri, 18 Aug 2006) | 2 lines
Typo in tp_clear docs.
........
r51378 | andrew.kuchling | 2006-08-18 15:57:13 +0200 (Fri, 18 Aug 2006) | 1 line
Minor edits
........
r51379 | thomas.heller | 2006-08-18 16:38:46 +0200 (Fri, 18 Aug 2006) | 6 lines
Add asserts to check for 'impossible' NULL values, with comments.
In one place where I'n not 1000% sure about the non-NULL, raise
a RuntimeError for safety.
This should fix the klocwork issues that Neal sent me. If so,
it should be applied to the release25-maint branch also.
........
r51400 | neal.norwitz | 2006-08-19 06:22:33 +0200 (Sat, 19 Aug 2006) | 5 lines
Move initialization of interned strings to before allocating the
object so we don't leak op. (Fixes an earlier patch to this code)
Klockwork #350
........
r51401 | neal.norwitz | 2006-08-19 06:23:04 +0200 (Sat, 19 Aug 2006) | 4 lines
Move assert to after NULL check, otherwise we deref NULL in the assert.
Klocwork #307
........
r51402 | neal.norwitz | 2006-08-19 06:25:29 +0200 (Sat, 19 Aug 2006) | 2 lines
SF #1542693: Remove semi-colon at end of PyImport_ImportModuleEx macro
........
r51403 | neal.norwitz | 2006-08-19 06:28:55 +0200 (Sat, 19 Aug 2006) | 6 lines
Move initialization to after the asserts for non-NULL values.
Klocwork 286-287.
(I'm not backporting this, but if someone wants to, feel free.)
........
r51404 | neal.norwitz | 2006-08-19 06:52:03 +0200 (Sat, 19 Aug 2006) | 6 lines
Handle PyString_FromInternedString() failing (unlikely, but possible).
Klocwork #325
(I'm not backporting this, but if someone wants to, feel free.)
........
r51416 | georg.brandl | 2006-08-20 15:15:39 +0200 (Sun, 20 Aug 2006) | 2 lines
Patch #1542948: fix urllib2 header casing issue. With new test.
........
r51428 | jeremy.hylton | 2006-08-21 18:19:37 +0200 (Mon, 21 Aug 2006) | 3 lines
Move peephole optimizer to separate file.
........
r51429 | jeremy.hylton | 2006-08-21 18:20:29 +0200 (Mon, 21 Aug 2006) | 2 lines
Move peephole optimizer to separate file. (Forgot .h in previous checkin.)
........
r51432 | neal.norwitz | 2006-08-21 19:59:46 +0200 (Mon, 21 Aug 2006) | 5 lines
Fix bug #1543303, tarfile adds padding that breaks gunzip.
Patch # 1543897.
Will backport to 2.5
........
r51433 | neal.norwitz | 2006-08-21 20:01:30 +0200 (Mon, 21 Aug 2006) | 2 lines
Add assert to make Klocwork happy (#276)
........
2006-08-21 16:07:27 -03:00
|
|
|
To prevent naive misuse, you must write your own C extension
|
|
|
|
to call this. Must be called with the GIL held.
|
|
|
|
Returns the number of thread states modified; this is normally one, but
|
|
|
|
will be zero if the thread id isn't found. If \var{exc} is
|
|
|
|
\constant{NULL}, the pending exception (if any) for the thread is cleared.
|
2003-06-28 23:14:31 -03:00
|
|
|
This raises no exceptions.
|
|
|
|
\versionadded{2.3}
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
2004-07-10 10:31:18 -03:00
|
|
|
\begin{cfuncdesc}{PyGILState_STATE}{PyGILState_Ensure}{}
|
2005-06-20 09:12:45 -03:00
|
|
|
Ensure that the current thread is ready to call the Python C API
|
|
|
|
regardless of the current state of Python, or of its thread lock.
|
|
|
|
This may be called as many times as desired by a thread as long as
|
|
|
|
each call is matched with a call to \cfunction{PyGILState_Release()}.
|
|
|
|
In general, other thread-related APIs may be used between
|
|
|
|
\cfunction{PyGILState_Ensure()} and \cfunction{PyGILState_Release()}
|
|
|
|
calls as long as the thread state is restored to its previous state
|
|
|
|
before the Release(). For example, normal usage of the
|
|
|
|
\csimplemacro{Py_BEGIN_ALLOW_THREADS} and
|
|
|
|
\csimplemacro{Py_END_ALLOW_THREADS} macros is acceptable.
|
2004-07-10 10:31:18 -03:00
|
|
|
|
|
|
|
The return value is an opaque "handle" to the thread state when
|
|
|
|
\cfunction{PyGILState_Acquire()} was called, and must be passed to
|
|
|
|
\cfunction{PyGILState_Release()} to ensure Python is left in the same
|
|
|
|
state. Even though recursive calls are allowed, these handles
|
|
|
|
\emph{cannot} be shared - each unique call to
|
|
|
|
\cfunction{PyGILState_Ensure} must save the handle for its call to
|
|
|
|
\cfunction{PyGILState_Release}.
|
|
|
|
|
|
|
|
When the function returns, the current thread will hold the GIL.
|
|
|
|
Failure is a fatal error.
|
|
|
|
\versionadded{2.3}
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{void}{PyGILState_Release}{PyGILState_STATE}
|
|
|
|
Release any resources previously acquired. After this call, Python's
|
|
|
|
state will be the same as it was prior to the corresponding
|
2004-07-10 10:42:52 -03:00
|
|
|
\cfunction{PyGILState_Ensure} call (but generally this state will be
|
|
|
|
unknown to the caller, hence the use of the GILState API.)
|
2004-07-10 10:31:18 -03:00
|
|
|
|
|
|
|
Every call to \cfunction{PyGILState_Ensure()} must be matched by a call to
|
|
|
|
\cfunction{PyGILState_Release()} on the same thread.
|
|
|
|
\versionadded{2.3}
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
2001-10-12 16:01:43 -03:00
|
|
|
|
|
|
|
\section{Profiling and Tracing \label{profiling}}
|
|
|
|
|
|
|
|
\sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
|
|
|
|
|
|
|
|
The Python interpreter provides some low-level support for attaching
|
|
|
|
profiling and execution tracing facilities. These are used for
|
|
|
|
profiling, debugging, and coverage analysis tools.
|
|
|
|
|
|
|
|
Starting with Python 2.2, the implementation of this facility was
|
|
|
|
substantially revised, and an interface from C was added. This C
|
|
|
|
interface allows the profiling or tracing code to avoid the overhead
|
|
|
|
of calling through Python-level callable objects, making a direct C
|
|
|
|
function call instead. The essential attributes of the facility have
|
|
|
|
not changed; the interface allows trace functions to be installed
|
|
|
|
per-thread, and the basic events reported to the trace function are
|
|
|
|
the same as had been reported to the Python-level trace functions in
|
|
|
|
previous versions.
|
|
|
|
|
|
|
|
\begin{ctypedesc}[Py_tracefunc]{int (*Py_tracefunc)(PyObject *obj,
|
|
|
|
PyFrameObject *frame, int what,
|
|
|
|
PyObject *arg)}
|
|
|
|
The type of the trace function registered using
|
|
|
|
\cfunction{PyEval_SetProfile()} and \cfunction{PyEval_SetTrace()}.
|
|
|
|
The first parameter is the object passed to the registration
|
|
|
|
function as \var{obj}, \var{frame} is the frame object to which the
|
|
|
|
event pertains, \var{what} is one of the constants
|
2004-03-24 17:57:10 -04:00
|
|
|
\constant{PyTrace_CALL}, \constant{PyTrace_EXCEPTION},
|
|
|
|
\constant{PyTrace_LINE}, \constant{PyTrace_RETURN},
|
|
|
|
\constant{PyTrace_C_CALL}, \constant{PyTrace_C_EXCEPTION},
|
|
|
|
or \constant{PyTrace_C_RETURN}, and \var{arg}
|
2001-10-12 16:01:43 -03:00
|
|
|
depends on the value of \var{what}:
|
|
|
|
|
|
|
|
\begin{tableii}{l|l}{constant}{Value of \var{what}}{Meaning of \var{arg}}
|
|
|
|
\lineii{PyTrace_CALL}{Always \NULL.}
|
2004-03-24 17:57:10 -04:00
|
|
|
\lineii{PyTrace_EXCEPTION}{Exception information as returned by
|
2001-10-12 16:01:43 -03:00
|
|
|
\function{sys.exc_info()}.}
|
|
|
|
\lineii{PyTrace_LINE}{Always \NULL.}
|
|
|
|
\lineii{PyTrace_RETURN}{Value being returned to the caller.}
|
2004-03-24 17:57:10 -04:00
|
|
|
\lineii{PyTrace_C_CALL}{Name of function being called.}
|
|
|
|
\lineii{PyTrace_C_EXCEPTION}{Always \NULL.}
|
|
|
|
\lineii{PyTrace_C_RETURN}{Always \NULL.}
|
2001-10-12 16:01:43 -03:00
|
|
|
\end{tableii}
|
|
|
|
\end{ctypedesc}
|
|
|
|
|
|
|
|
\begin{cvardesc}{int}{PyTrace_CALL}
|
|
|
|
The value of the \var{what} parameter to a \ctype{Py_tracefunc}
|
|
|
|
function when a new call to a function or method is being reported,
|
|
|
|
or a new entry into a generator. Note that the creation of the
|
|
|
|
iterator for a generator function is not reported as there is no
|
|
|
|
control transfer to the Python bytecode in the corresponding frame.
|
|
|
|
\end{cvardesc}
|
|
|
|
|
2004-03-24 17:57:10 -04:00
|
|
|
\begin{cvardesc}{int}{PyTrace_EXCEPTION}
|
2001-10-12 16:01:43 -03:00
|
|
|
The value of the \var{what} parameter to a \ctype{Py_tracefunc}
|
2001-10-16 16:23:55 -03:00
|
|
|
function when an exception has been raised. The callback function
|
|
|
|
is called with this value for \var{what} when after any bytecode is
|
|
|
|
processed after which the exception becomes set within the frame
|
2003-10-19 04:32:24 -03:00
|
|
|
being executed. The effect of this is that as exception propagation
|
2001-10-16 16:23:55 -03:00
|
|
|
causes the Python stack to unwind, the callback is called upon
|
2002-12-06 18:42:13 -04:00
|
|
|
return to each frame as the exception propagates. Only trace
|
2001-10-16 16:23:55 -03:00
|
|
|
functions receives these events; they are not needed by the
|
|
|
|
profiler.
|
2001-10-12 16:01:43 -03:00
|
|
|
\end{cvardesc}
|
|
|
|
|
|
|
|
\begin{cvardesc}{int}{PyTrace_LINE}
|
|
|
|
The value passed as the \var{what} parameter to a trace function
|
|
|
|
(but not a profiling function) when a line-number event is being
|
|
|
|
reported.
|
|
|
|
\end{cvardesc}
|
|
|
|
|
|
|
|
\begin{cvardesc}{int}{PyTrace_RETURN}
|
|
|
|
The value for the \var{what} parameter to \ctype{Py_tracefunc}
|
2003-10-19 04:32:24 -03:00
|
|
|
functions when a call is returning without propagating an exception.
|
2001-10-12 16:01:43 -03:00
|
|
|
\end{cvardesc}
|
|
|
|
|
2004-03-24 17:57:10 -04:00
|
|
|
\begin{cvardesc}{int}{PyTrace_C_CALL}
|
|
|
|
The value for the \var{what} parameter to \ctype{Py_tracefunc}
|
|
|
|
functions when a C function is about to be called.
|
|
|
|
\end{cvardesc}
|
|
|
|
|
|
|
|
\begin{cvardesc}{int}{PyTrace_C_EXCEPTION}
|
|
|
|
The value for the \var{what} parameter to \ctype{Py_tracefunc}
|
|
|
|
functions when a C function has thrown an exception.
|
|
|
|
\end{cvardesc}
|
|
|
|
|
|
|
|
\begin{cvardesc}{int}{PyTrace_C_RETURN}
|
|
|
|
The value for the \var{what} parameter to \ctype{Py_tracefunc}
|
|
|
|
functions when a C function has returned.
|
|
|
|
\end{cvardesc}
|
|
|
|
|
2001-10-12 16:01:43 -03:00
|
|
|
\begin{cfuncdesc}{void}{PyEval_SetProfile}{Py_tracefunc func, PyObject *obj}
|
|
|
|
Set the profiler function to \var{func}. The \var{obj} parameter is
|
|
|
|
passed to the function as its first parameter, and may be any Python
|
|
|
|
object, or \NULL. If the profile function needs to maintain state,
|
|
|
|
using a different value for \var{obj} for each thread provides a
|
|
|
|
convenient and thread-safe place to store it. The profile function
|
|
|
|
is called for all monitored events except the line-number events.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{void}{PyEval_SetTrace}{Py_tracefunc func, PyObject *obj}
|
2003-08-11 21:01:16 -03:00
|
|
|
Set the tracing function to \var{func}. This is similar to
|
2001-10-12 16:01:43 -03:00
|
|
|
\cfunction{PyEval_SetProfile()}, except the tracing function does
|
|
|
|
receive line-number events.
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
|
|
|
|
\section{Advanced Debugger Support \label{advanced-debugging}}
|
|
|
|
\sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
|
|
|
|
|
|
|
|
These functions are only intended to be used by advanced debugging
|
|
|
|
tools.
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{PyInterpreterState*}{PyInterpreterState_Head}{}
|
|
|
|
Return the interpreter state object at the head of the list of all
|
|
|
|
such objects.
|
|
|
|
\versionadded{2.2}
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{PyInterpreterState*}{PyInterpreterState_Next}{PyInterpreterState *interp}
|
|
|
|
Return the next interpreter state object after \var{interp} from the
|
|
|
|
list of all such objects.
|
|
|
|
\versionadded{2.2}
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{PyThreadState *}{PyInterpreterState_ThreadHead}{PyInterpreterState *interp}
|
|
|
|
Return the a pointer to the first \ctype{PyThreadState} object in
|
|
|
|
the list of threads associated with the interpreter \var{interp}.
|
|
|
|
\versionadded{2.2}
|
|
|
|
\end{cfuncdesc}
|
|
|
|
|
|
|
|
\begin{cfuncdesc}{PyThreadState*}{PyThreadState_Next}{PyThreadState *tstate}
|
|
|
|
Return the next thread state object after \var{tstate} from the list
|
|
|
|
of all such objects belonging to the same \ctype{PyInterpreterState}
|
|
|
|
object.
|
|
|
|
\versionadded{2.2}
|
|
|
|
\end{cfuncdesc}
|