aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/py/source/clmeth.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'externals/grill/py/source/clmeth.cpp')
-rw-r--r--externals/grill/py/source/clmeth.cpp105
1 files changed, 72 insertions, 33 deletions
diff --git a/externals/grill/py/source/clmeth.cpp b/externals/grill/py/source/clmeth.cpp
index 30474eff..c8d38f81 100644
--- a/externals/grill/py/source/clmeth.cpp
+++ b/externals/grill/py/source/clmeth.cpp
@@ -17,6 +17,7 @@ PyMethodDef pyext::meth_tbl[] =
{"__init__", pyext::pyext__init__, METH_VARARGS, "Constructor"},
{"__del__", pyext::pyext__del__, METH_VARARGS, "Destructor"},
*/
+ {"__str__", pyext::pyext__str__, METH_VARARGS, "stringify"},
{"_outlet", pyext::pyext_outlet, METH_VARARGS,"Send message to outlet"},
#if FLEXT_SYS == FLEXT_SYS_PD
{"_tocanvas", pyext::pyext_tocanvas, METH_VARARGS,"Send message to canvas" },
@@ -28,8 +29,6 @@ PyMethodDef pyext::meth_tbl[] =
{ "_detach", pyext::pyext_detach, METH_VARARGS,"Set detach flag for called methods" },
{ "_stop", pyext::pyext_stop, METH_VARARGS,"Stop running threads" },
#endif
- { "_isthreaded", pyext::pyext_isthreaded, METH_O,"Query whether threading is enabled" },
-
{ "_invec", pyext::pyext_invec, METH_VARARGS,"Get input vector" },
{ "_outvec", pyext::pyext_outvec, METH_VARARGS,"Get output vector" },
{NULL, NULL, 0, NULL} /* Sentinel */
@@ -53,11 +52,12 @@ const char *pyext::pyext_doc =
#endif
"_bind(self,name,func): Bind a python function to a symbol\n"
"_unbind(self,name,func): Unbind a python function from a symbol\n"
+ "_isthreaded: Query whether threading is enabled\n"
#ifdef FLEXT_THREADS
"_detach(self,int): Define whether a called Python method has its own thread\n"
"_stop(self): Stop running threads\n"
+ "_shouldexit: Query whether threads should terminate\n"
#endif
- "_isthreaded(self): Query whether threading is enabled\n"
;
/*
@@ -78,10 +78,22 @@ PyObject* pyext::pyext__del__(PyObject *,PyObject *args)
}
*/
+PyObject* pyext::pyext__str__(PyObject *,PyObject *args)
+{
+ PyObject *self;
+ if(!PyArg_ParseTuple(args, "O:pyext__str__",&self)) {
+ // handle error
+ ERRINTERNAL();
+ return NULL;
+ }
+
+ return PyString_FromFormat("<pyext object %p>",self);
+}
+
PyObject* pyext::pyext_setattr(PyObject *,PyObject *args)
{
PyObject *self,*name,*val;
- if(!PyArg_ParseTuple(args, "OOO:test_foo", &self,&name,&val)) {
+ if(!PyArg_ParseTuple(args, "OOO:pyext_setattr", &self,&name,&val)) {
// handle error
ERRINTERNAL();
return NULL;
@@ -111,28 +123,38 @@ PyObject* pyext::pyext_setattr(PyObject *,PyObject *args)
PyObject* pyext::pyext_getattr(PyObject *,PyObject *args)
{
PyObject *self,*name,*ret = NULL;
- if(!PyArg_ParseTuple(args, "OO:test_foo", &self,&name)) {
+ if(!PyArg_ParseTuple(args, "OO:pyext_getattr", &self,&name)) {
// handle error
ERRINTERNAL();
}
-#ifdef FLEXT_THREADS
if(PyString_Check(name)) {
char* sname = PyString_AS_STRING(name);
if(sname) {
+#ifdef FLEXT_THREADS
if(!strcmp(sname,"_shouldexit")) {
pyext *ext = GetThis(self);
if(ext)
ret = PyLong_FromLong(ext->shouldexit?1:0);
else {
+ // return true for _shouldexit if association has been removed
Py_INCREF(Py_True);
ret = Py_True;
}
}
-// post("pyext::getattr %s",sname);
+ else
+#endif
+ if(!strcmp(sname,"_isthreaded")) {
+ #ifdef FLEXT_THREADS
+ Py_INCREF(Py_True);
+ ret = Py_True;
+ #else
+ Py_INCREF(Py_False);
+ ret = Py_False;
+ #endif
+ }
}
}
-#endif
if(!ret) {
#if PY_VERSION_HEX >= 0x02020000
@@ -165,7 +187,10 @@ PyObject *pyext::pyext_outlet(PyObject *,PyObject *args)
(outl = PyTuple_GET_ITEM(args,1)) != NULL && PyInt_Check(outl)
) {
pyext *ext = GetThis(self);
- FLEXT_ASSERT(ext);
+ if(!ext) {
+ PyErr_SetString(PyExc_RuntimeError,"pyext - _outlet: instance not associated with pd object");
+ return NULL;
+ }
PyObject *val;
#if 0
@@ -230,7 +255,11 @@ PyObject *pyext::pyext_detach(PyObject *,PyObject *args)
}
else {
pyext *ext = GetThis(self);
- FLEXT_ASSERT(ext);
+ if(!ext) {
+ PyErr_SetString(PyExc_RuntimeError,"pyext - _detach: instance not associated with pd object");
+ return NULL;
+ }
+
ext->detach = val;
}
@@ -254,7 +283,11 @@ PyObject *pyext::pyext_stop(PyObject *,PyObject *args)
}
else {
pyext *ext = GetThis(self);
- FLEXT_ASSERT(ext);
+ if(!ext) {
+ PyErr_SetString(PyExc_RuntimeError,"pyext - _stop: instance not associated with pd object");
+ return NULL;
+ }
+
int cnt;
t_atom at;
if(val >= 0) cnt = 1,flext::SetInt(at,val);
@@ -268,17 +301,6 @@ PyObject *pyext::pyext_stop(PyObject *,PyObject *args)
#endif
-//! Query whether threading is enabled
-PyObject *pyext::pyext_isthreaded(PyObject *,PyObject *)
-{
- return PyInt_FromLong(
-#ifdef FLEXT_THREADED
- 1
-#else
- 0
-#endif
- );
-}
#if FLEXT_SYS == FLEXT_SYS_PD
//! Send message to canvas
@@ -295,7 +317,11 @@ PyObject *pyext::pyext_tocanvas(PyObject *,PyObject *args)
(self = PyTuple_GET_ITEM(args,0)) != NULL && PyInstance_Check(self)
) {
pyext *ext = GetThis(self);
- FLEXT_ASSERT(ext);
+ if(!ext) {
+ PyErr_SetString(PyExc_RuntimeError,"pyext - _tocanvas: instance not associated with pd object");
+ return NULL;
+ }
+
PyObject *val;
bool tp =
@@ -310,10 +336,13 @@ PyObject *pyext::pyext_tocanvas(PyObject *,PyObject *args)
flext::AtomListStatic<16> lst;
const t_symbol *sym = GetPyArgs(lst,val);
if(sym) {
- t_glist *gl = ext->thisCanvas(); //canvas_getcurrent();
- t_class **cl = (t_pd *)gl;
- if(cl)
- pd_forwardmess(cl,lst.Count(),lst.Atoms());
+ t_glist *gl = ext->thisCanvas();
+ if(gl) {
+ // \TODO find a flext-based non-locking method
+ sys_lock();
+ pd_forwardmess((t_class **)gl,lst.Count(),lst.Atoms());
+ sys_unlock();
+ }
#ifdef FLEXT_DEBUG
else
post("pyext - no parent canvas?!");
@@ -351,9 +380,14 @@ PyObject *pyext::pyext_invec(PyObject *,PyObject *args)
}
else {
pyext *ext = GetThis(self);
- FLEXT_ASSERT(ext);
- PyObject *b = ext->GetSig(val,true);
- if(b) return b;
+ if(ext) {
+ PyObject *b = ext->GetSig(val,true);
+ if(b) return b;
+ }
+ else {
+ PyErr_SetString(PyExc_RuntimeError,"pyext - _invec: instance not associated with pd object");
+ return NULL;
+ }
}
Py_INCREF(Py_None);
@@ -375,9 +409,14 @@ PyObject *pyext::pyext_outvec(PyObject *,PyObject *args)
}
else {
pyext *ext = GetThis(self);
- FLEXT_ASSERT(ext);
- PyObject *b = ext->GetSig(val,false);
- if(b) return b;
+ if(ext) {
+ PyObject *b = ext->GetSig(val,false);
+ if(b) return b;
+ }
+ else {
+ PyErr_SetString(PyExc_RuntimeError,"pyext - _outvec: instance not associated with pd object");
+ return NULL;
+ }
}
Py_INCREF(Py_None);