@@ -569,7 +569,8 @@ end subroutine get_json_core_in_file
569
569
570
570
function initialize_json_file (p ,&
571
571
#include "json_initialize_dummy_arguments.inc"
572
- ) result(file_object)
572
+ , nullify_pointer &
573
+ ) result(file_object)
573
574
574
575
implicit none
575
576
@@ -578,6 +579,13 @@ function initialize_json_file(p,&
578
579
! ! as a `json_file` object. This
579
580
! ! will be nullified.
580
581
#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). Normally,
584
+ ! ! this should be done, because the [[json_file]] will destroy
585
+ ! ! the pointer when the class goes out of scope (causing `p` to be
586
+ ! ! a dangling pointer). However, if the intent is to use `p` in
587
+ ! ! a [[json_file]] and then call [[json_file:nullify]] and continue
588
+ ! ! to use `p`, then this should be set to False.
581
589
582
590
call file_object% initialize(&
583
591
#include " json_initialize_dummy_arguments.inc"
@@ -588,7 +596,11 @@ function initialize_json_file(p,&
588
596
! we have to nullify it to avoid
589
597
! a dangling pointer when the file
590
598
! goes out of scope
591
- nullify(p)
599
+ if (present (nullify_pointer)) then
600
+ if (nullify_pointer) nullify(p)
601
+ else
602
+ nullify(p)
603
+ end if
592
604
end if
593
605
594
606
end function initialize_json_file
0 commit comments