------------------------------------------------------------------------------
| 428 | |
| 429 | //------------------------------------------------------------------------------ |
| 430 | bool 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; |
nothing calls this directly
no test coverage detected