| 39 | } |
| 40 | |
| 41 | int ExtensionContainerPy::initialization() |
| 42 | { |
| 43 | |
| 44 | if (!this->ob_type->tp_dict) { |
| 45 | if (PyType_Ready(this->ob_type) < 0) { |
| 46 | return 0; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | ExtensionContainer::ExtensionIterator it = this->getExtensionContainerPtr()->extensionBegin(); |
| 51 | for (; it != this->getExtensionContainerPtr()->extensionEnd(); ++it) { |
| 52 | |
| 53 | // The PyTypeObject is shared by all instances of this type and therefore |
| 54 | // we have to add new methods only once. |
| 55 | PyObject* obj = (*it).second->getExtensionPyObject(); |
| 56 | PyMethodDef* meth = obj->ob_type->tp_methods; |
| 57 | PyTypeObject* type = this->ob_type; |
| 58 | PyObject* dict = type->tp_dict; |
| 59 | |
| 60 | // make sure to do the initialization only once |
| 61 | if (meth->ml_name) { |
| 62 | PyObject* item = PyDict_GetItemString(dict, meth->ml_name); |
| 63 | if (!item) { |
| 64 | // Note: this adds the methods to the type object to make sure |
| 65 | // it appears in the call tips. The function will not be bound |
| 66 | // to an instance |
| 67 | Py_INCREF(dict); |
| 68 | while (meth->ml_name) { |
| 69 | PyObject* func; |
| 70 | func = PyCFunction_New(meth, 0); |
| 71 | if (!func) { |
| 72 | break; |
| 73 | } |
| 74 | if (PyDict_SetItemString(dict, meth->ml_name, func) < 0) { |
| 75 | break; |
| 76 | } |
| 77 | Py_DECREF(func); |
| 78 | ++meth; |
| 79 | } |
| 80 | |
| 81 | Py_DECREF(dict); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | Py_DECREF(obj); |
| 86 | } |
| 87 | return 1; |
| 88 | } |
| 89 | |
| 90 | int ExtensionContainerPy::finalization() |
| 91 | { |
nothing calls this directly
no test coverage detected