diff options
Diffstat (limited to 'externals/grill/py')
-rw-r--r-- | externals/grill/py/build/config-lnx.def | 5 | ||||
-rw-r--r-- | externals/grill/py/build/config-mac.def | 5 | ||||
-rw-r--r-- | externals/grill/py/build/config-win.def | 5 | ||||
-rw-r--r-- | externals/grill/py/build/gnumake-lnx-gcc.inc | 4 | ||||
-rw-r--r-- | externals/grill/py/build/gnumake-mac-gcc.inc | 6 | ||||
-rw-r--r-- | externals/grill/py/build/gnumake-win-cygwin.inc | 6 | ||||
-rw-r--r-- | externals/grill/py/build/nmake-win-msvc.inc | 4 | ||||
-rw-r--r-- | externals/grill/py/py.vcproj | 12 | ||||
-rw-r--r-- | externals/grill/py/readme.txt | 3 | ||||
-rw-r--r-- | externals/grill/py/source/main.h | 2 | ||||
-rw-r--r-- | externals/grill/py/source/modmeth.cpp | 32 | ||||
-rw-r--r-- | externals/grill/py/source/py.cpp | 2 | ||||
-rw-r--r-- | externals/grill/py/source/pybase.cpp | 11 | ||||
-rw-r--r-- | externals/grill/py/source/pybase.h | 5 | ||||
-rw-r--r-- | externals/grill/py/source/pybuffer.cpp | 17 | ||||
-rw-r--r-- | externals/grill/py/source/pyext.cpp | 28 | ||||
-rw-r--r-- | externals/grill/py/source/pyext.h | 1 | ||||
-rw-r--r-- | externals/grill/py/source/pyprefix.h | 7 |
18 files changed, 136 insertions, 19 deletions
diff --git a/externals/grill/py/build/config-lnx.def b/externals/grill/py/build/config-lnx.def index 10e518f5..86477fcc 100644 --- a/externals/grill/py/build/config-lnx.def +++ b/externals/grill/py/build/config-lnx.def @@ -11,4 +11,7 @@ PY_NUMPY=1 # PY_NUMERIC=1 # use thread-safe GIL functionality (do this for python version >= 2.3!) -PY_USE_GIL=1
\ No newline at end of file +PY_USE_GIL=1 + +# use inofficial (pure data) functionality +# PY_USE_INOFFICIAL=1 diff --git a/externals/grill/py/build/config-mac.def b/externals/grill/py/build/config-mac.def index 752ee335..43f31fa6 100644 --- a/externals/grill/py/build/config-mac.def +++ b/externals/grill/py/build/config-mac.def @@ -5,4 +5,7 @@ PY_NUMPY=1 # PY_NUMERIC=1 # use thread-safe GIL functionality (do this for python version >= 2.3!) -PY_USE_GIL=1
\ No newline at end of file +PY_USE_GIL=1 + +# use inofficial (pure data) functionality +# PY_USE_INOFFICIAL=1 diff --git a/externals/grill/py/build/config-win.def b/externals/grill/py/build/config-win.def index 98ab5552..9c81bf35 100644 --- a/externals/grill/py/build/config-win.def +++ b/externals/grill/py/build/config-win.def @@ -11,4 +11,7 @@ PY_NUMPY=1 # PY_NUMERIC=1 # use thread-safe GIL functionality (do this for python version >= 2.3!) -PY_USE_GIL=1
\ No newline at end of file +PY_USE_GIL=1 + +# use inofficial (pure data) functionality +# PY_USE_INOFFICIAL=1 diff --git a/externals/grill/py/build/gnumake-lnx-gcc.inc b/externals/grill/py/build/gnumake-lnx-gcc.inc index 2babf197..7bbde1f0 100644 --- a/externals/grill/py/build/gnumake-lnx-gcc.inc +++ b/externals/grill/py/build/gnumake-lnx-gcc.inc @@ -15,3 +15,7 @@ endif ifdef PY_USE_GIL DEFS += -DPY_USE_GIL endif + +ifdef PY_USE_INOFFICIAL +DEFS += -DPY_USE_INOFFICIAL +endif diff --git a/externals/grill/py/build/gnumake-mac-gcc.inc b/externals/grill/py/build/gnumake-mac-gcc.inc index 8f8591af..775a8762 100644 --- a/externals/grill/py/build/gnumake-mac-gcc.inc +++ b/externals/grill/py/build/gnumake-mac-gcc.inc @@ -14,4 +14,8 @@ endif ifdef PY_USE_GIL DEFS += -DPY_USE_GIL -endif
\ No newline at end of file +endif + +ifdef PY_USE_INOFFICIAL +DEFS += -DPY_USE_INOFFICIAL +endif diff --git a/externals/grill/py/build/gnumake-win-cygwin.inc b/externals/grill/py/build/gnumake-win-cygwin.inc index d9487833..a64fd9e1 100644 --- a/externals/grill/py/build/gnumake-win-cygwin.inc +++ b/externals/grill/py/build/gnumake-win-cygwin.inc @@ -15,4 +15,8 @@ endif ifdef PY_USE_GIL DEFS += -DPY_USE_GIL -endif
\ No newline at end of file +endif + +ifdef PY_USE_INOFFICIAL +DEFS += -DPY_USE_INOFFICIAL +endif diff --git a/externals/grill/py/build/nmake-win-msvc.inc b/externals/grill/py/build/nmake-win-msvc.inc index a23e03ca..7cf0d04d 100644 --- a/externals/grill/py/build/nmake-win-msvc.inc +++ b/externals/grill/py/build/nmake-win-msvc.inc @@ -17,3 +17,7 @@ DEFS = $(DEFS) /DPY_NUMERIC !ifdef PY_USE_GIL DEFS = $(DEFS) /DPY_USE_GIL !endif + +!ifdef PY_USE_INOFFICIAL +DEFS = $(DEFS) /DPY_USE_INOFFICIAL +!endif diff --git a/externals/grill/py/py.vcproj b/externals/grill/py/py.vcproj index 0a42243a..86f45387 100644 --- a/externals/grill/py/py.vcproj +++ b/externals/grill/py/py.vcproj @@ -22,7 +22,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="c:\programme\audio\pd\src;..\flext\source;C:\Programme\prog\Python24\include" - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PY_EXPORTS;FLEXT_SYS=2" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PY_EXPORTS;FLEXT_SYS=2;PY_USE_GIL;PY_USE_INOFFICIAL" BasicRuntimeChecks="3" RuntimeLibrary="5" RuntimeTypeInfo="TRUE" @@ -85,8 +85,8 @@ <Tool Name="VCCLCompilerTool" Optimization="0" - AdditionalIncludeDirectories="C:\data\prog\packs\pthreads\include;"c:\data\pd\pd-cvs\src";..\flext\source;C:\Programme\prog\Python24\include;"C:\Programme\prog\Python24\Lib\site-packages\numpy\core\include"" - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PY_EXPORTS;FLEXT_SYS=2;FLEXT_THREADS;PY_NUMPY;FLEXT_USECMEM;PY_USE_GIL" + AdditionalIncludeDirectories="$(prereq)\pthreads\include;$(pdmax)\pd\src;..\flext\source;C:\Python24\include;"C:\Python24\Lib\site-packages\numpy\core\include"" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PY_EXPORTS;FLEXT_SYS=2;FLEXT_THREADS;PY_NUMPY;FLEXT_USECMEM;xPY_USE_GIL;PY_USE_INOFFICIAL" BasicRuntimeChecks="3" RuntimeLibrary="1" RuntimeTypeInfo="TRUE" @@ -105,7 +105,7 @@ OutputFile="$(outdir)/py.dll" LinkIncremental="1" SuppressStartupBanner="TRUE" - AdditionalLibraryDirectories=""C:\data\prog\packs\Python-2.4\PCbuild";C:\data\prog\packs\pthreads\lib;"c:\data\pd\pd-cvs\bin"" + AdditionalLibraryDirectories="$(prereq)\python-2.4.4\pcbuild;$(prereq)\pthreads\lib;$(pdmax)\pd\bin" GenerateDebugInformation="TRUE" ProgramDatabaseFile="$(outdir)/py.pdb" SubSystem="2" @@ -1249,10 +1249,6 @@ BrowseInformation="1"/> </FileConfiguration> </File> - </Filter> - <Filter - Name="meth" - Filter=""> <File RelativePath=".\source\pymeth.cpp"> </File> diff --git a/externals/grill/py/readme.txt b/externals/grill/py/readme.txt index c10b2b6a..cd0b66cb 100644 --- a/externals/grill/py/readme.txt +++ b/externals/grill/py/readme.txt @@ -122,6 +122,9 @@ Version history: - ADD: enable usage of module packages (with module/__init__.py[co]) - ADD: make use of the PyGILState_*() functions - ADD: always run the Python interpreter in the background (to keep alive Python threads) +- ADD: added PY_USE_INOFFICIAL to enable usage of s_stuff.h PD header, to have access to search and help paths +- ADD: pyext: _init method is now called after __init__ (after inlets/outlets have been created) +- FIX: buffer protocol adapted to Python 2.5 0.2.0: - ADD: handling of Python threads 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 |