Skip to content

Commit 803edb0

Browse files
Some function in pythonBuffer need to be inlined or made static.
1 parent cfc8bfa commit 803edb0

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

pythonBuffer.h

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,10 @@ struct CppWrapperType: public PyTypeObject
526526
tp_as_mapping=&mappingMethods;
527527
PyType_Ready(this);
528528
}
529-
} cppWrapperType;
529+
};
530530

531-
CppWrapper::CppWrapper(const string& command): command(command) {
531+
inline CppWrapper::CppWrapper(const string& command): command(command) {
532+
static CppWrapperType cppWrapperType;
532533
ob_refcnt=1;
533534
ob_type=&cppWrapperType;
534535
methods.emplace("__dict__",cppWrapperType.tp_dict);
@@ -581,7 +582,7 @@ struct CppWrapperType: public PyTypeObject
581582
};
582583

583584

584-
PyObject* callOnRegistry(const string& command, const PythonBuffer& arguments)
585+
inline PyObject* callOnRegistry(const string& command, const PythonBuffer& arguments)
585586
{
586587
try
587588
{
@@ -629,31 +630,34 @@ struct CppWrapperType: public PyTypeObject
629630
}
630631
};
631632

632-
void initModule()
633+
namespace
633634
{
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+
}
657661
}
658662
}
659663

0 commit comments

Comments
 (0)