Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0539bfa

Browse files
committed
There is no longer a -X option to the interpreter, so remove the comments
on how PyErr_NewException() behaves in that case. Clarify why an owned reference is kept in an extension module's variable that refers to the result of PyErr_NewException(); one reader thought that was a leak. Clean up some tabs and simplify some markup.
1 parent 78d7dc4 commit 0539bfa

1 file changed

Lines changed: 16 additions & 21 deletions

File tree

Doc/ext/ext.tex

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,19 @@ \section{Intermezzo: Errors and Exceptions
277277

278278
Note that the Python name for the exception object is
279279
\exception{spam.error}. The \cfunction{PyErr_NewException()} function
280-
may create either a string or class, depending on whether the
281-
\programopt{-X} flag was passed to the interpreter. If
282-
\programopt{-X} was used, \cdata{SpamError} will be a string object,
283-
otherwise it will be a class object with the base class being
284-
\exception{Exception}, described in the
280+
may create a class with the base class being \exception{Exception}
281+
(unless another class is passed in instead of \NULL), described in the
285282
\citetitle[../lib/lib.html]{Python Library Reference} under ``Built-in
286283
Exceptions.''
287284

285+
Note also that the \cdata{SpamError} variable retains a reference to
286+
the newly created exception class; this is intentional! Since the
287+
exception could be removed from the module by external code, an owned
288+
reference to the class is needed to ensure that it will not be
289+
discarded, causing \cdata{SpamError} to become a dangling pointer.
290+
Should it become a dangling pointer, C code which raises the exception
291+
could cause a core dump or other unintended side effects.
292+
288293

289294
\section{Back to the Example
290295
\label{backToExample}}
@@ -2127,22 +2132,12 @@ \section{Type Methods
21272132
will implement.
21282133

21292134
\begin{verbatim}
2130-
destructor tp_dealloc;
2131-
\end{verbatim}
2132-
\begin{verbatim}
2133-
printfunc tp_print;
2134-
\end{verbatim}
2135-
\begin{verbatim}
2136-
getattrfunc tp_getattr;
2137-
\end{verbatim}
2138-
\begin{verbatim}
2139-
setattrfunc tp_setattr;
2140-
\end{verbatim}
2141-
\begin{verbatim}
2142-
cmpfunc tp_compare;
2143-
\end{verbatim}
2144-
\begin{verbatim}
2145-
reprfunc tp_repr;
2135+
destructor tp_dealloc;
2136+
printfunc tp_print;
2137+
getattrfunc tp_getattr;
2138+
setattrfunc tp_setattr;
2139+
cmpfunc tp_compare;
2140+
reprfunc tp_repr;
21462141
\end{verbatim}
21472142

21482143

0 commit comments

Comments
 (0)