Guest User

Untitled

a guest
Feb 18th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | None | 0 0
  1. /* Support for dynamic loading of extension modules under vxworks */
  2.  
  3. #include "Python.h"
  4. #include "importdl.h"
  5.  
  6. #include <ioLib.h>
  7. #include <loadLib.h>
  8. #include <symLib.h>
  9. #include <sysSymTbl.h>
  10.  
  11. const struct filedescr _PyImport_DynLoadFiletab[] = {
  12.         {".pyd", "rb", C_EXTENSION},
  13.         {"module.pyd", "rb", C_EXTENSION},
  14.     {0, 0}
  15. };
  16.  
  17. dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
  18.                     const char *pathname, FILE *fp)
  19. {
  20.     dl_funcptr p;
  21.     SYM_TYPE type;
  22.         MODULE_ID handle;
  23.     char funcname[258];
  24.     char pathbuf[260];
  25.  
  26.     if (strchr(pathname, '/') == NULL) {
  27.         PyOS_snprintf(pathbuf, sizeof(pathbuf), "./%-.255s", pathname);
  28.         pathname = pathbuf;
  29.     }
  30.  
  31.     PyOS_snprintf(funcname, sizeof(funcname), "init%.200s", shortname);
  32.  
  33.     if (symFindByName(sysSymTbl, funcname, (char **)&p, &type) == OK)
  34.         return p;
  35.  
  36.     if (Py_VerboseFlag)
  37.         PySys_WriteStderr("loadModule(\"%s\");\n", pathname);
  38.  
  39.         if (fp != NULL) {
  40.         handle = loadModule(fileno(fp), LOAD_GLOBAL_SYMBOLS);
  41.         } else {
  42.         int fd = open(pathname, O_RDONLY, 0644);
  43.         handle = loadModule(fd, LOAD_GLOBAL_SYMBOLS);
  44.         close(fd);
  45.     }
  46.  
  47.     if (handle == NULL) {
  48.         const char *error = strerror(errno);
  49.         if (error == NULL)
  50.             error = "unknown loadModule() error";
  51.         PyErr_SetString(PyExc_ImportError, error);
  52.         return NULL;
  53.     }
  54.     if (symFindByName(sysSymTbl, funcname, (char **)&p, &type) != OK)
  55.     {
  56.         const char *error = strerror(errno);
  57.         if (error == NULL)
  58.             error = "unknown symFindByName() error";
  59.         PyErr_SetString(PyExc_ImportError, error);
  60.         return NULL;
  61.     }
  62.     return p;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment