[Python-checkins] CVS: python/dist/src/Objects object.c,2.164,2.165
Martin v. L?wis
loewis@users.sourceforge.net
Fri, 15 Mar 2002 05:40:33 -0800
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv24784
Modified Files:
object.c
Log Message:
Patch #517521: Consider byte strings before Unicode strings
in PyObject_Get/SetAttr.
Index: object.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/object.c,v
retrieving revision 2.164
retrieving revision 2.165
diff -C2 -d -r2.164 -r2.165
*** object.c 2 Mar 2002 08:43:19 -0000 2.164
--- object.c 15 Mar 2002 13:40:30 -0000 2.165
***************
*** 1086,1104 ****
PyTypeObject *tp = v->ob_type;
#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
#endif
! if (!PyString_Check(name)) {
! PyErr_SetString(PyExc_TypeError,
! "attribute name must be string");
! return NULL;
}
if (tp->tp_getattro != NULL)
--- 1086,1106 ----
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
#endif
! {
! PyErr_SetString(PyExc_TypeError,
! "attribute name must be string");
! return NULL;
! }
}
if (tp->tp_getattro != NULL)
***************
*** 1130,1148 ****
int err;
#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
#endif
! if (!PyString_Check(name)){
! PyErr_SetString(PyExc_TypeError,
! "attribute name must be string");
! return -1;
}
else
--- 1132,1152 ----
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
#endif
! {
! PyErr_SetString(PyExc_TypeError,
! "attribute name must be string");
! return -1;
! }
}
else
***************
*** 1218,1236 ****
PyObject **dictptr;
#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
#endif
! if (!PyString_Check(name)){
! PyErr_SetString(PyExc_TypeError,
! "attribute name must be string");
! return NULL;
}
else
--- 1222,1242 ----
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
#endif
! {
! PyErr_SetString(PyExc_TypeError,
! "attribute name must be string");
! return NULL;
! }
}
else
***************
*** 1292,1310 ****
int res = -1;
#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
#endif
! if (!PyString_Check(name)){
! PyErr_SetString(PyExc_TypeError,
! "attribute name must be string");
! return -1;
}
else
--- 1298,1318 ----
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
#endif
! {
! PyErr_SetString(PyExc_TypeError,
! "attribute name must be string");
! return -1;
! }
}
else