[Python-checkins] python/dist/src/Objects weakrefobject.c, 1.13.6.3, 1.13.6.4

fdrake at users.sourceforge.net fdrake at users.sourceforge.net
Tue Aug 3 16:46:59 CEST 2004


Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv776/Objects

Modified Files:
      Tag: release23-maint
	weakrefobject.c 
Log Message:
Be more careful about maintaining the invariants; it was actually
possible that the callback-less flavors of the ref or proxy could have
been added during GC, so we don't want to replace them.


Index: weakrefobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/weakrefobject.c,v
retrieving revision 1.13.6.3
retrieving revision 1.13.6.4
diff -C2 -d -r1.13.6.3 -r1.13.6.4
*** weakrefobject.c	4 Feb 2004 23:13:43 -0000	1.13.6.3
--- weakrefobject.c	3 Aug 2004 14:46:57 -0000	1.13.6.4
***************
*** 640,650 ****
          result = new_weakref(ob, callback);
          if (result != NULL) {
              if (callback == NULL) {
!                 insert_head(result, list);
              }
              else {
                  PyWeakReference *prev;
  
-                 get_basic_refs(*list, &ref, &proxy);
                  prev = (proxy == NULL) ? ref : proxy;
                  if (prev == NULL)
--- 640,660 ----
          result = new_weakref(ob, callback);
          if (result != NULL) {
+             get_basic_refs(*list, &ref, &proxy);
              if (callback == NULL) {
!                 if (ref == NULL)
!                     insert_head(result, list);
!                 else {
!                     /* Someone else added a ref without a callback
!                        during GC.  Return that one instead of this one
!                        to avoid violating the invariants of the list
!                        of weakrefs for ob. */
!                     Py_DECREF(result);
!                     Py_INCREF(ref);
!                     result = ref;
!                 }
              }
              else {
                  PyWeakReference *prev;
  
                  prev = (proxy == NULL) ? ref : proxy;
                  if (prev == NULL)
***************
*** 696,701 ****
                  result->ob_type = &_PyWeakref_ProxyType;
              get_basic_refs(*list, &ref, &proxy);
!             if (callback == NULL)
                  prev = ref;
              else
                  prev = (proxy == NULL) ? ref : proxy;
--- 706,721 ----
                  result->ob_type = &_PyWeakref_ProxyType;
              get_basic_refs(*list, &ref, &proxy);
!             if (callback == NULL) {
!                 if (proxy != NULL) {
!                     /* Someone else added a proxy without a callback
!                        during GC.  Return that one instead of this one
!                        to avoid violating the invariants of the list
!                        of weakrefs for ob. */
!                     Py_DECREF(result);
!                     Py_INCREF(result = proxy);
!                     goto skip_insert;
!                 }
                  prev = ref;
+             }
              else
                  prev = (proxy == NULL) ? ref : proxy;
***************
*** 705,708 ****
--- 725,730 ----
              else
                  insert_after(result, prev);
+         skip_insert:
+             ;
          }
      }



More information about the Python-checkins mailing list