diff options
Diffstat (limited to 'Objects/object.c')
-rw-r--r-- | Objects/object.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/Objects/object.c b/Objects/object.c index ada1d1ec9e..81f5669453 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -422,7 +422,8 @@ PyObject_Str(PyObject *v) return NULL; if (PyUnicode_Check(res)) { PyObject* str; - str = PyUnicode_AsEncodedString(res, NULL, NULL); + str = _PyUnicode_AsDefaultEncodedString(res, NULL); + Py_XINCREF(str); Py_DECREF(res); if (str) res = str; @@ -929,12 +930,12 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value) PyTypeObject *tp = v->ob_type; int err; - if (!PyString_Check(name)){ + if (!PyString_Check(name)) { /* The Unicode to string conversion is done here because the existing tp_setattro slots expect a string object as name and we wouldn't want to break those. */ if (PyUnicode_Check(name)) { - name = PyUnicode_AsEncodedString(name, NULL, NULL); + name = _PyUnicode_AsDefaultEncodedString(name, NULL); if (name == NULL) return -1; } @@ -946,8 +947,7 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value) return -1; } } - else - Py_INCREF(name); + Py_INCREF(name); PyString_InternInPlace(&name); if (tp->tp_setattro != NULL) { @@ -961,6 +961,7 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value) return err; } Py_DECREF(name); + assert(name->ob_refcnt >= 1); if (tp->tp_getattr == NULL && tp->tp_getattro == NULL) PyErr_Format(PyExc_TypeError, "'%.100s' object has no attributes " |