[Python-checkins] CVS: python/dist/src/Python ceval.c,2.175,2.176

Guido van Rossum python-dev@python.org
2000年4月21日 17:17:42 -0400 (EDT)


Update of /projects/cvsroot/python/dist/src/Python
In directory eric:/projects/python/develop/guido/src/Python
Modified Files:
	ceval.c 
Log Message:
Charles Waldman writes:
"""
Running "test_extcall" repeatedly results in memory leaks.
One of these can't be fixed (at least not easily!), it happens since
this code:
def saboteur(**kw):
 kw['x'] = locals()
d = {}
saboteur(a=1, **d)
creates a circular reference - d['x']['d']==d
The others are due to some missing decrefs in ceval.c, fixed by the
patch attached below. 
Note: I originally wrote this without the "goto", just adding the
missing decref's where needed. But I think the goto is justified in
keeping the executable code size of ceval as small as possible.
"""
[I think the circular reference is more like kw['x']['kw'] == kw. --GvR]
Index: ceval.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Python/ceval.c,v
retrieving revision 2.175
retrieving revision 2.176
diff -C2 -r2.175 -r2.176
*** ceval.c	2000年04月10日 12:45:10	2.175
--- ceval.c	2000年04月21日 21:17:39	2.176
***************
*** 1624,1629 ****
 				PyErr_SetString(PyExc_TypeError,
 					"** argument must be a dictionary");
! 				x = NULL;
! 				break;
 			 }
 			}
--- 1624,1628 ----
 				PyErr_SetString(PyExc_TypeError,
 					"** argument must be a dictionary");
! 				goto extcall_fail;
 			 }
 			}
***************
*** 1633,1638 ****
 				PyErr_SetString(PyExc_TypeError,
 					"* argument must be a sequence");
! 				x = NULL;
! 				break;
 			 }
 			 /* Convert abstract sequence to concrete tuple */
--- 1632,1636 ----
 				PyErr_SetString(PyExc_TypeError,
 					"* argument must be a sequence");
! 				goto extcall_fail;
 			 }
 			 /* Convert abstract sequence to concrete tuple */
***************
*** 1641,1646 ****
 				t = PySequence_Tuple(stararg);
 				if (t == NULL) {
! 				 x = NULL;
! 				 break;
 				}
 				Py_DECREF(stararg);
--- 1639,1643 ----
 				t = PySequence_Tuple(stararg);
 				if (t == NULL) {
! 				 goto extcall_fail;
 				}
 				Py_DECREF(stararg);
***************
*** 1649,1654 ****
 			 nstar = PyTuple_GET_SIZE(stararg);
 			 if (nstar < 0) {
! 				x = NULL;
! 				break;
 			 }
 			}
--- 1646,1650 ----
 			 nstar = PyTuple_GET_SIZE(stararg);
 			 if (nstar < 0) {
! 				goto extcall_fail;
 			 }
 			}
***************
*** 1657,1662 ****
 				kwdict = PyDict_New();
 				if (kwdict == NULL) {
! 				 x = NULL;
! 				 break;
 				}
 			 }
--- 1653,1657 ----
 				kwdict = PyDict_New();
 				if (kwdict == NULL) {
! 				 goto extcall_fail;
 				}
 			 }
***************
*** 1664,1669 ****
 				 PyObject *d = PyDict_Copy(kwdict);
 				 if (d == NULL) {
! 					 x = NULL;
! 					 break;
 				 }
 				 Py_DECREF(kwdict);
--- 1659,1663 ----
 				 PyObject *d = PyDict_Copy(kwdict);
 				 if (d == NULL) {
! 					 goto extcall_fail;
 				 }
 				 Py_DECREF(kwdict);
***************
*** 1681,1685 ****
 				 Py_DECREF(key);
 				 Py_DECREF(value);
! 				 break;
 				}
 				err = PyDict_SetItem(kwdict, key, value);
--- 1675,1679 ----
 				 Py_DECREF(key);
 				 Py_DECREF(value);
! 				 goto extcall_fail;
 				}
 				err = PyDict_SetItem(kwdict, key, value);
***************
*** 1690,1694 ****
 			 }
 			 if (err) {
! 				Py_DECREF(kwdict);
 				break;
 			 }
--- 1684,1692 ----
 			 }
 			 if (err) {
! 			 extcall_fail:
! 				Py_XDECREF(kwdict);
! 				Py_XDECREF(stararg);
! 				Py_DECREF(func);
! 				x=NULL;
 				break;
 			 }
***************
*** 2383,2386 ****
--- 2381,2385 ----
 		PyErr_SetString(PyExc_TypeError,
 				"keyword list must be a dictionary");
+ 		Py_DECREF(arg);
 		return NULL;
 	}

AltStyle によって変換されたページ (->オリジナル) /