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

Skip to content

Commit 4447513

Browse files
committed
Filled in some more blanks, with the help of Drew Csillag.
1 parent 955a2f5 commit 4447513

2 files changed

Lines changed: 186 additions & 58 deletions

File tree

Doc/api.tex

Lines changed: 93 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,8 @@ \section{Importing Modules}
980980
a new one and insert in in the modules dictionary. Because the former
981981
action is most common, this does not return a new reference, and you
982982
do not own the returned reference. Return \NULL{} with an
983-
exception set on failure.
983+
exception set on failure. NOTE: this function returns
984+
a ``borrowed'' reference.
984985
\end{cfuncdesc}
985986
986987
\begin{cfuncdesc}{PyObject*}{PyImport_ExecCodeModule}{char *name, PyObject *co}
@@ -1697,7 +1698,8 @@ \subsection{The None Object}
16971698
\label{noneObject}
16981699
16991700
\begin{cvardesc}{PyObject *}{Py_None}
1700-
XXX macro
1701+
The Python \code{None} object, denoting lack of value. This object has
1702+
no methods.
17011703
\end{cvardesc}
17021704
17031705
@@ -1753,32 +1755,53 @@ \subsection{String Objects}
17531755
\begin{cfuncdesc}{void}{PyString_ConcatAndDel}{PyObject **string,
17541756
PyObject *newpart}
17551757
Creates a new string object in \var{*string} containing the contents
1756-
of \var{newpart} appended to \var{string}. --WHAT IS THE
1757-
DIFFERENCE BETWEEN THIS AND PLAIN CONCAT?--
1758+
of \var{newpart} appended to \var{string}. This version decrements
1759+
the reference count of \var{newpart}.
17581760
\end{cfuncdesc}
17591761
17601762
\begin{cfuncdesc}{int}{_PyString_Resize}{PyObject **string, int newsize}
1763+
A way to resize a string object even though it is ``immutable''.
1764+
Only use this to build up a brand new string object; don't use this if
1765+
the string may already be known in other parts of the code.
17611766
\end{cfuncdesc}
17621767
17631768
\begin{cfuncdesc}{PyObject*}{PyString_Format}{PyObject *format,
17641769
PyObject *args}
1770+
Returns a new string object from \var{format} and \var{args}. Analogous
1771+
to \code{\var{format} \% \var{args}}. The \var{args} argument must be
1772+
a tuple.
17651773
\end{cfuncdesc}
17661774
17671775
\begin{cfuncdesc}{void}{PyString_InternInPlace}{PyObject **string}
1776+
Intern the argument \var{*string} in place. The argument must be the
1777+
address of a pointer variable pointing to a Python string object.
1778+
If there is an existing interned string that is the same as
1779+
\var{*string}, it sets \var{*string} to it (decrementing the reference
1780+
count of the old string object and incrementing the reference count of
1781+
the interned string object), otherwise it leaves \var{*string} alone
1782+
and interns it (incrementing its reference count). (Clarification:
1783+
even though there is a lot of talk about reference counts, think of
1784+
this function as reference-count-neutral; you owned the object after
1785+
the call if and only if you own it after the call.)
17681786
\end{cfuncdesc}
17691787
17701788
\begin{cfuncdesc}{PyObject*}{PyString_InternFromString}{const char *v}
1789+
A combination of \code{PyString_FromString()} and
1790+
\code{PyString_InternInPlace()}, returning either a new string object
1791+
that has been interned, or a new (``owned'') reference to an earlier
1792+
interned string object with the same value.
17711793
\end{cfuncdesc}
17721794
17731795
\begin{cfuncdesc}{char*}{PyString_AS_STRING}{PyObject *string}
1774-
1796+
Macro form of \code{PyString_AsString} but without error checking.
17751797
\end{cfuncdesc}
17761798
17771799
\begin{cfuncdesc}{int}{PyString_GET_SIZE}{PyObject *string}
1778-
1800+
Macro form of \code{PyString_GetSize} but without error checking.
17791801
\end{cfuncdesc}
17801802
17811803
1804+
17821805
\subsection{Tuple Objects}
17831806
\label{tupleObjects}
17841807
@@ -1806,7 +1829,8 @@ \subsection{Tuple Objects}
18061829
\begin{cfuncdesc}{PyObject*}{PyTuple_GetItem}{PyTupleObject *p, int pos}
18071830
Returns the object at position \var{pos} in the tuple pointed
18081831
to by \var{p}. If \var{pos} is out of bounds, returns \NULL{} and
1809-
raises an \exception{IndexError} exception.
1832+
sets an \exception{IndexError} exception. NOTE: this function returns
1833+
a ``borrowed'' reference.
18101834
\end{cfuncdesc}
18111835
18121836
\begin{cfuncdesc}{PyObject*}{PyTuple_GET_ITEM}{PyTupleObject *p, int pos}
@@ -1873,7 +1897,10 @@ \subsection{List Objects}
18731897
\end{cfuncdesc}
18741898
18751899
\begin{cfuncdesc}{PyObject*}{PyList_GetItem}{PyObject *list, int index}
1876-
Returns the item in \var{list} at index \var{index}.
1900+
Returns the object at position \var{pos} in the list pointed
1901+
to by \var{p}. If \var{pos} is out of bounds, returns \NULL{} and
1902+
sets an \exception{IndexError} exception. NOTE: this function returns
1903+
a ``borrowed'' reference.
18771904
\end{cfuncdesc}
18781905
18791906
\begin{cfuncdesc}{int}{PyList_SetItem}{PyObject *list, int index,
@@ -1882,46 +1909,52 @@ \subsection{List Objects}
18821909
\end{cfuncdesc}
18831910
18841911
\begin{cfuncdesc}{int}{PyList_Insert}{PyObject *list, int index,
1885-
PyObject *index}
1886-
Inserts the item \var{item} into list \var{list} in front of index \var{index}
1887-
and returns true if successful.
1888-
For example:
1889-
\begin{verbatim}
1890-
PyList_Insert(list, 0, object);
1891-
\end{verbatim}
1912+
PyObject *item}
1913+
Inserts the item \var{item} into list \var{list} in front of index
1914+
\var{index}. Returns 0 if successful; returns -1 and sets an
1915+
exception if unsuccessful. Analogous to \code{list.insert(index, item)}.
18921916
\end{cfuncdesc}
1893-
would insert \var{object} at the front of the list.
18941917
18951918
\begin{cfuncdesc}{int}{PyList_Append}{PyObject *list, PyObject *item}
1896-
Appends the object \var{item} at the end of list \var{list}.
1919+
Appends the object \var{item} at the end of list \var{list}. Returns
1920+
0 if successful; returns -1 and sets an exception if unsuccessful.
1921+
Analogous to \code{list.append(item)}.
18971922
\end{cfuncdesc}
18981923
18991924
\begin{cfuncdesc}{PyObject*}{PyList_GetSlice}{PyObject *list,
19001925
int low, int high}
19011926
Returns a list of the objects in \var{list} containing the objects
1902-
\emph{between} \var{low} and \var{high}. Analogous to \var{list[low:high]}.
1927+
\emph{between} \var{low} and \var{high}. Returns NULL and sets an
1928+
exception if unsuccessful.
1929+
Analogous to \code{list[low:high]}.
19031930
\end{cfuncdesc}
19041931
19051932
\begin{cfuncdesc}{int}{PyList_SetSlice}{PyObject *list,
19061933
int low, int high,
19071934
PyObject *itemlist}
1935+
Sets the slice of \var{list} between \var{low} and \var{high} to the contents
1936+
of \var{itemlist}. Analogous to \code{list[low:high]=itemlist}. Returns 0
1937+
on success, -1 on failure.
19081938
\end{cfuncdesc}
19091939
19101940
\begin{cfuncdesc}{int}{PyList_Sort}{PyObject *list}
1911-
1941+
Sorts the items of \var{list} in place. Returns 0 on success, -1 on failure.
19121942
\end{cfuncdesc}
19131943
19141944
\begin{cfuncdesc}{int}{PyList_Reverse}{PyObject *list}
1945+
Reverses the items of \var{list} in place. Returns 0 on success, -1 on failure.
19151946
\end{cfuncdesc}
19161947
19171948
\begin{cfuncdesc}{PyObject*}{PyList_AsTuple}{PyObject *list}
19181949
Returns a new tuple object containing the contents of \var{list}.
19191950
\end{cfuncdesc}
19201951
19211952
\begin{cfuncdesc}{PyObject*}{PyList_GET_ITEM}{PyObject *list, int i}
1953+
Macro form of \code{PyList_GetItem} without error checking.
19221954
\end{cfuncdesc}
19231955
19241956
\begin{cfuncdesc}{int}{PyList_GET_SIZE}{PyObject *list}
1957+
Macro form of \code{PyList_GetSize} without error checking.
19251958
\end{cfuncdesc}
19261959
19271960
@@ -1979,29 +2012,31 @@ \subsection{Dictionary Objects}
19792012
19802013
\begin{cfuncdesc}{PyObject*}{PyDict_GetItem}{PyDictObject *p, PyObject *key}
19812014
Returns the object from dictionary \var{p} which has a key
1982-
\var{key}. Returns \NULL{} if the key \var{key} is not present.
2015+
\var{key}. Returns \NULL{} if the key \var{key} is not present, but
2016+
without (!) setting an exception. NOTE: this function returns a
2017+
``borrowed'' reference.
19832018
\end{cfuncdesc}
19842019
19852020
\begin{cfuncdesc}{PyObject*}{PyDict_GetItemString}{PyDictObject *p, char *key}
1986-
Does the same, but \var{key} is specified as a
1987-
\code{char *}, rather than a \code{PyObject *}.
2021+
This is the same as \code{PyDict_GetItem()}, but \var{key} is
2022+
specified as a \code{char *}, rather than a \code{PyObject *}.
19882023
\end{cfuncdesc}
19892024
19902025
\begin{cfuncdesc}{PyObject*}{PyDict_Items}{PyDictObject *p}
19912026
Returns a \code{PyListObject} containing all the items
1992-
from the dictionary, as in the mapping method \method{items()} (see
2027+
from the dictionary, as in the dictinoary method \method{items()} (see
19932028
the \emph{Python Library Reference}).
19942029
\end{cfuncdesc}
19952030
19962031
\begin{cfuncdesc}{PyObject*}{PyDict_Keys}{PyDictObject *p}
19972032
Returns a \code{PyListObject} containing all the keys
1998-
from the dictionary, as in the mapping method \method{keys()} (see the
2033+
from the dictionary, as in the dictionary method \method{keys()} (see the
19992034
\emph{Python Library Reference}).
20002035
\end{cfuncdesc}
20012036
20022037
\begin{cfuncdesc}{PyObject*}{PyDict_Values}{PyDictObject *p}
20032038
Returns a \code{PyListObject} containing all the values
2004-
from the dictionary \var{p}, as in the mapping method
2039+
from the dictionary \var{p}, as in the dictionary method
20052040
\method{values()} (see the \emph{Python Library Reference}).
20062041
\end{cfuncdesc}
20072042
@@ -2093,16 +2128,16 @@ \subsection{Long Integer Objects}
20932128
20942129
\begin{cfuncdesc}{long}{PyLong_AsLong}{PyObject *pylong}
20952130
Returns a \C{} \code{long} representation of the contents of \var{pylong}.
2096-
WHAT HAPPENS IF \var{pylong} > MAXLONG?
2131+
WHAT HAPPENS IF \var{pylong} is greater than \code{LONG_MAX}?
20972132
\end{cfuncdesc}
20982133
20992134
\begin{cfuncdesc}{unsigned long}{PyLong_AsUnsignedLong}{PyObject *pylong}
21002135
Returns a \C{} \code{unsigned long} representation of the contents of
2101-
\var{pylong}. WHAT HAPPENS IF \var{pylong} > MAXLONG?
2136+
\var{pylong}. WHAT HAPPENS IF \var{pylong} is greater than \code{ULONG_MAX}?
21022137
\end{cfuncdesc}
21032138
21042139
\begin{cfuncdesc}{double}{PyLong_AsDouble}{PyObject *pylong}
2105-
Returns a \C{} \code{double} representation of teh contents of \var{pylong}.
2140+
Returns a \C{} \code{double} representation of the contents of \var{pylong}.
21062141
\end{cfuncdesc}
21072142
21082143
\begin{cfuncdesc}{PyObject*}{PyLong_FromString}{char *str, char **pend,
@@ -2278,8 +2313,37 @@ \subsection{File Objects}
22782313
\subsection{CObjects}
22792314
\label{cObjects}
22802315
2281-
XXX
2316+
\begin{ctypedesc}{PyCObject}
2317+
This subtype of \code{PyObject} represents an opaque value, useful for
2318+
\C{} extension modules who need to pass an opaque value (as a
2319+
\code{void *} pointer) through Python code to other \C{} code. It is
2320+
often used to make a C function pointer defined in one module
2321+
available to other modules, so the regular import mechanism can be
2322+
used to access C APIs defined in dynamically loaded modules.
2323+
\end{ctypedesc}
22822324
2325+
\begin{cfuncdesc}{PyObject *}{PyCObject_FromVoidPtr}{void* cobj,
2326+
void (*destr)(void *)}
2327+
Creates a \code{PyCObject} from the \code{void *} \var{cobj}. The \var{destr}
2328+
function will be called when the object is reclaimed.
2329+
\end{cfuncdesc}
2330+
2331+
\begin{cfuncdesc}{PyObject *}{PyCObject_FromVoidPtrAndDesc}{void* cobj,
2332+
void* desc, void (*destr)(void *, void *) }
2333+
Creates a \code{PyCObject} from the \code{void *} \var{cobj}. The \var{destr}
2334+
function will be called when the object is reclaimed. The \var{desc} argument
2335+
can be used to pass extra callback data for the destructor function.
2336+
\end{cfuncdesc}
2337+
2338+
\begin{cfuncdesc}{void *}{PyCObject_AsVoidPtr}{PyObject* self}
2339+
Returns the object \code{void *} that the \code{PyCObject} \var{self}
2340+
was created with.
2341+
\end{cfuncdesc}
2342+
2343+
\begin{cfuncdesc}{void *}{PyCObject_GetDesc}{PyObject* self}
2344+
Returns the description \code{void *} that the \code{PyCObject}
2345+
\var{self} was created with.
2346+
\end{cfuncdesc}
22832347
22842348
\chapter{Initialization, Finalization, and Threads}
22852349
\label{initialization}

0 commit comments

Comments
 (0)