Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14768/src
Modified Files: Tag: devel_0_39 m_class.c m_pd.h s_loader.c s_main.c s_stuff.h Log Message: changed loader functionality according to Miller's 0.40 version encoded naming now supported
Index: s_loader.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_loader.c,v retrieving revision 1.4.4.5.2.6 retrieving revision 1.4.4.5.2.7 diff -C2 -d -r1.4.4.5.2.6 -r1.4.4.5.2.7 *** s_loader.c 6 Mar 2006 14:51:00 -0000 1.4.4.5.2.6 --- s_loader.c 9 Mar 2006 14:22:51 -0000 1.4.4.5.2.7 *************** *** 53,60 **** void class_set_extern_dir(t_symbol *s);
! static int sys_load_lib_internal(char *dirname, char *classname) { char symname[MAXPDSTRING], filename[MAXPDSTRING], dirbuf[MAXPDSTRING], ! classname2[MAXPDSTRING], *nameptr, *lastdot; void *dlobj; t_xxx makeout = NULL; --- 53,61 ---- void class_set_extern_dir(t_symbol *s);
! static int sys_load_lib_alt(char *dirname, char *classname, char *altname) { char symname[MAXPDSTRING], filename[MAXPDSTRING], dirbuf[MAXPDSTRING], ! classname2[MAXPDSTRING], *nameptr, *lastdot, ! altsymname[MAXPDSTRING]; void *dlobj; t_xxx makeout = NULL; *************** *** 79,83 **** dirbuf, &nameptr, MAXPDSTRING, 1)) < 0) { ! return (0); } } --- 80,103 ---- dirbuf, &nameptr, MAXPDSTRING, 1)) < 0) { ! /* next try (alternative_classname).(sys_dllextent) */ ! if(altname) ! { ! if ((fd = open_via_path(dirname, altname, sys_dllextent, ! dirbuf, &nameptr, MAXPDSTRING, 1)) < 0) ! ! /* next try (alternative_classname)/(alternative_classname).(sys_dllextent) ... */ ! strncpy(classname2, altname, MAXPDSTRING); ! filename[MAXPDSTRING-2] = 0; ! strcat(classname2, "/"); ! strncat(classname2, altname, MAXPDSTRING-strlen(classname2)); ! filename[MAXPDSTRING-1] = 0; ! if ((fd = open_via_path(dirname, classname2, sys_dllextent, ! dirbuf, &nameptr, MAXPDSTRING, 1)) < 0) ! { ! return 0; ! } ! } ! else ! return (0); } } *************** *** 103,109 **** --- 123,140 ---- strcpy(symname, "_"); strcat(symname, nameptr); + if(altname) + { + strcpy(altsymname, "_setup_"); + strcat(symname, altname); + } #else strcpy(symname, nameptr); + if(altname) + { + strcpy(altsymname, "setup_"); + strcat(altsymname, altname); + } #endif + /* if the last character is a tilde, replace with "_tilde" */ if (symname[strlen(symname) - 1] == '~') *************** *** 113,120 **** #ifdef DL_OPEN dlobj = dlopen(filename, RTLD_NOW | RTLD_GLOBAL); ! if(dlobj) ! makeout = (t_xxx)dlsym(dlobj, symname); ! if(!makeout) ! post("%s: %s",filename,dlerror()); #elif defined(MSW) sys_bashfilename(filename, filename); --- 144,155 ---- #ifdef DL_OPEN dlobj = dlopen(filename, RTLD_NOW | RTLD_GLOBAL); ! if (!dlobj) ! { ! post("%s: %s", filename, dlerror()); ! class_set_extern_dir(&s_); ! return (0); ! } ! makeout = (t_xxx)dlsym(dlobj, symname); ! if(!makeout)makeout = (t_xxx)dlsym(dlobj, altsymname); #elif defined(MSW) sys_bashfilename(filename, filename); *************** *** 127,130 **** --- 162,166 ---- } makeout = (t_xxx)GetProcAddress(ntdll, symname); + if(!makeout)makeout = (t_xxx)GetProcAddress(ntdll, altsymname); #elif defined(__APPLE__) { *************** *** 151,156 **** } ret = NSLinkModule( image, filename, ! NSLINKMODULE_OPTION_BINDNOW | ! //NSLINKMODULE_OPTION_PRIVATE | NSLINKMODULE_OPTION_RETURN_ON_ERROR);
--- 187,191 ---- } ret = NSLinkModule( image, filename, ! NSLINKMODULE_OPTION_BINDNOW | NSLINKMODULE_OPTION_RETURN_ON_ERROR);
*************** *** 162,168 **** post("link error %d %s %s", err, fname, errt); return 0; ! } s = NSLookupSymbolInModule(ret, symname);
if (s) makeout = (t_xxx)NSAddressOfSymbol( s); --- 197,205 ---- post("link error %d %s %s", err, fname, errt); return 0; ! } s = NSLookupSymbolInModule(ret, symname);
+ if(!s)s=NSLookupSymbolInModule(ret, altsymname); + if (s) makeout = (t_xxx)NSAddressOfSymbol( s); *************** *** 170,176 **** --- 207,216 ---- } #endif + if (!makeout) { post("load_object: Symbol "%s" not found", symname); + if(altname) + post("load_object: Symbol "%s" not found", altsymname); class_set_extern_dir(&s_); return 0; *************** *** 193,198 **** }
! /* callback type definition */ ! typedef int (*loader_t)(char *dirname, char *classname);
/* linked list of loaders */ --- 233,238 ---- }
! //* callback type definition */ ! typedef int (*loader_t)(char *dirname, char *classname, char *altname);
/* linked list of loaders */ *************** *** 202,215 **** } loader_queue_t;
! static loader_queue_t loaders = {sys_load_lib_internal,NULL};
/* register class loader function */ ! void sys_loader(loader_t loader) { loader_queue_t *q = &loaders; ! for(;;) { ! if(q->next) q = q->next; ! else { q->next = (loader_queue_t *)getbytes(sizeof(loader_queue_t)); q->next->loader = loader; --- 242,257 ---- } loader_queue_t;
! static loader_queue_t loaders = {sys_load_lib_alt, NULL};
/* register class loader function */ ! void sys_register_loader(loader_t loader) { loader_queue_t *q = &loaders; ! while (1) ! { ! if (q->next) q = q->next; ! else ! { q->next = (loader_queue_t *)getbytes(sizeof(loader_queue_t)); q->next->loader = loader; *************** *** 220,235 **** }
! /* this is the "classic" pd loader function */ ! int sys_load_lib(char *dirname, char *classname) { int dspstate = canvas_suspend_dsp(); - int ok = 0; loader_queue_t *q; for(q = &loaders; q; q = q->next) ! if(ok = q->loader(dirname,classname)) break;
canvas_resume_dsp(dspstate); return ok; } - --- 262,275 ---- }
! ! int sys_load_lib(char *dirname, char *classname, char *altname) { int dspstate = canvas_suspend_dsp(); int ok = 0; loader_queue_t *q; for(q = &loaders; q; q = q->next) ! if(ok = q->loader(dirname, classname, altname)) break;
canvas_resume_dsp(dspstate); return ok; }
Index: m_class.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/m_class.c,v retrieving revision 1.3.4.7.2.11 retrieving revision 1.3.4.7.2.12 diff -C2 -d -r1.3.4.7.2.11 -r1.3.4.7.2.12 *** m_class.c 30 Nov 2005 13:36:57 -0000 1.3.4.7.2.11 --- m_class.c 9 Mar 2006 14:22:51 -0000 1.3.4.7.2.12 *************** *** 619,622 **** --- 619,658 ---- int pd_setloadingabstraction(t_symbol *sym);
+ + /* replace everything but [a-zA-Z0-9_] by "0x%x" */ + static char*alternative_classname(char*classname) + { + char *altname=(char*)getbytes(sizeof(char)*MAXPDSTRING); + int count=0; + int i=0; + for(i=0; i<MAXPDSTRING; i++) + altname[i]=0; + i=0; + while(*classname) + { + char c=*classname; + if((c>=48 && c<=57)|| /* [0-9] */ + (c>=65 && c<=90)|| /* [A-Z] */ + (c>=97 && c<=122)||/* [a-z] */ + (c==95)) /* [_] */ + { + altname[i]=c; + i++; + } + else /* a "bad" character */ + { + sprintf(altname+i, "0x%02x", c); + i+=4; + count++; + } + classname++; + } + if(count>0)return altname; + /* seems like the given classname is fine as can be */ + freebytes(altname, sizeof(char)*MAXPDSTRING); + return 0; + } + + /* this routine is called when a new "object" is requested whose class Pd doesn't know. Pd tries to load it as an extern, then as an abstraction. */ *************** *** 627,634 **** int fd; char dirbuf[MAXPDSTRING], *nameptr; if (tryingalready) return; newest = 0; class_loadsym = s; ! if (sys_load_lib(dir->s_name, s->s_name)) { tryingalready = 1; --- 663,671 ---- int fd; char dirbuf[MAXPDSTRING], *nameptr; + char *altname=alternative_classname(s->s_name); if (tryingalready) return; newest = 0; class_loadsym = s; ! if (sys_load_lib(dir->s_name, s->s_name, altname)) { tryingalready = 1;
Index: s_main.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_main.c,v retrieving revision 1.7.4.17.2.10 retrieving revision 1.7.4.17.2.11 diff -C2 -d -r1.7.4.17.2.10 -r1.7.4.17.2.11 *** s_main.c 30 Nov 2005 13:36:58 -0000 1.7.4.17.2.10 --- s_main.c 9 Mar 2006 14:22:51 -0000 1.7.4.17.2.11 *************** *** 244,248 **** /* load dynamic libraries specified with "-lib" args */ for (nl = sys_externlist; nl; nl = nl->nl_next) ! if (!sys_load_lib(cwd, nl->nl_string)) post("%s: can't load library", nl->nl_string); /* open patches specifies with "-open" args */ --- 244,248 ---- /* load dynamic libraries specified with "-lib" args */ for (nl = sys_externlist; nl; nl = nl->nl_next) ! if (!sys_load_lib(cwd, nl->nl_string, 0)) post("%s: can't load library", nl->nl_string); /* open patches specifies with "-open" args */
Index: s_stuff.h =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_stuff.h,v retrieving revision 1.5.4.10.2.2 retrieving revision 1.5.4.10.2.3 diff -C2 -d -r1.5.4.10.2.2 -r1.5.4.10.2.3 *** s_stuff.h 8 Sep 2005 08:50:51 -0000 1.5.4.10.2.2 --- s_stuff.h 9 Mar 2006 14:22:51 -0000 1.5.4.10.2.3 *************** *** 60,64 ****
/* s_loader.c */ ! int sys_load_lib(char *dirname, char *filename);
/* s_audio.c */ --- 60,64 ----
/* s_loader.c */ ! int sys_load_lib(char *dirname, char *filename, char *altname);
/* s_audio.c */
Index: m_pd.h =================================================================== RCS file: /cvsroot/pure-data/pd/src/m_pd.h,v retrieving revision 1.4.4.11.2.16 retrieving revision 1.4.4.11.2.17 diff -C2 -d -r1.4.4.11.2.16 -r1.4.4.11.2.17 *** m_pd.h 22 Dec 2005 00:44:40 -0000 1.4.4.11.2.16 --- m_pd.h 9 Mar 2006 14:22:51 -0000 1.4.4.11.2.17 *************** *** 499,503 ****
/* grrrr: register class loader */ ! EXTERN void sys_loader(int (*callback) (char *dirname,char *classname));
/* ------------ printing --------------------------------- */ --- 499,503 ----
/* grrrr: register class loader */ ! EXTERN void sys_register_loader(int (*callback) (char *dirname,char *classname,char *altname));
/* ------------ printing --------------------------------- */