MCPcopy Create free account
hub / github.com/BasisResearch/lean.py / leanpy_keep_alive

Function leanpy_keep_alive

LeanPy/native/python_bridge.c:35–44  ·  view source on GitHub ↗

* 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

Source from the content-addressed store, hash-verified

33 * which breaks Python's FFI assumption that all parameters are owned.
34 */
35LEAN_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.

Callers

nothing calls this directly

Calls 4

lean_is_scalarFunction · 0.85
lean_ptr_tagFunction · 0.85
lean_decFunction · 0.85
lean_boxFunction · 0.85

Tested by

no test coverage detected