mirror of
https://github.com/python/cpython.git
synced 2025-12-01 15:24:51 +00:00
Issue #1445: Fix a SystemError when accessing the `cell_contents`
attribute of an empty cell object. Now a ValueError is raised.
This commit is contained in:
parent
6dae85f409
commit
ce7d10ccc4
3 changed files with 21 additions and 1 deletions
|
|
@ -242,6 +242,17 @@ def test_func_closure():
|
||||||
verify(c[0].__class__.__name__ == "cell") # don't have a type object handy
|
verify(c[0].__class__.__name__ == "cell") # don't have a type object handy
|
||||||
cantset(f, "func_closure", c)
|
cantset(f, "func_closure", c)
|
||||||
|
|
||||||
|
def test_empty_cell():
|
||||||
|
def f(): print a
|
||||||
|
try:
|
||||||
|
f.func_closure[0].cell_contents
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise TestFailed, "shouldn't be able to read an empty cell"
|
||||||
|
|
||||||
|
a = 12
|
||||||
|
|
||||||
def test_func_doc():
|
def test_func_doc():
|
||||||
def f(): pass
|
def f(): pass
|
||||||
verify(f.__doc__ is None)
|
verify(f.__doc__ is None)
|
||||||
|
|
@ -385,6 +396,7 @@ def test_im_name():
|
||||||
|
|
||||||
def testmore():
|
def testmore():
|
||||||
test_func_closure()
|
test_func_closure()
|
||||||
|
test_empty_cell()
|
||||||
test_func_doc()
|
test_func_doc()
|
||||||
test_func_globals()
|
test_func_globals()
|
||||||
test_func_name()
|
test_func_name()
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,9 @@ What's New in Python 2.6 alpha 1?
|
||||||
Core and builtins
|
Core and builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #1445: Fix a SystemError when accessing the ``cell_contents``
|
||||||
|
attribute of an empty cell object.
|
||||||
|
|
||||||
- Issue #1460: The utf-7 incremental decoder did not accept truncated input.
|
- Issue #1460: The utf-7 incremental decoder did not accept truncated input.
|
||||||
It now correctly saves its state between chunks of data.
|
It now correctly saves its state between chunks of data.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,12 @@ cell_clear(PyCellObject *op)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
cell_get_contents(PyCellObject *op, void *closure)
|
cell_get_contents(PyCellObject *op, void *closure)
|
||||||
{
|
{
|
||||||
Py_XINCREF(op->ob_ref);
|
if (op->ob_ref == NULL)
|
||||||
|
{
|
||||||
|
PyErr_SetString(PyExc_ValueError, "Cell is empty");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
Py_INCREF(op->ob_ref);
|
||||||
return op->ob_ref;
|
return op->ob_ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue