[Python-checkins] CVS: python/dist/src/Python ceval.c,2.301.4.1,2.301.4.2

Guido van Rossum gvanrossum@users.sourceforge.net
Thu, 28 Mar 2002 12:18:51 -0800


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv8924

Modified Files:
      Tag: release22-maint
	ceval.c 
Log Message:
Backport to 2.2.1.

Fix an issue that was reported in but unrelated to the main problem of
SF bug 535905 (Evil Trashcan and GC interaction).

The SETLOCAL() macro should not DECREF the local variable in-place and
then store the new value; it should copy the old value to a temporary
value, then store the new value, and then DECREF the temporary value.
This is because it is possible that during the DECREF the frame is
accessed by other code (e.g. a __del__ method or gc.collect()) and the
variable would be pointing to already-freed memory.

BUGFIX CANDIDATE!


Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.301.4.1
retrieving revision 2.301.4.2
diff -C2 -d -r2.301.4.1 -r2.301.4.2
*** ceval.c	28 Dec 2001 10:22:15 -0000	2.301.4.1
--- ceval.c	28 Mar 2002 20:18:48 -0000	2.301.4.2
***************
*** 555,560 ****
  
  #define GETLOCAL(i)	(fastlocals[i])
! #define SETLOCAL(i, value)	do { Py_XDECREF(GETLOCAL(i)); \
! 				     GETLOCAL(i) = value; } while (0)
  
  /* Start of code */
--- 555,568 ----
  
  #define GETLOCAL(i)	(fastlocals[i])
! 
! /* The SETLOCAL() macro must not DECREF the local variable in-place and
!    then store the new value; it must copy the old value to a temporary
!    value, then store the new value, and then DECREF the temporary value.
!    This is because it is possible that during the DECREF the frame is
!    accessed by other code (e.g. a __del__ method or gc.collect()) and the
!    variable would be pointing to already-freed memory. */
! #define SETLOCAL(i, value)	do { PyObject *tmp = GETLOCAL(i); \
! 				     GETLOCAL(i) = value; \
!                                      Py_XDECREF(tmp); } while (0)
  
  /* Start of code */