| 541 | PyObject *tup = p_PyTuple_New((Py_ssize_t)n); |
| 542 | if (!tup) return raise_py_error(); |
| 543 | for (size_t i = 0; i < n; i++) { |
| 544 | lean_object *elem = lean_array_get_core(arr, i); |
| 545 | PyObject *po = unwrap_pyobject(elem); |
| 546 | p_Py_IncRef(po); |
| 547 | p_PyTuple_SetItem(tup, (Py_ssize_t)i, po); |
| 548 | } |
| 549 | return lean_io_result_mk_ok(wrap_pyobject(tup)); |
| 550 | } |
| 551 | |
| 552 | LEAN_EXPORT lean_obj_res lean_py_of_dict(b_lean_obj_arg arr, lean_obj_arg world) { |
| 553 | (void)world; ENSURE_INIT(); WITH_GIL(); |
| 554 | PyObject *d = p_PyDict_New(); |
| 555 | if (!d) return raise_py_error(); |
| 556 | size_t n = lean_array_size(arr); |
| 557 | for (size_t i = 0; i < n; i++) { |
| 558 | /* Each element is a Prod Py Py — a 2-arg ctor object. */ |
| 559 | lean_object *kv = lean_array_get_core(arr, i); |
| 560 | lean_object *kobj = lean_ctor_get(kv, 0); |
| 561 | lean_object *vobj = lean_ctor_get(kv, 1); |
| 562 | PyObject *k = unwrap_pyobject(kobj); |
| 563 | PyObject *v = unwrap_pyobject(vobj); |
| 564 | if (p_PyDict_SetItem(d, k, v) != 0) { |
nothing calls this directly
no test coverage detected