summaryrefslogtreecommitdiffstats
path: root/Doc/extending/extending.rst
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2009-07-11 10:14:54 (GMT)
committerGeorg Brandl <georg@python.org>2009-07-11 10:14:54 (GMT)
commit0294de028f1d5ca224c7abcb5223c13ff07aa943 (patch)
treed737e526414200c6c6c0f2b7c97e9471db587583 /Doc/extending/extending.rst
parent3405cbcf063bc91d67c377df239ee1a62313c111 (diff)
downloadcpython-0294de028f1d5ca224c7abcb5223c13ff07aa943.zip
cpython-0294de028f1d5ca224c7abcb5223c13ff07aa943.tar.gz
cpython-0294de028f1d5ca224c7abcb5223c13ff07aa943.tar.bz2
#6446: fix import_spam() function to use correct error and reference handling.
Diffstat (limited to 'Doc/extending/extending.rst')
-rw-r--r--Doc/extending/extending.rst25
1 files changed, 16 insertions, 9 deletions
diff --git a/Doc/extending/extending.rst b/Doc/extending/extending.rst
index d052ec2..5c99c3d 100644
--- a/Doc/extending/extending.rst
+++ b/Doc/extending/extending.rst
@@ -1219,16 +1219,23 @@ like this::
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);
+ PyObject *c_api_object;
+ PyObject *module;
+
+ module = PyImport_ImportModule("spam");
+ if (module == NULL)
+ return -1;
+
+ c_api_object = PyObject_GetAttrString(module, "_C_API");
+ if (c_api_object == NULL) {
+ Py_DECREF(module);
+ return -1;
}
+ if (PyCObject_Check(c_api_object))
+ PySpam_API = (void **)PyCObject_AsVoidPtr(c_api_object);
+
+ Py_DECREF(c_api_object);
+ Py_DECREF(module);
return 0;
}