You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.8 KiB

  1. /* Support for dynamic loading of extension modules */
  2. #include "dl.h"
  3. #include <errno.h>
  4. #include "Python.h"
  5. #include "importdl.h"
  6. #if defined(__hp9000s300)
  7. #define FUNCNAME_PATTERN "_PyInit_%.200s"
  8. #else
  9. #define FUNCNAME_PATTERN "PyInit_%.200s"
  10. #endif
  11. const char *_PyImport_DynLoadFiletab[] = {SHLIB_EXT, NULL};
  12. dl_funcptr _PyImport_GetDynLoadFunc(const char *shortname,
  13. const char *pathname, FILE *fp)
  14. {
  15. dl_funcptr p;
  16. shl_t lib;
  17. int flags;
  18. char funcname[258];
  19. flags = BIND_FIRST | BIND_DEFERRED;
  20. if (Py_VerboseFlag) {
  21. flags = BIND_FIRST | BIND_IMMEDIATE |
  22. BIND_NONFATAL | BIND_VERBOSE;
  23. printf("shl_load %s\n",pathname);
  24. }
  25. lib = shl_load(pathname, flags, 0);
  26. /* XXX Chuck Blake once wrote that 0 should be BIND_NOSTART? */
  27. if (lib == NULL) {
  28. char buf[256];
  29. PyObject *pathname_ob = NULL;
  30. PyObject *buf_ob = NULL;
  31. PyObject *shortname_ob = NULL;
  32. if (Py_VerboseFlag)
  33. perror(pathname);
  34. PyOS_snprintf(buf, sizeof(buf), "Failed to load %.200s",
  35. pathname);
  36. buf_ob = PyUnicode_FromString(buf);
  37. shortname_ob = PyUnicode_FromString(shortname);
  38. pathname_ob = PyUnicode_FromString(pathname);
  39. PyErr_SetImportError(buf_ob, shortname_ob, pathname_ob);
  40. Py_DECREF(buf_ob);
  41. Py_DECREF(shortname_ob);
  42. Py_DECREF(pathname_ob);
  43. return NULL;
  44. }
  45. PyOS_snprintf(funcname, sizeof(funcname), FUNCNAME_PATTERN, shortname);
  46. if (Py_VerboseFlag)
  47. printf("shl_findsym %s\n", funcname);
  48. if (shl_findsym(&lib, funcname, TYPE_UNDEFINED, (void *) &p) == -1) {
  49. shl_unload(lib);
  50. p = NULL;
  51. }
  52. if (p == NULL && Py_VerboseFlag)
  53. perror(funcname);
  54. return p;
  55. }