[Python-checkins] CVS: python/dist/src/Objects dictobject.c,2.98,2.99
Tim Peters
tim_one@users.sourceforge.net
Sat, 02 Jun 2001 01:02:58 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv27849/python/dist/src/Objects
Modified Files:
dictobject.c
Log Message:
Coredumpers from Michael Hudson, mutating dicts while printing or
converting to string.
Critical bugfix candidate -- if you take this seriously <wink>.
Index: dictobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/dictobject.c,v
retrieving revision 2.98
retrieving revision 2.99
diff -C2 -r2.98 -r2.99
*** dictobject.c 2001/06/02 05:42:29 2.98
--- dictobject.c 2001/06/02 08:02:56 2.99
***************
*** 741,745 ****
register int i;
register int any;
- register dictentry *ep;
i = Py_ReprEnter((PyObject*)mp);
--- 741,744 ----
***************
*** 753,761 ****
fprintf(fp, "{");
any = 0;
! for (i = 0, ep = mp->ma_table; i < mp->ma_size; i++, ep++) {
! if (ep->me_value != NULL) {
if (any++ > 0)
fprintf(fp, ", ");
if (PyObject_Print((PyObject *)ep->me_key, fp, 0)!=0) {
Py_ReprLeave((PyObject*)mp);
return -1;
--- 752,766 ----
fprintf(fp, "{");
any = 0;
! for (i = 0; i < mp->ma_size; i++) {
! dictentry *ep = mp->ma_table + i;
! PyObject *pvalue = ep->me_value;
! if (pvalue != NULL) {
! /* Prevent PyObject_Repr from deleting value during
! key format */
! Py_INCREF(pvalue);
if (any++ > 0)
fprintf(fp, ", ");
if (PyObject_Print((PyObject *)ep->me_key, fp, 0)!=0) {
+ Py_DECREF(pvalue);
Py_ReprLeave((PyObject*)mp);
return -1;
***************
*** 763,769 ****
--- 768,776 ----
fprintf(fp, ": ");
if (PyObject_Print(ep->me_value, fp, 0) != 0) {
+ Py_DECREF(pvalue);
Py_ReprLeave((PyObject*)mp);
return -1;
}
+ Py_DECREF(pvalue);
}
}
***************
*** 780,784 ****
register int i;
register int any;
- register dictentry *ep;
i = Py_ReprEnter((PyObject*)mp);
--- 787,790 ----
***************
*** 793,803 ****
colon = PyString_FromString(": ");
any = 0;
! for (i = 0, ep = mp->ma_table; i < mp->ma_size && v; i++, ep++) {
! if (ep->me_value != NULL) {
if (any++)
PyString_Concat(&v, sepa);
PyString_ConcatAndDel(&v, PyObject_Repr(ep->me_key));
PyString_Concat(&v, colon);
! PyString_ConcatAndDel(&v, PyObject_Repr(ep->me_value));
}
}
--- 799,815 ----
colon = PyString_FromString(": ");
any = 0;
! for (i = 0; i < mp->ma_size && v; i++) {
! dictentry *ep = mp->ma_table + i;
! PyObject *pvalue = ep->me_value;
! if (pvalue != NULL) {
! /* Prevent PyObject_Repr from deleting value during
! key format */
! Py_INCREF(pvalue);
if (any++)
PyString_Concat(&v, sepa);
PyString_ConcatAndDel(&v, PyObject_Repr(ep->me_key));
PyString_Concat(&v, colon);
! PyString_ConcatAndDel(&v, PyObject_Repr(pvalue));
! Py_DECREF(pvalue);
}
}