home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / python / pysrc / !Python_Monty_c_importdl < prev    next >
Encoding:
Text File  |  1996-08-13  |  2.7 KB  |  91 lines

  1. /***********************************************************
  2. Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
  3. The Netherlands.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its
  8. documentation for any purpose and without fee is hereby granted,
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in
  11. supporting documentation, and that the names of Stichting Mathematisch
  12. Centrum or CWI not be used in advertising or publicity pertaining to
  13. distribution of the software without specific, written prior permission.
  14.  
  15. STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  16. THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  18. FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  20. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  21. OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. /* Support for dynamic loading of extension modules */
  26. /* If no dynamic linking is supported, this file still generates some code! */
  27.  
  28. /* This version is completely rewritten for RISCOS using dlk */
  29.  
  30. #include "allobjects.h"
  31. #include "osdefs.h"
  32. #include "importdl.h"
  33.  
  34. extern int verbose; /* Defined in pythonrun.c */
  35.  
  36. #ifdef DLK
  37. #define DYNAMIC_LINK
  38. #include "h.os"
  39. #include "h.dlk"
  40. extern char *getprogramname();
  41. #endif
  42.  
  43. /* Max length of module suffix searched for -- accommodates "module.slb" */
  44. #ifndef MAXSUFFIXSIZE
  45. #define MAXSUFFIXSIZE 12
  46. #endif
  47.  
  48. /* Pass it on to import.c */
  49. int import_maxsuffixsize = MAXSUFFIXSIZE;
  50.  
  51. struct filedescr import_filetab[] = {
  52. #ifdef DYNAMIC_LINK
  53.     {"d.", "rb", C_EXTENSION},
  54. #endif /* DYNAMIC_LINK */
  55.     {"py.", "r", PY_SOURCE},
  56.     {"pyc.", "rb", PY_COMPILED},
  57.     {0, 0}
  58. };
  59.  
  60. object *
  61. load_dynamic_module(name, pathname,fp)
  62.     char *name;
  63.     char *pathname;
  64.     FILE *fp;
  65. {
  66. #ifndef DYNAMIC_LINK
  67.     err_setstr(ImportError, "dynamically linked modules not supported");
  68.     return NULL;
  69. #else
  70.     object *m;
  71.         int err;
  72.         err=dlk_load(pathname);
  73.         if(err) printf("dlk error %d\n\n", err);
  74.     if (err) { err_setstr(ImportError,"dlk failure");return NULL;}
  75.  
  76.     m = dictlookup(import_modules, name);
  77.     if (m == NULL) {
  78.         if (err_occurred() == NULL)
  79.             err_setstr(SystemError,
  80.                    "dynamic module not initialized properly");
  81.         return NULL;
  82.     }
  83.     if (verbose)
  84.         fprintf(stderr,
  85.             "import %s # dynamically loaded from %s\n",
  86.             name, pathname);
  87.     INCREF(m);
  88.     return m;
  89. #endif /* DYNAMIC_LINK */
  90. }
  91.