cpython: 56dc7b09f390 (original) (raw)
Mercurial > cpython
changeset 78604:56dc7b09f390 3.2
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly. Patch by Serhiy Storchaka. [#15604]
Antoine Pitrou solipsis@pitrou.net | |
---|---|
date | Wed, 15 Aug 2012 23🔞25 +0200 |
parents | fa9eedea0b48 |
children | b878df1d23b1 8ff172a1b679 |
files | Misc/NEWS Modules/_csv.c Modules/_io/textio.c Modules/_posixsubprocess.c Modules/_ssl.c Modules/itertoolsmodule.c Modules/parsermodule.c Modules/pyexpat.c Objects/typeobject.c Python/bltinmodule.c Python/import.c |
diffstat | 11 files changed, 87 insertions(+), 39 deletions(-)[+] [-] Misc/NEWS 3 Modules/_csv.c 8 Modules/_io/textio.c 5 Modules/_posixsubprocess.c 2 Modules/_ssl.c 6 Modules/itertoolsmodule.c 13 Modules/parsermodule.c 18 Modules/pyexpat.c 42 Objects/typeobject.c 12 Python/bltinmodule.c 4 Python/import.c 13 |
line wrap: on
line diff
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.2.4 Core and Builtins ----------------- +- Issue #15604: Update uses of PyObject_IsTrue() to check for and handle
--- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -166,8 +166,12 @@ static int { if (src == NULL) *target = dflt;
- else {
int b = PyObject_IsTrue(src);[](#l2.10)
if (b < 0)[](#l2.11)
return -1;[](#l2.12)
*target = b;[](#l2.13)
- } return 0; }
--- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1046,8 +1046,11 @@ textiowrapper_init(textio *self, PyObjec res = PyObject_CallMethod(buffer, "seekable", NULL); if (res == NULL) goto error;
- r = PyObject_IsTrue(res); Py_DECREF(res);
- if (r < 0)
goto error;[](#l3.11)
- self->seekable = self->telling = r;
self->has_read1 = PyObject_HasAttrString(buffer, "read1");
--- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -525,6 +525,8 @@ subprocess_fork_exec(PyObject* self, PyO return NULL; close_fds = PyObject_IsTrue(py_close_fds);
- if (close_fds < 0)
if (close_fds && errpipe_write < 3) { /* precondition */ PyErr_SetString(PyExc_ValueError, "errpipe_write must be >= 3"); return NULL;return NULL;[](#l4.8)
--- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -883,6 +883,7 @@ PySSL_peercert(PySSLSocket *self, PyObje int len; int verification; PyObject *binary_mode = Py_None;
if (!PyArg_ParseTuple(args, "|O:peer_certificate", &binary_mode)) return NULL; @@ -890,7 +891,10 @@ PySSL_peercert(PySSLSocket *self, PyObje if (!self->peer_cert) Py_RETURN_NONE;
- b = PyObject_IsTrue(binary_mode);
- if (b < 0)
return NULL;[](#l5.18)
- if (b) { /* return cert in DER-encoded format */
unsigned char *bytes_buf = NULL;
--- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -903,11 +903,13 @@ dropwhile_next(dropwhileobject *lz) } ok = PyObject_IsTrue(good); Py_DECREF(good);
if (!ok) {[](#l6.7)
if (ok == 0) {[](#l6.8) lz->start = 1;[](#l6.9) return item;[](#l6.10) }[](#l6.11) Py_DECREF(item);[](#l6.12)
if (ok < 0)[](#l6.13)
} } @@ -1043,10 +1045,11 @@ takewhile_next(takewhileobject *lz) } ok = PyObject_IsTrue(good); Py_DECREF(good);return NULL;[](#l6.14)
- if (ok == 0)
return NULL; } @@ -2959,9 +2962,11 @@ filterfalse_next(filterfalseobject *lz) ok = PyObject_IsTrue(good); Py_DECREF(good); }lz->stop = 1;[](#l6.28)
if (!ok)[](#l6.36)
if (ok == 0)[](#l6.37) return item;[](#l6.38) Py_DECREF(item);[](#l6.39)
if (ok < 0)[](#l6.40)
} }return NULL;[](#l6.41)
--- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -401,10 +401,14 @@ parser_st2tuple(PyST_Object *self, PyObj int lineno = 0; int col_offset = 0; if (line_option != NULL) {
lineno = (PyObject_IsTrue(line_option) != 0) ? 1 : 0;[](#l7.7)
lineno = PyObject_IsTrue(line_option);[](#l7.8)
if (lineno < 0)[](#l7.9)
return NULL;[](#l7.10) }[](#l7.11) if (col_option != NULL) {[](#l7.12)
col_offset = (PyObject_IsTrue(col_option) != 0) ? 1 : 0;[](#l7.13)
col_offset = PyObject_IsTrue(col_option);[](#l7.14)
if (col_offset < 0)[](#l7.15)
return NULL;[](#l7.16) }[](#l7.17) /*[](#l7.18) * Convert ST into a tuple representation. Use Guido's function,[](#l7.19)
@@ -444,10 +448,14 @@ parser_st2list(PyST_Object *self, PyObje int lineno = 0; int col_offset = 0; if (line_option != 0) {
lineno = PyObject_IsTrue(line_option) ? 1 : 0;[](#l7.24)
lineno = PyObject_IsTrue(line_option);[](#l7.25)
if (lineno < 0)[](#l7.26)
return NULL;[](#l7.27) }[](#l7.28)
if (col_option != NULL) {[](#l7.29)
col_offset = (PyObject_IsTrue(col_option) != 0) ? 1 : 0;[](#l7.30)
if (col_option != 0) {[](#l7.31)
col_offset = PyObject_IsTrue(col_option);[](#l7.32)
if (col_offset < 0)[](#l7.33)
return NULL;[](#l7.34) }[](#l7.35) /*[](#l7.36) * Convert ST into a tuple representation. Use Guido's function,[](#l7.37)
--- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -1033,13 +1033,16 @@ static PyObject * xmlparse_UseForeignDTD(xmlparseobject *self, PyObject *args) { PyObject *flagobj = NULL;
- if (flagobj != NULL)
flag = PyObject_IsTrue(flagobj) ? XML_TRUE : XML_FALSE;[](#l8.14)
- rc = XML_UseForeignDTD(self->itself, flag);
- if (flagobj != NULL) {
flag = PyObject_IsTrue(flagobj);[](#l8.17)
if (flag < 0)[](#l8.18)
return NULL;[](#l8.19)
- }
- rc = XML_UseForeignDTD(self->itself, flag ? XML_TRUE : XML_FALSE); if (rc != XML_ERROR_NONE) { return set_error(self, rc); } @@ -1397,7 +1400,10 @@ xmlparse_setattro(xmlparseobject *self, } assert(PyUnicode_Check(name)); if (PyUnicode_CompareWithASCIIString(name, "buffer_text") == 0) {
if (PyObject_IsTrue(v)) {[](#l8.29)
int b = PyObject_IsTrue(v);[](#l8.30)
if (b < 0)[](#l8.31)
return -1;[](#l8.32)
if (b) {[](#l8.33) if (self->buffer == NULL) {[](#l8.34) self->buffer = malloc(self->buffer_size);[](#l8.35) if (self->buffer == NULL) {[](#l8.36)
@@ -1416,25 +1422,25 @@ xmlparse_setattro(xmlparseobject *self, return 0; } if (PyUnicode_CompareWithASCIIString(name, "namespace_prefixes") == 0) {
if (PyObject_IsTrue(v))[](#l8.41)
self->ns_prefixes = 1;[](#l8.42)
else[](#l8.43)
self->ns_prefixes = 0;[](#l8.44)
int b = PyObject_IsTrue(v);[](#l8.45)
if (b < 0)[](#l8.46)
return -1;[](#l8.47)
} if (PyUnicode_CompareWithASCIIString(name, "ordered_attributes") == 0) {self->ns_prefixes = b;[](#l8.48) XML_SetReturnNSTriplet(self->itself, self->ns_prefixes);[](#l8.49) return 0;[](#l8.50)
if (PyObject_IsTrue(v))[](#l8.53)
self->ordered_attributes = 1;[](#l8.54)
else[](#l8.55)
self->ordered_attributes = 0;[](#l8.56)
int b = PyObject_IsTrue(v);[](#l8.57)
if (b < 0)[](#l8.58)
return -1;[](#l8.59)
} if (PyUnicode_CompareWithASCIIString(name, "specified_attributes") == 0) {self->ordered_attributes = b;[](#l8.60) return 0;[](#l8.61)
if (PyObject_IsTrue(v))[](#l8.64)
self->specified_attributes = 1;[](#l8.65)
else[](#l8.66)
self->specified_attributes = 0;[](#l8.67)
int b = PyObject_IsTrue(v);[](#l8.68)
if (b < 0)[](#l8.69)
return -1;[](#l8.70)
}self->specified_attributes = b;[](#l8.71) return 0;[](#l8.72)
--- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -340,11 +340,15 @@ type_set_abstractmethods(PyTypeObject *t abc.ABCMeta.new, so this function doesn't do anything special to update subclasses. */
- int abstract, res; if (value != NULL) {
abstract = PyObject_IsTrue(value);[](#l9.10)
if (abstract < 0)[](#l9.11)
} else {return -1;[](#l9.12) res = PyDict_SetItemString(type->tp_dict, "__abstractmethods__", value);[](#l9.13)
abstract = 0;[](#l9.16) res = PyDict_DelItemString(type->tp_dict, "__abstractmethods__");[](#l9.17) if (res && PyErr_ExceptionMatches(PyExc_KeyError)) {[](#l9.18) PyErr_SetString(PyExc_AttributeError, "__abstractmethods__");[](#l9.19)
@@ -353,12 +357,10 @@ type_set_abstractmethods(PyTypeObject *t } if (res == 0) { PyType_Modified(type);
if (value && PyObject_IsTrue(value)) {[](#l9.24)
if (abstract)[](#l9.25) type->tp_flags |= Py_TPFLAGS_IS_ABSTRACT;[](#l9.26)
}[](#l9.27)
else {[](#l9.28)
else[](#l9.29) type->tp_flags &= ~Py_TPFLAGS_IS_ABSTRACT;[](#l9.30)
--- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -428,9 +428,11 @@ filter_next(filterobject *lz) ok = PyObject_IsTrue(good); Py_DECREF(good); }
if (ok)[](#l10.7)
if (ok > 0)[](#l10.8) return item;[](#l10.9) Py_DECREF(item);[](#l10.10)
if (ok < 0)[](#l10.11)
} }return NULL;[](#l10.12)
--- a/Python/import.c +++ b/Python/import.c @@ -1338,7 +1338,10 @@ load_source_module(char *name, char *pat name, pathname); if (cpathname) { PyObject *ro = PySys_GetObject("dont_write_bytecode");
if (ro == NULL || !PyObject_IsTrue(ro))[](#l11.7)
int b = (ro == NULL) ? 0 : PyObject_IsTrue(ro);[](#l11.8)
if (b < 0)[](#l11.9)
goto error_exit;[](#l11.10)
} @@ -2504,7 +2507,13 @@ import_module_level(char *name, PyObject } if (fromlist != NULL) {if (!b)[](#l11.11) write_compiled_module(co, cpathname, &st);[](#l11.12) }[](#l11.13)
if (fromlist == Py_None || !PyObject_IsTrue(fromlist))[](#l11.19)