mirror of
https://github.com/python/cpython.git
synced 2025-11-02 19:12:55 +00:00
Add documentation for the public API for weak reference objects.
This commit is contained in:
parent
f7f8cad548
commit
bf88b68f38
1 changed files with 70 additions and 1 deletions
|
|
@ -1099,13 +1099,14 @@ completeness, here are all the variables:
|
||||||
\lineiii{PyExc_NotImplementedError}{\exception{NotImplementedError}}{}
|
\lineiii{PyExc_NotImplementedError}{\exception{NotImplementedError}}{}
|
||||||
\lineiii{PyExc_OSError}{\exception{OSError}}{}
|
\lineiii{PyExc_OSError}{\exception{OSError}}{}
|
||||||
\lineiii{PyExc_OverflowError}{\exception{OverflowError}}{}
|
\lineiii{PyExc_OverflowError}{\exception{OverflowError}}{}
|
||||||
|
\lineiii{PyExc_ReferenceError}{\exception{ReferenceError}}{(2)}
|
||||||
\lineiii{PyExc_RuntimeError}{\exception{RuntimeError}}{}
|
\lineiii{PyExc_RuntimeError}{\exception{RuntimeError}}{}
|
||||||
\lineiii{PyExc_SyntaxError}{\exception{SyntaxError}}{}
|
\lineiii{PyExc_SyntaxError}{\exception{SyntaxError}}{}
|
||||||
\lineiii{PyExc_SystemError}{\exception{SystemError}}{}
|
\lineiii{PyExc_SystemError}{\exception{SystemError}}{}
|
||||||
\lineiii{PyExc_SystemExit}{\exception{SystemExit}}{}
|
\lineiii{PyExc_SystemExit}{\exception{SystemExit}}{}
|
||||||
\lineiii{PyExc_TypeError}{\exception{TypeError}}{}
|
\lineiii{PyExc_TypeError}{\exception{TypeError}}{}
|
||||||
\lineiii{PyExc_ValueError}{\exception{ValueError}}{}
|
\lineiii{PyExc_ValueError}{\exception{ValueError}}{}
|
||||||
\lineiii{PyExc_WindowsError}{\exception{WindowsError}}{(2)}
|
\lineiii{PyExc_WindowsError}{\exception{WindowsError}}{(3)}
|
||||||
\lineiii{PyExc_ZeroDivisionError}{\exception{ZeroDivisionError}}{}
|
\lineiii{PyExc_ZeroDivisionError}{\exception{ZeroDivisionError}}{}
|
||||||
\end{tableiii}
|
\end{tableiii}
|
||||||
|
|
||||||
|
|
@ -1116,6 +1117,9 @@ Notes:
|
||||||
This is a base class for other standard exceptions.
|
This is a base class for other standard exceptions.
|
||||||
|
|
||||||
\item[(2)]
|
\item[(2)]
|
||||||
|
This is the same as \exception{weakref.ReferenceError}.
|
||||||
|
|
||||||
|
\item[(3)]
|
||||||
Only defined on Windows; protect code that uses this by testing that
|
Only defined on Windows; protect code that uses this by testing that
|
||||||
the preprocessor macro \code{MS_WINDOWS} is defined.
|
the preprocessor macro \code{MS_WINDOWS} is defined.
|
||||||
\end{description}
|
\end{description}
|
||||||
|
|
@ -4502,6 +4506,71 @@ returned.
|
||||||
\end{cfuncdesc}
|
\end{cfuncdesc}
|
||||||
|
|
||||||
|
|
||||||
|
\subsection{Weak Reference Objects \label{weakref-objects}}
|
||||||
|
|
||||||
|
Python supports \emph{weak references} as first-class objects. There
|
||||||
|
are two specific object types which directly implement weak
|
||||||
|
references. The first is a simple reference object, and the second
|
||||||
|
acts as a proxy for the original object as much as it can.
|
||||||
|
|
||||||
|
\begin{cfuncdesc}{int}{PyWeakref_Check}{ob}
|
||||||
|
Return true if \var{ob} is either a reference or proxy object.
|
||||||
|
\versionadded{2.2}
|
||||||
|
\end{cfuncdesc}
|
||||||
|
|
||||||
|
\begin{cfuncdesc}{int}{PyWeakref_CheckRef}{ob}
|
||||||
|
Return true if \var{ob} is a reference object.
|
||||||
|
\versionadded{2.2}
|
||||||
|
\end{cfuncdesc}
|
||||||
|
|
||||||
|
\begin{cfuncdesc}{int}{PyWeakref_CheckProxy}{ob}
|
||||||
|
Return true if \var{ob} is a proxy object.
|
||||||
|
\versionadded{2.2}
|
||||||
|
\end{cfuncdesc}
|
||||||
|
|
||||||
|
\begin{cfuncdesc}{PyObject*}{PyWeakref_NewRef}{PyObject *ob,
|
||||||
|
PyObject *callback}
|
||||||
|
Return a weak reference object for the object \var{ob}. This will
|
||||||
|
always return a new reference, but is not guaranteed to create a new
|
||||||
|
object; an existing reference object may be returned. The second
|
||||||
|
parameter, \var{callback}, can be a callable object that receives
|
||||||
|
notification when \var{ob} is garbage collected; it should accept a
|
||||||
|
single paramter, which will be the weak reference object itself.
|
||||||
|
\var{callback} may also be \code{None} or \NULL. If \var{ob}
|
||||||
|
is not a weakly-referencable object, or if \var{callback} is not
|
||||||
|
callable, \code{None}, or \NULL, this will return \NULL{} and
|
||||||
|
raise \exception{TypeError}.
|
||||||
|
\versionadded{2.2}
|
||||||
|
\end{cfuncdesc}
|
||||||
|
|
||||||
|
\begin{cfuncdesc}{PyObject*}{PyWeakref_NewProxy}{PyObject *ob,
|
||||||
|
PyObject *callback}
|
||||||
|
Return a weak reference proxy object for the object \var{ob}. This
|
||||||
|
will always return a new reference, but is not guaranteed to create
|
||||||
|
a new object; an existing proxy object may be returned. The second
|
||||||
|
parameter, \var{callback}, can be a callable object that receives
|
||||||
|
notification when \var{ob} is garbage collected; it should accept a
|
||||||
|
single paramter, which will be the weak reference object itself.
|
||||||
|
\var{callback} may also be \code{None} or \NULL. If \var{ob} is not
|
||||||
|
a weakly-referencable object, or if \var{callback} is not callable,
|
||||||
|
\code{None}, or \NULL, this will return \NULL{} and raise
|
||||||
|
\exception{TypeError}.
|
||||||
|
\versionadded{2.2}
|
||||||
|
\end{cfuncdesc}
|
||||||
|
|
||||||
|
\begin{cfuncdesc}{PyObject*}{PyWeakref_GetObject}{PyObject *ref}
|
||||||
|
Returns the referenced object from a weak reference, \var{ref}. If
|
||||||
|
the referent is no longer live, returns \NULL.
|
||||||
|
\versionadded{2.2}
|
||||||
|
\end{cfuncdesc}
|
||||||
|
|
||||||
|
\begin{cfuncdesc}{PyObject*}{PyWeakref_GET_OBJECT}{PyObject *ref}
|
||||||
|
Similar to \cfunction{PyWeakref_GetObject()}, but implemented as a
|
||||||
|
macro that does no error checking.
|
||||||
|
\versionadded{2.2}
|
||||||
|
\end{cfuncdesc}
|
||||||
|
|
||||||
|
|
||||||
\subsection{CObjects \label{cObjects}}
|
\subsection{CObjects \label{cObjects}}
|
||||||
|
|
||||||
\obindex{CObject}
|
\obindex{CObject}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue