[Python-checkins] python/dist/src/Objects weakrefobject.c,1.9,1.10

fdrake@users.sourceforge.net fdrake@users.sourceforge.net
Fri, 09 Aug 2002 11:34:19 -0700


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

Modified Files:
	weakrefobject.c 
Log Message:
Add support for the iterator protocol to weakref proxy objects.
Part of fixing SF bug #591704.


Index: weakrefobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/weakrefobject.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** weakrefobject.c	27 Mar 2002 15:18:21 -0000	1.9
--- weakrefobject.c	9 Aug 2002 18:34:16 -0000	1.10
***************
*** 384,387 ****
--- 384,405 ----
  }
  
+ /* iterator slots */
+ 
+ static PyObject *
+ proxy_iter(PyWeakReference *proxy)
+ {
+     if (!proxy_checkref(proxy))
+         return NULL;
+     return PyObject_GetIter(PyWeakref_GET_OBJECT(proxy));
+ }
+ 
+ static PyObject *
+ proxy_iternext(PyWeakReference *proxy)
+ {
+     if (!proxy_checkref(proxy))
+         return NULL;
+     return PyIter_Next(PyWeakref_GET_OBJECT(proxy));
+ }
+ 
  
  static PyNumberMethods proxy_as_number = {
***************
*** 448,471 ****
      0,
      /* methods */
!     (destructor)weakref_dealloc,/*tp_dealloc*/
!     (printfunc)proxy_print,     /*tp_print*/
!     0,				/*tp_getattr*/
!     0, 				/*tp_setattr*/
!     proxy_compare,		/*tp_compare*/
!     (unaryfunc)proxy_repr,	/*tp_repr*/
!     &proxy_as_number,		/*tp_as_number*/
!     &proxy_as_sequence,		/*tp_as_sequence*/
!     &proxy_as_mapping,		/*tp_as_mapping*/
!     0,	                        /*tp_hash*/
!     (ternaryfunc)0,	        /*tp_call*/
!     (unaryfunc)proxy_str,	/*tp_str*/
!     (getattrofunc)proxy_getattr,/*tp_getattro*/
!     (setattrofunc)proxy_setattr,/*tp_setattro*/
!     0,				/*tp_as_buffer*/
      Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC
!     |Py_TPFLAGS_CHECKTYPES,     /*tp_flags*/
!     0,                          /*tp_doc*/
!     (traverseproc)gc_traverse,  /*tp_traverse*/
!     (inquiry)gc_clear,          /*tp_clear*/
  };
  
--- 466,493 ----
      0,
      /* methods */
!     (destructor)weakref_dealloc,        /* tp_dealloc */
!     (printfunc)proxy_print,             /* tp_print */
!     0,				        /* tp_getattr */
!     0, 				        /* tp_setattr */
!     proxy_compare,		        /* tp_compare */
!     (unaryfunc)proxy_repr,	        /* tp_repr */
!     &proxy_as_number,		        /* tp_as_number */
!     &proxy_as_sequence,		        /* tp_as_sequence */
!     &proxy_as_mapping,		        /* tp_as_mapping */
!     0,	                                /* tp_hash */
!     (ternaryfunc)0,	                /* tp_call */
!     (unaryfunc)proxy_str,	        /* tp_str */
!     (getattrofunc)proxy_getattr,        /* tp_getattro */
!     (setattrofunc)proxy_setattr,        /* tp_setattro */
!     0,				        /* tp_as_buffer */
      Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC
!     | Py_TPFLAGS_CHECKTYPES,            /* tp_flags */
!     0,                                  /* tp_doc */
!     (traverseproc)gc_traverse,          /* tp_traverse */
!     (inquiry)gc_clear,                  /* tp_clear */
!     0,                                  /* tp_richcompare */
!     0,                                  /* tp_weaklistoffset */
!     (getiterfunc)proxy_iter,            /* tp_iter */
!     (iternextfunc)proxy_iternext,       /* tp_iternext */
  };
  
***************
*** 479,502 ****
      0,
      /* methods */
!     (destructor)weakref_dealloc,/*tp_dealloc*/
!     (printfunc)proxy_print,     /*tp_print*/
!     0,				/*tp_getattr*/
!     0, 				/*tp_setattr*/
!     proxy_compare,		/*tp_compare*/
!     (unaryfunc)proxy_repr,	/*tp_repr*/
!     &proxy_as_number,		/*tp_as_number*/
!     &proxy_as_sequence,		/*tp_as_sequence*/
!     &proxy_as_mapping,		/*tp_as_mapping*/
!     0,	                        /*tp_hash*/
!     (ternaryfunc)proxy_call,	/*tp_call*/
!     (unaryfunc)proxy_str,	/*tp_str*/
!     (getattrofunc)proxy_getattr,/*tp_getattro*/
!     (setattrofunc)proxy_setattr,/*tp_setattro*/
!     0,				/*tp_as_buffer*/
      Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC
!     |Py_TPFLAGS_CHECKTYPES,     /*tp_flags*/
!     0,                          /*tp_doc*/
!     (traverseproc)gc_traverse,  /*tp_traverse*/
!     (inquiry)gc_clear,          /*tp_clear*/
  };
  
--- 501,528 ----
      0,
      /* methods */
!     (destructor)weakref_dealloc,        /* tp_dealloc */
!     (printfunc)proxy_print,             /* tp_print */
!     0,				        /* tp_getattr */
!     0, 				        /* tp_setattr */
!     proxy_compare,		        /* tp_compare */
!     (unaryfunc)proxy_repr,	        /* tp_repr */
!     &proxy_as_number,		        /* tp_as_number */
!     &proxy_as_sequence,		        /* tp_as_sequence */
!     &proxy_as_mapping,		        /* tp_as_mapping */
!     0,	                                /* tp_hash */
!     (ternaryfunc)proxy_call,	        /* tp_call */
!     (unaryfunc)proxy_str,	        /* tp_str */
!     (getattrofunc)proxy_getattr,        /* tp_getattro */
!     (setattrofunc)proxy_setattr,        /* tp_setattro */
!     0,				        /* tp_as_buffer */
      Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC
!     | Py_TPFLAGS_CHECKTYPES,            /* tp_flags */
!     0,                                  /* tp_doc */
!     (traverseproc)gc_traverse,          /* tp_traverse */
!     (inquiry)gc_clear,                  /* tp_clear */
!     0,                                  /* tp_richcompare */
!     0,                                  /* tp_weaklistoffset */
!     (getiterfunc)proxy_iter,            /* tp_iter */
!     (iternextfunc)proxy_iternext,       /* tp_iternext */
  };