diff Python/structmember.c @ 8398:ff31f2501742 legacy-trunk

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.
author Guido van Rossum <guido@python.org>
date Wed, 20 May 1998 22:25:32 +0000
parents 5880384d7c71
children 916fb024ce94
line wrap: on
line diff
--- a/Python/structmember.c	Wed May 20 21:32:09 1998 +0000
+++ b/Python/structmember.c	Wed May 20 22:25:32 1998 +0000
@@ -167,6 +167,7 @@
 	PyObject *v;
 {
 	struct memberlist *l;
+	PyObject *oldv;
 	
 	for (l = mlist; l->name != NULL; l++) {
 		if (strcmp(l->name, name) == 0) {
@@ -253,9 +254,10 @@
 				}
 				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) &&