diff options
author | Thomas Grill <xovo@users.sourceforge.net> | 2005-04-18 15:11:43 +0000 |
---|---|---|
committer | Thomas Grill <xovo@users.sourceforge.net> | 2005-04-18 15:11:43 +0000 |
commit | 14719fd1f8cc2384398168788357930e29bde5c4 (patch) | |
tree | 8e7abc2070a13d6a40abd9a1d46b5c4688329249 /externals/grill/py/source/main.cpp | |
parent | f61347eda1d8f25fa6eb6542bd7eea32d894b6b2 (diff) |
check for PD version
better reload handling, but still far fom perfect
fixed minor other issues
fixed buglet
fixing strange gcc behavior
updates for DSP processing
better argument checking
svn path=/trunk/; revision=2781
Diffstat (limited to 'externals/grill/py/source/main.cpp')
-rw-r--r-- | externals/grill/py/source/main.cpp | 81 |
1 files changed, 60 insertions, 21 deletions
diff --git a/externals/grill/py/source/main.cpp b/externals/grill/py/source/main.cpp index fadb0173..fa5169b7 100644 --- a/externals/grill/py/source/main.cpp +++ b/externals/grill/py/source/main.cpp @@ -288,12 +288,9 @@ void pybase::SetArgs() bool pybase::ImportModule(const char *name) { if(!name) return false; - - SetArgs(); - module = PyImport_ImportModule((char *)name); // increases module_obj ref count by one - dict = module?PyModule_GetDict(module):NULL; - - return module != NULL; + if(modname == name) return true; + modname = name; + return ReloadModule(); } void pybase::UnimportModule() @@ -315,22 +312,22 @@ void pybase::UnimportModule() bool pybase::ReloadModule() { bool ok = false; - if(module) { - SetArgs(); - PyObject *newmod = PyImport_ReloadModule(module); - if(!newmod) { - // old module still exists?! -// dict = NULL; - } - else { - Py_XDECREF(module); - module = newmod; - dict = PyModule_GetDict(module); // borrowed - ok = true; - } + + SetArgs(); + PyObject *newmod = module + ?PyImport_ReloadModule(module) + :PyImport_ImportModule((char *)modname.c_str()); + + if(!newmod) { + // unload faulty module + if(module) UnimportModule(); + } + else { + Py_XDECREF(module); + module = newmod; + dict = PyModule_GetDict(module); // borrowed + ok = true; } - else - post("py/pyext - No module to reload"); return ok; } @@ -402,6 +399,48 @@ void pybase::Respond(bool b) } } +void pybase::Reload() +{ + PyThreadState *state = PyLockSys(); + + PyObject *reg = GetRegistry(REGNAME); + + if(reg) { + PyObject *key; + int pos = 0; + while(PyDict_Next(reg,&pos,&key,NULL)) { + pybase *th = (pybase *)PyLong_AsLong(key); + FLEXT_ASSERT(th); + th->Unload(); + } + + UnloadModule(); + } + + bool ok = ReloadModule(); + + if(ok) { + LoadModule(); + + if(reg) { + SetRegistry(REGNAME,reg); + + PyObject *key; + int pos = 0; + while(PyDict_Next(reg,&pos,&key,NULL)) { + pybase *th = (pybase *)PyLong_AsLong(key); + FLEXT_ASSERT(th); + th->Load(); + } + } + else + Load(); + } + + Report(); + PyUnlock(state); +} + static PyObject *output = NULL; |