From 0ed7a8b68dd73e2b0473b8127aeca99f3bac9061 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Wed, 1 Apr 2009 21:13:09 +0000 Subject: cleaned up grill externals - replaced with svn:externals to svn.grrrr.org/ext/trunk/ svn path=/trunk/; revision=10951 --- externals/grill/py/source/register.cpp | 153 --------------------------------- 1 file changed, 153 deletions(-) delete mode 100644 externals/grill/py/source/register.cpp (limited to 'externals/grill/py/source/register.cpp') diff --git a/externals/grill/py/source/register.cpp b/externals/grill/py/source/register.cpp deleted file mode 100644 index 0f8684b6..00000000 --- a/externals/grill/py/source/register.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* -py/pyext - python external object for PD and MaxMSP - -Copyright (c)2002-2008 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. - -$LastChangedRevision: 26 $ -$LastChangedDate: 2008-01-03 17:20:03 +0100 (Thu, 03 Jan 2008) $ -$LastChangedBy: thomas $ -*/ - -#include "pybase.h" - -#if 1 - -PyObject *pybase::GetRegistry(const char *regnm) -{ - if(module) { - FLEXT_ASSERT(dict); // module must have a valid dict - - // add this to module registry - PyObject *reg = PyDict_GetItemString(dict,(char *)regnm); // borrowed!!! - if(reg) - FLEXT_ASSERT(PyDict_Check(reg)); - else { - // make a new empty registry - reg = PyDict_New(); - PyDict_SetItemString(dict,(char *)regnm,reg); - } - return reg; - } - else - return NULL; -} - -void pybase::SetRegistry(const char *regnm,PyObject *reg) -{ - if(module) { - FLEXT_ASSERT(dict); // module must have a valid dict - FLEXT_ASSERT(reg && PyDict_Check(reg)); - PyDict_SetItemString(dict,(char *)regnm,reg); - } -} - -void pybase::Register(PyObject *reg) -{ - if(!module) return; - FLEXT_ASSERT(reg && PyDict_Check(reg)); - - // add this to module registry - Py_INCREF(Py_None); - PyObject *key = PyLong_FromUnsignedLong((size_t)this); - PyDict_SetItem(reg,key,Py_None); -} - -void pybase::Unregister(PyObject *reg) -{ - if(!module) return; - FLEXT_ASSERT(reg && PyDict_Check(reg)); - - // remove this from module registry - PyObject *key = PyLong_FromUnsignedLong((size_t)this); - PyObject *item = PyDict_GetItem(reg,key); - if(!item) - post("py/pyext - Internal error: object not found in registry"); - else - PyDict_DelItem(reg,key); -} - -/* -void pybase::RegLoad(PyObject *reg) -{ - -} - -void pybase::RegUnload(PyObject *reg) -{ -} -*/ - -#else - -void pybase::Register(const char *regnm) -{ - if(module) { - // add this to module registry - - PyObject *reg = PyDict_GetItemString(dict,(char *)regnm); // borrowed!!! - PyObject *add = Py_BuildValue("[i]",(long)this); - if(!reg || !PyList_Check(reg)) { - if(PyDict_SetItemString(dict,(char *)regnm,add)) { - post("py/pyext - Could not set registry"); - } - } - else { - PySequence_InPlaceConcat(reg,add); - } - } -} - -void pybase::Unregister(const char *regnm) -{ - if(module) { - // remove this from module registry - - PyObject *reg = PyDict_GetItemString(dict,(char *)regnm); // borrowed!!! - PyObject *add = Py_BuildValue("i",(int)this); - if(!reg || !PySequence_Check(reg)) - post("py/pyext - Internal error: Registry not found!?"); - else { - int ix = PySequence_Index(reg,add); - if(ix < 0) { - post("py/pyext - Internal error: object not found in registry?!"); - } - else { - PySequence_DelItem(reg,ix); - } - } - Py_DECREF(add); - } -} - -void pybase::Reregister(const char *regnm) -{ - if(module) { - // remove this from module registry - - PyObject *reg = PyDict_GetItemString(dict,(char *)regnm); // borrowed!!! - - if(!reg || !PySequence_Check(reg)) - post("py/pyext - Internal error: Registry not found!?"); - else { - int cnt = PySequence_Size(reg); - for(int i = 0; i < cnt; ++i) { - PyObject *it = PySequence_GetItem(reg,i); // new reference - if(!it || !PyInt_Check(it)) { - post("py/pyext - Internal error: Corrupt registry?!"); - } - else { - pybase *th = (pybase *)PyInt_AsLong(it); - th->module = module; - th->dict = dict; - th->Reload(); - } - - Py_XDECREF(it); - } - } - } -} - -#endif -- cgit v1.2.1