MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / createPyObject

Function createPyObject

src/Base/TypePyImp.cpp:187–212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

185}
186
187PyObject* createPyObject(BaseClass* base)
188{
189 PyObject* py = base->getPyObject();
190
191 if (PyObject_TypeCheck(py, &PyObjectBase::Type)) {
192 // if the Python wrapper is a sub-class of PyObjectBase then
193 // check if the C++ object must be added to the list of tracked objects
194 PyObjectBase* pybase = static_cast<PyObjectBase*>(py);
195 if (base == pybase->getTwinPointer()) {
196 // steal a reference because at this point the counter is at 2
197 Py_DECREF(py);
198 Py_TYPE(py)->tp_dealloc = deallocPyObject;
199 BindingManager::instance().registerWrapper(base, py);
200 }
201 else {
202 // The Python wrapper creates its own copy of the C++ object
203 delete base;
204 }
205 }
206 else {
207 // if the Python wrapper is not a sub-class of PyObjectBase then
208 // immediately destroy the C++ object
209 delete base;
210 }
211 return py;
212}
213
214} // namespace
215

Callers 1

createInstanceByNameMethod · 0.85

Calls 3

instanceFunction · 0.50
getPyObjectMethod · 0.45
registerWrapperMethod · 0.45

Tested by

no test coverage detected