@@ -93,11 +93,14 @@ inline void precheck_interpreter() {
93
93
}
94
94
}
95
95
96
+ PYBIND11_NAMESPACE_END (detail)
97
+
96
98
#if PY_VERSION_HEX >= PYBIND11_PYCONFIG_SUPPORT_PY_VERSION_HEX
97
99
inline void initialize_interpreter (PyConfig *config,
98
100
int argc = 0 ,
99
101
const char *const *argv = nullptr ,
100
102
bool add_program_dir_to_path = true ) {
103
+ detail::precheck_interpreter ();
101
104
PyStatus status = PyConfig_SetBytesArgv (config, argc, const_cast <char *const *>(argv));
102
105
if (PyStatus_Exception (status) != 0 ) {
103
106
// A failure here indicates a character-encoding failure or the python
@@ -125,6 +128,7 @@ inline void initialize_interpreter_pre_pyconfig(bool init_signal_handlers,
125
128
int argc,
126
129
const char *const *argv,
127
130
bool add_program_dir_to_path) {
131
+ detail::precheck_interpreter ();
128
132
Py_InitializeEx (init_signal_handlers ? 1 : 0 );
129
133
130
134
// Before it was special-cased in python 3.8, passing an empty or null argv
@@ -158,8 +162,6 @@ inline void initialize_interpreter_pre_pyconfig(bool init_signal_handlers,
158
162
}
159
163
#endif
160
164
161
- PYBIND11_NAMESPACE_END (detail)
162
-
163
165
/* * \rst
164
166
Initialize the Python interpreter. No other pybind11 or CPython API functions can be
165
167
called before this is done; with the exception of `PYBIND11_EMBEDDED_MODULE`. The
@@ -183,17 +185,15 @@ inline void initialize_interpreter(bool init_signal_handlers = true,
183
185
int argc = 0 ,
184
186
const char *const *argv = nullptr ,
185
187
bool add_program_dir_to_path = true ) {
186
- detail::precheck_interpreter ();
187
188
#if PY_VERSION_HEX < PYBIND11_PYCONFIG_SUPPORT_PY_VERSION_HEX
188
- detail::initialize_interpreter_pre_pyconfig (
189
- init_signal_handlers, argc, argv, add_program_dir_to_path);
189
+ initialize_interpreter_pre_pyconfig (init_signal_handlers, argc, argv, add_program_dir_to_path);
190
190
#else
191
191
PyConfig config;
192
192
PyConfig_InitIsolatedConfig (&config);
193
193
config.isolated = 0 ;
194
194
config.use_environment = 1 ;
195
195
config.install_signal_handlers = init_signal_handlers ? 1 : 0 ;
196
- detail:: initialize_interpreter (&config, argc, argv, add_program_dir_to_path);
196
+ initialize_interpreter (&config, argc, argv, add_program_dir_to_path);
197
197
#endif
198
198
}
199
199
@@ -286,8 +286,7 @@ class scoped_interpreter {
286
286
int argc = 0 ,
287
287
const char *const *argv = nullptr ,
288
288
bool add_program_dir_to_path = true ) {
289
- detail::precheck_interpreter ();
290
- detail::initialize_interpreter (config, argc, argv, add_program_dir_to_path);
289
+ initialize_interpreter (config, argc, argv, add_program_dir_to_path);
291
290
}
292
291
#endif
293
292
0 commit comments