[PD-cvs] externals/grill/py/source main.cpp,1.19,1.20 main.h,1.26,1.27 py.cpp,1.16,1.17 pyext.cpp,1.23,1.24
Thomas Grill
xovo at users.sourceforge.net
Mon Jan 10 06:00:58 CET 2005
Update of /cvsroot/pure-data/externals/grill/py/source
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17461/source
Modified Files:
main.cpp main.h py.cpp pyext.cpp
Log Message:
closed multi-interpreter branch (no chance to have several interpreters in the same thread!)
other thread-related cleanups
py: added ability to choose function from message tag
enabled int-tags for pyext class methods
Index: pyext.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/pyext.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** pyext.cpp 9 Jan 2005 04:59:30 -0000 1.23
--- pyext.cpp 10 Jan 2005 05:00:56 -0000 1.24
***************
*** 100,117 ****
- #if FLEXT_SYS == FLEXT_SYS_MAX
- static short patcher_myvol(t_patcher *x)
- {
- t_box *w;
- if (x->p_vol)
- return x->p_vol;
- else if (w = (t_box *)x->p_vnewobj)
- return patcher_myvol(w->b_patcher);
- else
- return 0;
- }
- #endif
-
-
PyObject *pyext::class_obj = NULL;
PyObject *pyext::class_dict = NULL;
--- 100,103 ----
***************
*** 510,521 ****
char str[256];
! {
! // try tag/inlet
sprintf(str,"%s_%i",GetString(s),n);
ret = call(str,0,NULL,argc,argv);
}
! if(!ret) {
! // try anything/inlet
sprintf(str,"_anything_%i",n);
if(s == sym_bang && !argc) {
--- 496,522 ----
char str[256];
! bool isfloat = s == sym_float && argc == 1;
!
! // if float equals an integer, try int_* method
! if(isfloat && GetAFloat(argv[0]) == GetAInt(argv[0])) {
! sprintf(str,"int_%i",n);
! ret = call(str,0,NULL,1,argv);
! }
!
! // try tag/inlet
! if(!ret) {
sprintf(str,"%s_%i",GetString(s),n);
ret = call(str,0,NULL,argc,argv);
}
! // try truncated int
! if(!ret && isfloat) {
! t_atom at; SetInt(at,GetAInt(argv[0]));
! sprintf(str,"int_%i",n);
! ret = call(str,0,NULL,1,&at);
! }
!
! // try anything/inlet
! if(!ret) {
sprintf(str,"_anything_%i",n);
if(s == sym_bang && !argc) {
***************
*** 527,536 ****
ret = call(str,0,s,argc,argv);
}
! if(!ret) {
! // try tag at any inlet
sprintf(str,"%s_",GetString(s));
ret = call(str,n,NULL,argc,argv);
}
! if(!ret) {
// try anything at any inlet
const char *str1 = "_anything_";
--- 528,550 ----
ret = call(str,0,s,argc,argv);
}
!
! // try int at any inlet
! if(!ret && isfloat && GetAFloat(argv[0]) == GetAInt(argv[0])) {
! ret = call("int_",0,NULL,1,argv);
! }
!
! // try tag at any inlet
! if(!ret) {
sprintf(str,"%s_",GetString(s));
ret = call(str,n,NULL,argc,argv);
}
!
! // try truncated int at any inlet
! if(!ret && isfloat) {
! t_atom at; SetInt(at,GetAInt(argv[0]));
! ret = call("int_",0,NULL,1,&at);
! }
!
! if(!ret) {
// try anything at any inlet
const char *str1 = "_anything_";
Index: py.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/py.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** py.cpp 9 Jan 2005 04:59:30 -0000 1.16
--- py.cpp 10 Jan 2005 05:00:56 -0000 1.17
***************
*** 26,30 ****
bool work(const t_symbol *s,int argc,const t_atom *argv);
- void m_bang() { callwork(sym_bang,0,NULL); }
void m_reload();
void m_reload_(int argc,const t_atom *argv);
--- 26,29 ----
***************
*** 38,41 ****
--- 37,41 ----
void callwork(const t_symbol *s,int argc,const t_atom *argv);
+ void m_bang() { callwork(sym_bang,0,NULL); }
void m_py_list(int argc,const t_atom *argv) { callwork(sym_list,argc,argv); }
void m_py_float(int argc,const t_atom *argv) { callwork(sym_float,argc,argv); }
***************
*** 45,48 ****
--- 45,49 ----
const t_symbol *funname;
PyObject *function;
+ bool withfunction;
virtual void Reload();
***************
*** 103,107 ****
pyobj::pyobj(int argc,const t_atom *argv):
! function(NULL),funname(NULL)
{
PyThreadState *state = PyLock();
--- 104,108 ----
pyobj::pyobj(int argc,const t_atom *argv):
! function(NULL),funname(NULL),withfunction(false)
{
PyThreadState *state = PyLock();
***************
*** 131,139 ****
AddToPath(GetString(canvas_getcurrentdir()));
#elif FLEXT_SYS == FLEXT_SYS_MAX
- /*
short path = patcher_myvol(thisCanvas());
path_topathname(path,NULL,dir);
AddToPath(dir);
- */
#else
#pragma message("Adding current dir to path is not implemented")
--- 132,138 ----
***************
*** 147,150 ****
--- 146,151 ----
if(argc >= 2) {
+ withfunction = true;
+
// set function name
if(!IsString(argv[1]))
***************
*** 155,158 ****
--- 156,161 ----
}
}
+ else
+ withfunction = false;
PyUnlock(state);
***************
*** 281,288 ****
if(func) {
funname = MakeSymbol(func);
ResetFunction();
}
! else
function = NULL,funname = NULL;
}
--- 284,294 ----
if(func) {
funname = MakeSymbol(func);
+ withfunction = true;
ResetFunction();
}
! else {
! withfunction = false;
function = NULL,funname = NULL;
+ }
}
***************
*** 320,336 ****
bool ret = false;
! if(function) {
! PyThreadState *state = PyLock();
!
! PyObject *pargs = MakePyArgs(s,argc,argv);
! Py_INCREF(function);
! ret = gencall(function,pargs);
! PyUnlock(state);
}
! else {
! post("%s: no function defined",thisName());
! ret = false;
! }
Respond(ret);
--- 326,352 ----
bool ret = false;
! PyThreadState *state = PyLock();
! if(withfunction) {
! if(function) {
! PyObject *pargs = MakePyArgs(s,argc,argv);
! Py_INCREF(function);
! ret = gencall(function,pargs);
! }
! else
! post("%s: no valid function defined",thisName());
}
! else {
! // no function defined as creation argument -> use message tag
! PyObject *func = PyObject_GetAttrString(module,const_cast<char *>(GetString(s)));
! if(func) {
! PyObject *pargs = MakePyArgs(sym_list,argc,argv);
! ret = gencall(func,pargs);
! }
! else
! PyErr_Print();
! }
!
! PyUnlock(state);
Respond(ret);
Index: main.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/main.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** main.cpp 9 Jan 2005 04:59:30 -0000 1.19
--- main.cpp 10 Jan 2005 05:00:56 -0000 1.20
***************
*** 20,30 ****
#ifdef FLEXT_THREADS
typedef std::map<flext::thrid_t,PyThreadState *> PyThrMap;
! static PyInterpreterState *pystate = NULL;
static PyThreadState *pythrmain = NULL;
static PyThrMap pythrmap;
! PyThreadState *FindThreadState()
{
flext::thrid_t id = flext::GetThreadId();
--- 20,31 ----
#ifdef FLEXT_THREADS
+
typedef std::map<flext::thrid_t,PyThreadState *> PyThrMap;
! static PyInterpreterState *pymain = NULL;
static PyThreadState *pythrmain = NULL;
static PyThrMap pythrmap;
! PyThreadState *py::FindThreadState()
{
flext::thrid_t id = flext::GetThreadId();
***************
*** 32,36 ****
if(it == pythrmap.end()) {
// Make new thread state
! PyThreadState *st = PyThreadState_New(pystate);
pythrmap[id] = st;
return st;
--- 33,37 ----
if(it == pythrmap.end()) {
// Make new thread state
! PyThreadState *st = PyThreadState_New(pymain);
pythrmap[id] = st;
return st;
***************
*** 40,44 ****
}
! void FreeThreadState()
{
flext::thrid_t id = flext::GetThreadId();
--- 41,45 ----
}
! void py::FreeThreadState()
{
flext::thrid_t id = flext::GetThreadId();
***************
*** 59,71 ****
{
post("");
! post("--------------------------------------");
post("py/pyext %s - python script objects",PY__VERSION);
! post(" (C)2002-2005 Thomas Grill");
! post(" http://grrrr.org/ext");
#ifdef FLEXT_DEBUG
post("");
post("DEBUG version compiled on %s %s",__DATE__,__TIME__);
#endif
! post("--------------------------------------");
post("");
--- 60,73 ----
{
post("");
! post("------------------------------------------------");
post("py/pyext %s - python script objects",PY__VERSION);
! post("(C)2002-2005 Thomas Grill - http://grrrr.org/ext");
! post("");
! post("using Python %s",Py_GetVersion());
#ifdef FLEXT_DEBUG
post("");
post("DEBUG version compiled on %s %s",__DATE__,__TIME__);
#endif
! post("------------------------------------------------");
post("");
***************
*** 86,90 ****
pythrmain = PyThreadState_Get();
// get main interpreter state
! pystate = pythrmain->interp;
// add thread state of main thread to map
--- 88,92 ----
pythrmain = PyThreadState_Get();
// get main interpreter state
! pymain = pythrmain->interp;
// add thread state of main thread to map
***************
*** 105,117 ****
PySys_SetObject("stderr", py_out);
- #ifdef FLEXT_THREADS
- // release global lock
- PyEval_ReleaseLock();
- #endif
-
// -------------------------------------------------------------
FLEXT_SETUP(pyobj);
FLEXT_SETUP(pyext);
}
--- 107,119 ----
PySys_SetObject("stderr", py_out);
// -------------------------------------------------------------
FLEXT_SETUP(pyobj);
FLEXT_SETUP(pyext);
+
+ #ifdef FLEXT_THREADS
+ // release global lock
+ PyEval_ReleaseLock();
+ #endif
}
***************
*** 128,136 ****
stoptick(0)
{
- // interpreter = PyInterpreterState_New();
-
PyThreadState *state = PyLock();
Py_INCREF(module_obj);
! PyUnlock(state);
FLEXT_ADDTIMER(stoptmr,tick);
--- 130,136 ----
stoptick(0)
{
PyThreadState *state = PyLock();
Py_INCREF(module_obj);
! PyUnlock(state);
FLEXT_ADDTIMER(stoptmr,tick);
***************
*** 154,165 ****
post("%s - Okay, all threads have terminated",thisName());
}
!
Py_XDECREF(module_obj);
! /*
! PyEval_AcquireLock();
! PyInterpreterState_Clear(interpreter);
! PyInterpreterState_Delete(interpreter);
! PyEval_ReleaseLock();
! */
}
--- 154,161 ----
post("%s - Okay, all threads have terminated",thisName());
}
!
! PyThreadState *state = PyLock();
Py_XDECREF(module_obj);
! PyUnlock(state);
}
***************
*** 506,515 ****
--- 502,527 ----
Py_XDECREF(args);
}
+
PyUnlock(state);
}
+ #if FLEXT_SYS == FLEXT_SYS_MAX
+ short py::patcher_myvol(t_patcher *x)
+ {
+ t_box *w;
+ if (x->p_vol)
+ return x->p_vol;
+ else if (w = (t_box *)x->p_vnewobj)
+ return patcher_myvol(w->b_patcher);
+ else
+ return 0;
+ }
+ #endif
+
+
Fifo::~Fifo()
{
FifoEl *el = head;
+ head = tail = NULL; // reset it, in case there's a thread wanting to Pop
while(el) {
FifoEl *n = el->nxt;
Index: main.h
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/main.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** main.h 9 Jan 2005 04:59:30 -0000 1.26
--- main.h 10 Jan 2005 05:00:56 -0000 1.27
***************
*** 59,65 ****
- PyThreadState *FindThreadState();
- void FreeThreadState();
-
class py:
public flext_base
--- 59,62 ----
***************
*** 142,148 ****
virtual bool callpy(PyObject *fun,PyObject *args) = 0;
! private:
! // PyInterpreterState *interpreter;
bool qucall(PyObject *fun,PyObject *args);
void threadworker();
--- 139,147 ----
virtual bool callpy(PyObject *fun,PyObject *args) = 0;
! #if FLEXT_SYS == FLEXT_SYS_MAX
! static short patcher_myvol(t_patcher *x);
! #endif
+ private:
bool qucall(PyObject *fun,PyObject *args);
void threadworker();
***************
*** 158,161 ****
--- 157,165 ----
#endif
+ #ifdef FLEXT_THREADS
+ static PyThreadState *FindThreadState();
+ static void FreeThreadState();
+ #endif
+
public:
More information about the Pd-cvs
mailing list