Update of /cvsroot/pure-data/externals/grill/py/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27609/source
Modified Files: main.cpp main.h pyext.cpp Log Message: better cleanup behavior (shutdown hook method _del and garbage collection) - garbage collection at module scope update for flext build system - better handling of bang messages fixes for single-threaded compilation little restructuring
Index: pyext.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/pyext.cpp,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** pyext.cpp 11 Jan 2005 04:59:27 -0000 1.25 --- pyext.cpp 23 Feb 2005 04:57:19 -0000 1.26 *************** *** 226,251 **** ClearBinding();
if(pyobj) { ! if(pyobj->ob_refcnt > 1) { ! post("%s - Python object is still referenced",thisName()); ! ! // Force-quit object: ! // call __del__ manually ! // this is dangerous, because it could get called a second time ! // if object really has no more references then ! PyObject *meth = PyObject_GetAttrString(pyobj,"__del__"); // get ref ! if(meth) { ! if(PyMethod_Check(meth)) { ! PyObject *res = PyObject_CallObject(meth,NULL); ! if(!res) ! PyErr_Print(); ! else ! Py_DECREF(res); ! } ! Py_DECREF(meth); ! } } Py_DECREF(pyobj); // opposite of SetClssMeth } }
--- 226,249 ---- ClearBinding();
+ bool gcrun = false; if(pyobj) { ! // try to run del to clean up the class instance ! PyObject *objdel = PyObject_GetAttrString(pyobj,"_del"); ! if(objdel) { ! PyObject *args = PyTuple_New(0); ! PyObject *ret = PyObject_Call(objdel,args,NULL); ! if(!ret) ! post("%s - Could not call _del method",thisName()); ! else ! Py_DECREF(ret); ! Py_DECREF(args); ! Py_DECREF(objdel); } + + gcrun = pyobj->ob_refcnt > 1; Py_DECREF(pyobj); // opposite of SetClssMeth } + + if(gcrun) collect(); }
*************** *** 543,553 **** if(!ret) { sprintf(str,"_anything_%i",n); ! if(s == sym_bang && !argc) { ! t_atom argv; ! SetSymbol(argv,sym__); ! ret = call(str,0,s,1,&argv); ! } ! else ! ret = call(str,0,s,argc,argv); }
--- 541,545 ---- if(!ret) { sprintf(str,"_anything_%i",n); ! ret = call(str,0,s,argc,argv); }
Index: main.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/main.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** main.cpp 1 Feb 2005 04:57:06 -0000 1.22 --- main.cpp 23 Feb 2005 04:57:18 -0000 1.23 *************** *** 18,21 **** --- 18,22 ---- };
+ static PyObject *gcollect = NULL;
#ifdef FLEXT_THREADS *************** *** 120,123 **** --- 121,131 ---- PySys_SetObject("stderr", py_out);
+ // get garbage collector function + PyObject *gcobj = PyImport_ImportModule("gc"); + if(gcobj) { + gcollect = PyObject_GetAttrString(gcobj,"collect"); + Py_DECREF(gcobj); + } + // -------------------------------------------------------------
*************** *** 549,552 **** --- 557,575 ---- #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()
Index: main.h =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/main.h,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** main.h 1 Feb 2005 04:57:06 -0000 1.29 --- main.h 23 Feb 2005 04:57:19 -0000 1.30 *************** *** 91,95 **** void Respond(bool b);
! static bool IsAnything(const t_symbol *s) { return s && s != sym_bang && s != sym_float && s != sym_int && s != sym_symbol && s != sym_list && s != sym_pointer; }
enum retval { nothing,atom,sequ }; --- 91,95 ---- void Respond(bool b);
! static bool IsAnything(const t_symbol *s) { return s && s != sym_float && s != sym_int && s != sym_symbol && s != sym_list && s != sym_pointer; }
enum retval { nothing,atom,sequ }; *************** *** 133,136 **** --- 133,138 ---- #endif
+ static void collect(); + private:
*************** *** 143,146 **** --- 145,151 ---- ThrCond qucond;
+ static PyThreadState *FindThreadState(); + static void FreeThreadState(); + FLEXT_THREAD_X(work_wrapper) #else *************** *** 148,156 **** #endif
- #ifdef FLEXT_THREADS - static PyThreadState *FindThreadState(); - static void FreeThreadState(); - #endif - public:
--- 153,156 ----