Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
0c160a08
Commit
0c160a08
authored
Mar 15, 2002
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch #517521: Consider byte strings before Unicode strings
in PyObject_Get/SetAttr.
parent
e5363b7d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
52 deletions
+60
-52
Objects/object.c
Objects/object.c
+60
-52
No files found.
Objects/object.c
View file @
0c160a08
...
@@ -1085,21 +1085,23 @@ PyObject_GetAttr(PyObject *v, PyObject *name)
...
@@ -1085,21 +1085,23 @@ PyObject_GetAttr(PyObject *v, PyObject *name)
{
{
PyTypeObject
*
tp
=
v
->
ob_type
;
PyTypeObject
*
tp
=
v
->
ob_type
;
if
(
!
PyString_Check
(
name
))
{
#ifdef Py_USING_UNICODE
#ifdef Py_USING_UNICODE
/* The Unicode to string conversion is done here because the
/* The Unicode to string conversion is done here because the
existing tp_getattro slots expect a string object as name
existing tp_getattro slots expect a string object as name
and we wouldn't want to break those. */
and we wouldn't want to break those. */
if
(
PyUnicode_Check
(
name
))
{
if
(
PyUnicode_Check
(
name
))
{
name
=
_PyUnicode_AsDefaultEncodedString
(
name
,
NULL
);
name
=
_PyUnicode_AsDefaultEncodedString
(
name
,
NULL
);
if
(
name
==
NULL
)
if
(
name
==
NULL
)
return
NULL
;
return
NULL
;
}
}
else
else
#endif
#endif
if
(
!
PyString_Check
(
name
))
{
{
PyErr_SetString
(
PyExc_TypeError
,
PyErr_SetString
(
PyExc_TypeError
,
"attribute name must be string"
);
"attribute name must be string"
);
return
NULL
;
return
NULL
;
}
}
}
if
(
tp
->
tp_getattro
!=
NULL
)
if
(
tp
->
tp_getattro
!=
NULL
)
return
(
*
tp
->
tp_getattro
)(
v
,
name
);
return
(
*
tp
->
tp_getattro
)(
v
,
name
);
...
@@ -1129,21 +1131,23 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
...
@@ -1129,21 +1131,23 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
PyTypeObject
*
tp
=
v
->
ob_type
;
PyTypeObject
*
tp
=
v
->
ob_type
;
int
err
;
int
err
;
if
(
!
PyString_Check
(
name
)){
#ifdef Py_USING_UNICODE
#ifdef Py_USING_UNICODE
/* The Unicode to string conversion is done here because the
/* The Unicode to string conversion is done here because the
existing tp_setattro slots expect a string object as name
existing tp_setattro slots expect a string object as name
and we wouldn't want to break those. */
and we wouldn't want to break those. */
if
(
PyUnicode_Check
(
name
))
{
if
(
PyUnicode_Check
(
name
))
{
name
=
PyUnicode_AsEncodedString
(
name
,
NULL
,
NULL
);
name
=
PyUnicode_AsEncodedString
(
name
,
NULL
,
NULL
);
if
(
name
==
NULL
)
if
(
name
==
NULL
)
return
-
1
;
return
-
1
;
}
}
else
else
#endif
#endif
if
(
!
PyString_Check
(
name
)){
{
PyErr_SetString
(
PyExc_TypeError
,
PyErr_SetString
(
PyExc_TypeError
,
"attribute name must be string"
);
"attribute name must be string"
);
return
-
1
;
return
-
1
;
}
}
}
else
else
Py_INCREF
(
name
);
Py_INCREF
(
name
);
...
@@ -1217,21 +1221,23 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
...
@@ -1217,21 +1221,23 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
descrgetfunc
f
;
descrgetfunc
f
;
PyObject
**
dictptr
;
PyObject
**
dictptr
;
if
(
!
PyString_Check
(
name
)){
#ifdef Py_USING_UNICODE
#ifdef Py_USING_UNICODE
/* The Unicode to string conversion is done here because the
/* The Unicode to string conversion is done here because the
existing tp_setattro slots expect a string object as name
existing tp_setattro slots expect a string object as name
and we wouldn't want to break those. */
and we wouldn't want to break those. */
if
(
PyUnicode_Check
(
name
))
{
if
(
PyUnicode_Check
(
name
))
{
name
=
PyUnicode_AsEncodedString
(
name
,
NULL
,
NULL
);
name
=
PyUnicode_AsEncodedString
(
name
,
NULL
,
NULL
);
if
(
name
==
NULL
)
if
(
name
==
NULL
)
return
NULL
;
return
NULL
;
}
}
else
else
#endif
#endif
if
(
!
PyString_Check
(
name
)){
{
PyErr_SetString
(
PyExc_TypeError
,
PyErr_SetString
(
PyExc_TypeError
,
"attribute name must be string"
);
"attribute name must be string"
);
return
NULL
;
return
NULL
;
}
}
}
else
else
Py_INCREF
(
name
);
Py_INCREF
(
name
);
...
@@ -1291,21 +1297,23 @@ PyObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value)
...
@@ -1291,21 +1297,23 @@ PyObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value)
PyObject
**
dictptr
;
PyObject
**
dictptr
;
int
res
=
-
1
;
int
res
=
-
1
;
if
(
!
PyString_Check
(
name
)){
#ifdef Py_USING_UNICODE
#ifdef Py_USING_UNICODE
/* The Unicode to string conversion is done here because the
/* The Unicode to string conversion is done here because the
existing tp_setattro slots expect a string object as name
existing tp_setattro slots expect a string object as name
and we wouldn't want to break those. */
and we wouldn't want to break those. */
if
(
PyUnicode_Check
(
name
))
{
if
(
PyUnicode_Check
(
name
))
{
name
=
PyUnicode_AsEncodedString
(
name
,
NULL
,
NULL
);
name
=
PyUnicode_AsEncodedString
(
name
,
NULL
,
NULL
);
if
(
name
==
NULL
)
if
(
name
==
NULL
)
return
-
1
;
return
-
1
;
}
}
else
else
#endif
#endif
if
(
!
PyString_Check
(
name
)){
{
PyErr_SetString
(
PyExc_TypeError
,
PyErr_SetString
(
PyExc_TypeError
,
"attribute name must be string"
);
"attribute name must be string"
);
return
-
1
;
return
-
1
;
}
}
}
else
else
Py_INCREF
(
name
);
Py_INCREF
(
name
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment