[issue15604] PyObject_IsTrue failure checks

2012-08-15 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Patches updated again.

--
Added file: http://bugs.python.org/file26838/istrue_check-3.3_3.patch
Added file: http://bugs.python.org/file26839/istrue_check-3.2_3.patch
Added file: http://bugs.python.org/file26840/istrue_check-2.7_3.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15604
___diff -r 5dc2b4a542f1 Modules/_csv.c
--- a/Modules/_csv.cWed Aug 15 22:53:56 2012 +0300
+++ b/Modules/_csv.cWed Aug 15 23:48:49 2012 +0300
@@ -196,8 +196,12 @@
 {
 if (src == NULL)
 *target = dflt;
-else
-*target = PyObject_IsTrue(src);
+else {
+int b = PyObject_IsTrue(src);
+if (b  0)
+return -1;
+*target = b;
+}
 return 0;
 }
 
diff -r 5dc2b4a542f1 Modules/_io/textio.c
--- a/Modules/_io/textio.c  Wed Aug 15 22:53:56 2012 +0300
+++ b/Modules/_io/textio.c  Wed Aug 15 23:48:49 2012 +0300
@@ -1056,8 +1056,11 @@
 res = _PyObject_CallMethodId(buffer, PyId_seekable, NULL);
 if (res == NULL)
 goto error;
-self-seekable = self-telling = PyObject_IsTrue(res);
+r = PyObject_IsTrue(res);
 Py_DECREF(res);
+if (r  0)
+goto error;
+self-seekable = self-telling = r;
 
 self-has_read1 = _PyObject_HasAttrId(buffer, PyId_read1);
 
diff -r 5dc2b4a542f1 Modules/_posixsubprocess.c
--- a/Modules/_posixsubprocess.cWed Aug 15 22:53:56 2012 +0300
+++ b/Modules/_posixsubprocess.cWed Aug 15 23:48:49 2012 +0300
@@ -503,7 +503,7 @@
 subprocess_fork_exec(PyObject* self, PyObject *args)
 {
 PyObject *gc_module = NULL;
-PyObject *executable_list, *py_close_fds, *py_fds_to_keep;
+PyObject *executable_list, *py_fds_to_keep;
 PyObject *env_list, *preexec_fn;
 PyObject *process_args, *converted_args = NULL, *fast_args = NULL;
 PyObject *preexec_fn_args_tuple = NULL;
@@ -518,15 +518,14 @@
 Py_ssize_t arg_num;
 
 if (!PyArg_ParseTuple(
-args, OOiiO:fork_exec,
-process_args, executable_list, py_close_fds, py_fds_to_keep,
+args, OOpOOOiiO:fork_exec,
+process_args, executable_list, close_fds, py_fds_to_keep,
 cwd_obj, env_list,
 p2cread, p2cwrite, c2pread, c2pwrite,
 errread, errwrite, errpipe_read, errpipe_write,
 restore_signals, call_setsid, preexec_fn))
 return NULL;
 
-close_fds = PyObject_IsTrue(py_close_fds);
 if (close_fds  errpipe_write  3) {  /* precondition */
 PyErr_SetString(PyExc_ValueError, errpipe_write must be = 3);
 return NULL;
diff -r 5dc2b4a542f1 Modules/_ssl.c
--- a/Modules/_ssl.cWed Aug 15 22:53:56 2012 +0300
+++ b/Modules/_ssl.cWed Aug 15 23:48:49 2012 +0300
@@ -1037,15 +1037,15 @@
 PyObject *retval = NULL;
 int len;
 int verification;
-PyObject *binary_mode = Py_None;
+int binary_mode = 0;
 
-if (!PyArg_ParseTuple(args, |O:peer_certificate, binary_mode))
+if (!PyArg_ParseTuple(args, |p:peer_certificate, binary_mode))
 return NULL;
 
 if (!self-peer_cert)
 Py_RETURN_NONE;
 
-if (PyObject_IsTrue(binary_mode)) {
+if (binary_mode) {
 /* return cert in DER-encoded format */
 
 unsigned char *bytes_buf = NULL;
diff -r 5dc2b4a542f1 Modules/itertoolsmodule.c
--- a/Modules/itertoolsmodule.c Wed Aug 15 22:53:56 2012 +0300
+++ b/Modules/itertoolsmodule.c Wed Aug 15 23:48:49 2012 +0300
@@ -1105,11 +1105,13 @@
 }
 ok = PyObject_IsTrue(good);
 Py_DECREF(good);
-if (!ok) {
+if (ok == 0) {
 lz-start = 1;
 return item;
 }
 Py_DECREF(item);
+if (ok  0)
+return NULL;
 }
 }
 
@@ -1124,7 +1126,7 @@
 dropwhile_setstate(dropwhileobject *lz, PyObject *state)
 {
 int start = PyObject_IsTrue(state);
-if (start == -1)
+if (start  0)
 return NULL;
 lz-start = start;
 Py_RETURN_NONE;
@@ -1270,10 +1272,11 @@
 }
 ok = PyObject_IsTrue(good);
 Py_DECREF(good);
-if (ok)
+if (ok == 1)
 return item;
 Py_DECREF(item);
-lz-stop = 1;
+if (ok == 0)
+lz-stop = 1;
 return NULL;
 }
 
@@ -1288,7 +1291,7 @@
 takewhile_reduce_setstate(takewhileobject *lz, PyObject *state)
 {
 int stop = PyObject_IsTrue(state);
-if (stop == -1)
+if (stop  0)
 return NULL;
 lz-stop = stop;
 Py_RETURN_NONE;
@@ -3536,7 +3539,7 @@
 if (ok == 1)
 return datum;
 Py_DECREF(datum);
-if (ok == -1)
+if (ok  0)
 return NULL;
 }
 }
@@ -3692,9 +3695,11 @@
 ok = PyObject_IsTrue(good);
 Py_DECREF(good);
 }
-if (!ok)
+if (ok == 0)
 return item;
 Py_DECREF(item);
+if (ok  0)
+return NULL;
 }
 }
 
diff -r 

[issue15604] PyObject_IsTrue failure checks

2012-08-15 Thread Roundup Robot

Roundup Robot added the comment:

New changeset ba1c48f8b571 by Antoine Pitrou in branch '2.7':
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors 
correctly.
http://hg.python.org/cpython/rev/ba1c48f8b571

New changeset 56dc7b09f390 by Antoine Pitrou in branch '3.2':
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors 
correctly.
http://hg.python.org/cpython/rev/56dc7b09f390

New changeset b878df1d23b1 by Antoine Pitrou in branch 'default':
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors 
correctly.
http://hg.python.org/cpython/rev/b878df1d23b1

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15604
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15604] PyObject_IsTrue failure checks

2012-08-15 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Thank you Antoine.

--
resolution:  - fixed
stage: patch review - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15604
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15604] PyObject_IsTrue failure checks

2012-08-15 Thread Jesús Cea Avión

Changes by Jesús Cea Avión j...@jcea.es:


--
nosy: +jcea

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15604
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15604] PyObject_IsTrue failure checks

2012-08-14 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Patches updated to reflect Antoine's comments.

--
Added file: http://bugs.python.org/file26813/istrue_check-3.3_2.patch
Added file: http://bugs.python.org/file26814/istrue_check-3.2_2.patch
Added file: http://bugs.python.org/file26815/istrue_check-2.7_2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15604
___diff -r e2e85ed7f8ba Modules/_csv.c
--- a/Modules/_csv.cTue Aug 14 18:42:54 2012 +0300
+++ b/Modules/_csv.cWed Aug 15 00:36:48 2012 +0300
@@ -196,8 +196,12 @@
 {
 if (src == NULL)
 *target = dflt;
-else
-*target = PyObject_IsTrue(src);
+else {
+int b = PyObject_IsTrue(src);
+if (b  0)
+return -1;
+*target = b;
+}
 return 0;
 }
 
diff -r e2e85ed7f8ba Modules/_io/textio.c
--- a/Modules/_io/textio.c  Tue Aug 14 18:42:54 2012 +0300
+++ b/Modules/_io/textio.c  Wed Aug 15 00:36:48 2012 +0300
@@ -1056,8 +1056,11 @@
 res = _PyObject_CallMethodId(buffer, PyId_seekable, NULL);
 if (res == NULL)
 goto error;
-self-seekable = self-telling = PyObject_IsTrue(res);
+r = PyObject_IsTrue(res);
 Py_DECREF(res);
+if (r  0)
+goto error;
+self-seekable = self-telling = r;
 
 self-has_read1 = _PyObject_HasAttrId(buffer, PyId_read1);
 
diff -r e2e85ed7f8ba Modules/_posixsubprocess.c
--- a/Modules/_posixsubprocess.cTue Aug 14 18:42:54 2012 +0300
+++ b/Modules/_posixsubprocess.cWed Aug 15 00:36:48 2012 +0300
@@ -503,7 +503,7 @@
 subprocess_fork_exec(PyObject* self, PyObject *args)
 {
 PyObject *gc_module = NULL;
-PyObject *executable_list, *py_close_fds, *py_fds_to_keep;
+PyObject *executable_list, *py_fds_to_keep;
 PyObject *env_list, *preexec_fn;
 PyObject *process_args, *converted_args = NULL, *fast_args = NULL;
 PyObject *preexec_fn_args_tuple = NULL;
@@ -518,15 +518,14 @@
 Py_ssize_t arg_num;
 
 if (!PyArg_ParseTuple(
-args, OOiiO:fork_exec,
-process_args, executable_list, py_close_fds, py_fds_to_keep,
+args, OOpOOOiiO:fork_exec,
+process_args, executable_list, close_fds, py_fds_to_keep,
 cwd_obj, env_list,
 p2cread, p2cwrite, c2pread, c2pwrite,
 errread, errwrite, errpipe_read, errpipe_write,
 restore_signals, call_setsid, preexec_fn))
 return NULL;
 
-close_fds = PyObject_IsTrue(py_close_fds);
 if (close_fds  errpipe_write  3) {  /* precondition */
 PyErr_SetString(PyExc_ValueError, errpipe_write must be = 3);
 return NULL;
diff -r e2e85ed7f8ba Modules/_ssl.c
--- a/Modules/_ssl.cTue Aug 14 18:42:54 2012 +0300
+++ b/Modules/_ssl.cWed Aug 15 00:36:48 2012 +0300
@@ -1037,15 +1037,15 @@
 PyObject *retval = NULL;
 int len;
 int verification;
-PyObject *binary_mode = Py_None;
+int binary_mode = 0;
 
-if (!PyArg_ParseTuple(args, |O:peer_certificate, binary_mode))
+if (!PyArg_ParseTuple(args, |p:peer_certificate, binary_mode))
 return NULL;
 
 if (!self-peer_cert)
 Py_RETURN_NONE;
 
-if (PyObject_IsTrue(binary_mode)) {
+if (binary_mode) {
 /* return cert in DER-encoded format */
 
 unsigned char *bytes_buf = NULL;
diff -r e2e85ed7f8ba Modules/itertoolsmodule.c
--- a/Modules/itertoolsmodule.c Tue Aug 14 18:42:54 2012 +0300
+++ b/Modules/itertoolsmodule.c Wed Aug 15 00:36:48 2012 +0300
@@ -1105,11 +1105,13 @@
 }
 ok = PyObject_IsTrue(good);
 Py_DECREF(good);
-if (!ok) {
+if (ok == 0) {
 lz-start = 1;
 return item;
 }
 Py_DECREF(item);
+if (ok  0)
+return NULL;
 }
 }
 
@@ -1124,7 +1126,7 @@
 dropwhile_setstate(dropwhileobject *lz, PyObject *state)
 {
 int start = PyObject_IsTrue(state);
-if (start == -1)
+if (start  0)
 return NULL;
 lz-start = start;
 Py_RETURN_NONE;
@@ -1270,10 +1272,11 @@
 }
 ok = PyObject_IsTrue(good);
 Py_DECREF(good);
-if (ok)
+if (ok == 1)
 return item;
 Py_DECREF(item);
-lz-stop = 1;
+if (ok == 0)
+lz-stop = 1;
 return NULL;
 }
 
@@ -1288,7 +1291,7 @@
 takewhile_reduce_setstate(takewhileobject *lz, PyObject *state)
 {
 int stop = PyObject_IsTrue(state);
-if (stop == -1)
+if (stop  0)
 return NULL;
 lz-stop = stop;
 Py_RETURN_NONE;
@@ -3536,7 +3539,7 @@
 if (ok == 1)
 return datum;
 Py_DECREF(datum);
-if (ok == -1)
+if (ok  0)
 return NULL;
 }
 }
@@ -3692,9 +3695,11 @@
 ok = PyObject_IsTrue(good);
 Py_DECREF(good);
 }
-if (!ok)
+if (ok == 0)
 return item;
 Py_DECREF(item);
+if (ok  0)
+return NULL;
 

[issue15604] PyObject_IsTrue failure checks

2012-08-13 Thread Andrew Svetlov

Changes by Andrew Svetlov andrew.svet...@gmail.com:


--
nosy: +asvetlov

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15604
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15604] PyObject_IsTrue failure checks

2012-08-10 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I shall try to do this, but it will take a lot of time. Besides, now in the 
code there are a lot of *correct* checked usage of PyObject_IsTrue without test 
cases. So I'm not sure that the tests are needed here, and that they are worth 
the effort.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15604
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15604] PyObject_IsTrue failure checks

2012-08-09 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

PyObject_IsTrue can fail, but not everywhere in a code a returned value 
checked. Here is a patches which add such checks.

Note, patches for all three Python versions are rather different.

--
components: Interpreter Core, Library (Lib)
files: istrue_check-3.3.patch
keywords: needs review, patch
messages: 167789
nosy: storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: PyObject_IsTrue failure checks
type: resource usage
versions: Python 2.7, Python 3.2, Python 3.3
Added file: http://bugs.python.org/file26742/istrue_check-3.3.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15604
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15604] PyObject_IsTrue failure checks

2012-08-09 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


Added file: http://bugs.python.org/file26744/istrue_check-2.7.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15604
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15604] PyObject_IsTrue failure checks

2012-08-09 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


Added file: http://bugs.python.org/file26743/istrue_check-3.2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15604
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15604] PyObject_IsTrue failure checks

2012-08-09 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Is it possible to add test cases for (at least some of) these issues?

--
nosy: +pitrou

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15604
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com