[Python-checkins] python/dist/src/Objects dictobject.c,2.133,2.134

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
2002年12月03日 23:32:28 -0800


Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv25529/Objects
Modified Files:
	dictobject.c 
Log Message:
Replace BadInternalCall with TypeError. Add a test case. Fix whitespace.
Just van Rossum showed a weird, but clever way for pure python code to 
trigger the BadInternalCall. The C code had assumed that calling a class
constructor would return an instance of that class; however, classes that
abuse __new__ can invalidate that assumption.
Index: dictobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/dictobject.c,v
retrieving revision 2.133
retrieving revision 2.134
diff -C2 -d -r2.133 -r2.134
*** dictobject.c	27 Nov 2002 19:38:00 -0000	2.133
--- dictobject.c	4 Dec 2002 07:32:25 -0000	2.134
***************
*** 974,978 ****
 	int status;
 
! if (!PyArg_ParseTuple(args, "OO|O:fromkeys", &cls, &seq, &value))
 		return NULL;
 
--- 974,978 ----
 	int status;
 
! 	if (!PyArg_ParseTuple(args, "OO|O:fromkeys", &cls, &seq, &value))
 		return NULL;
 
***************
*** 981,986 ****
 		return NULL;
 	if (!PyDict_Check(d)) {
- 		PyErr_BadInternalCall();
 		Py_DECREF(d);
 		return NULL;
 	}
--- 981,987 ----
 		return NULL;
 	if (!PyDict_Check(d)) {
 		Py_DECREF(d);
+ 		PyErr_SetString(PyExc_TypeError,
+ 			"class constructor must return a subclass of dict");
 		return NULL;
 	}

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