summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Python/bltinmodule.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 362cdaa..571cfe2 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -890,6 +890,17 @@ builtin_getattr(PyObject *self, PyObject *args)
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) {
PyErr_Clear();