diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-02-27 06:59:17 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-02-27 06:59:17 +0300 |
commit | a11c80d3bb254037ecb37476feeec5529bb02434 (patch) | |
tree | d3582a27bbd5a271fa3466399b56417afcd52fbd /source/gameengine/Ketsji/KX_PythonSeq.cpp | |
parent | 484ab618a770a283644b70d85b8ac4053a7abb76 (diff) |
cyclic gc support for KX_PythonSeq
Diffstat (limited to 'source/gameengine/Ketsji/KX_PythonSeq.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonSeq.cpp | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/source/gameengine/Ketsji/KX_PythonSeq.cpp b/source/gameengine/Ketsji/KX_PythonSeq.cpp index d60b5a7dc74..04a53fbb493 100644 --- a/source/gameengine/Ketsji/KX_PythonSeq.cpp +++ b/source/gameengine/Ketsji/KX_PythonSeq.cpp @@ -45,18 +45,30 @@ 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 ***/ |