cpython: ba1c48f8b571 (original) (raw)
Mercurial > cpython
changeset 78603:ba1c48f8b571 2.7
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:16:51 +0200 |
parents | 59f520542c1c |
children | 78b0f294674c |
files | Misc/NEWS Modules/_csv.c Modules/_io/textio.c Modules/_ssl.c Modules/cStringIO.c Modules/itertoolsmodule.c Modules/parsermodule.c Modules/pyexpat.c Objects/typeobject.c Python/bltinmodule.c Python/import.c |
diffstat | 11 files changed, 112 insertions(+), 52 deletions(-)[+] [-] Misc/NEWS 3 Modules/_csv.c 8 Modules/_io/textio.c 5 Modules/_ssl.c 6 Modules/cStringIO.c 6 Modules/itertoolsmodule.c 17 Modules/parsermodule.c 18 Modules/pyexpat.c 54 Objects/typeobject.c 12 Python/bltinmodule.c 22 Python/import.c 13 |
line wrap: on
line diff
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -9,6 +9,9 @@ What's New in Python 2.7.4 Core and Builtins ----------------- +- Issue #15604: Update uses of PyObject_IsTrue() to check for and handle
- Issue #15041: Update "see also" list in tkinter documentation.
- Issue #14579: Fix error handling bug in the utf-16 decoder. Patch by
--- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -208,8 +208,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 @@ -1013,8 +1013,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->encoding_start_of_stream = 0; if (self->seekable && self->encoder) {
--- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -1005,6 +1005,7 @@ PySSL_peercert(PySSLObject *self, PyObje int len; int verification; PyObject *binary_mode = Py_None;
if (!PyArg_ParseTuple(args, "|O:peer_certificate", &binary_mode)) return NULL; @@ -1012,7 +1013,10 @@ PySSL_peercert(PySSLObject *self, PyObje if (!self->peer_cert) Py_RETURN_NONE;
- b = PyObject_IsTrue(binary_mode);
- if (b < 0)
return NULL;[](#l4.18)
- if (b) { /* return cert in DER-encoded format */
unsigned char *bytes_buf = NULL;
--- a/Modules/cStringIO.c +++ b/Modules/cStringIO.c @@ -127,12 +127,16 @@ IO_cgetval(PyObject *self) { static PyObject * IO_getval(IOobject *self, PyObject *args) { PyObject *use_pos=Py_None;
- int b; Py_ssize_t s; if (!IO__opencheck(self)) return NULL; if (!PyArg_UnpackTuple(args,"getval", 0, 1,&use_pos)) return NULL;
- b = PyObject_IsTrue(use_pos);
- if (b < 0)
return NULL;[](#l5.16)
- if (b) { s=self->pos; if (s > self->string_size) s=self->string_size; }
--- 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; } @@ -3001,9 +3004,11 @@ ifilter_next(ifilterobject *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)
} } @@ -3144,9 +3149,11 @@ ifilterfalse_next(ifilterfalseobject *lz ok = PyObject_IsTrue(good); Py_DECREF(good); }return NULL;[](#l6.41)
if (!ok)[](#l6.49)
if (ok == 0)[](#l6.50) return item;[](#l6.51) Py_DECREF(item);[](#l6.52)
if (ok < 0)[](#l6.53)
} }return NULL;[](#l6.54)
--- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -350,10 +350,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)
@@ -401,10 +405,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 @@ -1174,13 +1174,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); } @@ -1549,7 +1552,10 @@ xmlparse_setattr(xmlparseobject *self, c return -1; } if (strcmp(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)
@@ -1568,39 +1574,39 @@ xmlparse_setattr(xmlparseobject *self, c return 0; } if (strcmp(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 (strcmp(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 (strcmp(name, "returns_unicode") == 0) {self->ordered_attributes = b;[](#l8.60) return 0;[](#l8.61)
if (PyObject_IsTrue(v)) {[](#l8.64)
int b = PyObject_IsTrue(v);[](#l8.65)
if (b < 0)[](#l8.66)
return -1;[](#l8.67)
if (b) {[](#l8.69) PyErr_SetString(PyExc_ValueError,[](#l8.70) "Unicode support not available");[](#l8.71) return -1;[](#l8.72)
self->returns_unicode = 1;[](#l8.74)
}[](#l8.75)
}[](#l8.77)
else[](#l8.78)
self->returns_unicode = 0;[](#l8.79)
} if (strcmp(name, "specified_attributes") == 0) {self->returns_unicode = b;[](#l8.80) return 0;[](#l8.81)
if (PyObject_IsTrue(v))[](#l8.84)
self->specified_attributes = 1;[](#l8.85)
else[](#l8.86)
self->specified_attributes = 0;[](#l8.87)
int b = PyObject_IsTrue(v);[](#l8.88)
if (b < 0)[](#l8.89)
return -1;[](#l8.90)
}self->specified_attributes = b;[](#l8.91) return 0;[](#l8.92)
--- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -327,11 +327,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)
@@ -340,12 +344,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 @@ -313,7 +313,7 @@ builtin_filter(PyObject *self, PyObject ok = PyObject_IsTrue(good); Py_DECREF(good); }
if (ok) {[](#l10.7)
if (ok > 0) {[](#l10.8) if (j < len)[](#l10.9) PyList_SET_ITEM(result, j, item);[](#l10.10) else {[](#l10.11)
@@ -324,8 +324,11 @@ builtin_filter(PyObject *self, PyObject } ++j; }
else[](#l10.16)
else {[](#l10.17) Py_DECREF(item);[](#l10.18)
if (ok < 0)[](#l10.19)
goto Fail_result_it;[](#l10.20)
} @@ -2784,12 +2787,15 @@ filtertuple(PyObject *func, PyObject *tu } ok = PyObject_IsTrue(good); Py_DECREF(good);}[](#l10.21)
if (ok) {[](#l10.29)
if (ok > 0) {[](#l10.30) if (PyTuple_SetItem(result, j++, item) < 0)[](#l10.31) goto Fail_1;[](#l10.32) }[](#l10.33)
else[](#l10.34)
else {[](#l10.35) Py_DECREF(item);[](#l10.36)
if (ok < 0)[](#l10.37)
goto Fail_1;[](#l10.38)
} if (_PyTuple_Resize(&result, j) < 0) @@ -2851,7 +2857,7 @@ filterstring(PyObject *func, PyObject *s ok = PyObject_IsTrue(good); Py_DECREF(good); }}[](#l10.39)
if (ok) {[](#l10.47)
if (ok > 0) {[](#l10.48) Py_ssize_t reslen;[](#l10.49) if (!PyString_Check(item)) {[](#l10.50) PyErr_SetString(PyExc_TypeError, "can't filter str to str:"[](#l10.51)
@@ -2917,6 +2923,8 @@ filterstring(PyObject *func, PyObject *s } } Py_DECREF(item);
if (ok < 0)[](#l10.56)
} if (j < outlen) @@ -2977,7 +2985,7 @@ filterunicode(PyObject *func, PyObject * ok = PyObject_IsTrue(good); Py_DECREF(good); }goto Fail_1;[](#l10.57)
if (ok) {[](#l10.65)
if (ok > 0) {[](#l10.66) Py_ssize_t reslen;[](#l10.67) if (!PyUnicode_Check(item)) {[](#l10.68) PyErr_SetString(PyExc_TypeError,[](#l10.69)
@@ -3032,6 +3040,8 @@ filterunicode(PyObject *func, PyObject * } } Py_DECREF(item);
--- a/Python/import.c +++ b/Python/import.c @@ -1043,7 +1043,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)
} @@ -2200,7 +2203,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)