summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2002-03-15 13:40:30 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2002-03-15 13:40:30 (GMT)
commit0c160a08f2228045437a94ea6e00306ace8dbfb4 (patch)
tree7c176acc89083239e5ef5400901cb72b17d3ff32
parente5363b7de5bb99f5a00d748fa2ca89d631bbf40d (diff)
downloadcpython-0c160a08f2228045437a94ea6e00306ace8dbfb4.zip
cpython-0c160a08f2228045437a94ea6e00306ace8dbfb4.tar.gz
cpython-0c160a08f2228045437a94ea6e00306ace8dbfb4.tar.bz2
Patch #517521: Consider byte strings before Unicode strings
in PyObject_Get/SetAttr.
-rw-r--r--Objects/object.c112
1 files changed, 60 insertions, 52 deletions
diff --git a/Objects/object.c b/Objects/object.c
index bcc129c..26ddd13 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1085,21 +1085,23 @@ PyObject_GetAttr(PyObject *v, PyObject *name)
{
PyTypeObject *tp = v->ob_type;
+ if (!PyString_Check(name)) {
#ifdef Py_USING_UNICODE
- /* The Unicode to string conversion is done here because the
- existing tp_getattro slots expect a string object as name
- and we wouldn't want to break those. */
- if (PyUnicode_Check(name)) {
- name = _PyUnicode_AsDefaultEncodedString(name, NULL);
- if (name == NULL)
- return NULL;
- }
- else
+ /* The Unicode to string conversion is done here because the
+ existing tp_getattro slots expect a string object as name
+ and we wouldn't want to break those. */
+ if (PyUnicode_Check(name)) {
+ name = _PyUnicode_AsDefaultEncodedString(name, NULL);
+ if (name == NULL)
+ return NULL;
+ }
+ else
#endif
- if (!PyString_Check(name)) {
- PyErr_SetString(PyExc_TypeError,
- "attribute name must be string");
- return NULL;
+ {
+ PyErr_SetString(PyExc_TypeError,
+ "attribute name must be string");
+ return NULL;
+ }
}
if (tp->tp_getattro != NULL)
return (*tp->tp_getattro)(v, name);
@@ -1129,21 +1131,23 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
PyTypeObject *tp = v->ob_type;
int err;
+ if (!PyString_Check(name)){
#ifdef Py_USING_UNICODE
- /* 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);
- if (name == NULL)
- return -1;
- }
- else
+ /* 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);
+ if (name == NULL)
+ return -1;
+ }
+ else
#endif
- if (!PyString_Check(name)){
- PyErr_SetString(PyExc_TypeError,
- "attribute name must be string");
- return -1;
+ {
+ PyErr_SetString(PyExc_TypeError,
+ "attribute name must be string");
+ return -1;
+ }
}
else
Py_INCREF(name);
@@ -1217,21 +1221,23 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
descrgetfunc f;
PyObject **dictptr;
+ if (!PyString_Check(name)){
#ifdef Py_USING_UNICODE
- /* 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);
- if (name == NULL)
- return NULL;
- }
- else
+ /* 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);
+ if (name == NULL)
+ return NULL;
+ }
+ else
#endif
- if (!PyString_Check(name)){
- PyErr_SetString(PyExc_TypeError,
- "attribute name must be string");
- return NULL;
+ {
+ PyErr_SetString(PyExc_TypeError,
+ "attribute name must be string");
+ return NULL;
+ }
}
else
Py_INCREF(name);
@@ -1291,21 +1297,23 @@ PyObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value)
PyObject **dictptr;
int res = -1;
+ if (!PyString_Check(name)){
#ifdef Py_USING_UNICODE
- /* 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);
- if (name == NULL)
- return -1;
- }
- else
+ /* 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);
+ if (name == NULL)
+ return -1;
+ }
+ else
#endif
- if (!PyString_Check(name)){
- PyErr_SetString(PyExc_TypeError,
- "attribute name must be string");
- return -1;
+ {
+ PyErr_SetString(PyExc_TypeError,
+ "attribute name must be string");
+ return -1;
+ }
}
else
Py_INCREF(name);