Skip to content

Commit 764f89b

Browse files
committed
add a new option to json_file constructor
If nullify_pointer is False, the pointer is not nullified Fixes #564
1 parent c19763f commit 764f89b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/json_file_module.F90

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,8 @@ end subroutine get_json_core_in_file
569569

570570
function initialize_json_file(p,&
571571
#include "json_initialize_dummy_arguments.inc"
572-
) result(file_object)
572+
, nullify_pointer &
573+
) result(file_object)
573574

574575
implicit none
575576

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

582585
call file_object%initialize(&
583586
#include "json_initialize_dummy_arguments.inc"
@@ -588,7 +591,11 @@ function initialize_json_file(p,&
588591
! we have to nullify it to avoid
589592
! a dangling pointer when the file
590593
! goes out of scope
591-
nullify(p)
594+
if (present(nullify_pointer)) then
595+
if (nullify_pointer) nullify(p)
596+
else
597+
nullify(p)
598+
end if
592599
end if
593600

594601
end function initialize_json_file

0 commit comments

Comments
 (0)