diff Doc/api/api.tex @ 15453:7721fb509462 legacy-trunk

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.
author Fred Drake <fdrake@acm.org>
date Wed, 29 Nov 2000 15:48:22 +0000
parents 7e514f1fe31f
children 35749a557f1e
line wrap: on
line diff
--- a/Doc/api/api.tex	Wed Nov 29 12:13:59 2000 +0000
+++ b/Doc/api/api.tex	Wed Nov 29 15:48:22 2000 +0000
@@ -456,7 +456,7 @@
         item = dict[key]
     except KeyError:
         item = 0
-    return item + 1
+    dict[key] = item + 1
 \end{verbatim}
 \ttindex{incr_item()}
 
@@ -472,21 +472,25 @@
     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 (PyObject_SetItem(dict, key, incremented_item) < 0) goto error;
+    if (incremented_item == NULL)
+        goto error;
+
+    if (PyObject_SetItem(dict, key, incremented_item) < 0)
+        goto error;
     rv = 0; /* Success */
     /* Continue with cleanup code */