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

Method _resolve_init_symbol

lean_py/library.py:461–496  ·  view source on GitHub ↗

Resolve the module-initializer symbol, allowing for the Lake-naming variations Lean has gone through. The canonical name is `initialize_ `, but newer toolchains sometimes prefix the package or use double underscores. As a last resort we ask `nm` for any `initiali

(self)

Source from the content-addressed store, hash-verified

459 setattr(self, fi.exportName, wrap)
460
461 # -- internal ---------------------------------------------------------
462
463 _task_manager_initialized: bool = False
464
465 def _ensure_task_manager(self) -> None:
466 """Initialise Lean's task manager once per process.
467
468 `Lean.importModules` (and any kernel operation that allocates a
469 `Task`) asserts on `g_task_manager` being non-null. The Lean
470 executable runtime does this for you in `lean_main`; when we host
471 Lean inside Python we need to call it ourselves. Idempotent.
472 """
473 if LeanLibrary._task_manager_initialized:
474 return
475 # The symbol lives in libleanshared, not the user dylib.
476 # Try the user dylib first (works on macOS with RTLD_GLOBAL),
477 # then fall back to the FFI's lean shared lib handle.
478 init = None
479 for handle in (self.lib, self.ffi.lib):
480 try:
481 init = handle.lean_init_task_manager
482 break
483 except AttributeError:
484 continue
485 if init is None:
486 return
487 init.argtypes = []
488 init.restype = None
489 init()
490 LeanLibrary._task_manager_initialized = True
491
492 def _resolve_init_symbol(self) -> str:
493 """Resolve the module-initializer symbol, allowing for the
494 Lake-naming variations Lean has gone through.
495
496 The canonical name is `initialize_<lib>`, but newer toolchains
497 sometimes prefix the package or use double underscores. As a
498 last resort we ask `nm` for any `initialize_*` symbol exported
499 by the dylib and pick the best fit."""

Callers 1

Calls 1

_list_init_symbolsFunction · 0.85

Tested by

no test coverage detected