/[ascend]/trunk/base/generic/utilities/ascDynaLoad.c
ViewVC logotype

Diff of /trunk/base/generic/utilities/ascDynaLoad.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 158 by johnpye, Mon Jan 2 09:02:52 2006 UTC revision 159 by johnpye, Mon Jan 2 09:54:52 2006 UTC
# Line 160  void AscCheckDuplicateLoad(CONST char *p Line 160  void AscCheckDuplicateLoad(CONST char *p
160    struct ascend_dlrecord *r;    struct ascend_dlrecord *r;
161    
162    if (NULL == path) {    if (NULL == path) {
163      FPRINTF(stderr,"Null path in AscCheckDuplicateLoad\n");      error_reporter(ASC_PROG_ERR,NULL,0,"Null path in AscCheckDuplicateLoad.");
164      return;      return;
165    }    }
166    
167    r = g_ascend_dllist;    r = g_ascend_dllist;
168    while (r != NULL) {    while (r != NULL) {
169      if (strcmp(path,r->path)==0) {      if (strcmp(path,r->path)==0) {
170        FPRINTF(stderr,"Attempt to load already loaded %s\n",path);        error_reporter(ASC_PROG_ERR,NULL,0,"Attempt to load already loaded '%s'.",path);
171        return;        return;
172      }      }
173      r = r->next;      r = r->next;
# Line 202  int Asc_DynamicLoad(CONST char *path, CO Line 202  int Asc_DynamicLoad(CONST char *path, CO
202    
203    xlib = LoadLibrary(path);    xlib = LoadLibrary(path);
204    if (xlib == NULL) {    if (xlib == NULL) {
205      FPRINTF(stderr,"Asc_DynamicLoad: LoadLibrary failed\n");      error_reporter(ASC_PROG_ERR,NULL,0,"Asc_DynamicLoad: LoadLibrary failed\n");
206      return 1;      return 1;
207    }    }
208    if (NULL != initFun) {    if (NULL != initFun) {
209      install = (int (*)())GetProcAddress(xlib,initFun);      install = (int (*)())GetProcAddress(xlib,initFun);
210      if (install == NULL) {      if (install == NULL) {
211        FPRINTF(stderr,"Asc_DynamicLoad: Required function %s not found\n", initFun);        error_reporter(ASC_PROG_ERR,NULL,0,"Asc_DynamicLoad: Required function %s not found\n", initFun);
212        (void)FreeLibrary(xlib);        (void)FreeLibrary(xlib);
213        return 1;        return 1;
214      }else{      }else{
# Line 216  int Asc_DynamicLoad(CONST char *path, CO Line 216  int Asc_DynamicLoad(CONST char *path, CO
216      }      }
217    }    }
218    if (0 != AscAddRecord(xlib,path)) {    if (0 != AscAddRecord(xlib,path)) {
219      FPRINTF(stderr,"Asc_DynamicLoad failed to record library (%s)\n",path);      error_reporter(ASC_PROG_ERR,NULL,0,"Asc_DynamicLoad failed to record library (%s)\n",path);
220    }    }
221    return (install == NULL) ? 0 : (*install)();    return (install == NULL) ? 0 : (*install)();
222  }  }
# Line 252  int Asc_DynamicLoad(CONST char *path, CO Line 252  int Asc_DynamicLoad(CONST char *path, CO
252    int (*install)() = NULL;    int (*install)() = NULL;
253    
254    if (NULL == path) {    if (NULL == path) {
255      FPRINTF(stderr,"Asc_DynamicLoad failed: Null path\n");      error_reporter(ASC_PROG_ERR,NULL,0,"Asc_DynamicLoad failed: Null path\n");
256      return 1;      return 1;
257    }    }
258    
# Line 264  int Asc_DynamicLoad(CONST char *path, CO Line 264  int Asc_DynamicLoad(CONST char *path, CO
264     */     */
265    xlib = dlopen(path, 1);    xlib = dlopen(path, 1);
266    if (xlib == NULL) {    if (xlib == NULL) {
267      FPRINTF(stderr,"%s\n",(char *)dlerror());      error_reporter(ASC_PROG_ERR,NULL,0,"%s",(char *)dlerror());
268      return 1;      return 1;
269    }    }
270    if (NULL != initFun) {    if (NULL != initFun) {
271      install = (int (*)())dlsym(xlib, initFun);      install = (int (*)())dlsym(xlib, initFun);
272      if (install == NULL) {      if (install == NULL) {
273        FPRINTF(stderr,"%s\n",(char *)dlerror());        error_reporter(ASC_PROG_ERR,NULL,0,"%s",(char *)dlerror());
274        dlclose(xlib);        dlclose(xlib);
275        return 1;        return 1;
276      }      }
277    }    }
278        
279    if (0 != AscAddRecord(xlib,path)) {    if (0 != AscAddRecord(xlib,path)) {
280      FPRINTF(stderr,"Asc_DynamicLoad failed to record library (%s)\n",path);      error_reporter(ASC_PROG_ERR,NULL,0,"Asc_DynamicLoad failed to record library (%s)\n",path);
281    }    }
282    return (install == NULL) ? 0 : (*install)();    return (install == NULL) ? 0 : (*install)();
283  }  }
# Line 307  int Asc_DynamicLoad(CONST char *path, CO Line 307  int Asc_DynamicLoad(CONST char *path, CO
307    int i;    int i;
308    
309    if (NULL == path) {    if (NULL == path) {
310      FPRINTF(stderr,"Asc_DynamicLoad failed: Null path\n");      error_reporter(ASC_PROG_ERR,NULL,0,"Asc_DynamicLoad failed: Null path\n");
311      return 1;      return 1;
312    }    }
313    
# Line 319  int Asc_DynamicLoad(CONST char *path, CO Line 319  int Asc_DynamicLoad(CONST char *path, CO
319     */     */
320    xlib = shl_load(path, BIND_IMMEDIATE | BIND_VERBOSE, 0L);    xlib = shl_load(path, BIND_IMMEDIATE | BIND_VERBOSE, 0L);
321    if (xlib == (shl_t) NULL)  {    if (xlib == (shl_t) NULL)  {
322      FPRINTF(stderr,"Unable to load shared library : %s\n",strerror(errno));      error_reporter(ASC_PROG_ERR,NULL,0,"Unable to load shared library : %s\n",strerror(errno));
323      return 1;      return 1;
324    }    }
325    if (NULL != initFun) {    if (NULL != initFun) {
326      i = shl_findsym(&xlib, initFun, TYPE_PROCEDURE, &install);      i = shl_findsym(&xlib, initFun, TYPE_PROCEDURE, &install);
327      if (i == -1) {      if (i == -1) {
328        FPRINTF(stderr,"Unable to find needed symbol %s %s\n",        error_reporter(ASC_PROG_ERR,NULL,0,"Unable to find needed symbol %s %s\n",
329                 initFun, strerror(errno));                 initFun, strerror(errno));
330        shl_unload(xlib); /* baa */        shl_unload(xlib); /* baa */
331        return 1;        return 1;
332      }      }
333      if (install == NULL) {      if (install == NULL) {
334        FPRINTF(stderr,"Unable to find needed symbol %s\n",initFun);        error_reporter(ASC_PROG_ERR,NULL,0,"Unable to find needed symbol %s\n",initFun);
335        FPRINTF(stderr,"Error type unknown\n");        error_reporter(ASC_PROG_ERR,NULL,0,"Error type unknown\n");
336        shl_unload(xlib); /* baa */        shl_unload(xlib); /* baa */
337        return 1;        return 1;
338      }      }
339    }    }
340    if (0 != AscAddRecord(xlib,path)) {    if (0 != AscAddRecord(xlib,path)) {
341      FPRINTF(stderr,"Asc_DynamicLoad failed to record library (%s)\n",path);      error_reporter(ASC_PROG_ERR,NULL,0,"Asc_DynamicLoad failed to record library (%s)\n",path);
342    }    }
343    return (install == NULL) ? 0 : (*install)();    return (install == NULL) ? 0 : (*install)();
344  }  }
# Line 384  int Asc_DynamicUnLoad(CONST char *path) Line 384  int Asc_DynamicUnLoad(CONST char *path)
384    int retval;    int retval;
385        
386    if (NULL == path) {    if (NULL == path) {
387      FPRINTF(stderr, "Asc_DynamicUnLoad failed: Null path\n");      error_reporter(ASC_PROG_ERR,NULL,0, "Asc_DynamicUnLoad failed: Null path\n");
388      return -3;      return -3;
389    }    }
390    
391    dlreturn = AscDeleteRecord(path);    dlreturn = AscDeleteRecord(path);
392    if (dlreturn == NULL) {    if (dlreturn == NULL) {
393      FPRINTF(stderr, "Asc_DynamicUnLoad: unable to remember or unload %s\n", path);      error_reporter(ASC_PROG_ERR,NULL,0, "Asc_DynamicUnLoad: unable to remember or unload %s\n", path);
394      return -3;      return -3;
395    }    }
396    FPRINTF(stderr, "Asc_DynamicUnLoad: forgetting & unloading %s \n", path);    error_reporter(ASC_PROG_ERR,NULL,0, "Asc_DynamicUnLoad: forgetting & unloading %s \n", path);
397    /*    /*
398     *  dlclose() returns 0 on success, FreeLibrary() returns TRUE.     *  dlclose() returns 0 on success, FreeLibrary() returns TRUE.
399     *  A uniform convention is preferable, so trap and return 0 on success.     *  A uniform convention is preferable, so trap and return 0 on success.
# Line 412  void *Asc_DynamicVariable(CONST char *li Line 412  void *Asc_DynamicVariable(CONST char *li
412  #endif  #endif
413    
414    if (libname == NULL) {    if (libname == NULL) {
415      FPRINTF(stderr,"Asc_DynamicSymbol failed:  Null libname\n");      error_reporter(ASC_PROG_ERR,NULL,0,"Asc_DynamicSymbol failed:  Null libname\n");
416      return NULL;      return NULL;
417    }    }
418    if (symbol == NULL) {    if (symbol == NULL) {
419      FPRINTF(stderr,"Asc_DynamicSymbol failed:  Null symbol\n");      error_reporter(ASC_PROG_ERR,NULL,0,"Asc_DynamicSymbol failed:  Null symbol\n");
420      return NULL;      return NULL;
421    }    }
422    
423    dlreturn = AscFindDLRecord(libname);    dlreturn = AscFindDLRecord(libname);
424    if (dlreturn == NULL) {    if (dlreturn == NULL) {
425      FPRINTF(stderr,"Asc_DynamicSymbol: Unable to find requested library %s\n", libname);      error_reporter(ASC_PROG_ERR,NULL,0,"Asc_DynamicSymbol: Unable to find requested library %s\n", libname);
426      return NULL;      return NULL;
427    }    }
428  #ifdef __hpux  #ifdef __hpux
429    i = shl_findsym(&dlreturn, symbol, TYPE_UNDEFINED, &symreturn);    i = shl_findsym(&dlreturn, symbol, TYPE_UNDEFINED, &symreturn);
430    if (i == -1) {    if (i == -1) {
431      FPRINTF(stderr,"Asc_DynamicSymbol: Unable to find requested symbol %s in %s (%s)\n",      error_reporter(ASC_PROG_ERR,NULL,0,"Asc_DynamicSymbol: Unable to find requested symbol %s in %s (%s)\n",
432                         symbol, libname, strerror(errno));                         symbol, libname, strerror(errno));
433      symreturn = NULL;      symreturn = NULL;
434    }    }
# Line 450  void *Asc_DynamicVariable(CONST char *li Line 450  void *Asc_DynamicVariable(CONST char *li
450    symreturn = dlsym(dlreturn, symbol);    symreturn = dlsym(dlreturn, symbol);
451  #endif  #endif
452    if (symreturn == NULL) {    if (symreturn == NULL) {
453      FPRINTF(stderr,"Asc_DynamicSymbol: Unable to find requested symbol %s in %s\n",symbol,libname);      error_reporter(ASC_PROG_ERR,NULL,0,"Asc_DynamicSymbol: Unable to find requested symbol %s in %s\n",symbol,libname);
454      FPRINTF(stderr,"Error type %s\n",ASC_DLERRSTRING);      error_reporter(ASC_PROG_ERR,NULL,0,"Error type %s\n",ASC_DLERRSTRING);
455    }    }
456    return symreturn;    return symreturn;
457  }  }
# Line 466  DynamicF Asc_DynamicFunction(CONST char Line 466  DynamicF Asc_DynamicFunction(CONST char
466  #endif  #endif
467    
468    if (libname == NULL) {    if (libname == NULL) {
469      FPRINTF(stderr,"Asc_DynamicFunction failed:  Null library name\n");      error_reporter(ASC_PROG_ERR,NULL,0,"Asc_DynamicFunction failed:  Null library name\n");
470      return NULL;      return NULL;
471    }    }
472    if (symbol == NULL) {    if (symbol == NULL) {
473      FPRINTF(stderr,"Asc_DynamicFunction failed:  Null function name\n");      error_reporter(ASC_PROG_ERR,NULL,0,"Asc_DynamicFunction failed:  Null function name\n");
474      return NULL;      return NULL;
475    }    }
476    
477    dlreturn = AscFindDLRecord(libname);    dlreturn = AscFindDLRecord(libname);
478    if (dlreturn == NULL) {    if (dlreturn == NULL) {
479      FPRINTF(stderr,"Asc_DynamicFunction: Unable to find requested library %s\n", libname);      error_reporter(ASC_PROG_ERR,NULL,0,"Asc_DynamicFunction: Unable to find requested library %s\n", libname);
480      return NULL;      return NULL;
481    }    }
482  #ifdef __hpux  #ifdef __hpux
483    i = shl_findsym(&dlreturn, symbol, TYPE_UNDEFINED, &symreturn);    i = shl_findsym(&dlreturn, symbol, TYPE_UNDEFINED, &symreturn);
484    if (i == -1) {    if (i == -1) {
485      FPRINTF(stderr,"Asc_DynamicFunction: Unable to find requested function %s in %s (%s)\n",      error_reporter(ASC_PROG_ERR,NULL,0,"Asc_DynamicFunction: Unable to find requested function %s in %s (%s)\n",
486                         symbol, libname, strerror(errno));                         symbol, libname, strerror(errno));
487      symreturn = NULL;      symreturn = NULL;
488    }    }
# Line 503  DynamicF Asc_DynamicFunction(CONST char Line 503  DynamicF Asc_DynamicFunction(CONST char
503    *(void**)(&symreturn) = dlsym(dlreturn, symbol);    *(void**)(&symreturn) = dlsym(dlreturn, symbol);
504  #endif  #endif
505    if (symreturn == NULL) {    if (symreturn == NULL) {
506      FPRINTF(stderr,"Asc_DynamicFunction: Unable to find requested function %s in %s\n",symbol,libname);      error_reporter(ASC_PROG_ERR,NULL,0,"Asc_DynamicFunction: Unable to find requested function %s in %s\n",symbol,libname);
507      FPRINTF(stderr,"Error type %s\n",ASC_DLERRSTRING);      error_reporter(ASC_PROG_ERR,NULL,0,"Error type %s\n",ASC_DLERRSTRING);
508    }    }
509    return symreturn;    return symreturn;
510  }  }

Legend:
Removed from v.158  
changed lines
  Added in v.159

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22