Mailing List Archive

python/dist/src/Doc/ext embedding.tex,1.4,1.5
Update of /cvsroot/python/python/dist/src/Doc/ext
In directory usw-pr-cvs1:/tmp/cvs-serv23151/ext

Modified Files:
embedding.tex
Log Message:
Change example of retrieving & calling a Python function to not use
PyModule_GetDict(), which is also more flexible: it does not assume that the
"module" is a real module.


Index: embedding.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/ext/embedding.tex,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** embedding.tex 28 Nov 2001 07:26:14 -0000 1.4
--- embedding.tex 12 Apr 2002 19:04:17 -0000 1.5
***************
*** 179,200 ****

\begin{verbatim}
! pDict = PyModule_GetDict(pModule);
! /* pDict is a borrowed reference */
!
! pFunc = PyDict_GetItemString(pDict, argv[2]);
! /* pFun is a borrowed reference */

if (pFunc && PyCallable_Check(pFunc)) {
...
}
\end{verbatim}

! Once the script is loaded, its dictionary is retrieved with
! \cfunction{PyModule_GetDict()}. The dictionary is then searched using
! the normal dictionary access routines for the function name. If the
! name exists, and the object retunred is callable, you can safely
! assume that it is a function. The program then proceeds by
! constructing a tuple of arguments as normal. The call to the python
! function is then made with:

\begin{verbatim}
--- 179,197 ----

\begin{verbatim}
! pFunc = PyObject_GetAttrString(pModule, argv[2]);
! /* pFunc is a new reference */

if (pFunc && PyCallable_Check(pFunc)) {
...
}
+ Py_XDECREF(pFunc);
\end{verbatim}

! Once the script is loaded, the name we're looking for is retrieved
! using \cfunction{PyObject_GetAttrString()}. If the name exists, and
! the object retunred is callable, you can safely assume that it is a
! function. The program then proceeds by constructing a tuple of
! arguments as normal. The call to the Python function is then made
! with:

\begin{verbatim}