cyclic gc support for KX_PythonSeq
authorCampbell Barton <ideasman42@gmail.com>
Sun, 27 Feb 2011 03:59:17 +0000 (03:59 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 27 Feb 2011 03:59:17 +0000 (03:59 +0000)
source/gameengine/Ketsji/KX_PythonSeq.cpp

index d60b5a7dc74485a73bd1f6fb7f259d6f09f21c37..04a53fbb49314ab296826308a781d281db43c3f7 100644 (file)
 
 PyObject *KX_PythonSeq_CreatePyObject( PyObject *base, short type )
 {
-       KX_PythonSeq *seq = PyObject_NEW( KX_PythonSeq, &KX_PythonSeq_Type);
+       KX_PythonSeq *seq = PyObject_GC_New(KX_PythonSeq, &KX_PythonSeq_Type);
        seq->base = base;
        Py_INCREF(base); /* so we can always access to check if its valid */
        seq->type = type;
        seq->iter = -1; /* init */
        return (PyObject *)seq;
- }
- static void KX_PythonSeq_dealloc( KX_PythonSeq * self )
+}
+
+static int KX_PythonSeq_traverse(KX_PythonSeq *self, visitproc visit, void *arg)
+{
+       Py_VISIT(self->base);
+       return 0;
+}
+
+static int KX_PythonSeq_clear(KX_PythonSeq *self)
+{
+       Py_CLEAR(self->base);
+       return 0;
+}
+
+static void KX_PythonSeq_dealloc(KX_PythonSeq * self)
 {
-       Py_DECREF(self->base);
-       PyObject_DEL( self );
+       KX_PythonSeq_clear(self);
+       PyObject_GC_Del(self);
 }
 
 static Py_ssize_t KX_PythonSeq_len( PyObject * self )
@@ -470,15 +482,15 @@ PyTypeObject KX_PythonSeq_Type = {
        NULL,                       /* PyBufferProcs *tp_as_buffer; */
 
   /*** Flags to define presence of optional/expanded features ***/
-       Py_TPFLAGS_DEFAULT,         /* long tp_flags; */
+       Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* long tp_flags; */
 
        NULL,                       /*  char *tp_doc;  Documentation string */
   /*** Assigned meaning in release 2.0 ***/
        /* call function for all accessible objects */
-       NULL,                                           /* traverseproc tp_traverse; */
+       (traverseproc)KX_PythonSeq_traverse,    /* traverseproc tp_traverse; */
 
        /* delete references to contained objects */
-       NULL,                       /* inquiry tp_clear; */
+       (inquiry)KX_PythonSeq_clear,    /* inquiry tp_clear; */
 
   /***  Assigned meaning in release 2.1 ***/
   /*** rich comparisons ***/