Skip to content

Commit fc9421e

Browse files
committed
fix: copy strings on Python 2
1 parent 1ede69e commit fc9421e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

include/pybind11/embed.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ inline void set_interpreter_argv(int argc, const char* const* argv, bool add_pro
144144
auto pysys_argv = widened_argv.get();
145145
#else
146146
// python 2.x
147-
char** pysys_argv = const_cast<char**>safe_argv;
147+
std::vector<std::string> strings{safe_argv, safe_argv+argc};
148+
std::vector<char*> char_strings{std::begin(strings), std::end(strings)};
149+
char** pysys_argv = char_strings.data();
148150
#endif
149151

150152
PySys_SetArgvEx(argc, pysys_argv, static_cast<int>(add_program_dir_to_path));

0 commit comments

Comments
 (0)