Skip to content

Commit fd224fa

Browse files
committed
Merge pull request #162 from jacobwilliams/clone
Clone
2 parents d0adc46 + b53c9a6 commit fd224fa

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/json_module.F90

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,11 +1004,12 @@ recursive subroutine json_value_clone_func(from,to,parent,previous,next,children
10041004
allocate(to)
10051005

10061006
!copy over the data variables:
1007-
1008-
if (allocated(from%name)) allocate(to%name, source=from%name)
1007+
! [note: the allocate() statements don't work here for the
1008+
! deferred-length characters in gfortran-4.9]
1009+
if (allocated(from%name)) to%name = from%name
10091010
if (allocated(from%dbl_value)) allocate(to%dbl_value,source=from%dbl_value)
10101011
if (allocated(from%log_value)) allocate(to%log_value,source=from%log_value)
1011-
if (allocated(from%str_value)) allocate(to%str_value,source=from%str_value)
1012+
if (allocated(from%str_value)) to%str_value = from%str_value
10121013
if (allocated(from%int_value)) allocate(to%int_value,source=from%int_value)
10131014
to%var_type = from%var_type
10141015
to%n_children = from%n_children

src/tests/jf_test_2.f90

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ subroutine test_2(error_cnt)
2828
type(json_value),pointer :: p, inp, traj, p_tmp, p_integer_array, p_clone
2929

3030
integer :: iunit
31-
character(len=:),allocatable :: name
31+
character(kind=CK,len=:),allocatable :: name
3232
integer :: ival,ival_clone
3333
logical :: found
3434

@@ -152,6 +152,18 @@ subroutine test_2(error_cnt)
152152

153153
write(error_unit,'(A)') 'json_clone test'
154154
call json_clone(p,p_clone)
155+
156+
write(error_unit,'(A)') ''
157+
write(error_unit,'(A)') '============='
158+
write(error_unit,'(A)') ' p_clone'
159+
write(error_unit,'(A)') '============='
160+
call json_print(p_clone,error_unit)
161+
write(error_unit,'(A)') '============='
162+
write(error_unit,'(A)') ''
163+
164+
if (.not. associated(p)) write(error_unit,'(A)') 'ERROR: p has become unassociated'
165+
if (.not. associated(p_clone)) write(error_unit,'(A)') 'ERROR: p_clone is not associated'
166+
155167
if (json_failed()) then
156168
call json_print_error_message(error_unit)
157169
error_cnt = error_cnt + 1

0 commit comments

Comments
 (0)