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.

53 lines
1.0 KiB

First part of package support. This doesn't yet support "import a.b.c" or "from a.b.c import x", but it does recognize directories. When importing a directory, it initializes __path__ to a list containing the directory name, and loads the __init__ module if found. The (internal) find_module() and load_module() functions are restructured so that they both also handle built-in and frozen modules and Mac resources (and directories of course). The imp module's find_module() and (new) load_module() also have this functionality. Moreover, imp unconditionally defines constants for all module types, and has two more new functions: find_module_in_package() and find_module_in_directory(). There's also a new API function, PyImport_ImportModuleEx(), which takes all four __import__ arguments (name, globals, locals, fromlist). The last three may be NULL. This is currently the same as PyImport_ImportModule() but in the future it will be able to do relative dotted-path imports. Other changes: - bltinmodule.c: in __import__, call PyImport_ImportModuleEx(). - ceval.c: always pass the fromlist to __import__, even if it is a C function, so PyImport_ImportModuleEx() is useful. - getmtime.c: the function has a second argument, the FILE*, on which it applies fstat(). According to Sjoerd this is much faster. The first (pathname) argument is ignored, but remains for backward compatibility (so the Mac version still works without changes). By cleverly combining the new imp functionality, the full support for dotted names in Python (mini.py, not checked in) is now about 7K, lavishly commented (vs. 14K for ni plus 11K for ihooks, also lavishly commented). Good night!
29 years ago
First part of package support. This doesn't yet support "import a.b.c" or "from a.b.c import x", but it does recognize directories. When importing a directory, it initializes __path__ to a list containing the directory name, and loads the __init__ module if found. The (internal) find_module() and load_module() functions are restructured so that they both also handle built-in and frozen modules and Mac resources (and directories of course). The imp module's find_module() and (new) load_module() also have this functionality. Moreover, imp unconditionally defines constants for all module types, and has two more new functions: find_module_in_package() and find_module_in_directory(). There's also a new API function, PyImport_ImportModuleEx(), which takes all four __import__ arguments (name, globals, locals, fromlist). The last three may be NULL. This is currently the same as PyImport_ImportModule() but in the future it will be able to do relative dotted-path imports. Other changes: - bltinmodule.c: in __import__, call PyImport_ImportModuleEx(). - ceval.c: always pass the fromlist to __import__, even if it is a C function, so PyImport_ImportModuleEx() is useful. - getmtime.c: the function has a second argument, the FILE*, on which it applies fstat(). According to Sjoerd this is much faster. The first (pathname) argument is ignored, but remains for backward compatibility (so the Mac version still works without changes). By cleverly combining the new imp functionality, the full support for dotted names in Python (mini.py, not checked in) is now about 7K, lavishly commented (vs. 14K for ni plus 11K for ihooks, also lavishly commented). Good night!
29 years ago
  1. #ifndef Py_IMPORTDL_H
  2. #define Py_IMPORTDL_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /* Definitions for dynamic loading of extension modules */
  7. enum filetype {
  8. SEARCH_ERROR,
  9. PY_SOURCE,
  10. PY_COMPILED,
  11. C_EXTENSION,
  12. PY_RESOURCE, /* Mac only */
  13. PKG_DIRECTORY,
  14. C_BUILTIN,
  15. PY_FROZEN,
  16. PY_CODERESOURCE, /* Mac only */
  17. IMP_HOOK
  18. };
  19. struct filedescr {
  20. char *suffix;
  21. char *mode;
  22. enum filetype type;
  23. };
  24. extern struct filedescr * _PyImport_Filetab;
  25. extern const struct filedescr _PyImport_DynLoadFiletab[];
  26. extern PyObject *_PyImport_LoadDynamicModule(char *name, char *pathname,
  27. FILE *);
  28. /* Max length of module suffix searched for -- accommodates "module.slb" */
  29. #define MAXSUFFIXSIZE 12
  30. #ifdef MS_WINDOWS
  31. #include <windows.h>
  32. typedef FARPROC dl_funcptr;
  33. #else
  34. #if defined(PYOS_OS2) && !defined(PYCC_GCC)
  35. #include <os2def.h>
  36. typedef int (* APIENTRY dl_funcptr)();
  37. #else
  38. typedef void (*dl_funcptr)(void);
  39. #endif
  40. #endif
  41. #ifdef __cplusplus
  42. }
  43. #endif
  44. #endif /* !Py_IMPORTDL_H */