| 487 | namespace PYBIND11_NAMESPACE { |
| 488 | namespace detail { |
| 489 | bool type_caster<OpDef>::load(handle src, bool convert) { |
| 490 | PyObject* obj = src.ptr(); |
| 491 | if (!PyObject_TypeCheck(obj, &PyOpType(OpDef))) { |
| 492 | return false; |
| 493 | } |
| 494 | value = reinterpret_cast<PyOp(OpDef)*>(obj)->op; |
| 495 | if (!value) { |
| 496 | // opdef only defined in Python |
| 497 | value = std::make_shared<GenericPyOp>(reinterpret_borrow<object>(src)); |
| 498 | } |
| 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(); |