diff options
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/object.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/Objects/object.c b/Objects/object.c index ab9d4ed..5560792 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -600,8 +600,13 @@ PyObject_GetAttr(v, name) { if (v->ob_type->tp_getattro != NULL) return (*v->ob_type->tp_getattro)(v, name); - else - return PyObject_GetAttrString(v, PyString_AsString(name)); + + if (!PyString_Check(name)) { + PyErr_SetString(PyExc_TypeError, + "attribute name must be string"); + return NULL; + } + return PyObject_GetAttrString(v, PyString_AS_STRING(name)); } int @@ -626,12 +631,19 @@ PyObject_SetAttr(v, name, value) { int err; Py_INCREF(name); - PyString_InternInPlace(&name); + if (PyString_Check(name)) + PyString_InternInPlace(&name); if (v->ob_type->tp_setattro != NULL) err = (*v->ob_type->tp_setattro)(v, name, value); - else + else if (PyString_Check(name)) { err = PyObject_SetAttrString( - v, PyString_AsString(name), value); + v, PyString_AS_STRING(name), value); + } + else { + PyErr_SetString(PyExc_TypeError, + "attribute name must be string"); + err = -1; + } Py_DECREF(name); return err; } |