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

Workarounds for stack overflows on Windows when using ifort #577

Merged
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
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