Skip to content

Commit

Permalink
add a new option to json_file constructor
Browse files Browse the repository at this point in the history
If nullify_pointer is False, the pointer is not nullified
Fixes #564
  • Loading branch information
jacobwilliams committed Jun 1, 2024
1 parent c19763f commit 764f89b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/json_file_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ end subroutine get_json_core_in_file

function initialize_json_file(p,&
#include "json_initialize_dummy_arguments.inc"
) result(file_object)
, nullify_pointer &
) result(file_object)

implicit none

Expand All @@ -578,6 +579,8 @@ function initialize_json_file(p,&
!! as a `json_file` object. This
!! will be nullified.
#include "json_initialize_arguments.inc"
logical(LK),intent(in),optional :: nullify_pointer !! if True, then `p` will be nullified
!! if present. (default is True)

call file_object%initialize(&
#include "json_initialize_dummy_arguments.inc"
Expand All @@ -588,7 +591,11 @@ function initialize_json_file(p,&
! we have to nullify it to avoid
! a dangling pointer when the file
! goes out of scope
nullify(p)
if (present(nullify_pointer)) then
if (nullify_pointer) nullify(p)
else
nullify(p)
end if
end if

end function initialize_json_file
Expand Down

0 comments on commit 764f89b

Please sign in to comment.