* Called from Lean @[extern "leanpy_keep_alive"] to force the compiler * to treat the parameter as owned (consumed). The function simply * decrements the refcount (consuming the owned reference) and returns * IO.ok (). Without this, the Lean compiler's borrowing inference may * make @[export] functions borrow arguments instead of consuming them, * which breaks Python's FFI assumption that all
| 33 | * which breaks Python's FFI assumption that all parameters are owned. |
| 34 | */ |
| 35 | LEAN_EXPORT lean_obj_res leanpy_keep_alive(lean_obj_arg x, lean_obj_arg w) { |
| 36 | #ifdef LEANPY_RC_DEBUG |
| 37 | if (!lean_is_scalar(x)) { |
| 38 | fprintf(stderr, "[keepAlive] ptr=%p m_rc=%d tag=%u -> dec\n", |
| 39 | (void*)x, (int)x->m_rc, (unsigned)lean_ptr_tag(x)); |
| 40 | } |
| 41 | #endif |
| 42 | lean_dec(x); |
| 43 | return lean_io_result_mk_ok(lean_box(0)); |
| 44 | } |
| 45 | |
| 46 | /* |
| 47 | * Debug helper: read the m_rc of a lean_object* passed from Python. |
nothing calls this directly
no test coverage detected