summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2000-11-29 15:48:22 (GMT)
committerFred Drake <fdrake@acm.org>2000-11-29 15:48:22 (GMT)
commit6b3f3f2861fdb86f0065b7d797ea76098797e06c (patch)
treec5f0d15b092c8e2e263710a2e99bcf2284f42cf5 /Doc
parent15ffc71c0f811d4c3053efb0480d70502ec35c99 (diff)
downloadcpython-6b3f3f2861fdb86f0065b7d797ea76098797e06c.zip
cpython-6b3f3f2861fdb86f0065b7d797ea76098797e06c.tar.gz
cpython-6b3f3f2861fdb86f0065b7d797ea76098797e06c.tar.bz2
In the first discussion showing how to handle exceptions from C, make the
Python equivalent actually equivalent to the C code. Also, in the C code, place the "goto" statements on a line by themselves for better visibility of statements that affect control flow. This closes bug #123398.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/api/api.tex18
1 files changed, 11 insertions, 7 deletions
diff --git a/Doc/api/api.tex b/Doc/api/api.tex
index e38e0b5..28fd985 100644
--- a/Doc/api/api.tex
+++ b/Doc/api/api.tex
@@ -456,7 +456,7 @@ def incr_item(dict, key):
item = dict[key]
except KeyError:
item = 0
- return item + 1
+ dict[key] = item + 1
\end{verbatim}
\ttindex{incr_item()}
@@ -472,21 +472,25 @@ int incr_item(PyObject *dict, PyObject *key)
item = PyObject_GetItem(dict, key);
if (item == NULL) {
/* Handle KeyError only: */
- if (!PyErr_ExceptionMatches(PyExc_KeyError)) goto error;
+ if (!PyErr_ExceptionMatches(PyExc_KeyError))
+ goto error;
/* Clear the error and use zero: */
PyErr_Clear();
item = PyInt_FromLong(0L);
- if (item == NULL) goto error;
+ if (item == NULL)
+ goto error;
}
-
const_one = PyInt_FromLong(1L);
- if (const_one == NULL) goto error;
+ if (const_one == NULL)
+ goto error;
incremented_item = PyNumber_Add(item, const_one);
- if (incremented_item == NULL) goto error;
+ if (incremented_item == NULL)
+ goto error;
- if (PyObject_SetItem(dict, key, incremented_item) < 0) goto error;
+ if (PyObject_SetItem(dict, key, incremented_item) < 0)
+ goto error;
rv = 0; /* Success */
/* Continue with cleanup code */