[Python-checkins] CVS: python/dist/src/Objects dictobject.c,2.80.2.8,2.80.2.9
Guido van Rossum
gvanrossum@users.sourceforge.net
Thu, 07 Jun 2001 04:38:57 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv5732
Modified Files:
Tag: descr-branch
dictobject.c
Log Message:
Make PyDict_SetItem() and PyDict_DelItem() call on their PyObject_
cousins when the type is a derived type from PyDict_Type -- this makes
it possible to create a derived dictionary class that implements
restrictions on item assignments and pass that as the dict to
exec/eval, for example.
Don't do this for PyDict_Clear(). It's trickier there: there's no
PyObject_Clear(), and calling self.clear() might recurse right into
PyDict_Clear(). PyDict_Clear() is only used by the standard library
in a few places, and in at least one of those (GC) setting a trap
would be inappropriate anyway.
Index: dictobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/dictobject.c,v
retrieving revision 2.80.2.8
retrieving revision 2.80.2.9
diff -C2 -r2.80.2.8 -r2.80.2.9
*** dictobject.c 2001/06/06 14:27:54 2.80.2.8
--- dictobject.c 2001/06/07 11:38:55 2.80.2.9
***************
*** 424,428 ****
register int n_used;
! if (!PyDict_Check(op)) {
PyErr_BadInternalCall();
return -1;
--- 424,430 ----
register int n_used;
! if (op->ob_type != &PyDict_Type) {
! if (PyDict_Check(op))
! return PyObject_SetItem(op, key, value);
PyErr_BadInternalCall();
return -1;
***************
*** 486,490 ****
PyObject *old_value, *old_key;
! if (!PyDict_Check(op)) {
PyErr_BadInternalCall();
return -1;
--- 488,494 ----
PyObject *old_value, *old_key;
! if (op->ob_type != &PyDict_Type) {
! if (PyDict_Check(op))
! return PyObject_DelItem(op, key);
PyErr_BadInternalCall();
return -1;