MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / PP_Load_Module

Function PP_Load_Module

src/Base/PyTools.c:442–475  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

440
441
442PyObject * /* returns module object named modname */
443PP_Load_Module(const char *modname) /* modname can be "package.module" form */
444{ /* reload just resets C extension mods */
445 /*
446 * 4 cases:
447 * - module "__main__" has no file, and not prebuilt: fetch or make
448 * - dummy modules have no files: don't try to reload them
449 * - reload=on and already loaded (on sys.modules): "reload()" before use
450 * - not loaded yet, or loaded but reload=off: "import" to fetch or load
451 */
452
453 PyObject *module = NULL, *sysmods = NULL;
454 modname = PP_Init(modname); /* default to __main__ */
455
456 if (strcmp(modname, "__main__") == 0) /* main: no file */
457 return PyImport_AddModule(modname); /* not increfd */
458
459 sysmods = PyImport_GetModuleDict(); /* get sys.modules dict */
460 module = PyDict_GetItemString(sysmods, modname); /* mod in sys.modules? */
461
462 if (module != NULL && /* dummy: no file */
463 PyModule_Check(module) &&
464 PyDict_GetItemString(PyModule_GetDict(module), "__dummy__")) {
465 return module; /* not increfd */
466 }
467 if (PP_RELOAD && module != NULL && PyModule_Check(module)) {
468 module = PyImport_ReloadModule(module); /* reload file,run code */
469 Py_XDECREF(module); /* still on sys.modules */
470 return module; /* not increfd */
471 }
472 module = PyImport_ImportModule(modname); /* fetch or load module */
473 Py_XDECREF(module); /* still on sys.modules */
474 return module; /* not increfd */
475}
476
477
478PyObject *

Callers 9

runStringMethod · 0.85
runStringObjectMethod · 0.85
runInteractiveStringMethod · 0.85
loadModuleMethod · 0.85
getValueMethod · 0.85
PP_Set_GlobalFunction · 0.85
PP_Load_AttributeFunction · 0.85
PP_Run_CodestrFunction · 0.85
PP_Run_BytecodeFunction · 0.85

Calls 1

PP_InitFunction · 0.85

Tested by

no test coverage detected