diff options
author | thegeorg <thegeorg@yandex-team.com> | 2023-10-03 11:19:48 +0300 |
---|---|---|
committer | thegeorg <thegeorg@yandex-team.com> | 2023-10-03 11:43:28 +0300 |
commit | cda0c13f23f6b169fb0a49dc504b40a0aaecea09 (patch) | |
tree | 26476e92e5af2c856e017afb1df8f8dff42495bf /library/cpp/pybind/pod.h | |
parent | 4854116da9c5e3c95bb8440f2ea997c54b6e1a61 (diff) | |
download | ydb-cda0c13f23f6b169fb0a49dc504b40a0aaecea09.tar.gz |
Move contrib/tools/jdk to build/platform/java/jdk/testing
Diffstat (limited to 'library/cpp/pybind/pod.h')
-rw-r--r-- | library/cpp/pybind/pod.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/library/cpp/pybind/pod.h b/library/cpp/pybind/pod.h new file mode 100644 index 00000000000..90165fdbec6 --- /dev/null +++ b/library/cpp/pybind/pod.h @@ -0,0 +1,53 @@ +#pragma once + +#define PY_SSIZE_T_CLEAN +#include <Python.h> +#include "attr.h" +#include "typedesc.h" + +namespace NPyBind { + struct TPOD { + TPyObjectPtr Dict; + + TPOD() + : Dict(PyDict_New(), true) + { + } + bool SetAttr(const char* name, PyObject* value) { + return PyDict_SetItemString(Dict.Get(), name, value) == 0; + } + PyObject* GetAttr(const char* name) const { + PyObject* res = PyDict_GetItemString(Dict.Get(), name); + Py_XINCREF(res); + return res; + } + }; + + class TPODTraits: public NPyBind::TPythonType<TPOD, TPOD, TPODTraits> { + private: + typedef TPythonType<TPOD, TPOD, TPODTraits> MyParent; + friend class TPythonType<TPOD, TPOD, TPODTraits>; + TPODTraits(); + + public: + static TPOD* GetObject(TPOD& obj) { + return &obj; + } + }; + + template <> + inline bool FromPyObject<TPOD*>(PyObject* obj, TPOD*& res) { + res = TPODTraits::CastToObject(obj); + if (res == nullptr) + return false; + return true; + } + template <> + inline bool FromPyObject<const TPOD*>(PyObject* obj, const TPOD*& res) { + res = TPODTraits::CastToObject(obj); + if (res == nullptr) + return false; + return true; + } + +} |