aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/py/source
diff options
context:
space:
mode:
authorThomas Grill <xovo@users.sourceforge.net>2007-07-06 21:44:56 +0000
committerThomas Grill <xovo@users.sourceforge.net>2007-07-06 21:44:56 +0000
commit3922cb5abcd451238047713829456e50f94dade2 (patch)
tree990cb81fcccfc5bbe3807442401615ec76b66d44 /externals/grill/py/source
parentd58dd27f1324e4d33a3f09637b2c06198dd27df4 (diff)
adapting to new flext lockfree structures
much better detach method handling (one thread for all object instances) use PyGILState_\*() functionality (enabled with PY_USE_GIL) ooops, fixing typo fixing numpy initialization quirks pyext._init is now called after __init__ enabled use of inofficial PD functionality for search and help path access (#define PY_USE_INOFFICIAL) added sketch for new pye (Python expression) object buffer protocol adapted for Python 2.5 svn path=/trunk/; revision=7903
Diffstat (limited to 'externals/grill/py/source')
-rw-r--r--externals/grill/py/source/main.h2
-rw-r--r--externals/grill/py/source/modmeth.cpp32
-rw-r--r--externals/grill/py/source/py.cpp2
-rw-r--r--externals/grill/py/source/pybase.cpp11
-rw-r--r--externals/grill/py/source/pybase.h5
-rw-r--r--externals/grill/py/source/pybuffer.cpp17
-rw-r--r--externals/grill/py/source/pyext.cpp28
-rw-r--r--externals/grill/py/source/pyext.h1
-rw-r--r--externals/grill/py/source/pyprefix.h7
9 files changed, 99 insertions, 6 deletions
diff --git a/externals/grill/py/source/main.h b/externals/grill/py/source/main.h
index 86098b4c..3a49937c 100644
--- a/externals/grill/py/source/main.h
+++ b/externals/grill/py/source/main.h
@@ -28,7 +28,7 @@ WARRANTIES, see the file, "license.txt," in this distribution.
class pybase;
class FifoEl
- : public Fifo::Cell
+ : public FifoCell
{
public:
void Set(pybase *t,PyObject *f,PyObject *a) { th = t,fun = f,args = a; }
diff --git a/externals/grill/py/source/modmeth.cpp b/externals/grill/py/source/modmeth.cpp
index 52f5b964..039eb6cc 100644
--- a/externals/grill/py/source/modmeth.cpp
+++ b/externals/grill/py/source/modmeth.cpp
@@ -23,6 +23,9 @@ PyMethodDef pybase::func_tbl[] =
{ "_samplerate", pybase::py_samplerate, METH_NOARGS,"Get system sample rate" },
{ "_blocksize", pybase::py_blocksize, METH_NOARGS,"Get system block size" },
+ { "_searchpaths", pybase::py_searchpaths, METH_NOARGS,"Get system search paths" },
+ { "_helppaths", pybase::py_helppaths, METH_NOARGS,"Get system help paths" },
+
#if FLEXT_SYS == FLEXT_SYS_PD
{ "_getvalue", pybase::py_getvalue, METH_VARARGS,"Get value of a 'value' object" },
{ "_setvalue", pybase::py_setvalue, METH_VARARGS,"Set value of a 'value' object" },
@@ -51,7 +54,6 @@ const char *pybase::py_doc =
"_tuple(args...): Make a tuple from args\n"
;
-
#ifdef FLEXT_THREADS
void pybase::tick(void *)
{
@@ -111,6 +113,34 @@ PyObject *pybase::py_blocksize(PyObject *self,PyObject *args)
return PyLong_FromLong(sys_getblksize());
}
+PyObject *pybase::py_searchpaths(PyObject *self,PyObject *args)
+{
+#if FLEXT_SYS == FLEXT_SYS_PD && defined(PY_USE_INOFFICIAL)
+ PyObject *ret = PyList_New(0);
+ char *dir;
+ for(int i = 0; (dir = namelist_get(sys_searchpath,i)) != NULL; ++i)
+ PyList_Append(ret,PyString_FromString(dir));
+ return ret;
+#else
+ Py_INCREF(Py_None);
+ return Py_None;
+#endif
+}
+
+PyObject *pybase::py_helppaths(PyObject *self,PyObject *args)
+{
+#if FLEXT_SYS == FLEXT_SYS_PD && defined(PY_USE_INOFFICIAL)
+ PyObject *ret = PyList_New(0);
+ char *dir;
+ for(int i = 0; (dir = namelist_get(sys_helppath,i)) != NULL; ++i)
+ PyList_Append(ret,PyString_FromString(dir));
+ return ret;
+#else
+ Py_INCREF(Py_None);
+ return Py_None;
+#endif
+}
+
PyObject *pybase::py_send(PyObject *,PyObject *args)
{
// should always be a tuple
diff --git a/externals/grill/py/source/py.cpp b/externals/grill/py/source/py.cpp
index f19ec36a..c7b526a0 100644
--- a/externals/grill/py/source/py.cpp
+++ b/externals/grill/py/source/py.cpp
@@ -188,12 +188,12 @@ pyobj::pyobj(int argc,const t_atom *argv)
pyobj::~pyobj()
{
+ ThrState state = PyLockSys();
if(objects) {
for(int i = 0; i < CntIn()-1; ++i) Py_DECREF(objects[i]);
delete[] objects;
}
- ThrState state = PyLockSys();
Unregister(GetRegistry(REGNAME));
Report();
PyUnlock(state);
diff --git a/externals/grill/py/source/pybase.cpp b/externals/grill/py/source/pybase.cpp
index a74df81e..16d9301e 100644
--- a/externals/grill/py/source/pybase.cpp
+++ b/externals/grill/py/source/pybase.cpp
@@ -129,7 +129,7 @@ void pybase::lib_setup()
Py_Initialize();
#ifdef FLEXT_DEBUG
- Py_DebugFlag = 1;
+// Py_DebugFlag = 1;
// Py_VerboseFlag = 1;
#else
Py_OptimizeFlag = 1;
@@ -199,6 +199,15 @@ void pybase::lib_setup()
PyModule_AddObject(module_obj,"Bundle",(PyObject *)&pyBundle_Type);
// -------------------------------------------------------------
+#ifdef PY_USE_INOFFICIAL
+ // add PD paths
+
+ char *dir;
+ for(int i = 0; (dir = namelist_get(sys_searchpath,i)) != NULL; ++i) {
+ AddToPath(dir);
+ }
+#endif
+ // -------------------------------------------------------------
FLEXT_SETUP(pyobj);
FLEXT_SETUP(pymeth);
diff --git a/externals/grill/py/source/pybase.h b/externals/grill/py/source/pybase.h
index 61518a2a..437fa85f 100644
--- a/externals/grill/py/source/pybase.h
+++ b/externals/grill/py/source/pybase.h
@@ -108,7 +108,7 @@ protected:
static PyObject *module_obj,*module_dict;
static PyObject *builtins_obj,*builtins_dict;
- static PyMethodDef func_tbl[];
+ static PyMethodDef func_tbl[],attr_tbl[];
static PyObject *py__doc__(PyObject *,PyObject *args);
static PyObject *py_send(PyObject *,PyObject *args);
@@ -120,6 +120,9 @@ protected:
static PyObject *py_samplerate(PyObject *,PyObject *args);
static PyObject *py_blocksize(PyObject *,PyObject *args);
+ static PyObject *py_searchpaths(PyObject *,PyObject *args);
+ static PyObject *py_helppaths(PyObject *,PyObject *args);
+
#if FLEXT_SYS == FLEXT_SYS_PD
static PyObject *py_getvalue(PyObject *,PyObject *args);
static PyObject *py_setvalue(PyObject *,PyObject *args);
diff --git a/externals/grill/py/source/pybuffer.cpp b/externals/grill/py/source/pybuffer.cpp
index 5452c254..4f7155ea 100644
--- a/externals/grill/py/source/pybuffer.cpp
+++ b/externals/grill/py/source/pybuffer.cpp
@@ -186,28 +186,45 @@ static PyMethodDef buffer_methods[] = {
// support the buffer protocol
+
+#if PY_VERSION_HEX >= 0x02050000
+static Py_ssize_t buffer_readbuffer(PyObject *obj, Py_ssize_t segment, void **ptrptr)
+#else
static int buffer_readbuffer(PyObject *obj, int segment, void **ptrptr)
+#endif
{
flext::buffer *b = ((pySamplebuffer *)obj)->buf;
ptrptr[0] = b->Data();
return b->Channels()*b->Frames()*sizeof(t_sample);
}
+#if PY_VERSION_HEX >= 0x02050000
+static Py_ssize_t buffer_writebuffer(PyObject *obj, Py_ssize_t segment, void **ptrptr)
+#else
static int buffer_writebuffer(PyObject *obj, int segment, void **ptrptr)
+#endif
{
flext::buffer *b = ((pySamplebuffer *)obj)->buf;
ptrptr[0] = b->Data();
return b->Channels()*b->Frames()*sizeof(t_sample);
}
+#if PY_VERSION_HEX >= 0x02050000
+static Py_ssize_t buffer_segcount(PyObject *obj, Py_ssize_t *lenp)
+#else
static int buffer_segcount(PyObject *obj, int *lenp)
+#endif
{
flext::buffer *b = ((pySamplebuffer *)obj)->buf;
if(lenp) lenp[0] = b->Channels()*b->Frames()*sizeof(t_sample);
return 1;
}
+#if PY_VERSION_HEX >= 0x02050000
+static Py_ssize_t buffer_charbuffer(PyObject *obj, Py_ssize_t segment, char **ptrptr)
+#else
static int buffer_charbuffer(PyObject *obj, int segment, const char **ptrptr)
+#endif
{
flext::buffer *b = ((pySamplebuffer *)obj)->buf;
ptrptr[0] = (char *)b->Data();
diff --git a/externals/grill/py/source/pyext.cpp b/externals/grill/py/source/pyext.cpp
index 31945277..2eabf12e 100644
--- a/externals/grill/py/source/pyext.cpp
+++ b/externals/grill/py/source/pyext.cpp
@@ -219,6 +219,34 @@ bool pyext::Init()
return pyobj && flext_dsp::Init();
}
+bool pyext::Finalize()
+{
+ bool ok = true;
+ ThrState state = PyLockSys();
+
+ PyObject *init = PyObject_GetAttrString(pyobj,"_init"); // get ref
+ if(init) {
+ if(PyMethod_Check(init)) {
+ PyObject *res = PyObject_CallObject(init,NULL);
+ if(!res) {
+ // exception is set
+ ok = false;
+ // we want to know why __init__ failed...
+ PyErr_Print();
+ }
+ else
+ Py_DECREF(res);
+ }
+ Py_DECREF(init);
+ }
+ else
+ // __init__ has not been found - don't care
+ PyErr_Clear();
+
+ PyUnlock(state);
+ return ok && flext_dsp::Finalize();
+}
+
void pyext::Exit()
{
pybase::Exit(); // exit threads
diff --git a/externals/grill/py/source/pyext.h b/externals/grill/py/source/pyext.h
index da08aa53..14adace7 100644
--- a/externals/grill/py/source/pyext.h
+++ b/externals/grill/py/source/pyext.h
@@ -49,6 +49,7 @@ public:
protected:
virtual bool Init();
+ virtual bool Finalize();
virtual void Exit();
virtual bool CbMethodResort(int n,const t_symbol *s,int argc,const t_atom *argv);
diff --git a/externals/grill/py/source/pyprefix.h b/externals/grill/py/source/pyprefix.h
index 9be12e85..42befa60 100644
--- a/externals/grill/py/source/pyprefix.h
+++ b/externals/grill/py/source/pyprefix.h
@@ -2,7 +2,7 @@
py/pyext - python script object for PD and MaxMSP
-Copyright (c)2002-2005 Thomas Grill (gr@grrrr.org)
+Copyright (c)2002-2007 Thomas Grill (gr@grrrr.org)
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "license.txt," in this distribution.
@@ -39,5 +39,10 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#include <flcontainers.h>
#include <string>
+#ifdef PY_USE_INOFFICIAL
+extern "C" {
+#include <s_stuff.h>
+}
+#endif
#endif