summaryrefslogtreecommitdiffstats
path: root/library/cpp/pybind/v2.cpp
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2025-08-28 14:27:58 +0300
committerrobot-piglet <[email protected]>2025-08-28 14:57:06 +0300
commit81d828c32c8d5477cb2f0ce5da06a1a8d9392ca3 (patch)
tree3081d566f0d5158d76e9093261344f6406fd09f7 /library/cpp/pybind/v2.cpp
parent77ea11423f959e51795cc3ef36a48d808b4ffb98 (diff)
Intermediate changes
commit_hash:d5b1af16dbe9030537a04c27eb410c88c2f496cd
Diffstat (limited to 'library/cpp/pybind/v2.cpp')
-rw-r--r--library/cpp/pybind/v2.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/library/cpp/pybind/v2.cpp b/library/cpp/pybind/v2.cpp
new file mode 100644
index 00000000000..221b956801b
--- /dev/null
+++ b/library/cpp/pybind/v2.cpp
@@ -0,0 +1,53 @@
+#include "v2.h"
+namespace NPyBind {
+ namespace Detail {
+
+ TVector<PyTypeObject*> GetParentTypes(const TVector<TParentData>& parentsData) {
+ TVector<PyTypeObject*> res;
+ Transform(
+ parentsData.begin(),
+ parentsData.end(),
+ back_inserter(res),
+ [](const TParentData& el) { return el.ParentType; }
+ );
+ return res;
+ }
+
+ TString DefaultParentResolver(const TString&, const THashSet<TString>& parentModules) {
+ return *parentModules.begin();
+ }
+
+ template <bool InitEnabled>
+ void UpdateClassNamesInModule(TPyModuleDefinition& M, const TString& name, PyTypeObject* pythonType) {
+ if (!InitEnabled) {
+ return;
+ }
+ M.ClassName2Type[name] = pythonType;
+ }
+
+ template <bool InitEnabled>
+ void UpdateGetContextInModule(TPyModuleDefinition& M, const TString& name, IGetContextBase* base) {
+ if (!InitEnabled) {
+ return;
+ }
+ M.Class2ContextGetter[name] = base;
+ }
+
+ TPyModuleRegistry::TPyModuleRegistry() {
+#if PY_MAJOR_VERSION >= 3
+ NPrivate::AddFinalizationCallBack([this]() {
+ if (UnnamedModule) {
+ UnnamedModule.Clear();
+ }
+ Name2Def.clear();
+ });
+#endif
+ }
+ template void UpdateClassNamesInModule<false>(TPyModuleDefinition& M, const TString& name, PyTypeObject* pythonType);
+ template void UpdateClassNamesInModule<true>(TPyModuleDefinition& M, const TString& name, PyTypeObject* pythonType);
+
+
+ template void UpdateGetContextInModule<false>(TPyModuleDefinition& M, const TString& name, IGetContextBase* pythonType);
+ template void UpdateGetContextInModule<true>(TPyModuleDefinition& M, const TString& name, IGetContextBase* pythonType);
+ }//Detail
+}//NPyBind