@@ -89,6 +89,17 @@ struct embedded_module {
89
89
}
90
90
};
91
91
92
+ struct wide_char_arg_deleter {
93
+ void operator ()(void * ptr) const {
94
+ #if PY_VERSION_HEX >= 0x030500f0
95
+ // API docs: https://docs.python.org/3/c-api/sys.html#c.Py_DecodeLocale
96
+ PyMem_RawFree (ptr);
97
+ #else
98
+ delete ptr;
99
+ #endif
100
+ }
101
+ };
102
+
92
103
// / Python 2.x/3.x-compatible version of `PySys_SetArgv`
93
104
inline void set_interpreter_argv (int argc, char ** argv, bool add_current_dir_to_path) {
94
105
// Before it was special-cased in python 3.8, passing an empty or null argv
@@ -106,18 +117,7 @@ inline void set_interpreter_argv(int argc, char** argv, bool add_current_dir_to_
106
117
size_t argv_size = static_cast <size_t >(argc);
107
118
// SetArgv* on python 3 takes wchar_t, so we have to convert.
108
119
std::unique_ptr<wchar_t *[]> widened_argv (new wchar_t *[argv_size]);
109
- # if PY_MINOR_VERSION >= 5
110
- // Use of PyMem_RawFree here instead of PyMem_Free is as recommended by the python
111
- // API docs: https://docs.python.org/3/c-api/sys.html#c.Py_DecodeLocale
112
- struct pymem_rawfree_deleter {
113
- void operator ()(void * ptr) const {
114
- PyMem_RawFree (ptr);
115
- }
116
- };
117
- std::vector< std::unique_ptr<wchar_t [], pymem_rawfree_deleter> > widened_argv_entries;
118
- # else
119
- std::vector< std::unique_ptr<wchar_t []> > widened_argv_entries;
120
- # endif
120
+ std::vector< std::unique_ptr<wchar_t [], wide_char_arg_deleter> > widened_argv_entries;
121
121
for (size_t ii = 0 ; ii < argv_size; ++ii) {
122
122
# if PY_MINOR_VERSION >= 5
123
123
// From Python 3.5 onwards, we're supposed to use Py_DecodeLocale to
0 commit comments