Update of /cvsroot/pure-data/externals/clr In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22039/clr
Modified Files: clr.cpp Removed Files: test-clr.pd Log Message: adapted to PD version 0.40 better handler flexibility and argument checking added Zmölnigs counter example
--- test-clr.pd DELETED ---
Index: clr.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/clr/clr.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** clr.cpp 9 Mar 2006 11:51:20 -0000 1.12 --- clr.cpp 9 Mar 2006 14:34:33 -0000 1.13 *************** *** 42,45 **** --- 42,48 ---- static MonoProperty *clr_prop_method;
+ static t_symbol *sym_object; + + struct AtomList { *************** *** 50,57 **** };
// temporary workspace items
! static MonoArray *clr_objarr_1,*clr_objarr_3; static MonoObject *clr_obj_int,*clr_obj_single,*clr_obj_symbol,*clr_obj_pointer,*clr_obj_atomlist; static int *clr_val_int; --- 53,100 ---- };
+ // transforms a pointer (like MonoObject *) into a 3 element-list + struct ObjectAtom + { + enum { size = 3,bitshift = 22 }; + + // 64-bit safe... + t_atom msg[size]; + + ObjectAtom() {} + + ObjectAtom(void *o) + { + size_t ptr = (size_t)o; + for(int i = 0; i < size; ++i) { + SETFLOAT(msg+i,(int)(ptr&((1<<bitshift)-1))); + ptr >>= bitshift; + } + } + + static bool check(int argc,const t_atom *argv) + { + if(argc != size) return false; + for(int i = 0; i < size; ++i) + if(argv[i].a_type != A_FLOAT) return false; + return true; + } + + static void *ptr(const t_atom *argv) + { + size_t ret = 0; + for(int i = size-1; i >= 0; --i) + ret = (ret<<bitshift)+(int)argv[i].a_w.w_float; + return (void *)ret; + } + + template<class T> static T ptr(const t_atom *argv) { return (T)ptr(argv); } + + operator t_atom *() { return msg; } + }; +
// temporary workspace items
! static MonoArray *clr_objarr_1,*clr_objarr_2,*clr_objarr_3; static MonoObject *clr_obj_int,*clr_obj_single,*clr_obj_symbol,*clr_obj_pointer,*clr_obj_atomlist; static int *clr_val_int; *************** *** 66,70 **** struct Delegate { ! enum Kind { k_bang,k_float,k_symbol,k_pointer,k_list,k_anything };
inline operator bool() const { return methodinfo != NULL; } --- 109,113 ---- struct Delegate { ! enum Kind { k_bang,k_float,k_symbol,k_pointer,k_list,k_anything,k_object };
inline operator bool() const { return methodinfo != NULL; } *************** *** 81,85 **** }
! inline MonoObject *operator()(MonoObject *obj,void *arg = NULL) const { gpointer args[2] = {obj,arg}; --- 124,128 ---- }
! inline MonoObject *invoke(MonoObject *obj,void *arg) const { gpointer args[2] = {obj,arg}; *************** *** 93,97 **** { mono_array_set(clr_objarr_1,void*,0,atom); ! return operator()(obj,clr_objarr_1); }
--- 136,145 ---- { mono_array_set(clr_objarr_1,void*,0,atom); ! return invoke(obj,clr_objarr_1); ! } ! ! inline MonoObject *operator()(MonoObject *obj) const ! { ! return invoke(obj,NULL); }
*************** *** 128,132 **** mono_array_set(clr_objarr_3,void*,1,clr_obj_symbol); mono_array_set(clr_objarr_3,void*,2,clr_obj_atomlist); ! return operator()(obj,clr_objarr_3); } }; --- 176,188 ---- mono_array_set(clr_objarr_3,void*,1,clr_obj_symbol); mono_array_set(clr_objarr_3,void*,2,clr_obj_atomlist); ! return invoke(obj,clr_objarr_3); ! } ! ! inline MonoObject *operator()(MonoObject *obj,int inlet,MonoObject *clrobj) const ! { ! *clr_val_int = inlet; ! mono_array_set(clr_objarr_2,void*,0,clr_obj_int); ! mono_array_set(clr_objarr_2,void*,1,clrobj); ! return invoke(obj,clr_objarr_2); } }; *************** *** 145,149 **** MonoClassField *obj_field; // ptr field in PureData.External t_symbol *name; ! Delegate method_bang,method_float,method_symbol,method_pointer,method_list,method_anything; ClrMethods *methods; // explicit method selectors }; --- 201,205 ---- MonoClassField *obj_field; // ptr field in PureData.External t_symbol *name; ! Delegate method_bang,method_float,method_symbol,method_pointer,method_list,method_anything,method_object; ClrMethods *methods; // explicit method selectors }; *************** *** 227,231 **** { assert(x && x->clr_clss); ! MonoObject *exc = x->clr_clss->method_symbol(x->mono_obj,argc,argv); if(exc) error_exc("Exception raised",x->clr_clss->name->s_name,exc); } --- 283,287 ---- { assert(x && x->clr_clss); ! MonoObject *exc = x->clr_clss->method_list(x->mono_obj,argc,argv); if(exc) error_exc("Exception raised",x->clr_clss->name->s_name,exc); } *************** *** 269,285 **** switch(d->kind) { case Delegate::k_bang: - assert(argc == 0); exc = (*d)(x->mono_obj); break; case Delegate::k_float: ! assert(argc == 1 && argv[0].a_type == A_FLOAT); exc = (*d)(x->mono_obj,argv[0].a_w.w_float); break; case Delegate::k_symbol: ! assert(argc == 1 && argv[0].a_type == A_SYMBOL); exc = (*d)(x->mono_obj,argv[0].a_w.w_symbol); break; case Delegate::k_pointer: ! assert(argc == 1 && argv[0].a_type == A_POINTER); exc = (*d)(x->mono_obj,argv[0].a_w.w_gpointer); break; --- 325,349 ---- switch(d->kind) { case Delegate::k_bang: exc = (*d)(x->mono_obj); break; case Delegate::k_float: ! if(argc == 0 || argv[0].a_type != A_FLOAT) { ! error("%s - %s handler: float argument expected",x->clr_clss->name->s_name,s->s_name); ! return; ! } exc = (*d)(x->mono_obj,argv[0].a_w.w_float); break; case Delegate::k_symbol: ! if(argc == 0 || argv[0].a_type != A_SYMBOL) { ! error("%s - %s handler: symbol argument expected",x->clr_clss->name->s_name,s->s_name); ! return; ! } exc = (*d)(x->mono_obj,argv[0].a_w.w_symbol); break; case Delegate::k_pointer: ! if(argc == 0 || argv[0].a_type != A_POINTER) { ! error("%s - %s handler: pointer argument expected",x->clr_clss->name->s_name,s->s_name); ! return; ! } exc = (*d)(x->mono_obj,argv[0].a_w.w_gpointer); break; *************** *** 290,293 **** --- 354,364 ---- exc = (*d)(x->mono_obj,inlet,s,argc,argv); break; + case Delegate::k_object: + if(s != sym_object || !ObjectAtom::check(argc,argv)) { + error("CLR - object handler: invalid arguments"); + return; + } + exc = (*d)(x->mono_obj,inlet,ObjectAtom::ptr<MonoObject *>(argv)); + break; default: assert(false); *************** *** 352,360 **** }
- static void PD_AddMethodSelector(int inlet,t_symbol *sym,MonoObject *method) - { - PD_AddMethodHandler(inlet,sym,method,Delegate::k_anything); - } - static void PD_AddMethodBang(int inlet,MonoObject *method) { --- 423,426 ---- *************** *** 417,420 **** --- 483,521 ---- }
+ static void PD_AddMethodSelBang(int inlet,t_symbol *sym,MonoObject *method) + { + PD_AddMethodHandler(inlet,sym,method,Delegate::k_bang); + } + + static void PD_AddMethodSelFloat(int inlet,t_symbol *sym,MonoObject *method) + { + PD_AddMethodHandler(inlet,sym,method,Delegate::k_float); + } + + static void PD_AddMethodSelSymbol(int inlet,t_symbol *sym,MonoObject *method) + { + PD_AddMethodHandler(inlet,sym,method,Delegate::k_symbol); + } + + static void PD_AddMethodSelPointer(int inlet,t_symbol *sym,MonoObject *method) + { + PD_AddMethodHandler(inlet,sym,method,Delegate::k_pointer); + } + + static void PD_AddMethodSelList(int inlet,t_symbol *sym,MonoObject *method) + { + PD_AddMethodHandler(inlet,sym,method,Delegate::k_list); + } + + static void PD_AddMethodSelAnything(int inlet,t_symbol *sym,MonoObject *method) + { + PD_AddMethodHandler(inlet,sym,method,Delegate::k_anything); + } + + static void PD_AddMethodObject(int inlet,MonoObject *method) + { + PD_AddMethodHandler(inlet,sym_object,method,Delegate::k_object); + } +
static void PD_AddInletAlias(t_clr *obj,t_symbol *sel,t_symbol *to_sel) *************** *** 539,542 **** --- 640,654 ---- }
+ + static void PD_OutletObject(t_clr *obj,int n,MonoObject *o) + { + assert(obj); + assert(obj->outlets); + assert(n >= 0 && n < (int)obj->outlets->size()); + ObjectAtom oa(o); + outlet_anything((*obj->outlets)[n],sym_object,oa.size,oa); + } + + static void PD_SendAtom(t_symbol *dst,t_atom a) { *************** *** 558,561 **** --- 670,684 ---- }
+ static void PD_SendObject(t_symbol *dst,MonoObject *o) + { + void *cl = dst->s_thing; + // assert(mono_object_get_class(&l->obj) == clr_atom); + if(cl) { + ObjectAtom oa(o); + pd_typedmess((t_class **)cl,sym_object,oa.size,oa); + } + } + + void *clr_new(t_symbol *classname, int argc, t_atom *argv) { *************** *** 624,628 **** }
! static int classloader(char *dirname, char *classname) { t_clr_class *clr_class = NULL; --- 747,751 ---- }
! static int classloader(char *dirname, char *classname, char *altname) { t_clr_class *clr_class = NULL; *************** *** 633,642 **** int flags = CLASS_DEFAULT;
char dirbuf[MAXPDSTRING],*nameptr; // search for classname.dll in the PD path int fd; ! if ((fd = open_via_path(dirname, classname, "." DLLEXT, dirbuf, &nameptr, MAXPDSTRING, 1)) < 0) ! // not found ! goto bailout;
// found --- 756,767 ---- int flags = CLASS_DEFAULT;
+ char *realname; char dirbuf[MAXPDSTRING],*nameptr; // search for classname.dll in the PD path int fd; ! if ((fd = open_via_path(dirname, realname = classname, "." DLLEXT, dirbuf, &nameptr, MAXPDSTRING, 1)) < 0) ! if (!altname || (fd = open_via_path(dirname, realname = altname, "." DLLEXT, dirbuf, &nameptr, MAXPDSTRING, 1)) < 0) ! // not found ! goto bailout;
// found *************** *** 649,653 **** // try to load assembly strcat(dirbuf,"/"); ! strcat(dirbuf,classname); strcat(dirbuf,"." DLLEXT);
--- 774,778 ---- // try to load assembly strcat(dirbuf,"/"); ! strcat(dirbuf,realname); strcat(dirbuf,"." DLLEXT);
*************** *** 663,667 **** // try to find class // "" means no namespace ! clr_class->mono_class = mono_class_from_name(image,"",classname); if(!clr_class->mono_class) { error("Can't find %s class in %s\n",classname,mono_image_get_filename(image)); --- 788,792 ---- // try to find class // "" means no namespace ! clr_class->mono_class = mono_class_from_name(image,"",realname); if(!clr_class->mono_class) { error("Can't find %s class in %s\n",classname,mono_image_get_filename(image)); *************** *** 780,784 **** // try to find PureData.dll in the PD path char dirbuf[MAXPDSTRING],*nameptr; ! // search for classname.dll in the PD path int fd; if ((fd = open_via_path("",CORELIB,"." DLLEXT,dirbuf,&nameptr,MAXPDSTRING,1)) >= 0) { --- 905,909 ---- // try to find PureData.dll in the PD path char dirbuf[MAXPDSTRING],*nameptr; ! // search in the PD path int fd; if ((fd = open_via_path("",CORELIB,"." DLLEXT,dirbuf,&nameptr,MAXPDSTRING,1)) >= 0) { *************** *** 808,818 **** mono_add_internal_call("PureData.External::PostVerbose(int,string)",(const void *)PD_PostVerbose);
! mono_add_internal_call("PureData.External::AddMethod(int,PureData.External/MethodBang)", (const void *)PD_AddMethodBang); mono_add_internal_call("PureData.External::AddMethod(int,PureData.External/MethodFloat)", (const void *)PD_AddMethodFloat); mono_add_internal_call("PureData.External::AddMethod(int,PureData.External/MethodSymbol)", (const void *)PD_AddMethodSymbol); mono_add_internal_call("PureData.External::AddMethod(int,PureData.External/MethodPointer)", (const void *)PD_AddMethodPointer); mono_add_internal_call("PureData.External::AddMethod(int,PureData.External/MethodList)", (const void *)PD_AddMethodList); - mono_add_internal_call("PureData.External::AddMethod(int,PureData.Symbol,PureData.External/MethodAnything)", (const void *)PD_AddMethodSelector); mono_add_internal_call("PureData.External::AddMethod(int,PureData.External/MethodAnything)", (const void *)PD_AddMethodAnything);
mono_add_internal_call("PureData.Internal::AddInlet(void*,PureData.Symbol,PureData.Symbol)", (const void *)PD_AddInletAlias); --- 933,949 ---- mono_add_internal_call("PureData.External::PostVerbose(int,string)",(const void *)PD_PostVerbose);
! mono_add_internal_call("PureData.External::AddMethod(int,PureData.External/Method)", (const void *)PD_AddMethodBang); mono_add_internal_call("PureData.External::AddMethod(int,PureData.External/MethodFloat)", (const void *)PD_AddMethodFloat); mono_add_internal_call("PureData.External::AddMethod(int,PureData.External/MethodSymbol)", (const void *)PD_AddMethodSymbol); mono_add_internal_call("PureData.External::AddMethod(int,PureData.External/MethodPointer)", (const void *)PD_AddMethodPointer); mono_add_internal_call("PureData.External::AddMethod(int,PureData.External/MethodList)", (const void *)PD_AddMethodList); mono_add_internal_call("PureData.External::AddMethod(int,PureData.External/MethodAnything)", (const void *)PD_AddMethodAnything); + mono_add_internal_call("PureData.External::AddMethod(int,PureData.Symbol,PureData.External/Method)", (const void *)PD_AddMethodSelBang); + mono_add_internal_call("PureData.External::AddMethod(int,PureData.Symbol,PureData.External/MethodFloat)", (const void *)PD_AddMethodSelFloat); + mono_add_internal_call("PureData.External::AddMethod(int,PureData.Symbol,PureData.External/MethodSymbol)", (const void *)PD_AddMethodSelSymbol); + mono_add_internal_call("PureData.External::AddMethod(int,PureData.Symbol,PureData.External/MethodPointer)", (const void *)PD_AddMethodSelPointer); + mono_add_internal_call("PureData.External::AddMethod(int,PureData.Symbol,PureData.External/MethodList)", (const void *)PD_AddMethodSelList); + mono_add_internal_call("PureData.External::AddMethod(int,PureData.Symbol,PureData.External/MethodAnything)", (const void *)PD_AddMethodSelAnything); + mono_add_internal_call("PureData.External::AddMethod(int,PureData.External/MethodObject)", (const void *)PD_AddMethodObject);
mono_add_internal_call("PureData.Internal::AddInlet(void*,PureData.Symbol,PureData.Symbol)", (const void *)PD_AddInletAlias); *************** *** 832,835 **** --- 963,967 ---- mono_add_internal_call("PureData.Internal::Outlet(void*,int,PureData.Symbol,PureData.AtomList)", (const void *)PD_OutletAnything); mono_add_internal_call("PureData.Internal::Outlet(void*,int,PureData.Symbol,PureData.Atom[])", (const void *)PD_OutletAnything2); + mono_add_internal_call("PureData.Internal::OutletEx(void*,int,object)", (const void *)PD_OutletObject);
// mono_add_internal_call("PureData.Internal::Bind(void*,PureData.Symbol)", (const void *)PD_Bind); *************** *** 839,842 **** --- 971,975 ---- mono_add_internal_call("PureData.External::Send(PureData.Symbol,PureData.Symbol,PureData.AtomList)", (const void *)PD_SendAnything); mono_add_internal_call("PureData.External::Send(PureData.Symbol,PureData.Symbol,PureData.Atom[])", (const void *)PD_SendAnything2); + mono_add_internal_call("PureData.External::SendEx(PureData.Symbol,object)", (const void *)PD_SendObject);
// load important classes *************** *** 867,870 **** --- 1000,1004 ---- // static objects to avoid allocation at method call time clr_objarr_1 = mono_array_new(monodomain,mono_get_object_class(),1); + clr_objarr_2 = mono_array_new(monodomain,mono_get_object_class(),2); clr_objarr_3 = mono_array_new(monodomain,mono_get_object_class(),3); clr_obj_int = mono_object_new(monodomain,mono_get_int32_class()); *************** *** 884,889 **** class_addanything(proxy_class,clr_method_proxy);
// install loader hook ! sys_loader(classloader);
// ready! --- 1018,1026 ---- class_addanything(proxy_class,clr_method_proxy);
+ // symbol for Mono object handling + sym_object = gensym("clr-object"); + // install loader hook ! sys_register_loader(classloader);
// ready!