# HG changeset patch
# User ZyX <[email protected]>
# Date 1368672552 -14400
# Branch python-extended-2
# Node ID 5f8adb1d88b905d73dc2b4d106740759a66113b3
# Parent  02c4f613343a69eeba16a8a4742f5a9dee269861
Add tp_traverse and tp_clear

diff -r 02c4f613343a -r 5f8adb1d88b9 src/if_py_both.h
--- a/src/if_py_both.h  Thu May 16 06:57:54 2013 +0400
+++ b/src/if_py_both.h  Thu May 16 06:49:12 2013 +0400
@@ -543,6 +543,8 @@
 
 typedef PyObject *(*nextfun)(void **);
 typedef void (*destructorfun)(void *);
+typedef int (*traversefun)(void *, visitproc, void *);
+typedef int (*clearfun)(void **);
 
 /* Main purpose of this object is removing the need for do python 
initialization 
  * (i.e. PyType_Ready and setting type attributes) for a big bunch of objects.
@@ -554,10 +556,13 @@
     void *cur;
     nextfun next;
     destructorfun destruct;
+    traversefun traverse;
+    clearfun clear;
 } IterObject;
 
     static PyObject *
-IterNew(void *start, destructorfun destruct, nextfun next)
+IterNew(void *start, destructorfun destruct, nextfun next, traversefun 
traverse,
+       clearfun clear)
 {
     IterObject *self;
 
@@ -565,6 +570,8 @@
     self->cur = start;
     self->next = next;
     self->destruct = destruct;
+    self->traverse = traverse;
+    self->clear = clear;
 
     return (PyObject *)(self);
 }
@@ -579,6 +586,28 @@
     DESTRUCTOR_FINISH(self);
 }
 
+    static int
+IterTraverse(PyObject *self, visitproc visit, void *arg)
+{
+    IterObject *this = (IterObject *)(self);
+
+    if (this->traverse != NULL)
+       return this->traverse(this->cur, visit, arg);
+    else
+       return 0;
+}
+
+    static int
+IterClear(PyObject *self)
+{
+    IterObject *this = (IterObject *)(self);
+
+    if (this->clear != NULL)
+       return this->clear(&this->cur);
+    else
+       return 0;
+}
+
     static PyObject *
 IterNext(PyObject *self)
 {
@@ -1034,7 +1063,8 @@
     lii->list = l;
 
     return IterNew(lii,
-           (destructorfun) ListIterDestruct, (nextfun) ListIterNext);
+           (destructorfun) ListIterDestruct, (nextfun) ListIterNext,
+           NULL, NULL);
 }
 
     static int
@@ -1348,6 +1378,53 @@
     PyObject *fromObj;
 } OptionsObject;
 
+    static int
+dummy_check(void *arg UNUSED)
+{
+    return 0;
+}
+
+    static PyObject *
+OptionsNew(int opt_type, void *from, checkfun Check, PyObject *fromObj)
+{
+    OptionsObject      *self;
+
+    self = PyObject_NEW(OptionsObject, &OptionsType);
+    if (self == NULL)
+       return NULL;
+
+    self->opt_type = opt_type;
+    self->from = from;
+    self->Check = Check;
+    self->fromObj = fromObj;
+    if (fromObj)
+       Py_INCREF(fromObj);
+
+    return (PyObject *)(self);
+}
+
+    static void
+OptionsDestructor(PyObject *self)
+{
+    if (((OptionsObject *)(self))->fromObj)
+       Py_DECREF(((OptionsObject *)(self))->fromObj);
+    DESTRUCTOR_FINISH(self);
+}
+
+    static int
+OptionsTraverse(PyObject *self, visitproc visit, void *arg)
+{
+    Py_VISIT(((OptionsObject *)(self))->fromObj);
+    return 0;
+}
+
+    static int
+OptionsClear(PyObject *self)
+{
+    Py_CLEAR(((OptionsObject *)(self))->fromObj);
+    return 0;
+}
+
     static PyObject *
 OptionsItem(OptionsObject *this, PyObject *keyObject)
 {
@@ -1562,39 +1639,6 @@
     return r;
 }
 
-    static int
-dummy_check(void *arg UNUSED)
-{
-    return 0;
-}
-
-    static PyObject *
-OptionsNew(int opt_type, void *from, checkfun Check, PyObject *fromObj)
-{
-    OptionsObject      *self;
-
-    self = PyObject_NEW(OptionsObject, &OptionsType);
-    if (self == NULL)
-       return NULL;
-
-    self->opt_type = opt_type;
-    self->from = from;
-    self->Check = Check;
-    self->fromObj = fromObj;
-    if (fromObj)
-       Py_INCREF(fromObj);
-
-    return (PyObject *)(self);
-}
-
-    static void
-OptionsDestructor(PyObject *self)
-{
-    if (((OptionsObject *)(self))->fromObj)
-       Py_DECREF(((OptionsObject *)(self))->fromObj);
-    DESTRUCTOR_FINISH(self);
-}
-
 static PyMappingMethods OptionsAsMapping = {
     (lenfunc)       NULL,
     (binaryfunc)    OptionsItem,
@@ -1843,6 +1887,19 @@
     else
        return firstwin;
 }
+    static int
+WindowTraverse(PyObject *self, visitproc visit, void *arg)
+{
+    Py_VISIT(((PyObject *)(((WindowObject *)(self))->tabObject)));
+    return 0;
+}
+
+    static int
+WindowClear(PyObject *self)
+{
+    Py_CLEAR((((WindowObject *)(self))->tabObject));
+    return 0;
+}
 
     static PyObject *
 WindowAttr(WindowObject *this, char *name)
@@ -3197,6 +3254,20 @@
     }
 }
 
+    static int
+BufMapIterTraverse(PyObject *buffer, visitproc visit, void *arg)
+{
+    Py_VISIT(buffer);
+    return 0;
+}
+
+    static int
+BufMapIterClear(PyObject **buffer)
+{
+    Py_CLEAR(*buffer);
+    return 0;
+}
+
     static PyObject *
 BufMapIterNext(PyObject **buffer)
 {
@@ -3232,7 +3303,8 @@
 
     buffer = BufferNew(firstbuf);
     return IterNew(buffer,
-           (destructorfun) BufMapIterDestruct, (nextfun) BufMapIterNext);
+           (destructorfun) BufMapIterDestruct, (nextfun) BufMapIterNext,
+           (traversefun) BufMapIterTraverse, (clearfun) BufMapIterClear);
 }
 
 static PyMappingMethods BufMapAsMapping = {
@@ -3841,6 +3913,8 @@
     IterType.tp_iter = IterIter;
     IterType.tp_iternext = IterNext;
     IterType.tp_dealloc = IterDestructor;
+    IterType.tp_traverse = IterTraverse;
+    IterType.tp_clear = IterClear;
 
     vim_memset(&BufferType, 0, sizeof(BufferType));
     BufferType.tp_name = "vim.buffer";
@@ -3869,6 +3943,8 @@
     WindowType.tp_flags = Py_TPFLAGS_DEFAULT;
     WindowType.tp_doc = "vim Window object";
     WindowType.tp_methods = WindowMethods;
+    WindowType.tp_traverse = WindowTraverse;
+    WindowType.tp_clear = WindowClear;
 #if PY_MAJOR_VERSION >= 3
     WindowType.tp_getattro = WindowGetattro;
     WindowType.tp_setattro = WindowSetattro;
@@ -4007,6 +4083,8 @@
     OptionsType.tp_doc = "object for manipulating options";
     OptionsType.tp_as_mapping = &OptionsAsMapping;
     OptionsType.tp_dealloc = OptionsDestructor;
+    OptionsType.tp_traverse = OptionsTraverse;
+    OptionsType.tp_clear = OptionsClear;
 
 #if PY_MAJOR_VERSION >= 3
     vim_memset(&vimmodule, 0, sizeof(vimmodule));

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


*** /tmp/extdiff.hP05AS/vim.02c4f613343a/src/if_py_both.h	2013-05-16 07:07:15.641170975 +0400
--- vim.5f8adb1d88b9/src/if_py_both.h	2013-05-16 07:07:15.646170923 +0400
***************
*** 543,548 ****
--- 543,550 ----
  
  typedef PyObject *(*nextfun)(void **);
  typedef void (*destructorfun)(void *);
+ typedef int (*traversefun)(void *, visitproc, void *);
+ typedef int (*clearfun)(void **);
  
  /* Main purpose of this object is removing the need for do python initialization 
   * (i.e. PyType_Ready and setting type attributes) for a big bunch of objects.
***************
*** 554,563 ****
      void *cur;
      nextfun next;
      destructorfun destruct;
  } IterObject;
  
      static PyObject *
! IterNew(void *start, destructorfun destruct, nextfun next)
  {
      IterObject *self;
  
--- 556,568 ----
      void *cur;
      nextfun next;
      destructorfun destruct;
+     traversefun traverse;
+     clearfun clear;
  } IterObject;
  
      static PyObject *
! IterNew(void *start, destructorfun destruct, nextfun next, traversefun traverse,
! 	clearfun clear)
  {
      IterObject *self;
  
***************
*** 565,570 ****
--- 570,577 ----
      self->cur = start;
      self->next = next;
      self->destruct = destruct;
+     self->traverse = traverse;
+     self->clear = clear;
  
      return (PyObject *)(self);
  }
***************
*** 579,584 ****
--- 586,613 ----
      DESTRUCTOR_FINISH(self);
  }
  
+     static int
+ IterTraverse(PyObject *self, visitproc visit, void *arg)
+ {
+     IterObject *this = (IterObject *)(self);
+ 
+     if (this->traverse != NULL)
+ 	return this->traverse(this->cur, visit, arg);
+     else
+ 	return 0;
+ }
+ 
+     static int
+ IterClear(PyObject *self)
+ {
+     IterObject *this = (IterObject *)(self);
+ 
+     if (this->clear != NULL)
+ 	return this->clear(&this->cur);
+     else
+ 	return 0;
+ }
+ 
      static PyObject *
  IterNext(PyObject *self)
  {
***************
*** 1034,1040 ****
      lii->list = l;
  
      return IterNew(lii,
! 	    (destructorfun) ListIterDestruct, (nextfun) ListIterNext);
  }
  
      static int
--- 1063,1070 ----
      lii->list = l;
  
      return IterNew(lii,
! 	    (destructorfun) ListIterDestruct, (nextfun) ListIterNext,
! 	    NULL, NULL);
  }
  
      static int
***************
*** 1348,1353 ****
--- 1378,1430 ----
      PyObject *fromObj;
  } OptionsObject;
  
+     static int
+ dummy_check(void *arg UNUSED)
+ {
+     return 0;
+ }
+ 
+     static PyObject *
+ OptionsNew(int opt_type, void *from, checkfun Check, PyObject *fromObj)
+ {
+     OptionsObject	*self;
+ 
+     self = PyObject_NEW(OptionsObject, &OptionsType);
+     if (self == NULL)
+ 	return NULL;
+ 
+     self->opt_type = opt_type;
+     self->from = from;
+     self->Check = Check;
+     self->fromObj = fromObj;
+     if (fromObj)
+ 	Py_INCREF(fromObj);
+ 
+     return (PyObject *)(self);
+ }
+ 
+     static void
+ OptionsDestructor(PyObject *self)
+ {
+     if (((OptionsObject *)(self))->fromObj)
+ 	Py_DECREF(((OptionsObject *)(self))->fromObj);
+     DESTRUCTOR_FINISH(self);
+ }
+ 
+     static int
+ OptionsTraverse(PyObject *self, visitproc visit, void *arg)
+ {
+     Py_VISIT(((OptionsObject *)(self))->fromObj);
+     return 0;
+ }
+ 
+     static int
+ OptionsClear(PyObject *self)
+ {
+     Py_CLEAR(((OptionsObject *)(self))->fromObj);
+     return 0;
+ }
+ 
      static PyObject *
  OptionsItem(OptionsObject *this, PyObject *keyObject)
  {
***************
*** 1562,1600 ****
      return r;
  }
  
-     static int
- dummy_check(void *arg UNUSED)
- {
-     return 0;
- }
- 
-     static PyObject *
- OptionsNew(int opt_type, void *from, checkfun Check, PyObject *fromObj)
- {
-     OptionsObject	*self;
- 
-     self = PyObject_NEW(OptionsObject, &OptionsType);
-     if (self == NULL)
- 	return NULL;
- 
-     self->opt_type = opt_type;
-     self->from = from;
-     self->Check = Check;
-     self->fromObj = fromObj;
-     if (fromObj)
- 	Py_INCREF(fromObj);
- 
-     return (PyObject *)(self);
- }
- 
-     static void
- OptionsDestructor(PyObject *self)
- {
-     if (((OptionsObject *)(self))->fromObj)
- 	Py_DECREF(((OptionsObject *)(self))->fromObj);
-     DESTRUCTOR_FINISH(self);
- }
- 
  static PyMappingMethods OptionsAsMapping = {
      (lenfunc)       NULL,
      (binaryfunc)    OptionsItem,
--- 1639,1644 ----
***************
*** 1843,1848 ****
--- 1887,1905 ----
      else
  	return firstwin;
  }
+     static int
+ WindowTraverse(PyObject *self, visitproc visit, void *arg)
+ {
+     Py_VISIT(((PyObject *)(((WindowObject *)(self))->tabObject)));
+     return 0;
+ }
+ 
+     static int
+ WindowClear(PyObject *self)
+ {
+     Py_CLEAR((((WindowObject *)(self))->tabObject));
+     return 0;
+ }
  
      static PyObject *
  WindowAttr(WindowObject *this, char *name)
***************
*** 3197,3202 ****
--- 3254,3273 ----
      }
  }
  
+     static int
+ BufMapIterTraverse(PyObject *buffer, visitproc visit, void *arg)
+ {
+     Py_VISIT(buffer);
+     return 0;
+ }
+ 
+     static int
+ BufMapIterClear(PyObject **buffer)
+ {
+     Py_CLEAR(*buffer);
+     return 0;
+ }
+ 
      static PyObject *
  BufMapIterNext(PyObject **buffer)
  {
***************
*** 3232,3238 ****
  
      buffer = BufferNew(firstbuf);
      return IterNew(buffer,
! 	    (destructorfun) BufMapIterDestruct, (nextfun) BufMapIterNext);
  }
  
  static PyMappingMethods BufMapAsMapping = {
--- 3303,3310 ----
  
      buffer = BufferNew(firstbuf);
      return IterNew(buffer,
! 	    (destructorfun) BufMapIterDestruct, (nextfun) BufMapIterNext,
! 	    (traversefun) BufMapIterTraverse, (clearfun) BufMapIterClear);
  }
  
  static PyMappingMethods BufMapAsMapping = {
***************
*** 3841,3846 ****
--- 3913,3920 ----
      IterType.tp_iter = IterIter;
      IterType.tp_iternext = IterNext;
      IterType.tp_dealloc = IterDestructor;
+     IterType.tp_traverse = IterTraverse;
+     IterType.tp_clear = IterClear;
  
      vim_memset(&BufferType, 0, sizeof(BufferType));
      BufferType.tp_name = "vim.buffer";
***************
*** 3869,3874 ****
--- 3943,3950 ----
      WindowType.tp_flags = Py_TPFLAGS_DEFAULT;
      WindowType.tp_doc = "vim Window object";
      WindowType.tp_methods = WindowMethods;
+     WindowType.tp_traverse = WindowTraverse;
+     WindowType.tp_clear = WindowClear;
  #if PY_MAJOR_VERSION >= 3
      WindowType.tp_getattro = WindowGetattro;
      WindowType.tp_setattro = WindowSetattro;
***************
*** 4007,4012 ****
--- 4083,4090 ----
      OptionsType.tp_doc = "object for manipulating options";
      OptionsType.tp_as_mapping = &OptionsAsMapping;
      OptionsType.tp_dealloc = OptionsDestructor;
+     OptionsType.tp_traverse = OptionsTraverse;
+     OptionsType.tp_clear = OptionsClear;
  
  #if PY_MAJOR_VERSION >= 3
      vim_memset(&vimmodule, 0, sizeof(vimmodule));

Raspunde prin e-mail lui