[Python-checkins] python/dist/src/Doc/ext extending.tex,1.18,1.19

fdrake@sourceforge.net fdrake@sourceforge.net
2002年4月12日 12:08:34 -0700


Update of /cvsroot/python/python/dist/src/Doc/ext
In directory usw-pr-cvs1:/tmp/cvs-serv24289/ext
Modified Files:
	extending.tex 
Log Message:
Do not use PyModule_GetDict().
Clean up the example of exporting a C-callable API from an extension module.
Add a hyperlink to a related section in the Python/C API reference.
Index: extending.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/ext/extending.tex,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** extending.tex	9 Apr 2002 21:09:42 -0000	1.18
--- extending.tex	12 Apr 2002 19:08:31 -0000	1.19
***************
*** 218,227 ****
 initspam(void)
 {
! PyObject *m, *d;
 
 m = Py_InitModule("spam", SpamMethods);
! d = PyModule_GetDict(m);
 SpamError = PyErr_NewException("spam.error", NULL, NULL);
! PyDict_SetItemString(d, "error", SpamError);
 }
 \end{verbatim}
--- 218,228 ----
 initspam(void)
 {
! PyObject *m;
 
 m = Py_InitModule("spam", SpamMethods);
! 
 SpamError = PyErr_NewException("spam.error", NULL, NULL);
! Py_INCREF(SpamError);
! PyModule_AddObject(m, "error", SpamError);
 }
 \end{verbatim}
***************
*** 1278,1288 ****
 c_api_object = PyCObject_FromVoidPtr((void *)PySpam_API, NULL);
 
! if (c_api_object != NULL) {
! /* Create a name for this object in the module's namespace */
! PyObject *d = PyModule_GetDict(m);
! 
! PyDict_SetItemString(d, "_C_API", c_api_object);
! Py_DECREF(c_api_object);
! }
 }
 \end{verbatim}
--- 1279,1284 ----
 c_api_object = PyCObject_FromVoidPtr((void *)PySpam_API, NULL);
 
! if (c_api_object != NULL)
! PyModule_AddObject(m, "_C_API", c_api_object);
 }
 \end{verbatim}
***************
*** 1325,1338 ****
 (*(PySpam_System_RETURN (*)PySpam_System_PROTO) PySpam_API[PySpam_System_NUM])
 
! #define import_spam() \
! { \
! PyObject *module = PyImport_ImportModule("spam"); \
! if (module != NULL) { \
! PyObject *module_dict = PyModule_GetDict(module); \
! PyObject *c_api_object = PyDict_GetItemString(module_dict, "_C_API"); \
! if (PyCObject_Check(c_api_object)) { \
! PySpam_API = (void **)PyCObject_AsVoidPtr(c_api_object); \
! } \
! } \
 }
 
--- 1321,1339 ----
 (*(PySpam_System_RETURN (*)PySpam_System_PROTO) PySpam_API[PySpam_System_NUM])
 
! /* Return -1 and set exception on error, 0 on success. */
! static int
! import_spam(void)
! {
! PyObject *module = PyImport_ImportModule("spam");
! 
! if (module != NULL) {
! PyObject *c_api_object = PyObject_GetAttrString(module, "_C_API");
! if (c_api_object == NULL)
! return -1;
! if (PyCObject_Check(c_api_object))
! PySpam_API = (void **)PyCObject_AsVoidPtr(c_api_object);
! Py_DECREF(c_api_object);
! }
! return 0;
 }
 
***************
*** 1358,1362 ****
 
 Py_InitModule("client", ClientMethods);
! import_spam();
 }
 \end{verbatim}
--- 1359,1365 ----
 
 Py_InitModule("client", ClientMethods);
! if (import_spam() < 0)
! return;
! /* additional initialization can happen here */
 }
 \end{verbatim}
***************
*** 1371,1375 ****
 deallocation of the pointer stored in a CObject. The details
 are described in the \citetitle[../api/api.html]{Python/C API
! Reference Manual} in the section ``CObjects'' and in the
! implementation of CObjects (files \file{Include/cobject.h} and
 \file{Objects/cobject.c} in the Python source code distribution).
--- 1374,1379 ----
 deallocation of the pointer stored in a CObject. The details
 are described in the \citetitle[../api/api.html]{Python/C API
! Reference Manual} in the section
! ``\ulink{CObjects}{../api/cObjects.html}'' and in the implementation
! of CObjects (files \file{Include/cobject.h} and
 \file{Objects/cobject.c} in the Python source code distribution).

AltStyle によって変換されたページ (->オリジナル) /