| 8621 | } |
| 8622 | |
| 8623 | PyObject *pyrna_struct_CreatePyObject(PointerRNA *ptr) |
| 8624 | { |
| 8625 | /* NOTE: don't rely on this to return None since nullptr data with a valid type can often crash. |
| 8626 | */ |
| 8627 | if (ptr->data == nullptr && ptr->type == nullptr) { /* Operator RNA has nullptr data. */ |
| 8628 | Py_RETURN_NONE; |
| 8629 | } |
| 8630 | |
| 8631 | BPy_StructRNA *pyrna = nullptr; |
| 8632 | |
| 8633 | /* NOTE(@ideasman42): New in 2.8x, since not many types support instancing |
| 8634 | * we may want to use a flag to avoid looping over all classes. */ |
| 8635 | void **instance = ptr->data ? RNA_struct_instance(ptr) : nullptr; |
| 8636 | if (instance && *instance) { |
| 8637 | pyrna = static_cast<BPy_StructRNA *>(*instance); |
| 8638 | |
| 8639 | /* Refine may have changed types after the first instance was created. */ |
| 8640 | if (ptr->type == pyrna->ptr->type) { |
| 8641 | Py_INCREF(pyrna); |
| 8642 | return reinterpret_cast<PyObject *>(pyrna); |
| 8643 | } |
| 8644 | |
| 8645 | /* Existing users will need to use 'type_recast' method. */ |
| 8646 | Py_DECREF(pyrna); |
| 8647 | *instance = nullptr; |
| 8648 | /* Continue as if no instance was available. */ |
| 8649 | } |
| 8650 | |
| 8651 | PyTypeObject *tp = reinterpret_cast<PyTypeObject *>(pyrna_struct_Subtype(ptr)); |
| 8652 | pyrna = reinterpret_cast<BPy_StructRNA *>( |
| 8653 | pyrna_struct_CreatePyObject_from_type(ptr, tp, instance)); |
| 8654 | Py_XDECREF(tp); /* `srna` owns, can't hold a reference. */ |
| 8655 | |
| 8656 | return reinterpret_cast<PyObject *>(pyrna); |
| 8657 | } |
| 8658 | |
| 8659 | PyObject *pyrna_struct_CreatePyObject_with_primitive_support(PointerRNA *ptr) |
| 8660 | { |
no test coverage detected