| 185 | } |
| 186 | |
| 187 | PyObject* 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 |
no test coverage detected