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.

66 lines
1.9 KiB

bpo-36763: Implement the PEP 587 (GH-13592) * Add a whole new documentation page: "Python Initialization Configuration" * PyWideStringList_Append() return type is now PyStatus, instead of int * PyInterpreterState_New() now calls PyConfig_Clear() if PyConfig_InitPythonConfig() fails. * Rename files: * Python/coreconfig.c => Python/initconfig.c * Include/cpython/coreconfig.h => Include/cpython/initconfig.h * Include/internal/: pycore_coreconfig.h => pycore_initconfig.h * Rename structures * _PyCoreConfig => PyConfig * _PyPreConfig => PyPreConfig * _PyInitError => PyStatus * _PyWstrList => PyWideStringList * Rename PyConfig fields: * use_module_search_paths => module_search_paths_set * module_search_path_env => pythonpath_env * Rename PyStatus field: _func => func * PyInterpreterState: rename core_config field to config * Rename macros and functions: * _PyCoreConfig_SetArgv() => PyConfig_SetBytesArgv() * _PyCoreConfig_SetWideArgv() => PyConfig_SetArgv() * _PyCoreConfig_DecodeLocale() => PyConfig_SetBytesString() * _PyInitError_Failed() => PyStatus_Exception() * _Py_INIT_ERROR_TYPE_xxx enums => _PyStatus_TYPE_xxx * _Py_UnixMain() => Py_BytesMain() * _Py_ExitInitError() => Py_ExitStatusException() * _Py_PreInitializeFromArgs() => Py_PreInitializeFromBytesArgs() * _Py_PreInitializeFromWideArgs() => Py_PreInitializeFromArgs() * _Py_PreInitialize() => Py_PreInitialize() * _Py_RunMain() => Py_RunMain() * _Py_InitializeFromConfig() => Py_InitializeFromConfig() * _Py_INIT_XXX() => _PyStatus_XXX() * _Py_INIT_FAILED() => _PyStatus_EXCEPTION() * Rename 'err' PyStatus variables to 'status' * Convert RUN_CODE() macro to config_run_code() static inline function * Remove functions: * _Py_InitializeFromArgs() * _Py_InitializeFromWideArgs() * _PyInterpreterState_GetCoreConfig()
7 years ago
  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. #include "pycore_pystate.h"
  7. #if defined(__hp9000s300)
  8. #define FUNCNAME_PATTERN "_%.20s_%.200s"
  9. #else
  10. #define FUNCNAME_PATTERN "%.20s_%.200s"
  11. #endif
  12. const char *_PyImport_DynLoadFiletab[] = {SHLIB_EXT, NULL};
  13. dl_funcptr _PyImport_FindSharedFuncptr(const char *prefix,
  14. const char *shortname,
  15. const char *pathname, FILE *fp)
  16. {
  17. int flags = BIND_FIRST | BIND_DEFERRED;
  18. int verbose = _PyInterpreterState_GET_UNSAFE()->config.verbose;
  19. if (verbose) {
  20. flags = BIND_FIRST | BIND_IMMEDIATE |
  21. BIND_NONFATAL | BIND_VERBOSE;
  22. printf("shl_load %s\n",pathname);
  23. }
  24. shl_t lib = shl_load(pathname, flags, 0);
  25. /* XXX Chuck Blake once wrote that 0 should be BIND_NOSTART? */
  26. if (lib == NULL) {
  27. if (verbose) {
  28. perror(pathname);
  29. }
  30. char buf[256];
  31. PyOS_snprintf(buf, sizeof(buf), "Failed to load %.200s",
  32. pathname);
  33. PyObject *buf_ob = PyUnicode_FromString(buf);
  34. PyObject *shortname_ob = PyUnicode_FromString(shortname);
  35. PyObject *pathname_ob = PyUnicode_FromString(pathname);
  36. PyErr_SetImportError(buf_ob, shortname_ob, pathname_ob);
  37. Py_DECREF(buf_ob);
  38. Py_DECREF(shortname_ob);
  39. Py_DECREF(pathname_ob);
  40. return NULL;
  41. }
  42. char funcname[258];
  43. PyOS_snprintf(funcname, sizeof(funcname), FUNCNAME_PATTERN,
  44. prefix, shortname);
  45. if (verbose) {
  46. printf("shl_findsym %s\n", funcname);
  47. }
  48. dl_funcptr p;
  49. if (shl_findsym(&lib, funcname, TYPE_UNDEFINED, (void *) &p) == -1) {
  50. shl_unload(lib);
  51. p = NULL;
  52. }
  53. if (p == NULL && verbose) {
  54. perror(funcname);
  55. }
  56. return p;
  57. }