| 160 | } |
| 161 | |
| 162 | PyObject* PyExtensionType::GetInstance() const { |
| 163 | if (!type_instance_) { |
| 164 | PyErr_SetString(PyExc_TypeError, "Not an instance"); |
| 165 | return nullptr; |
| 166 | } |
| 167 | ARROW_DCHECK(PyWeakref_CheckRef(type_instance_.obj())); |
| 168 | PyObject* inst = NULL; |
| 169 | int result = PyWeakref_GetRef(type_instance_.obj(), &inst); |
| 170 | if (result == 1) { |
| 171 | // Alive: inst is a new strong reference |
| 172 | return inst; |
| 173 | } else if (result == 0) { |
| 174 | // Weakref is dead, must reconstruct from serialized form |
| 175 | // XXX cache again? |
| 176 | return DeserializeExtInstance(type_class_.obj(), storage_type_, serialized_); |
| 177 | } else { |
| 178 | // -1 = exception |
| 179 | return nullptr; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | Status PyExtensionType::SetInstance(PyObject* inst) const { |
| 184 | // Check we have the right type |
no test coverage detected