MCPcopy Create free account
hub / github.com/Kitware/VTK / InitializeWithArgs

Method InitializeWithArgs

Utilities/PythonInterpreter/vtkPythonInterpreter.cxx:430–583  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

428
429//------------------------------------------------------------------------------
430bool vtkPythonInterpreter::InitializeWithArgs(
431 int initsigs, int argc, char* argv[], const char* programName)
432{
433 bool isolated = vtkPythonPreConfig();
434
435 if (Py_IsInitialized() == 0)
436 {
437 if (programName)
438 {
439 vtkPythonInterpreter::SetProgramName(programName);
440 }
441 else
442 {
443 // If no program name is specified,
444 // guide the mechanism to locate Python standard library, if possible.
445 SetupPythonPrefix(isolated);
446 }
447 bool signals_installed = initsigs != 0;
448
449 // Need two copies of args, because programs might modify the first
450 using OwnedWideString = std::unique_ptr<wchar_t, CharDeleter>;
451 std::vector<wchar_t*> argvForPython;
452 std::vector<OwnedWideString> argvCleanup;
453 for (int i = 0; i < argc; i++)
454 {
455 OwnedWideString argCopy(vtk_Py_UTF8ToWide(argv[i]), CharDeleter());
456 if (argCopy == nullptr)
457 {
458 vtk::print(stderr,
459 "Fatal vtkpython error: "
460 "unable to decode the command line argument #{:d}\n",
461 i + 1);
462 return false;
463 }
464
465 argvForPython.push_back(argCopy.get());
466 argvCleanup.emplace_back(std::move(argCopy));
467 }
468 argvForPython.push_back(nullptr);
469
470#if PY_VERSION_HEX < 0x03080000
471 Py_InitializeEx(initsigs);
472 // setup default argv. Without this, code snippets that check `sys.argv` may
473 // fail when run in embedded VTK Python environment.
474 PySys_SetArgvEx(argc, argvForPython.data(), 0);
475
476 isolated = Py_FrozenFlag;
477#else
478 PyConfig config;
479 PyStatus status;
480 PyConfig_InitPythonConfig(&config);
481 config.install_signal_handlers = initsigs;
482 config.program_name = PythonProgramName.pop_last();
483 status = PyConfig_SetArgv(&config, argc, argvForPython.data());
484 if (PyStatus_IsError(status))
485 {
486 PyConfig_Clear(&config);
487 return false;

Callers

nothing calls this directly

Calls 15

vtkPythonPreConfigFunction · 0.85
SetupPythonPrefixFunction · 0.85
vtk_Py_UTF8ToWideFunction · 0.85
CharDeleterClass · 0.85
SetupPythonPathsFunction · 0.85
vtkPrependPythonPathFunction · 0.85
NotifyInterpretersFunction · 0.85
pop_lastMethod · 0.80
printFunction · 0.50
push_backMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected