[issue20945] why save the item to be replaced as olditem in PyTuple_SetItem? It's not useful at all.

2014-06-19 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
stage:  - resolved

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



[issue20945] why save the item to be replaced as olditem in PyTuple_SetItem? It's not useful at all.

2014-03-16 Thread coder.maliubiao

New submission from coder.maliubiao:

code:
int
PyTuple_SetItem(register PyObject *op, register Py_ssize_t i, PyObject *newitem)
{
register PyObject *olditem;
register PyObject **p;
if (!PyTuple_Check(op) || op-ob_refcnt != 1) {
Py_XDECREF(newitem);
PyErr_BadInternalCall();
return -1;
}
if (i  0 || i = Py_SIZE(op)) {
Py_XDECREF(newitem);
PyErr_SetString(PyExc_IndexError,
tuple assignment index out of range);
return -1;
}
p = ((PyTupleObject *)op) - ob_item + i;
olditem = *p;
*p = newitem;
Py_XDECREF(olditem);
return 0;
}

olditem is not useful.

--
components: Devguide
messages: 213730
nosy: ezio.melotti, maliub...@gmail.com
priority: normal
severity: normal
status: open
title: why save the item to be replaced as olditem in PyTuple_SetItem?  It's 
not useful at all.
versions: Python 2.7

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



[issue20945] why save the item to be replaced as olditem in PyTuple_SetItem? It's not useful at all.

2014-03-16 Thread coder.maliubiao

Changes by coder.maliubiao maliub...@gmail.com:


--
type:  - performance

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



[issue20945] why save the item to be replaced as olditem in PyTuple_SetItem? It's not useful at all.

2014-03-16 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 olditem is not useful

It is. Py_XDECREF() may have massive side effects (such as calling a __del__ 
method and executing arbitrary code). Therefore, you have to ensure that the 
tuple item is set to the new value *before* the old value is DECREF'ed. 
Otherwise, any code invoked by Py_XDECREF will see invalid tuple contents, and 
the interpreter may crash.

--
nosy: +pitrou

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



[issue20945] why save the item to be replaced as olditem in PyTuple_SetItem? It's not useful at all.

2014-03-16 Thread Benjamin Peterson

Changes by Benjamin Peterson bp+pyb...@benjamin-peterson.org:


--
resolution:  - invalid
status: open - closed

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