summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-12-30 19:47:05 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-12-30 19:47:05 (GMT)
commit533849a27a461a6aee9688bbd18f2205da70a8df (patch)
tree4c9bc12ec54f0834b8df1ccf2dfeb58e4693749d /Python
parent078d2c9c5fc1b2dffe810e5b1b05525ecf5d80d1 (diff)
downloadcpython-533849a27a461a6aee9688bbd18f2205da70a8df.zip
cpython-533849a27a461a6aee9688bbd18f2205da70a8df.tar.gz
cpython-533849a27a461a6aee9688bbd18f2205da70a8df.tar.bz2
Merged revisions 77161 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r77161 | benjamin.peterson | 2009-12-30 13:44:54 -0600 (Wed, 30 Dec 2009) | 12 lines Merged revisions 77157 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r77157 | benjamin.peterson | 2009-12-30 13:34:10 -0600 (Wed, 30 Dec 2009) | 5 lines check if the attribute is set before deleting it with T_OBJECT_EX (fixes #7604) Also, add a note to the docs about the better behavior of T_OBJECT_EX as compared to T_OBJECT. ........ ................
Diffstat (limited to 'Python')
-rw-r--r--Python/structmember.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/Python/structmember.c b/Python/structmember.c
index 9f08a6b..8edc354 100644
--- a/Python/structmember.c
+++ b/Python/structmember.c
@@ -104,17 +104,27 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v)
{
PyObject *oldv;
+ addr += l->offset;
+
if ((l->flags & READONLY) || l->type == T_STRING)
{
PyErr_SetString(PyExc_AttributeError, "readonly attribute");
return -1;
}
- if (v == NULL && l->type != T_OBJECT_EX && l->type != T_OBJECT) {
- PyErr_SetString(PyExc_TypeError,
- "can't delete numeric/char attribute");
- return -1;
+ if (v == NULL) {
+ if (l->type == T_OBJECT_EX) {
+ /* Check if the attribute is set. */
+ if (*(PyObject **)addr == NULL) {
+ PyErr_SetString(PyExc_AttributeError, l->name);
+ return -1;
+ }
+ }
+ else if (l->type != T_OBJECT) {
+ PyErr_SetString(PyExc_TypeError,
+ "can't delete numeric/char attribute");
+ return -1;
+ }
}
- addr += l->offset;
switch (l->type) {
case T_BOOL:{
if (!PyBool_Check(v)) {