diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-08-15 21:20:39 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-08-15 21:20:39 (GMT) |
commit | 721738fbee8d75dab5a5d3c4f3dbd7c72d76925e (patch) | |
tree | c0e693ed7f2e6c44d48555f3cc4d8775ac8e14bb /Modules/parsermodule.c | |
parent | 9351117139363f3e600c541bc88139702a055db8 (diff) | |
parent | 6f430e496339aea3e688165340456b555d5e1035 (diff) | |
download | cpython-721738fbee8d75dab5a5d3c4f3dbd7c72d76925e.zip cpython-721738fbee8d75dab5a5d3c4f3dbd7c72d76925e.tar.gz cpython-721738fbee8d75dab5a5d3c4f3dbd7c72d76925e.tar.bz2 |
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Patch by Serhiy Storchaka.
Diffstat (limited to 'Modules/parsermodule.c')
-rw-r--r-- | Modules/parsermodule.c | 48 |
1 files changed, 16 insertions, 32 deletions
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index 2c079ad..b4602f5 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -382,36 +382,28 @@ parser_sizeof(PyST_Object *st, void *unused) static PyObject* parser_st2tuple(PyST_Object *self, PyObject *args, PyObject *kw) { - PyObject *line_option = 0; - PyObject *col_option = 0; + int line_info = 0; + int col_info = 0; PyObject *res = 0; int ok; static char *keywords[] = {"st", "line_info", "col_info", NULL}; if (self == NULL || PyModule_Check(self)) { - ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|OO:st2tuple", keywords, - &PyST_Type, &self, &line_option, - &col_option); + ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|pp:st2tuple", keywords, + &PyST_Type, &self, &line_info, + &col_info); } else - ok = PyArg_ParseTupleAndKeywords(args, kw, "|OO:totuple", &keywords[1], - &line_option, &col_option); + ok = PyArg_ParseTupleAndKeywords(args, kw, "|pp:totuple", &keywords[1], + &line_info, &col_info); if (ok != 0) { - int lineno = 0; - int col_offset = 0; - if (line_option != NULL) { - lineno = (PyObject_IsTrue(line_option) != 0) ? 1 : 0; - } - if (col_option != NULL) { - col_offset = (PyObject_IsTrue(col_option) != 0) ? 1 : 0; - } /* * Convert ST into a tuple representation. Use Guido's function, * since it's known to work already. */ res = node2tuple(((PyST_Object*)self)->st_node, - PyTuple_New, PyTuple_SetItem, lineno, col_offset); + PyTuple_New, PyTuple_SetItem, line_info, col_info); } return (res); } @@ -426,35 +418,27 @@ parser_st2tuple(PyST_Object *self, PyObject *args, PyObject *kw) static PyObject* parser_st2list(PyST_Object *self, PyObject *args, PyObject *kw) { - PyObject *line_option = 0; - PyObject *col_option = 0; + int line_info = 0; + int col_info = 0; PyObject *res = 0; int ok; static char *keywords[] = {"st", "line_info", "col_info", NULL}; if (self == NULL || PyModule_Check(self)) - ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|OO:st2list", keywords, - &PyST_Type, &self, &line_option, - &col_option); + ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|pp:st2list", keywords, + &PyST_Type, &self, &line_info, + &col_info); else - ok = PyArg_ParseTupleAndKeywords(args, kw, "|OO:tolist", &keywords[1], - &line_option, &col_option); + ok = PyArg_ParseTupleAndKeywords(args, kw, "|pp:tolist", &keywords[1], + &line_info, &col_info); if (ok) { - int lineno = 0; - int col_offset = 0; - if (line_option != 0) { - lineno = PyObject_IsTrue(line_option) ? 1 : 0; - } - if (col_option != NULL) { - col_offset = (PyObject_IsTrue(col_option) != 0) ? 1 : 0; - } /* * Convert ST into a tuple representation. Use Guido's function, * since it's known to work already. */ res = node2tuple(self->st_node, - PyList_New, PyList_SetItem, lineno, col_offset); + PyList_New, PyList_SetItem, line_info, col_info); } return (res); } |