Lines Matching +full:module +full:- +full:importer
1 /* Module definition and import implementation */
40 module _imp
61 int verbose = _PyInterpreterState_GetConfig(tstate->interp)->verbose; in _PyImportZip_Init()
68 _PyErr_Clear(tstate); /* No zip import module -- okay */ in _PyImportZip_Init()
77 _PyErr_Clear(tstate); /* No zipimporter object -- okay */ in _PyImportZip_Init()
102 /* Locking primitives to prevent parallel imports of the same module
103 in different threads to return with a partially loaded module.
144 return -1; in _PyImport_ReleaseLock()
145 import_lock_level--; in _PyImport_ReleaseLock()
173 import_lock_level--; in _PyImport_ReInitLock()
191 _imp_lock_held_impl(PyObject *module) in _imp_lock_held_impl() argument
202 This lock should be used by import hooks to ensure thread-safety when importing
207 _imp_acquire_lock_impl(PyObject *module) in _imp_acquire_lock_impl() argument
223 _imp_release_lock_impl(PyObject *module) in _imp_release_lock_impl() argument
267 if (interp->modules == NULL) { in PyImport_GetModuleDict()
270 return interp->modules; in PyImport_GetModuleDict()
280 if (interp->modules == NULL) in _PyImport_IsInitialized()
299 PyObject *modules = interp->modules; in _PyImport_SetModule()
307 PyObject *modules = interp->modules; in _PyImport_SetModuleString()
314 PyObject *modules = tstate->interp->modules; in import_get_module()
346 stuffing the new module in sys.modules. in import_ensure_initialized()
352 /* Wait until module is done importing. */ in import_ensure_initialized()
354 interp->importlib, &_Py_ID(_lock_unlock_module), name); in import_ensure_initialized()
356 return -1; in import_ensure_initialized()
364 /* Helper for pythonrun.c -- return magic number and tag. */
373 external = PyObject_GetAttrString(interp->importlib, "_bootstrap_external"); in PyImport_GetMagicNumber()
375 return -1; in PyImport_GetMagicNumber()
379 return -1; in PyImport_GetMagicNumber()
395 /* Magic for extension modules (built-in as well as dynamically
396 loaded). To prevent initializing an extension module more than
398 (module name, module name) (for built-in modules) or by
399 (filename, module name) (for dynamically loaded modules), containing these
400 modules. A copy of the module's dictionary is stored by calling
401 _PyImport_FixupExtensionObject() immediately after the module initialization
406 field to a non-negative number (indicating the size of the
407 module-specific state). They are still recorded in the extensions
417 return -1; in _PyImport_FixupExtensionObject()
423 return -1; in _PyImport_FixupExtensionObject()
428 return -1; in _PyImport_FixupExtensionObject()
432 return -1; in _PyImport_FixupExtensionObject()
435 // bpo-44050: Extensions and def->m_base.m_copy can be updated in _PyImport_FixupExtensionObject()
436 // when the extension module doesn't support sub-interpreters. in _PyImport_FixupExtensionObject()
437 if (_Py_IsMainInterpreter(tstate->interp) || def->m_size == -1) { in _PyImport_FixupExtensionObject()
438 if (def->m_size == -1) { in _PyImport_FixupExtensionObject()
439 if (def->m_base.m_copy) { in _PyImport_FixupExtensionObject()
440 /* Somebody already imported the module, in _PyImport_FixupExtensionObject()
443 Py_CLEAR(def->m_base.m_copy); in _PyImport_FixupExtensionObject()
447 return -1; in _PyImport_FixupExtensionObject()
449 def->m_base.m_copy = PyDict_Copy(dict); in _PyImport_FixupExtensionObject()
450 if (def->m_base.m_copy == NULL) { in _PyImport_FixupExtensionObject()
451 return -1; in _PyImport_FixupExtensionObject()
458 return -1; in _PyImport_FixupExtensionObject()
464 return -1; in _PyImport_FixupExtensionObject()
469 return -1; in _PyImport_FixupExtensionObject()
483 return -1; in _PyImport_FixupBuiltin()
508 PyObject *modules = tstate->interp->modules; in import_find_extension()
510 if (def->m_size == -1) { in import_find_extension()
511 /* Module does not support repeated initialization */ in import_find_extension()
512 if (def->m_base.m_copy == NULL) in import_find_extension()
522 if (PyDict_Update(mdict, def->m_base.m_copy)) { in import_find_extension()
528 if (def->m_base.m_init == NULL) in import_find_extension()
530 mod = _PyImport_InitFunc_TrampolineCall(def->m_base.m_init); in import_find_extension()
533 if (PyObject_SetItem(modules, name, mod) == -1) { in import_find_extension()
544 int verbose = _PyInterpreterState_GetConfig(tstate->interp)->verbose; in import_find_extension()
553 /* Get the module object corresponding to a module name.
560 PyObject *modules = tstate->interp->modules; in import_add_module()
563 "no import module dictionary"); in import_add_module()
574 // For backward-compatibility we copy the behavior in import_add_module()
623 PyObject *module = PyImport_AddModuleObject(nameobj); in PyImport_AddModule() local
625 return module; in PyImport_AddModule()
640 PyObject *modules = tstate->interp->modules; in remove_module()
655 /* Execute a code object in a module and return the module object
657 * removed from sys.modules, to avoid leaving damaged module objects
659 * module object (if any) in this case; PyImport_ReloadModule is an
711 external= PyObject_GetAttrString(interp->importlib, in PyImport_ExecCodeModuleWithPathnames()
740 /* If the module is being reloaded, we get the old module back in module_dict_for_exec()
741 and re-use its dict to exec the new code. */ in module_dict_for_exec()
774 "Loaded module %R not found in sys.modules", in exec_code_in_module()
794 pathname = ((PyCodeObject *)co)->co_filename; in PyImport_ExecCodeModuleObject()
796 external = PyObject_GetAttrString(tstate->interp->importlib, in PyImport_ExecCodeModuleObject()
820 if (PyUnicode_Compare(co->co_filename, oldname)) in update_code_filenames()
824 Py_XSETREF(co->co_filename, newname); in update_code_filenames()
826 constants = co->co_consts; in update_code_filenames()
841 if (PyUnicode_Compare(co->co_filename, newname) == 0) in update_compiled_module()
844 oldname = co->co_filename; in update_compiled_module()
860 Changes code.co_filename to specify the passed-in file path.
864 _imp__fix_co_filename_impl(PyObject *module, PyCodeObject *code, in _imp__fix_co_filename_impl() argument
875 /* Helper to test for built-in module */
884 return -1; in is_builtin()
905 PyObject *importer; in get_path_importer() local
916 importer = PyDict_GetItemWithError(path_importer_cache, p); in get_path_importer()
917 if (importer != NULL || _PyErr_Occurred(tstate)) { in get_path_importer()
918 Py_XINCREF(importer); in get_path_importer()
919 return importer; in get_path_importer()
930 importer = PyObject_CallOneArg(hook, p); in get_path_importer()
931 if (importer != NULL) in get_path_importer()
939 if (importer == NULL) { in get_path_importer()
942 if (PyDict_SetItem(path_importer_cache, p, importer) < 0) { in get_path_importer()
943 Py_DECREF(importer); in get_path_importer()
946 return importer; in get_path_importer()
976 PyObject *modules = tstate->interp->modules; in create_builtin()
977 for (struct _inittab *p = PyImport_Inittab; p->name != NULL; p++) { in create_builtin()
978 if (_PyUnicode_EqualToASCIIString(name, p->name)) { in create_builtin()
979 if (p->initfunc == NULL) { in create_builtin()
980 /* Cannot re-init internal module ("sys" or "builtins") */ in create_builtin()
984 mod = _PyImport_InitFunc_TrampolineCall(*p->initfunc); in create_builtin()
993 /* Remember pointer to module init function. */ in create_builtin()
999 def->m_base.m_init = p->initfunc; in create_builtin()
1021 Create an extension module.
1025 _imp_create_builtin(PyObject *module, PyObject *spec) in _imp_create_builtin() argument
1042 to the original module name. If it is an alias but the original
1043 module isn't known then "alias" is set to NULL while true is returned. */
1050 if (entry->name == NULL) { in resolve_module_alias()
1054 if (strcmp(name, entry->name) == 0) { in resolve_module_alias()
1056 *alias = entry->orig; in resolve_module_alias()
1070 int override = interp->override_frozen_modules; in use_frozen()
1078 return interp->config.use_frozen_modules; in use_frozen()
1105 if (p->name == NULL) { in list_frozen_module_names()
1108 ADD_MODULE(p->name); in list_frozen_module_names()
1112 if (p->name == NULL) { in list_frozen_module_names()
1116 ADD_MODULE(p->name); in list_frozen_module_names()
1120 if (p->name == NULL) { in list_frozen_module_names()
1124 ADD_MODULE(p->name); in list_frozen_module_names()
1131 if (p->name == NULL) { in list_frozen_module_names()
1134 PyObject *nameobj = PyUnicode_FromString(p->name); in list_frozen_module_names()
1164 FROZEN_BAD_NAME, // The given module name wasn't valid.
1166 FROZEN_DISABLED, // -X frozen_modules=off (and not essential)
1168 (module is present but marked as unimportable, stops search). */
1213 if (p->name == NULL) { in look_up_frozen()
1214 // We hit the end-of-list sentinel value. in look_up_frozen()
1217 if (strcmp(name, p->name) == 0) { in look_up_frozen()
1225 if (p->name == NULL) { in look_up_frozen()
1228 if (strcmp(name, p->name) == 0) { in look_up_frozen()
1236 if (p->name == NULL) { in look_up_frozen()
1239 if (strcmp(name, p->name) == 0) { in look_up_frozen()
1244 if (p->name == NULL) { in look_up_frozen()
1247 if (strcmp(name, p->name) == 0) { in look_up_frozen()
1290 info->nameobj = nameobj; // borrowed in find_frozen()
1291 info->data = (const char *)p->code; in find_frozen()
1292 info->get_code = p->get_code; in find_frozen()
1293 info->size = p->size; in find_frozen()
1294 info->is_package = p->is_package; in find_frozen()
1295 if (p->size < 0) { in find_frozen()
1297 info->size = -(p->size); in find_frozen()
1298 info->is_package = true; in find_frozen()
1300 info->origname = name; in find_frozen()
1301 info->is_alias = resolve_module_alias(name, _PyImport_FrozenAliases, in find_frozen()
1302 &info->origname); in find_frozen()
1304 if (p->code == NULL && p->size == 0 && p->get_code != NULL) { in find_frozen()
1308 if (p->code == NULL) { in find_frozen()
1309 /* It is frozen but marked as un-importable. */ in find_frozen()
1312 if (p->code[0] == '\0' || p->size == 0) { in find_frozen()
1322 if (info->get_code) { in unmarshal_frozen_code()
1323 PyObject *code = info->get_code(); in unmarshal_frozen_code()
1327 PyObject *co = PyMarshal_ReadObjectFromString(info->data, info->size); in unmarshal_frozen_code()
1330 set_frozen_error(FROZEN_INVALID, info->nameobj); in unmarshal_frozen_code()
1337 info->nameobj); in unmarshal_frozen_code()
1345 /* Initialize a frozen module.
1346 Return 1 for success, 0 if the module is not found, and -1 with
1367 return -1; in PyImport_ImportFrozenModuleObject()
1371 return -1; in PyImport_ImportFrozenModuleObject()
1424 return -1; in PyImport_ImportFrozenModuleObject()
1434 return -1; in PyImport_ImportFrozenModule()
1441 /* Import a module, either built-in, frozen, or external, and return
1442 its module object WITH INCREMENTED REFERENCE COUNT */
1459 /* Import a module without blocking
1461 * At first it tries to fetch the module from sys.modules. If the module was
1466 * Returns the module object with incremented ref count.
1493 if (!exception || _PyInterpreterState_GetConfig(tstate->interp)->verbose) { in remove_importlib_frames()
1505 PyObject *next = (PyObject *) traceback->tb_next; in remove_importlib_frames()
1506 PyFrameObject *frame = traceback->tb_frame; in remove_importlib_frames()
1511 now_in_importlib = _PyUnicode_EqualToASCIIString(code->co_filename, importlib_filename) || in remove_importlib_frames()
1512 _PyUnicode_EqualToASCIIString(code->co_filename, external_filename); in remove_importlib_frames()
1521 _PyUnicode_EqualToASCIIString(code->co_name, remove_frames))) { in remove_importlib_frames()
1527 prev_link = (PyObject **) &traceback->tb_next; in remove_importlib_frames()
1640 0, PyUnicode_GET_LENGTH(package), -1); in resolve_name()
1641 if (dot == -2) { in resolve_name()
1644 else if (dot == -1) { in resolve_name()
1661 last_dot = PyUnicode_FindChar(package, '.', 0, last_dot, -1); in resolve_name()
1662 if (last_dot == -2) { in resolve_name()
1665 else if (last_dot == -1) { in resolve_name()
1667 "attempted relative import beyond top-level " in resolve_name()
1697 PyInterpreterState *interp = tstate->interp; in import_find_and_load()
1698 int import_time = _PyInterpreterState_GetConfig(interp)->import_time; in import_find_and_load()
1736 mod = PyObject_CallMethodObjArgs(interp->importlib, &_Py_ID(_find_and_load), in import_find_and_load()
1737 abs_name, interp->import_func, NULL); in import_find_and_load()
1744 _PyTime_t cum = _PyTime_GetPerfCounter() - t1; in import_find_and_load()
1746 import_level--; in import_find_and_load()
1748 (long)_PyTime_AsMicroseconds(cum - accumulated, _PyTime_ROUND_CEILING), in import_find_and_load()
1766 if (import_ensure_initialized(tstate->interp, mod, name) < 0) { in PyImport_GetModule()
1785 PyInterpreterState *interp = tstate->interp; in PyImport_ImportModuleLevelObject()
1789 _PyErr_SetString(tstate, PyExc_ValueError, "Empty module name"); in PyImport_ImportModuleLevelObject()
1798 "module name must be a string"); in PyImport_ImportModuleLevelObject()
1816 _PyErr_SetString(tstate, PyExc_ValueError, "Empty module name"); in PyImport_ImportModuleLevelObject()
1829 if (import_ensure_initialized(tstate->interp, mod, abs_name) < 0) { in PyImport_ImportModuleLevelObject()
1853 if (dot == -2) { in PyImport_ImportModuleLevelObject()
1857 if (dot == -1) { in PyImport_ImportModuleLevelObject()
1858 /* No dot in module name, simple exit */ in PyImport_ImportModuleLevelObject()
1874 Py_ssize_t cut_off = len - dot; in PyImport_ImportModuleLevelObject()
1877 abs_name_len - cut_off); in PyImport_ImportModuleLevelObject()
1907 interp->importlib, &_Py_ID(_handle_fromlist), in PyImport_ImportModuleLevelObject()
1908 mod, fromlist, interp->import_func, NULL); in PyImport_ImportModuleLevelObject()
1941 /* Re-import a module of any kind and return its module object, WITH
1966 /* Higher-level import emulator which emulates the "import" statement
1967 more accurately -- it invokes the __import__() function from the
1973 will return <module "gencache"> instead of <module "win32com">. */
1998 /* No globals -- use standard builtins, and fake globals */ in PyImport_Import()
2023 Calling for side-effect of import. */ in PyImport_Import()
2051 _imp_extension_suffixes_impl(PyObject *module) in _imp_extension_suffixes_impl() argument
2087 Initializes a frozen module.
2091 _imp_init_frozen_impl(PyObject *module, PyObject *name) in _imp_init_frozen_impl() argument
2114 Return info about the corresponding frozen module (if there is one) or None.
2116 The returned info (a 2-tuple):
2120 * origname the originally frozen module's name, or None if not
2121 a stdlib module (this will usually be the same as
2122 the module's current name)
2126 _imp_find_frozen_impl(PyObject *module, PyObject *name, int withdata) in _imp_find_frozen_impl() argument
2174 Create a code object for a frozen module.
2178 _imp_get_frozen_object_impl(PyObject *module, PyObject *name, in _imp_get_frozen_object_impl() argument
2225 Returns True if the module name is of a frozen package.
2229 _imp_is_frozen_package_impl(PyObject *module, PyObject *name) in _imp_is_frozen_package_impl() argument
2247 Returns True if the module name corresponds to a built-in module.
2251 _imp_is_builtin_impl(PyObject *module, PyObject *name) in _imp_is_builtin_impl() argument
2263 Returns True if the module name corresponds to a frozen module.
2267 _imp_is_frozen_impl(PyObject *module, PyObject *name) in _imp_is_frozen_impl() argument
2285 _imp__frozen_module_names_impl(PyObject *module) in _imp__frozen_module_names_impl() argument
2297 (internal-only) Override PyConfig.use_frozen_modules.
2299 (-1: "off", 1: "on", 0: no override)
2304 _imp__override_frozen_modules_for_tests_impl(PyObject *module, int override) in _imp__override_frozen_modules_for_tests_impl() argument
2308 interp->override_frozen_modules = override; in _imp__override_frozen_modules_for_tests_impl()
2345 Create an extension module.
2349 _imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file) in _imp_create_dynamic_impl() argument
2395 _imp.exec_dynamic -> int
2400 Initialize an extension module.
2404 _imp_exec_dynamic_impl(PyObject *module, PyObject *mod) in _imp_exec_dynamic_impl() argument
2414 _imp.exec_builtin -> int
2419 Initialize a built-in module.
2423 _imp_exec_builtin_impl(PyObject *module, PyObject *mod) in _imp_exec_builtin_impl() argument
2437 _imp_source_hash_impl(PyObject *module, long key, Py_buffer *source) in _imp_source_hash_impl() argument
2444 hash.x = _Py_KeyedHash((uint64_t)key, source->buf, source->len); in _imp_source_hash_impl()
2446 // Force to little-endian. There really ought to be a succinct standard way in _imp_source_hash_impl()
2450 hash.data[i] = hash.data[sizeof(hash.data) - i - 1]; in _imp_source_hash_impl()
2451 hash.data[sizeof(hash.data) - i - 1] = tmp; in _imp_source_hash_impl()
2459 "(Extremely) low-level import machinery bits as used by importlib and imp.");
2485 imp_module_exec(PyObject *module) in imp_module_exec() argument
2487 const wchar_t *mode = _Py_GetConfig()->check_hash_pycs_mode; in imp_module_exec()
2488 PyObject *pyc_mode = PyUnicode_FromWideChar(mode, -1); in imp_module_exec()
2490 return -1; in imp_module_exec()
2492 if (PyModule_AddObjectRef(module, "check_hash_based_pycs", pyc_mode) < 0) { in imp_module_exec()
2494 return -1; in imp_module_exec()
2525 // importlib requires the _imp module: this function fix the bootstrap issue.
2548 // Create the _imp module from its definition. in _PyImport_BootstrapImp()
2557 // Execute the _imp module: call imp_module_exec(). in _PyImport_BootstrapImp()
2571 to the table of built-in modules. This should normally be called
2572 *before* Py_Initialize(). When the table resize fails, -1 is
2599 if (i + n <= SIZE_MAX / sizeof(struct _inittab) - 1) { in PyImport_ExtendInittab()
2604 res = -1; in PyImport_ExtendInittab()