| 499 | return true; |
| 500 | } |
| 501 | handle type_caster<OpDef>::cast(const OpDef& op, return_value_policy, handle) { |
| 502 | if (auto* pyop = op.try_cast_final<GenericPyOp>()) { |
| 503 | return object(pyop->obj).release(); |
| 504 | } |
| 505 | PyTypeObject* pytype; |
| 506 | auto& c2p = PyOp(OpDef)::ctype2pytype; |
| 507 | auto&& iter = c2p.find(op.dyn_typeinfo()); |
| 508 | if (iter != c2p.end()) { // FIXME: should always meet this condition |
| 509 | pytype = iter->second; |
| 510 | } else { // which means unregistered op type, jsut make it as an opaque op type |
| 511 | // currently, only OprAttr goes into this branch |
| 512 | pytype = &PyOpType(OpDef); |
| 513 | } |
| 514 | PyObject* obj = pytype->tp_alloc(pytype, 0); |
| 515 | mgb_assert(PyObject_TypeCheck(obj, &PyOpType(OpDef))); |
| 516 | reinterpret_cast<PyOp(OpDef)*>(obj)->op = const_cast<OpDef&>(op).shared_from_this(); |
| 517 | return py::handle(obj); |
| 518 | } |
| 519 | |
| 520 | #define ENUM_CASTER_IMPL(T) \ |
| 521 | bool type_caster<T>::load(handle src, bool) { \ |
no test coverage detected