diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2023-03-10 19:23:59 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2023-03-10 19:23:59 +0300 |
commit | 7d576663c816bfaa02dcce5b6dfb8cfc3c7dec67 (patch) | |
tree | 0c83cd449f757a3ac93f05157b70a07b7e4833db /library/cpp/pybind | |
parent | 7c23836fb92f8c9713acb10fb00e286d8a5ed210 (diff) | |
download | ydb-7d576663c816bfaa02dcce5b6dfb8cfc3c7dec67.tar.gz |
Intermediate changes
Diffstat (limited to 'library/cpp/pybind')
-rw-r--r-- | library/cpp/pybind/embedding.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/library/cpp/pybind/embedding.cpp b/library/cpp/pybind/embedding.cpp index 78b608715e..cf8941a92a 100644 --- a/library/cpp/pybind/embedding.cpp +++ b/library/cpp/pybind/embedding.cpp @@ -7,11 +7,30 @@ #include <util/generic/yexception.h> namespace NPyBind { +#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 8 + class TDeleteRawMem { + public: + template <typename T> + static inline void Destroy(T* t) noexcept { + PyMem_RawFree(t); + } + }; + + template <typename T> + using TRawMemHolder = THolder<T, TDeleteRawMem>; + + static void SetProgramName(char* name) { + TRawMemHolder<wchar_t> wideName(Py_DecodeLocale(name, nullptr)); + Y_ENSURE(wideName); + Py_SetProgramName(wideName.Get()); + } +#endif + TEmbedding::TEmbedding(char* argv0) { #if PY_MAJOR_VERSION < 3 Py_SetProgramName(argv0); Py_Initialize(); -#else +#elif PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 8 PyStatus status; PyConfig config; @@ -32,6 +51,9 @@ namespace NPyBind { } PyConfig_Clear(&config); +#elif PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 8 + SetProgramName(argv0); + Py_Initialize(); #endif } |