unset_prev Subroutine

private subroutine unset_prev(this, deallocate_old)

Arguments

Type IntentOptional AttributesName
class(bidir_node), intent(inout) :: this
logical, intent(in), optional :: deallocate_old

Whether to deallocate (rather than just nullify) any existing p nodes in the chain. Defaults to .false..

Description

Unsets the pointer to the previous node in the chain, severing it. By default, the pointer is only nullified. This may result in a memory leak. Optionally, by setting deallocate_old=.true., the previous node (and all previous nodes it points to) can be deallocated. This may result in a segfault if another part of the program tries to access the former previous node.


Source Code

  subroutine unset_prev(this, deallocate_old)
    !* Author: Chris MacMackin
    !  Date: February 2016
    ! 
    ! Unsets the pointer to the previous node in the chain, severing it.
    ! By default, the pointer is only nullified. This may result in a
    ! memory leak. Optionally, by setting `deallocate_old=.true.`, the
    ! previous node (and all previous nodes it points to) can be
    ! deallocated. This may result in a segfault if another part of the
    ! program tries to access the former previous node.
    !
    class(bidir_node), intent(inout) :: this
    logical, optional, intent(in) :: deallocate_old
      !! Whether to deallocate (rather than just nullify) any existing
      !! p nodes in the chain. Defaults to `.false.`.
    if (.not. this%has_prev()) return
    if (present(deallocate_old)) then
      if (deallocate_old) then
        call this%prev%unset_prev(.true.)
        deallocate(this%prev)
        return
      end if
    end if
    nullify(this%prev)
  end subroutine unset_prev