Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a new option to json_file constructor #566

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 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,13 @@ 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). Normally,
!! this should be done, because the [[json_file]] will destroy
!! the pointer when the class goes out of scope (causing `p` to be
!! a dangling pointer). However, if the intent is to use `p` in
!! a [[json_file]] and then call [[json_file:nullify]] and continue
!! to use `p`, then this should be set to False.

call file_object%initialize(&
#include "json_initialize_dummy_arguments.inc"
Expand All @@ -588,7 +596,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