File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -242,6 +242,17 @@ def f(): print a
242242 verify (c [0 ].__class__ .__name__ == "cell" ) # don't have a type object handy
243243 cantset (f , "func_closure" , c )
244244
245+ def test_empty_cell ():
246+ def f (): print a
247+ try :
248+ f .func_closure [0 ].cell_contents
249+ except ValueError :
250+ pass
251+ else :
252+ raise TestFailed , "shouldn't be able to read an empty cell"
253+
254+ a = 12
255+
245256def test_func_doc ():
246257 def f (): pass
247258 verify (f .__doc__ is None )
@@ -385,6 +396,7 @@ def foo(self): pass
385396
386397def testmore ():
387398 test_func_closure ()
399+ test_empty_cell ()
388400 test_func_doc ()
389401 test_func_globals ()
390402 test_func_name ()
Original file line number Diff line number Diff line change @@ -12,6 +12,9 @@ What's New in Python 2.6 alpha 1?
1212Core and builtins
1313-----------------
1414
15+ - Issue #1445: Fix a SystemError when accessing the ``cell_contents``
16+ attribute of an empty cell object.
17+
1518- Issue #1460: The utf-7 incremental decoder did not accept truncated input.
1619 It now correctly saves its state between chunks of data.
1720
Original file line number Diff line number Diff line change @@ -89,7 +89,12 @@ cell_clear(PyCellObject *op)
8989static PyObject *
9090cell_get_contents (PyCellObject * op , void * closure )
9191{
92- Py_XINCREF (op -> ob_ref );
92+ if (op -> ob_ref == NULL )
93+ {
94+ PyErr_SetString (PyExc_ValueError , "Cell is empty" );
95+ return NULL ;
96+ }
97+ Py_INCREF (op -> ob_ref );
9398 return op -> ob_ref ;
9499}
95100
You can’t perform that action at this time.
0 commit comments