@@ -526,9 +526,10 @@ struct CppWrapperType: public PyTypeObject
526
526
tp_as_mapping=&mappingMethods;
527
527
PyType_Ready (this );
528
528
}
529
- } cppWrapperType ;
529
+ };
530
530
531
- CppWrapper::CppWrapper (const string& command): command(command) {
531
+ inline CppWrapper::CppWrapper (const string& command): command(command) {
532
+ static CppWrapperType cppWrapperType;
532
533
ob_refcnt=1 ;
533
534
ob_type=&cppWrapperType;
534
535
methods.emplace (" __dict__" ,cppWrapperType.tp_dict );
@@ -581,7 +582,7 @@ struct CppWrapperType: public PyTypeObject
581
582
};
582
583
583
584
584
- PyObject* callOnRegistry (const string& command, const PythonBuffer& arguments)
585
+ inline PyObject* callOnRegistry (const string& command, const PythonBuffer& arguments)
585
586
{
586
587
try
587
588
{
@@ -629,31 +630,34 @@ struct CppWrapperType: public PyTypeObject
629
630
}
630
631
};
631
632
632
- void initModule ()
633
+ namespace
633
634
{
634
- assert (pythonModule);
635
- // grab all toplevel objects already installed
636
- std::set<std::string> topLevelNames;
637
- for (auto & i: registry)
638
- if (!i.first .empty () && i.first [0 ]!=' @' )
639
- topLevelNames.insert (i.first .substr (0 ,i.first .find (' .' )));
640
- for (auto & i: topLevelNames)
641
- {
642
- PyObjectRef pyObject=CppWrapper::create (i);
643
- LimitRecursion ().attachMethods (pyObject,i);
644
- PyModule_AddObject (pythonModule, i.c_str (), pyObject.release ());
645
- }
646
-
647
- // enum reflection
648
- PyObjectRef enummer=PyDict_New ();
649
- auto enumList=registry.process (" @enum.@list" ,{});
650
- for (auto & i: enumList.array ())
651
- {
652
- string name=i.get_str ();
653
- PyDict_SetItemString (enummer, name.c_str (),
654
- newPyObjectJson (registry.process (" @enum." +name,{})));
655
- }
656
- PyModule_AddObject (pythonModule, " enum" , enummer.release ());
635
+ inline void initModule ()
636
+ {
637
+ assert (pythonModule);
638
+ // grab all toplevel objects already installed
639
+ std::set<std::string> topLevelNames;
640
+ for (auto & i: registry)
641
+ if (!i.first .empty () && i.first [0 ]!=' @' )
642
+ topLevelNames.insert (i.first .substr (0 ,i.first .find (' .' )));
643
+ for (auto & i: topLevelNames)
644
+ {
645
+ PyObjectRef pyObject=CppWrapper::create (i);
646
+ LimitRecursion ().attachMethods (pyObject,i);
647
+ PyModule_AddObject (pythonModule, i.c_str (), pyObject.release ());
648
+ }
649
+
650
+ // enum reflection
651
+ PyObjectRef enummer=PyDict_New ();
652
+ auto enumList=registry.process (" @enum.@list" ,{});
653
+ for (auto & i: enumList.array ())
654
+ {
655
+ string name=i.get_str ();
656
+ PyDict_SetItemString (enummer, name.c_str (),
657
+ newPyObjectJson (registry.process (" @enum." +name,{})));
658
+ }
659
+ PyModule_AddObject (pythonModule, " enum" , enummer.release ());
660
+ }
657
661
}
658
662
}
659
663
0 commit comments