Trivial little change: when setting a member to an object, hold the

old value in a temporary and XDECREF it only after then new value has
been set.  This prevents the (unlikely) case where the destructor of
the member uses the containing object -- it would find it in an
undefined state.
This commit is contained in:
Guido van Rossum 1998-05-20 22:25:32 +00:00
parent 885215c3da
commit adf0e437cb
1 changed files with 3 additions and 1 deletions

View File

@ -167,6 +167,7 @@ PyMember_Set(addr, mlist, name, v)
PyObject *v;
{
struct memberlist *l;
PyObject *oldv;
for (l = mlist; l->name != NULL; l++) {
if (strcmp(l->name, name) == 0) {
@ -253,9 +254,10 @@ PyMember_Set(addr, mlist, name, v)
}
break;
case T_OBJECT:
Py_XDECREF(*(PyObject **)addr);
Py_XINCREF(v);
oldv = *(PyObject **)addr;
*(PyObject **)addr = v;
Py_XDECREF(oldv);
break;
case T_CHAR:
if (PyString_Check(v) &&