diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-12-30 19:34:10 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-12-30 19:34:10 (GMT) |
commit | 0f02d3933bff50042dd914d5d17831af7093cf55 (patch) | |
tree | 68365aea879cae3caa8b4267e45922ec2fa49c18 /Python/structmember.c | |
parent | b7953f00b186baee159a2d5dfe1e80ca0ef00a29 (diff) | |
download | cpython-0f02d3933bff50042dd914d5d17831af7093cf55.zip cpython-0f02d3933bff50042dd914d5d17831af7093cf55.tar.gz cpython-0f02d3933bff50042dd914d5d17831af7093cf55.tar.bz2 |
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/structmember.c')
-rw-r--r-- | Python/structmember.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/Python/structmember.c b/Python/structmember.c index d230590..9f87c07 100644 --- a/Python/structmember.c +++ b/Python/structmember.c @@ -170,6 +170,8 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v) { PyObject *oldv; + addr += l->offset; + if ((l->flags & READONLY) || l->type == T_STRING) { PyErr_SetString(PyExc_TypeError, "readonly attribute"); @@ -179,12 +181,20 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v) PyErr_SetString(PyExc_RuntimeError, "restricted 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)) { |