handle_destroy Subroutine

public subroutine handle_destroy(c_handle)

Free an ocean handle. Idempotent on null/already-destroyed/garbage handles — silently no-ops rather than aborting, so a Python __del__ can call this blind. Caller is responsible for having already unwound device residency and called engine_teardown (engine%state%destroy() releases the god-state’s Fortran allocations) — h%state is only a pointer VIEW onto h%engine%state (see ocean_handle_t’s docstring), never separately allocated, so there is nothing to deallocate through it here; this only releases the handle’s own heap block (which takes engine — a value component — down with it). garbage or already destroyed

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(inout) :: c_handle

Called by

proc~~handle_destroy~~CalledByGraph proc~handle_destroy handle_destroy proc~build_pending_handle build_pending_handle proc~build_pending_handle->proc~handle_destroy proc~complete_ocean_create complete_ocean_create proc~complete_ocean_create->proc~handle_destroy proc~rdb_ocean_destroy rdb_ocean_destroy proc~rdb_ocean_destroy->proc~handle_destroy proc~rdb_ocean_create_finalize rdb_ocean_create_finalize proc~rdb_ocean_create_finalize->proc~complete_ocean_create proc~rdb_ocean_create_from_string rdb_ocean_create_from_string proc~rdb_ocean_create_from_string->proc~build_pending_handle proc~rdb_ocean_create_from_string->proc~complete_ocean_create proc~rdb_ocean_create_pending rdb_ocean_create_pending proc~rdb_ocean_create_pending->proc~build_pending_handle

Variables

Type Visibility Attributes Name Initial
type(ocean_handle_t), private, pointer :: h

Source Code

   subroutine handle_destroy(c_handle)
      !! Free an ocean handle. Idempotent on null/already-destroyed/garbage
      !! handles — silently no-ops rather than aborting, so a Python
      !! `__del__` can call this blind. Caller is responsible for having
      !! already unwound device residency and called `engine_teardown`
      !! (`engine%state%destroy()` releases the god-state's Fortran
      !! allocations) — `h%state` is only a pointer VIEW onto
      !! `h%engine%state` (see `ocean_handle_t`'s docstring), never
      !! separately allocated, so there is nothing to deallocate through
      !! it here; this only releases the handle's own heap block
      !! (which takes `engine` — a value component — down with it).
      type(c_ptr), intent(inout) :: c_handle
      type(ocean_handle_t), pointer :: h

      if (.not. c_associated(c_handle)) return
      call c_f_pointer(c_handle, h)
      if (h%magic /= MAGIC_OCEAN) return   !! garbage or already destroyed
      h%magic = MAGIC_DESTROYED
      h%state => null()
      deallocate (h)
      c_handle = c_null_ptr
   end subroutine handle_destroy