Skip to content

Commit

Permalink
workarounds for stack overflows on Windows using ifort
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrueger committed Jul 23, 2024
1 parent 3469376 commit e9b2bdb
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/json_value_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -5904,13 +5904,18 @@ subroutine json_value_to_string(json,p,str)

integer(IK) :: iloc !! used to keep track of size of str
!! since it is being allocated in chunks.
character(kind=CK,len=:),allocatable :: tmp !! temporary buffer for trimming `str`

str = repeat(space, print_str_chunk_size)
iloc = 0_IK
call json%json_value_print(p, iunit=unit2str, str=str, iloc=iloc, indent=1_IK, colon=.true.)

! trim the string if necessary:
if (len(str)>iloc) str = str(1:iloc)
if (len(str)>iloc) then
allocate(character(kind=CK,len=iloc)::tmp)
tmp(1:iloc) = str
call move_alloc(tmp, str)
endif

end subroutine json_value_to_string
!*****************************************************************************************
Expand Down Expand Up @@ -6032,10 +6037,11 @@ recursive subroutine json_value_print(json,p,iunit,str,indent,&
character(kind=CK,len=:),allocatable :: s_indent !! the string of spaces for
!! indenting (see `tab` and `spaces`)
character(kind=CK,len=:),allocatable :: s !! the string appended to `str`
character(kind=CK,len=:),allocatable :: buf !! temporary buffer for extending `str`
type(json_value),pointer :: element !! for getting children
integer(IK) :: tab !! number of `tabs` for indenting
integer(IK) :: spaces !! number of spaces for indenting
integer(IK) :: i !! counter
integer(IK) :: i,j !! counter
integer(IK) :: count !! number of children
logical(LK) :: print_comma !! if the comma will be printed after the value
logical(LK) :: write_file !! if we are writing to a file
Expand Down Expand Up @@ -6376,7 +6382,12 @@ subroutine write_it(advance,comma,space_after_comma)
if (room_left < n) then
! need to add another chunk to fit this string:
n_chunks_to_add = max(1_IK, ceiling( real(len(s)-room_left,RK) / real(chunk_size,RK), IK ) )
str = str // repeat(space, print_str_chunk_size*n_chunks_to_add)
allocate(character(kind=CK, len=len(str)+print_str_chunk_size*n_chunks_to_add)::buf)
buf(1:len(str)) = str
do j = len(str)+1, len(buf)
buf(j:j) = space
enddo
call move_alloc(buf, str)
end if
! append s to str:
str(iloc+1:iloc+n) = s
Expand Down

0 comments on commit e9b2bdb

Please sign in to comment.