@@ -95,10 +95,11 @@ shortly how it ends up being called)::
9595 spam_system(PyObject *self, PyObject *args)
9696 {
9797 const char *command;
98- if (!PyArg_ParseTuple(args, "s", &command)) {
98+ int sts;
99+
100+ if (!PyArg_ParseTuple(args, "s", &command))
99101 return NULL;
100- }
101- int sts = system(command);
102+ sts = system(command);
102103 return PyLong_FromLong(sts);
103104 }
104105
@@ -306,10 +307,11 @@ call to :c:func:`PyErr_SetString` as shown below::
306307 spam_system(PyObject *self, PyObject *args)
307308 {
308309 const char *command;
309- if (!PyArg_ParseTuple(args, "s", &command)) {
310+ int sts;
311+
312+ if (!PyArg_ParseTuple(args, "s", &command))
310313 return NULL;
311- }
312- int sts = system(command);
314+ sts = system(command);
313315 if (sts < 0) {
314316 spam_state *state = PyModule_GetState(self);
315317 if (state != NULL) {
@@ -329,9 +331,8 @@ Back to the Example
329331Going back to our example function, you should now be able to understand this
330332statement::
331333
332- if (!PyArg_ParseTuple(args, "s", &command)) {
334+ if (!PyArg_ParseTuple(args, "s", &command))
333335 return NULL;
334- }
335336
336337It returns ``NULL `` (the error indicator for functions returning object pointers)
337338if an error is detected in the argument list, relying on the exception set by
@@ -344,7 +345,7 @@ the variable :c:data:`!command` should properly be declared as ``const char
344345The next statement is a call to the Unix function :c:func: `system `, passing it
345346the string we just got from :c:func: `PyArg_ParseTuple `::
346347
347- int sts = system(command);
348+ sts = system(command);
348349
349350Our :func: `!spam.system ` function must return the value of :c:data: `!sts ` as a
350351Python object. This is done using the function :c:func: `PyLong_FromLong `. ::
@@ -1285,10 +1286,11 @@ The function :c:func:`!spam_system` is modified in a trivial way::
12851286 spam_system(PyObject *self, PyObject *args)
12861287 {
12871288 const char *command;
1288- if (!PyArg_ParseTuple(args, "s", &command)) {
1289+ int sts;
1290+
1291+ if (!PyArg_ParseTuple(args, "s", &command))
12891292 return NULL;
1290- }
1291- int sts = PySpam_System(command);
1293+ sts = PySpam_System(command);
12921294 return PyLong_FromLong(sts);
12931295 }
12941296
0 commit comments