From 4eb1464e5439332693a92ab76776b06d9b0c8700 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Mon, 26 Sep 2005 13:59:59 +0000 Subject: __str__ method for pyext, to enable print self calls enable symbol binding for all callables (not only functions and methods) enable optimization of Python code in reease build _isthreaded is now a data member instead of a method compiler flag to exclude DSP objects some cleanups pyext: fix for missing __init__ attribute some optimizations and py reload fix some ASSERTs for explicitly created pyext classes (should be runtime checks i guess) more safety for calls where association python-pd has already been removed fixed typos let _inlets and _outlets default to 0 svn path=/trunk/; revision=3637 --- externals/grill/py/source/pybase.cpp | 41 ++++------- externals/grill/py/source/pybase.h | 20 +++++- externals/grill/py/source/pybuffer.h | 128 +++++++++++++++++------------------ externals/grill/py/source/pyext.cpp | 2 + externals/grill/py/source/pysymbol.h | 2 +- 5 files changed, 98 insertions(+), 95 deletions(-) (limited to 'externals/grill/py/source') diff --git a/externals/grill/py/source/pybase.cpp b/externals/grill/py/source/pybase.cpp index 09fd8687..e68d9929 100644 --- a/externals/grill/py/source/pybase.cpp +++ b/externals/grill/py/source/pybase.cpp @@ -75,6 +75,7 @@ PyObject *pybase::builtins_obj = NULL; PyObject *pybase::builtins_dict = NULL; const t_symbol *pybase::sym_fint = NULL; +const t_symbol *pybase::sym_response = NULL; // ----------------------------------------------------------------------------------------------------------- @@ -83,8 +84,8 @@ void initsymbol(); void initsamplebuffer(); void pybase::lib_setup() -{ - post(""); +{ + post(""); post("------------------------------------------------"); post("py/pyext %s - python script objects",PY__VERSION); post("(C)2002-2005 Thomas Grill - http://grrrr.org/ext"); @@ -98,6 +99,16 @@ void pybase::lib_setup() // ------------------------------------------------------------- + sym_response = flext::MakeSymbol("response"); + +#if FLEXT_SYS == FLEXT_SYS_PD + sym_fint = sym_float; +#else + sym_fint = sym_int; +#endif + + // ------------------------------------------------------------- + Py_Initialize(); #ifdef FLEXT_DEBUG @@ -163,12 +174,6 @@ void pybase::lib_setup() initsamplebuffer(); PyModule_AddObject(module_obj,"Buffer",(PyObject *)&pySamplebuffer_Type); -#if FLEXT_SYS == FLEXT_SYS_PD - sym_fint = sym_float; -#else - sym_fint = sym_int; -#endif - // ------------------------------------------------------------- FLEXT_SETUP(pyobj); @@ -548,17 +553,6 @@ bool pybase::OutObject(flext_base *ext,int o,PyObject *obj) return false; } -static const t_symbol *sym_response = flext::MakeSymbol("response"); - -void pybase::Respond(bool b) -{ - if(respond) { - t_atom a; - SetBool(a,b); - DumpOut(sym_response,1,&a); - } -} - void pybase::Reload() { PyThreadState *state = PyLock(); @@ -725,15 +719,6 @@ void pybase::thrworker(thr_params *p) --th->thrcount; // \todo this should be atomic } -bool pybase::qucall(PyObject *fun,PyObject *args) -{ - FifoEl *el = qufifo.New(); - el->Set(this,fun,args); - qufifo.Put(el); - qucond.Signal(); - return true; -} - void pybase::quworker(thr_params *) { FifoEl *el; diff --git a/externals/grill/py/source/pybase.h b/externals/grill/py/source/pybase.h index 49eccbbc..59a1d062 100644 --- a/externals/grill/py/source/pybase.h +++ b/externals/grill/py/source/pybase.h @@ -81,7 +81,15 @@ protected: virtual void Unload() = 0; void OpenEditor(); - void Respond(bool b); + + void Respond(bool b) + { + if(respond) { + t_atom a; + SetBool(a,b); + DumpOut(sym_response,1,&a); + } + } void Report() { while(PyErr_Occurred()) PyErr_Print(); } @@ -158,7 +166,14 @@ protected: #ifdef FLEXT_THREADS static void thrworker(thr_params *data); - bool qucall(PyObject *fun,PyObject *args); + bool qucall(PyObject *fun,PyObject *args) + { + FifoEl *el = qufifo.New(); + el->Set(this,fun,args); + qufifo.Put(el); + qucond.Signal(); + return true; + } static void quworker(thr_params *); void erasethreads(); @@ -169,6 +184,7 @@ protected: #endif static const t_symbol *sym_fint; // float or int symbol, depending on native number message type + static const t_symbol *sym_response; static const t_symbol *getone(t_atom &at,PyObject *arg); static const t_symbol *getlist(t_atom *lst,PyObject *seq,int cnt,int offs = 0); diff --git a/externals/grill/py/source/pybuffer.h b/externals/grill/py/source/pybuffer.h index 1d59dd95..3889e563 100644 --- a/externals/grill/py/source/pybuffer.h +++ b/externals/grill/py/source/pybuffer.h @@ -1,52 +1,52 @@ -/* - -py/pyext - python script object for PD and Max/MSP - -Copyright (c)2002-2005 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. - -*/ - -#ifndef __PYBUFFER_H -#define __PYBUFFER_H - -#include - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 500) -#error You need at least flext version 0.5.0 -#endif - -#if FLEXT_OS == FLEXT_OS_MAC -#include -#else -#include -#endif - - -#ifdef _MSC_VER - #ifdef PY_EXPORTS - #define PY_EXPORT __declspec(dllexport) - #else - #define PY_EXPORT __declspec(dllimport) - #endif -#else - #define PY_EXPORT -#endif - -typedef struct { - PyObject_HEAD - /* Type-specific fields go here. */ - const t_symbol *sym; - flext::buffer *buf; - flext::buffer::lock_t lock; - bool dirty; -} pySamplebuffer; - -PY_EXPORT extern PyTypeObject pySamplebuffer_Type; - +/* + +py/pyext - python script object for PD and Max/MSP + +Copyright (c)2002-2005 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. + +*/ + +#ifndef __PYBUFFER_H +#define __PYBUFFER_H + +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 500) +#error You need at least flext version 0.5.0 +#endif + +#if FLEXT_OS == FLEXT_OS_MAC +#include +#else +#include +#endif + + +#ifdef _MSC_VER + #ifdef PY_EXPORTS + #define PY_EXPORT __declspec(dllexport) + #else + #define PY_EXPORT __declspec(dllimport) + #endif +#else + #define PY_EXPORT +#endif + +typedef struct { + PyObject_HEAD + /* Type-specific fields go here. */ + const t_symbol *sym; + flext::buffer *buf; + flext::buffer::lock_t lock; + bool dirty; +} pySamplebuffer; + +PY_EXPORT extern PyTypeObject pySamplebuffer_Type; + #define pySamplebuffer_Check(op) PyObject_TypeCheck(op, &pySamplebuffer_Type) -#define pySamplebuffer_CheckExact(op) ((op)->ob_type == &PySamplebuffer_Type) +#define pySamplebuffer_CheckExact(op) ((op)->ob_type == &pySamplebuffer_Type) PY_EXPORT PyObject *pySamplebuffer_FromSymbol(const t_symbol *sym); @@ -61,19 +61,19 @@ inline PyObject *pySamplebuffer_FromString(PyObject *str) return pySamplebuffer_FromString(PyString_AsString(str)); } -inline const t_symbol *pySamplebuffer_AS_SYMBOL(PyObject *op) -{ - return ((pySamplebuffer *)op)->sym; -} - -inline const t_symbol *pySamplebuffer_AsSymbol(PyObject *op) -{ - return pySamplebuffer_Check(op)?pySamplebuffer_AS_SYMBOL(op):NULL; -} - -inline const char *pySamplebuffer_AS_STRING(PyObject *op) -{ - return flext::GetString(pySamplebuffer_AS_SYMBOL(op)); -} - -#endif +inline const t_symbol *pySamplebuffer_AS_SYMBOL(PyObject *op) +{ + return ((pySamplebuffer *)op)->sym; +} + +inline const t_symbol *pySamplebuffer_AsSymbol(PyObject *op) +{ + return pySamplebuffer_Check(op)?pySamplebuffer_AS_SYMBOL(op):NULL; +} + +inline const char *pySamplebuffer_AS_STRING(PyObject *op) +{ + return flext::GetString(pySamplebuffer_AS_SYMBOL(op)); +} + +#endif diff --git a/externals/grill/py/source/pyext.cpp b/externals/grill/py/source/pyext.cpp index 633d4007..91be31e0 100644 --- a/externals/grill/py/source/pyext.cpp +++ b/externals/grill/py/source/pyext.cpp @@ -259,6 +259,8 @@ bool pyext::DoInit() } Py_DECREF(init); } + // __init__ has not been found - don't care + PyErr_Clear(); Py_DECREF(pargs); return ok; diff --git a/externals/grill/py/source/pysymbol.h b/externals/grill/py/source/pysymbol.h index e711f424..42f6765c 100644 --- a/externals/grill/py/source/pysymbol.h +++ b/externals/grill/py/source/pysymbol.h @@ -51,7 +51,7 @@ PY_EXPORT extern pySymbol *pySymbol_int; #define pySymbol_Check(op) PyObject_TypeCheck(op, &pySymbol_Type) -#define pySymbol_CheckExact(op) ((op)->ob_type == &PySymbol_Type) +#define pySymbol_CheckExact(op) ((op)->ob_type == &pySymbol_Type) PY_EXPORT PyObject *pySymbol_FromSymbol(const t_symbol *sym); -- cgit v1.2.1