aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/pybind/v2.cpp
blob: edce0be7195ee6fc23ebe1aaf31bb72fdabf7467 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "v2.h"
namespace NPyBind {
    namespace Detail {
        template <>
        PyTypeObject* GetParentType<void>(const TPyModuleDefinition&) {
            return nullptr;
        }


        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