diff options
Diffstat (limited to 'externals/grill/py/source/main.cpp')
-rw-r--r-- | externals/grill/py/source/main.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/externals/grill/py/source/main.cpp b/externals/grill/py/source/main.cpp index 89696b46..bf7345d5 100644 --- a/externals/grill/py/source/main.cpp +++ b/externals/grill/py/source/main.cpp @@ -17,6 +17,7 @@ static PyMethodDef StdOut_Methods[] = { NULL, NULL, } }; +static PyObject *gcollect = NULL; #ifdef FLEXT_THREADS @@ -119,6 +120,13 @@ void py::lib_setup() py_out = Py_InitModule("stderr", StdOut_Methods); PySys_SetObject("stderr", py_out); + // get garbage collector function + PyObject *gcobj = PyImport_ImportModule("gc"); + if(gcobj) { + gcollect = PyObject_GetAttrString(gcobj,"collect"); + Py_DECREF(gcobj); + } + // ------------------------------------------------------------- FLEXT_SETUP(pyobj); @@ -548,6 +556,21 @@ short py::patcher_myvol(t_patcher *x) } #endif +void py::collect() +{ + if(gcollect) { + PyObject *args = PyTuple_New(0); + PyObject *ret = PyObject_Call(gcollect,args,NULL); + Py_DECREF(args); + if(ret) { +#ifdef FLEXT_DEBUG + int refs = PyInt_AsLong(ret); + if(refs) post("py/pyext - Garbage collector reports %i unreachable objects",refs); +#endif + Py_DECREF(ret); + } + } +} Fifo::~Fifo() { |