From 1c81b18dc8779db3a9f8da41aa65186101329c33 Mon Sep 17 00:00:00 2001 From: Nick Wogan Date: Sat, 19 Feb 2022 13:39:22 -0800 Subject: [PATCH] changed errors to allocatable instead of pointers. This prevents small memeory leaks --- example.f90 | 12 ++++++------ yaml_types.f90 | 17 +++++++---------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/example.f90 b/example.f90 index 5ae823b..4016c0b 100644 --- a/example.f90 +++ b/example.f90 @@ -11,7 +11,7 @@ program example class(type_dictionary), pointer :: dict class (type_list), pointer :: list class (type_list_item), pointer :: item - type (type_error), pointer :: io_err + type (type_error), allocatable :: io_err character(len=:), allocatable :: string real(real_kind) :: pi @@ -28,7 +28,7 @@ program example print'(A,i3)','Number of key-value pairs in root dictionary = ',root%size() pi = root%get_real('pi',error=io_err) - if (associated(io_err)) then + if (allocated(io_err)) then print*,trim(io_err%message) stop 1 endif @@ -36,27 +36,27 @@ program example print*,'pi =',pi happy = root%get_logical('happy-today',error=io_err) - if (associated(io_err)) then + if (allocated(io_err)) then print*,trim(io_err%message) stop 1 endif print*,"happy: ",happy dict => root%get_dictionary('reaction',required=.true.,error=io_err) - if (associated(io_err)) then + if (allocated(io_err)) then print*,trim(io_err%message) stop 1 endif string = trim(dict%get_string("equation",error = io_err)) - if (associated(io_err)) then + if (allocated(io_err)) then print*,trim(io_err%message) stop 1 endif print*,"reaction equation = ",string list => root%get_list('groceries',required=.true.,error=io_err) - if (associated(io_err)) then + if (allocated(io_err)) then print*,trim(io_err%message) stop 1 endif diff --git a/yaml_types.f90 b/yaml_types.f90 index 34c6617..e7a0781 100644 --- a/yaml_types.f90 +++ b/yaml_types.f90 @@ -322,12 +322,11 @@ function dictionary_get_scalar(self,key,required,error) result(scalar) class (type_dictionary), intent(in) :: self character(len=*), intent(in) :: key logical, intent(in) :: required - type(type_error),pointer :: error + type(type_error),allocatable :: error class (type_scalar),pointer :: scalar class (type_node),pointer :: node - nullify(error) nullify(scalar) node => self%get(key) if (required.and..not.associated(node)) then @@ -355,12 +354,11 @@ function dictionary_get_dictionary(self,key,required,error) result(dictionary) class (type_dictionary), intent(in) :: self character(len=*), intent(in) :: key logical, intent(in) :: required - type(type_error),pointer :: error + type(type_error),allocatable :: error class (type_dictionary),pointer :: dictionary class (type_node),pointer :: node - nullify(error) nullify(dictionary) node => self%get(key) if (required.and..not.associated(node)) then @@ -385,12 +383,11 @@ function dictionary_get_list(self,key,required,error) result(list) class (type_dictionary), intent(in) :: self character(len=*), intent(in) :: key logical, intent(in) :: required - type(type_error),pointer :: error + type(type_error),allocatable :: error class (type_list),pointer :: list class (type_node),pointer :: node - nullify(error) nullify(list) node => self%get(key) if (required.and..not.associated(node)) then @@ -414,7 +411,7 @@ function dictionary_get_string(self,key,default,error) result(value) class (type_dictionary), intent(in) :: self character(len=*), intent(in) :: key character(len=*),optional,intent(in) :: default - type(type_error),pointer :: error + type(type_error),allocatable :: error character(len=string_length) :: value class(type_scalar),pointer :: node @@ -428,7 +425,7 @@ function dictionary_get_logical(self,key,default,error) result(value) class (type_dictionary), intent(in) :: self character(len=*), intent(in) :: key logical, optional,intent(in) :: default - type(type_error),pointer :: error + type(type_error),allocatable :: error logical :: value class (type_scalar),pointer :: node @@ -450,7 +447,7 @@ function dictionary_get_integer(self,key,default,error) result(value) class (type_dictionary), intent(in) :: self character(len=*), intent(in) :: key integer, optional,intent(in) :: default - type(type_error),pointer :: error + type(type_error),allocatable :: error integer :: value class (type_scalar),pointer :: node @@ -471,7 +468,7 @@ function dictionary_get_real(self,key,default,error) result(value) class (type_dictionary), intent(in) :: self character(len=*), intent(in) :: key real(real_kind), optional,intent(in) :: default - type(type_error),pointer :: error + type(type_error),allocatable :: error real(real_kind) :: value class (type_scalar),pointer :: node