| 391 | } |
| 392 | |
| 393 | LEAN_EXPORT lean_obj_res lean_py_initialize(lean_obj_arg unit, lean_obj_arg world) { |
| 394 | (void)world; |
| 395 | if (py_initialized) { |
| 396 | return lean_io_result_mk_ok(lean_box(0)); |
| 397 | } |
| 398 | if (!try_load_python()) { |
| 399 | return raise_io_error("LeanPy: could not load libpython (set LEANPY_LIBPYTHON to override)"); |
| 400 | } |
| 401 | #define X(ret, name, args) \ |
| 402 | p_##name = (ret (*) args) dlsym(py_handle, #name); \ |
| 403 | if (!p_##name) { \ |
| 404 | return raise_io_error("LeanPy: dlsym failed for " #name); \ |
| 405 | } |
| 406 | PYSYMS |
| 407 | #undef X |
| 408 | /* Singletons. */ |
| 409 | p_Py_None = (PyObject *) dlsym(py_handle, "_Py_NoneStruct"); |
| 410 | p_Py_True = (PyObject *) dlsym(py_handle, "_Py_TrueStruct"); |
| 411 | p_Py_False = (PyObject *) dlsym(py_handle, "_Py_FalseStruct"); |
| 412 | if (!p_Py_None || !p_Py_True || !p_Py_False) { |
| 413 | return raise_io_error("LeanPy: failed to resolve Py_None/True/False"); |
| 414 | } |
| 415 | /* PyExc_RuntimeError is exported as a `PyObject *` global; we want the |
| 416 | * value of the symbol, so dereference once. */ |
| 417 | { |
| 418 | PyObject **slot = (PyObject **) dlsym(py_handle, "PyExc_RuntimeError"); |
| 419 | if (slot) p_PyExc_RuntimeError = *slot; |
| 420 | } |
| 421 | if (!p_Py_IsInitialized()) { |
| 422 | p_Py_Initialize(); |
| 423 | } |
| 424 | py_initialized = 1; |
| 425 | return lean_io_result_mk_ok(lean_box(0)); |
| 426 | } |
| 427 | |
| 428 | LEAN_EXPORT lean_obj_res lean_py_is_initialized(lean_obj_arg unit, lean_obj_arg world) { |
| 429 | (void)world; |
nothing calls this directly
no test coverage detected