MCPcopy Create free account
hub / github.com/pybind/pybind11 / initialize_interpreter_pre_pyconfig

Function initialize_interpreter_pre_pyconfig

include/pybind11/embed.h:108–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106
107#if PY_VERSION_HEX < PYBIND11_PYCONFIG_SUPPORT_PY_VERSION_HEX
108inline void initialize_interpreter_pre_pyconfig(bool init_signal_handlers,
109 int argc,
110 const char *const *argv,
111 bool add_program_dir_to_path) {
112 detail::precheck_interpreter();
113 Py_InitializeEx(init_signal_handlers ? 1 : 0);
114
115 auto argv_size = static_cast<size_t>(argc);
116 // SetArgv* on python 3 takes wchar_t, so we have to convert.
117 std::unique_ptr<wchar_t *[]> widened_argv(new wchar_t *[argv_size]);
118 std::vector<std::unique_ptr<wchar_t[], detail::wide_char_arg_deleter>> widened_argv_entries;
119 widened_argv_entries.reserve(argv_size);
120 for (size_t ii = 0; ii < argv_size; ++ii) {
121 widened_argv_entries.emplace_back(detail::widen_chars(argv[ii]));
122 if (!widened_argv_entries.back()) {
123 // A null here indicates a character-encoding failure or the python
124 // interpreter out of memory. Give up.
125 return;
126 }
127 widened_argv[ii] = widened_argv_entries.back().get();
128 }
129
130 auto *pysys_argv = widened_argv.get();
131
132 PySys_SetArgvEx(argc, pysys_argv, static_cast<int>(add_program_dir_to_path));
133}
134#endif
135
136PYBIND11_NAMESPACE_END(detail)

Callers 1

initialize_interpreterFunction · 0.85

Calls 5

precheck_interpreterFunction · 0.85
widen_charsFunction · 0.85
emplace_backMethod · 0.80
reserveMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected