[Python-checkins] r59170 - in python/trunk: Lib/test/test_funcattrs.py Misc/NEWS Objects/cellobject.c
amaury.forgeotdarc
python-checkins at python.org
Sat Nov 24 14:44:18 CET 2007
Author: amaury.forgeotdarc
Date: Sat Nov 24 14:44:17 2007
New Revision: 59170
Modified:
python/trunk/Lib/test/test_funcattrs.py
python/trunk/Misc/NEWS
python/trunk/Objects/cellobject.c
Log:
Issue #1445: Fix a SystemError when accessing the ``cell_contents``
attribute of an empty cell object. Now a ValueError is raised.
Modified: python/trunk/Lib/test/test_funcattrs.py
==============================================================================
--- python/trunk/Lib/test/test_funcattrs.py (original)
+++ python/trunk/Lib/test/test_funcattrs.py Sat Nov 24 14:44:17 2007
@@ -242,6 +242,17 @@
verify(c[0].__class__.__name__ == "cell") # don't have a type object handy
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 f(): pass
verify(f.__doc__ is None)
@@ -385,6 +396,7 @@
def testmore():
test_func_closure()
+ test_empty_cell()
test_func_doc()
test_func_globals()
test_func_name()
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Sat Nov 24 14:44:17 2007
@@ -12,6 +12,9 @@
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.
It now correctly saves its state between chunks of data.
Modified: python/trunk/Objects/cellobject.c
==============================================================================
--- python/trunk/Objects/cellobject.c (original)
+++ python/trunk/Objects/cellobject.c Sat Nov 24 14:44:17 2007
@@ -89,7 +89,12 @@
static PyObject *
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;
}
More information about the Python-checkins
mailing list