Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13194
Modified Files: Tag: desiredata kernel.c m_pd.h Log Message: added class_addcreator2, class_new2
Index: m_pd.h =================================================================== RCS file: /cvsroot/pure-data/pd/src/m_pd.h,v retrieving revision 1.4.4.11.2.33.2.31 retrieving revision 1.4.4.11.2.33.2.32 diff -C2 -d -r1.4.4.11.2.33.2.31 -r1.4.4.11.2.33.2.32 *** m_pd.h 3 Jan 2007 19:45:24 -0000 1.4.4.11.2.33.2.31 --- m_pd.h 4 Jan 2007 17:15:22 -0000 1.4.4.11.2.33.2.32 *************** *** 483,490 ****
EXTERN t_class *class_find (t_symbol *s); ! EXTERN t_class *class_new(t_symbol *name, t_newmethod newmethod, t_method freemethod, size_t size, int flags, t_atomtypearg arg1, ...); ! EXTERN void class_addcreator(t_newmethod newmethod, t_symbol *sel, t_atomtypearg arg1, ...); ! EXTERN void class_addmethod(t_class *c, t_method fn, t_symbol *sel, t_atomtypearg arg1, ...); EXTERN void class_addmethod2(t_class *c, t_method fn, t_symbol *sel, const char *sig); EXTERN void class_addbang( t_class *c, t_method fn); --- 483,493 ----
EXTERN t_class *class_find (t_symbol *s); ! EXTERN t_class *class_new( t_symbol *name, t_newmethod newmethod, t_method freemethod, size_t size, int flags, t_atomtypearg arg1, ...); ! EXTERN t_class *class_new2(t_symbol *name, t_newmethod newmethod, ! t_method freemethod, size_t size, int flags, const char *sig); ! EXTERN void class_addcreator( t_newmethod newmethod, t_symbol *sel, t_atomtypearg arg1, ...); ! EXTERN void class_addcreator2(t_newmethod newmethod, t_symbol *sel, const char *sig); ! EXTERN void class_addmethod( t_class *c, t_method fn, t_symbol *sel, t_atomtypearg arg1, ...); EXTERN void class_addmethod2(t_class *c, t_method fn, t_symbol *sel, const char *sig); EXTERN void class_addbang( t_class *c, t_method fn);
Index: kernel.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/Attic/kernel.c,v retrieving revision 1.1.2.25 retrieving revision 1.1.2.26 diff -C2 -d -r1.1.2.25 -r1.1.2.26 *** kernel.c 3 Jan 2007 19:45:24 -0000 1.1.2.25 --- kernel.c 4 Jan 2007 17:15:22 -0000 1.1.2.26 *************** *** 1030,1054 **** }
! /* for now we assume that all "gobjs" are text unless explicitly ! overridden later by calling class_setbehavior(). I'm not sure ! how to deal with Pds that aren't gobjs; shouldn't there be a ! way to check that at run time? Perhaps the presence of a "newmethod" ! should be our cue, or perhaps the "tiny" flag. */ ! ! /* another matter. This routine does two unrelated things: it creates ! a Pd class, but also adds a "new" method to create an instance of it. ! These are combined for historical reasons and for brevity in writing ! objects. To avoid adding a "new" method send a null function pointer. ! To add additional ones, use class_addcreator below. Some "classes", like ! "select", are actually two classes of the same name, one for the single- ! argument form, one for the multiple one; see select_setup() to find out ! how this is handled. */
! t_class *class_new(t_symbol *s, t_newmethod newmethod, t_method freemethod, ! size_t size, int flags, t_atomtypearg type1, ...) { ! va_list ap; ! t_atomtype vec[MAXPDARG+1], *vp = vec; ! int count = 0; ! t_class *c; #ifdef QUALIFIED_NAME t_symbol *S=gensym(s->name); --- 1030,1044 ---- }
! t_symbol *qualified_name(t_symbol *s) { ! char namespacename[MAXPDSTRING]; ! sprintf(namespacename, "%s%s%s", pd_library_name, QUALIFIED_NAME, s->name); ! return gensym(namespacename); ! }
! /* Note that some classes such as "select", are actually two classes of the same name, ! one for the single-argument form, one for the multiple one; see select_setup() to ! find out how this is handled. */ ! t_class *class_new2(t_symbol *s, t_newmethod newmethod, t_method freemethod, ! size_t size, int flags, const char *sig) { #ifdef QUALIFIED_NAME t_symbol *S=gensym(s->name); *************** *** 1056,1106 **** int typeflag = flags & CLASS_TYPEMASK; if (!typeflag) typeflag = CLASS_PATCHABLE; - *vp = (t_atomtype)type1; - - va_start(ap, type1); - while (*vp) { - if (count == MAXPDARG) { - error("class %s: sorry: only %d creation args allowed", s->name, MAXPDARG); - break; - } - vp++; - count++; - *vp = (t_atomtype)va_arg(ap,int); - } - va_end(ap); - #ifdef QUALIFIED_NAME ! if (pd_library_name) { ! char namespacename[MAXPDSTRING]; ! sprintf(namespacename, "%s%s%s", pd_library_name, QUALIFIED_NAME, s->name); ! s=gensym(namespacename); ! } #endif - if (pd_objectmaker._class && newmethod) { /* add a "new" method by the name specified by the object */ ! class_addmethod(pd_objectmaker._class, (t_method)newmethod, s, vec[0], vec[1], vec[2], vec[3], vec[4], vec[5]); if (class_loadsym) { /* if we're loading an extern it might have been invoked by a longer file name; in this case, make this an admissible name too. */ ! char *loadstring = class_loadsym->name, ! l1 = strlen(s->name), l2 = strlen(loadstring); if (l2 > l1 && !strcmp(s->name, loadstring + (l2 - l1))) ! class_addmethod(pd_objectmaker._class, (t_method)newmethod, class_loadsym, ! vec[0], vec[1], vec[2], vec[3], vec[4], vec[5]); } } ! c = (t_class *)t_getbytes(sizeof(*c)); c->name = c->helpname = s; c->size = size; c->methods = (t_methodentry *)t_getbytes(0); c->nmethod = 0; ! c->freemethod = (t_method)freemethod; ! c->bangmethod = pd_defaultbang; c->pointermethod = pd_defaultpointer; ! c->floatmethod = pd_defaultfloat; ! c->symbolmethod = pd_defaultsymbol; ! c->listmethod = pd_defaultlist; ! c->anymethod = pd_defaultanything; c->firstin = ((flags & CLASS_NOINLET) == 0); c->firsttip = gensym("?"); --- 1046,1075 ---- int typeflag = flags & CLASS_TYPEMASK; if (!typeflag) typeflag = CLASS_PATCHABLE; #ifdef QUALIFIED_NAME ! if (pd_library_name) s = qualified_name(s); #endif if (pd_objectmaker._class && newmethod) { /* add a "new" method by the name specified by the object */ ! class_addmethod2(pd_objectmaker._class, (t_method)newmethod, s, sig); if (class_loadsym) { /* if we're loading an extern it might have been invoked by a longer file name; in this case, make this an admissible name too. */ ! char *loadstring = class_loadsym->name, l1 = strlen(s->name), l2 = strlen(loadstring); if (l2 > l1 && !strcmp(s->name, loadstring + (l2 - l1))) ! class_addmethod2(pd_objectmaker._class, (t_method)newmethod, class_loadsym, sig); } } ! t_class *c = (t_class *)t_getbytes(sizeof(*c)); c->name = c->helpname = s; c->size = size; c->methods = (t_methodentry *)t_getbytes(0); c->nmethod = 0; ! c->freemethod = (t_method)freemethod; ! c->bangmethod = pd_defaultbang; c->pointermethod = pd_defaultpointer; ! c->floatmethod = pd_defaultfloat; ! c->symbolmethod = pd_defaultsymbol; ! c->listmethod = pd_defaultlist; ! c->anymethod = pd_defaultanything; c->firstin = ((flags & CLASS_NOINLET) == 0); c->firsttip = gensym("?"); *************** *** 1116,1122 **** c->helpname = S; // like a class_addcreator ! if (pd_library_name && newmethod) { ! class_addmethod(pd_objectmaker._class, (t_method)newmethod, S, vec[0], vec[1], vec[2], vec[3], vec[4], vec[5]); ! } #endif hash_set(class_table, c->name, c); --- 1085,1090 ---- c->helpname = S; // like a class_addcreator ! if (pd_library_name && newmethod) ! class_addmethod2(pd_objectmaker._class, (t_method)newmethod, S, sig); #endif hash_set(class_table, c->name, c); *************** *** 1128,1156 **** can belong to, but this won't be used until the newmethod is actually called back (and the new method explicitly takes care of this.) */ ! void class_addcreator(t_newmethod newmethod, t_symbol *s, t_atomtypearg type1, ...) { ! va_list ap; ! t_atomtype vec[MAXPDARG+1], *vp = vec; ! int count = 0; ! *vp = (t_atomtype)type1; ! va_start(ap, type1); ! while (*vp) { ! if (count == MAXPDARG) { ! error("class %s: sorry: only %d creation args allowed", s->name, MAXPDARG); ! break; ! } ! vp++; ! count++; ! *vp = (t_atomtype)va_arg(ap,int); ! } ! va_end(ap); ! class_addmethod(pd_objectmaker._class, (t_method)newmethod, s, vec[0], vec[1], vec[2], vec[3], vec[4], vec[5]); ! #ifdef QUALIFIED_NAME ! if (pd_library_name) { ! char namespacename[MAXPDSTRING]; ! sprintf(namespacename, "%s%s%s", pd_library_name, QUALIFIED_NAME, s->name); ! s=gensym(namespacename); ! } ! class_addmethod(pd_objectmaker._class, (t_method)newmethod, s, vec[0], vec[1], vec[2], vec[3], vec[4], vec[5]); #endif hash_set(class_table,s,0); --- 1096,1104 ---- can belong to, but this won't be used until the newmethod is actually called back (and the new method explicitly takes care of this.) */ ! void class_addcreator2(t_newmethod newmethod, t_symbol *s, const char *sig) { ! class_addmethod2(pd_objectmaker._class, (t_method)newmethod, s, sig); #ifdef QUALIFIED_NAME ! if (pd_library_name) s = qualified_name(s); ! class_addmethod2(pd_objectmaker._class, (t_method)newmethod, s, sig); #endif hash_set(class_table,s,0); *************** *** 1170,1178 **** /* check for special cases. "Pointer" is missing here so that pd_objectmaker's pointer method can be typechecked differently. */ ! if (sel == &s_bang) {if (argtype) goto phooey; class_addbang(c, fn);} ! else if (sel == &s_float) {if (argtype!='f' || *fmt) goto phooey; class_doaddfloat(c,fn);} ! else if (sel == &s_symbol) {if (argtype!='s' || *fmt) goto phooey; class_addsymbol(c, fn);} ! else if (sel == &s_list) {if (argtype!='*') goto phooey; class_addlist(c, fn);} ! else if (sel == &s_anything) {if (argtype != A_GIMME) goto phooey; class_addanything(c, fn);} else { c->methods = (t_methodentry *)t_resizebytes(c->methods, --- 1118,1127 ---- /* check for special cases. "Pointer" is missing here so that pd_objectmaker's pointer method can be typechecked differently. */ ! /* is anyone actually using those five cases? */ ! if (sel==&s_bang) {if (argtype) goto phooey; class_addbang( c,fn);} ! else if (sel==&s_float) {if (argtype!='f'||*fmt) goto phooey; class_doaddfloat( c,fn);} ! else if (sel==&s_symbol) {if (argtype!='s'||*fmt) goto phooey; class_addsymbol( c,fn);} ! else if (sel==&s_list) {if (argtype!='*') goto phooey; class_addlist( c,fn);} ! else if (sel==&s_anything) {if (argtype!='*') goto phooey; class_addanything(c,fn);} else { c->methods = (t_methodentry *)t_resizebytes(c->methods, *************** *** 1202,1207 **** argtype = *fmt++; } ! if (argtype != A_NULL) ! error("%s_%s: only 5 arguments are typecheckable; use A_GIMME", c->name->name, sel->name); m->me_arg[nargs] = A_NULL; } --- 1151,1155 ---- argtype = *fmt++; } ! if (argtype) error("%s_%s: only 5 arguments are typecheckable; use A_GIMME aka '*'", c->name->name, sel->name); m->me_arg[nargs] = A_NULL; } *************** *** 1211,1229 **** }
void class_addmethod(t_class *c, t_method fn, t_symbol *sel, t_atomtypearg arg1, ...) { ! char fmt[42],*f=fmt; ! int t; ! va_list ap; ! va_start(ap,arg1); ! t=arg1; ! for(;;) { ! if (!t) break; if (t>A_CANT) {error("class_addmethod: ARRGH! t=%d",t); return;} *f++ = " fsp;,FS$@*!"[t]; t=(t_atomtype)va_arg(ap,int); } ! *f = 0; ! va_end(ap); ! class_addmethod2(c,fn,sel,fmt); }
--- 1159,1189 ---- }
+ t_class *class_new(t_symbol *s, t_newmethod newmethod, t_method freemethod, + size_t size, int flags, t_atomtypearg arg1, ...) { + char fmt[42],*f=fmt; va_list ap; va_start(ap,arg1); int t=arg1; + while(t) { + if (t>A_CANT) {error("class_new: ARRGH! t=%d",t); return 0;} + *f++ = " fsp;,FS$@*!"[t]; + t=(t_atomtype)va_arg(ap,int); + } + *f=0; va_end(ap); return class_new2(s,newmethod,freemethod,size,flags,fmt); + } + void class_addcreator(t_newmethod newmethod, t_symbol *s, t_atomtypearg arg1, ...) { + char fmt[42],*f=fmt; va_list ap; va_start(ap,arg1); int t=arg1; + while(t) { + if (t>A_CANT) {error("class_addcreator: ARRGH! t=%d",t); return;} + *f++ = " fsp;,FS$@*!"[t]; + t=(t_atomtype)va_arg(ap,int); + } + *f=0; va_end(ap); class_addcreator2(newmethod,s,fmt); + } void class_addmethod(t_class *c, t_method fn, t_symbol *sel, t_atomtypearg arg1, ...) { ! char fmt[42],*f=fmt; va_list ap; va_start(ap,arg1); int t=arg1; ! while(t) { if (t>A_CANT) {error("class_addmethod: ARRGH! t=%d",t); return;} *f++ = " fsp;,FS$@*!"[t]; t=(t_atomtype)va_arg(ap,int); } ! *f=0; va_end(ap); class_addmethod2(c,fn,sel,fmt); }