Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24902/src
Modified Files: Tag: devel_0_39 m_pd.h s_loader.c Log Message: class loader hook mechanism
Index: s_loader.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_loader.c,v retrieving revision 1.4.4.5.2.2 retrieving revision 1.4.4.5.2.3 diff -C2 -d -r1.4.4.5.2.2 -r1.4.4.5.2.3 *** s_loader.c 14 Jul 2005 23:17:33 -0000 1.4.4.5.2.2 --- s_loader.c 24 Nov 2005 11:14:43 -0000 1.4.4.5.2.3 *************** *** 47,51 **** void class_set_extern_dir(t_symbol *s);
! int sys_load_lib(char *dirname, char *classname) { char symname[MAXPDSTRING], filename[MAXPDSTRING], dirbuf[MAXPDSTRING], --- 47,51 ---- 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], *************** *** 54,58 **** t_xxx makeout = NULL; int fd; - int dspstate = canvas_suspend_dsp(); #ifdef MSW HINSTANCE ntdll; --- 54,57 ---- *************** *** 74,78 **** dirbuf, &nameptr, MAXPDSTRING, 1)) < 0) { - canvas_resume_dsp(dspstate); return (0); } --- 73,76 ---- *************** *** 121,125 **** post("%s: couldn't load", filename); class_set_extern_dir(&s_); - canvas_resume_dsp(dspstate); return (0); } --- 119,122 ---- *************** *** 147,151 **** post("%s: couldn't load (%s)", filename,errcode); class_set_extern_dir(&s_); - canvas_resume_dsp(dspstate); return 0; } --- 144,147 ---- *************** *** 161,165 **** NSLinkEditError(&c, &err, &fname, &errt); post("link error %d %s %s", err, fname, errt); - canvas_resume_dsp(dspstate); return 0; } --- 157,160 ---- *************** *** 175,193 **** post("load_object: Symbol "%s" not found", symname); class_set_extern_dir(&s_); - canvas_resume_dsp(dspstate); return 0; } (*makeout)(); class_set_extern_dir(&s_); - canvas_resume_dsp(dspstate); return (1); }
!
--- 170,231 ---- post("load_object: Symbol "%s" not found", symname); class_set_extern_dir(&s_); return 0; } + #if _MSC_VER + __try { + #endif (*makeout)(); + #if _MSC_VER + } + __except(EXCEPTION_EXECUTE_HANDLER) { + // EXCEPTION_POINTERS *ep = GetExceptionInformation(); + post("an exception occurred loading %s", classname); + class_set_extern_dir(&s_); + return 0; + } + #endif class_set_extern_dir(&s_); return (1); }
+ /* callback type definition */ + typedef int (*loader_t)(char *dirname, char *classname);
+ /* linked list of loaders */ + typedef struct loader_queue { + loader_t loader; + struct loader_queue *next; + } 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; + q->next->next = NULL; + break; + } + } + }
+ /* 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; ! }
Index: m_pd.h =================================================================== RCS file: /cvsroot/pure-data/pd/src/m_pd.h,v retrieving revision 1.4.4.11.2.14 retrieving revision 1.4.4.11.2.15 diff -C2 -d -r1.4.4.11.2.14 -r1.4.4.11.2.15 *** m_pd.h 15 Nov 2005 23:30:59 -0000 1.4.4.11.2.14 --- m_pd.h 24 Nov 2005 11:14:42 -0000 1.4.4.11.2.15 *************** *** 498,501 **** --- 498,504 ---- EXTERN int class_getfieldindex(t_class *x, const char *s);
+ /* grrrr: register class loader */ + EXTERN void sys_loader(int (*callback) (char *dirname,char *classname)); + /* ------------ printing --------------------------------- */ EXTERN void post(const char *fmt, ...);