Skip to content

Commit

Permalink
changed errors to allocatable instead of pointers. This prevents smal…
Browse files Browse the repository at this point in the history
…l memeory leaks
  • Loading branch information
Nicholaswogan committed Feb 19, 2022
1 parent 31259bb commit 1c81b18
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
12 changes: 6 additions & 6 deletions example.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,35 +28,35 @@ 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

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
Expand Down
17 changes: 7 additions & 10 deletions yaml_types.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 1c81b18

Please sign in to comment.