[Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.219,2.220
Jeremy Hylton
jhylton@users.sourceforge.net
Mon, 30 Jul 2001 15:39:33 -0700
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv28196
Modified Files:
bltinmodule.c
Log Message:
Fix for SF byg [ #420304 ] getattr function w/ default
Fix suggested by Michael Hudson: Raise TypeError if attribute name
passed to getattr() is not a string or Unicode. There is some
unfortunate duplication of code between builtin_getattr() and
PyObject_GetAttr(), but it appears to be unavoidable.
Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.219
retrieving revision 2.220
diff -C2 -d -r2.219 -r2.220
*** bltinmodule.c 2001/07/30 21:50:55 2.219
--- bltinmodule.c 2001/07/30 22:39:31 2.220
***************
*** 891,894 ****
--- 891,905 ----
if (!PyArg_ParseTuple(args, "OO|O:getattr", &v, &name, &dflt))
return NULL;
+ if (PyUnicode_Check(name)) {
+ name = _PyUnicode_AsDefaultEncodedString(name, NULL);
+ if (name == NULL)
+ return NULL;
+ }
+
+ if (!PyString_Check(name)) {
+ PyErr_SetString(PyExc_TypeError,
+ "attribute name must be string");
+ return NULL;
+ }
result = PyObject_GetAttr(v, name);
if (result == NULL && dflt != NULL) {