success (so a Python __del__ can call this blind). On a live
handle: unwind device residency (engine_exit_data) then release
the god-state’s host-side allocations + the process-global ocean-
halo module state (engine_teardown), then free the handle itself
and clear the single-live-handle guard.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(c_ptr), | intent(inout) | :: | c_handle |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| type(ocean_handle_t), | private, | pointer | :: | h | |||
| integer, | private | :: | hstat |
function rdb_ocean_destroy(c_handle) result(status) & bind(c, name="rdb_ocean_destroy") !! Idempotent: a null/already-destroyed/garbage handle is a no-op !! success (so a Python `__del__` can call this blind). On a live !! handle: unwind device residency (`engine_exit_data`) then release !! the god-state's host-side allocations + the process-global ocean- !! halo module state (`engine_teardown`), then free the handle itself !! and clear the single-live-handle guard. type(c_ptr), intent(inout) :: c_handle integer(c_int) :: status type(ocean_handle_t), pointer :: h integer :: hstat hstat = handle_check(c_handle, h) if (hstat /= HANDLE_OK) then ! Already destroyed, never created, or garbage: idempotent no-op. c_handle = c_null_ptr status = int(OCEAN_STATUS_OK, c_int) return end if if (h%device_mapped) then call engine_exit_data(h%engine) h%device_mapped = .false. end if ! P2.5: a handle that never got past rdb_ocean_create_pending (no ! finalize call, abandoned mid-staging) never ran engine_setup — ! engine%state was never init_from_config'd, ocean_halo_init/ ! engine%geo%init never ran, so there is nothing for engine_teardown ! to tear down. Guard on engine%is_setup (set only at the tail of ! engine_setup) rather than calling it unconditionally. if (h%engine%is_setup) call engine_teardown(h%engine) h%state => null() call handle_destroy(c_handle) g_handle_live = .false. status = int(OCEAN_STATUS_OK, c_int) end function rdb_ocean_destroy