Skip to content

Commit

Permalink
Merge pull request #479 from jacobwilliams/477-remove-bug-fix
Browse files Browse the repository at this point in the history
bug fix in json_value_remove
  • Loading branch information
jacobwilliams authored Jan 2, 2021
2 parents 690a8bd + 7df56d4 commit 8c12e7a
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.2.0
8.2.1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ builds/
build/
install/
doc/
.vscode/

*.gcov
*.gcov.md*
Expand Down
22 changes: 19 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

- [Change Log](#change-log)
- [Unreleased](#unreleased)
- [8.2.0 (2020-08-16)](#800-2020-08-16)
- [8.1.0 (2020-06-21)](#800-2020-06-21)
- [8.2.1 (2021-01-02)](#821-2021-01-02)
- [8.2.0 (2020-08-16)](#820-2020-08-16)
- [8.1.0 (2020-06-21)](#810-2020-06-21)
- [8.0.0 (2020-04-04)](#800-2020-04-04)
- [7.1.0 (2019-06-23)](#710-2019-06-23)
- [7.0.0 (2019-01-26)](#700-2019-01-26)
Expand Down Expand Up @@ -39,7 +40,22 @@

### [Unreleased](https://github.com/jacobwilliams/json-fortran/tree/HEAD)

[Complete Changeset](https://github.com/jacobwilliams/json-fortran/compare/8.2.0...HEAD)
[Complete Changeset](https://github.com/jacobwilliams/json-fortran/compare/8.2.1...HEAD)

### [8.2.1](https://github.com/jacobwilliams/json-fortran/tree/8.2.1) (2020-01-02)

[Complete Changeset](https://github.com/jacobwilliams/json-fortran/compare/8.2.0...8.2.1)
or [Download v8.2.1](https://github.com/jacobwilliams/json-fortran/releases/tag/8.2.1)

**Enhancements:**

- Fixed a couple compiler warnings when using the latest Intel Fortran compiler. [\#477](https://github.com/jacobwilliams/json-fortran/issues/480) ([jacobwilliams](https://github.com/jacobwilliams))
- replaced `-std15` with `-std18` for the Intel compiler in the FoBiS build file.
- Updated the Visual Studio test project with some missing test cases. ([jacobwilliams](https://github.com/jacobwilliams))

**Bug fixes:**

- Bug fix in `json_value_remove`: the parent and previous pointers should also be nullified when removing from an array. [\#477](https://github.com/jacobwilliams/json-fortran/issues/477) [\#479](https://github.com/jacobwilliams/json-fortran/pull/479) ([jacobwilliams](https://github.com/jacobwilliams))

### [8.2.0](https://github.com/jacobwilliams/json-fortran/tree/8.2.0) (2020-08-16)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ cmake_minimum_required ( VERSION 2.8.8 FATAL_ERROR )
enable_language ( Fortran )
project ( jf_test NONE )
find_package ( jsonfortran-${CMAKE_Fortran_COMPILER_ID} 8.2.0 REQUIRED )
find_package ( jsonfortran-${CMAKE_Fortran_COMPILER_ID} 8.2.1 REQUIRED )
include_directories ( "${jsonfortran_INCLUDE_DIRS}" )
file ( GLOB JF_TEST_SRCS "src/tests/jf_test_*.F90" )
Expand Down
4 changes: 2 additions & 2 deletions json-fortran.fobis
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ $SHARED_LIB = libjsonfortran.so
$OPTIMIZE = -O2
$CSTATIC_GNU = -c -fbacktrace -Wall -Wextra -Wno-maybe-uninitialized -Wno-unused-function -pedantic -std=f2008ts
$DEBUG_GNU = -O0 -g3 -Warray-bounds -Wcharacter-truncation -Wline-truncation -Wimplicit-interface -Wimplicit-procedure -Wunderflow -fcheck=all -fmodule-private -ffree-line-length-132 -fimplicit-none -fbacktrace -fdump-core -finit-real=nan -std=f2008ts -fall-intrinsics
$CSTATIC_INT = -c -std15
$DEBUG_INT = -O0 -debug all -check all -warn all -extend-source 132 -traceback -gen-interfaces -fpe-all=0 -fp-stack-check -fstack-protector-all -ftrapuv -no-ftz -std15
$CSTATIC_INT = -c -std18
$DEBUG_INT = -O0 -debug all -check all -warn all -extend-source 132 -traceback -gen-interfaces -fpe-all=0 -fp-stack-check -fstack-protector-all -ftrapuv -no-ftz -std18
$EXCLUDE_DIRS = ./src/tests/introspection
./visual_studio/jsonfortrantest

Expand Down
3 changes: 3 additions & 0 deletions pages/releases/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ documentation from the documentation for official releases other than
using the browser's back button. Feel free to bookmark this page, or
the [main project page](|url|/index.html) for convenient navigation.

* [8.2.1](http://jacobwilliams.github.io/json-fortran/8.2.1/index.html)
([FORD](https://github.com/Fortran-FOSS-Programmers/ford) generated documentation)
- [Download](https://github.com/jacobwilliams/json-fortran/releases/tag/8.2.1)
* [8.2.0](http://jacobwilliams.github.io/json-fortran/8.2.0/index.html)
([FORD](https://github.com/Fortran-FOSS-Programmers/ford) generated documentation)
- [Download](https://github.com/jacobwilliams/json-fortran/releases/tag/8.2.0)
Expand Down
2 changes: 1 addition & 1 deletion src/json_parameters.F90
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module json_parameters
!! [[json_get_by_path_default]]
character(kind=CK,len=*),parameter :: end_array_alt = CK_')' !! alternate end of JSON array for
!! [[json_get_by_path_default]]
character(kind=CK,len=*),parameter :: root = CK_'$' !! root for [[json_get_by_path_default]]
character(kind=CK,len=*),parameter :: root = achar(36, kind=CK) !! (`$`) root for [[json_get_by_path_default]]
character(kind=CK,len=*),parameter :: this = CK_'@' !! 'this' for [[json_get_by_path_default]]
character(kind=CK,len=*),parameter :: dot = CK_'.' !! path separator for [[json_get_by_path_default]]
character(kind=CK,len=*),parameter :: tilde = CK_'~' !! RFC 6901 escape character
Expand Down
2 changes: 1 addition & 1 deletion src/json_string_utilities.F90
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ end function default_neq_ucs4
!
! Returns lowercase version of the `CK` string.

pure elemental function lowercase_string(str) result(s_lower)
pure function lowercase_string(str) result(s_lower)

implicit none

Expand Down
8 changes: 6 additions & 2 deletions src/json_value_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2340,6 +2340,7 @@ end subroutine json_value_destroy
!
!### History
! * Jacob Williams : 12/28/2014 : added destroy optional argument.
! * Jacob Williams : 12/04/2020 : bug fix.

subroutine json_value_remove(json,p,destroy)

Expand Down Expand Up @@ -2374,9 +2375,7 @@ subroutine json_value_remove(json,p,destroy)
if (associated(p%next)) then

!there are later items in the list:

next => p%next
nullify(p%next)

if (associated(p%previous)) then
!there are earlier items in the list
Expand Down Expand Up @@ -2404,6 +2403,11 @@ subroutine json_value_remove(json,p,destroy)

end if

! nullify all pointers to original structure:
nullify(p%next)
nullify(p%previous)
nullify(p%parent)

parent%n_children = parent%n_children - 1

end if
Expand Down
146 changes: 146 additions & 0 deletions src/tests/jf_test_47.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
!*****************************************************************************************
!>
! Module for the 47th unit test

module jf_test_47_mod

use json_module, CK => json_CK, IK => json_IK, RK => json_RK, LK => json_LK
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit

implicit none

private
public :: test_47

contains

subroutine test_47(error_cnt)

!! testing of `remove`.

implicit none

integer,intent(out) :: error_cnt !! error counter

character(kind=CK,len=*), parameter :: STR = CK_'&
&{&
& "object1": {&
& "a": 1,&
& "b": 2,&
& "move1": 3,&
& "move2": 4,&
& "e": 5 &
& },&
& "object2": {&
& "f": 10,&
& "g": 11,&
& "h": 12,&
& "i": 13,&
& "j": 14 &
& }&
&}'

character(kind=CK,len=:), allocatable :: errtxt
type(json_core) :: json
type(json_value), pointer :: inp, p, p2
logical(LK) :: found, status_ok
integer(IK) :: ival

write(error_unit,'(A)') ''
write(error_unit,'(A)') '================================='
write(error_unit,'(A)') ' TEST 47'
write(error_unit,'(A)') '================================='
write(error_unit,'(A)') ''

call json%deserialize(inp, STR)
call json%check_for_errors(status_ok, errtxt)
if (.not. status_ok) then
write(error_unit,'(A)') errtxt
error_cnt = error_cnt + 1
else
call json%print(inp)
write(error_unit,'(A)') ''
write(error_unit,'(A)') 'Move object1.move1 to object2 [clone]...'
call json%get(inp, 'object1.move1', p, found)
if (found) then
call json%clone(p, p2)
call json%remove(p, .true.)
call json%add_by_path(inp, 'object2.move1', p2)
end if
write(error_unit,'(A)') ''
call json%print(inp)
write(error_unit,'(A)') ''
call json%get(inp, 'object2.move1', ival, found)
if (.not. found) then
write(error_unit,'(A)') 'Error moving move1'
error_cnt = error_cnt + 1
else
if (ival==3_IK) then
write(error_unit,'(A)') '...Success'
else
write(error_unit,'(A,1X,I5)') 'Invalid move1 value: ', ival
error_cnt = error_cnt + 1
end if
end if

write(error_unit,'(A)') ''
write(error_unit,'(A)') 'Move object1.move2 to object2...'

call json%get(inp, 'object1.move2', p, found)
if (found) then
call json%remove(p, .false.)
call json%add_by_path(inp, 'object2.move2', p)
end if
write(error_unit,'(A)') ''
call json%print(inp)
write(error_unit,'(A)') ''
call json%get(inp, 'object2.move2', ival, found)
if (.not. found) then
write(error_unit,'(A)') 'Error moving move2'
error_cnt = error_cnt + 1
else
if (ival==4_IK) then
write(error_unit,'(A)') '...Success'
else
write(error_unit,'(A,1X,I5)') 'Invalid move2 value: ', ival
error_cnt = error_cnt + 1
end if
end if

call json%check_for_errors(status_ok, errtxt)
if (.not. status_ok) then
write(error_unit,'(A)') errtxt
error_cnt = error_cnt + 1
end if

end if

write(error_unit,'(A)') ''
if (error_cnt==0) then
write(error_unit,'(A)') 'Success!'
else
write(error_unit,'(A)') 'Failed!'
end if
write(error_unit,'(A)') ''

end subroutine test_47

end module jf_test_47_mod
!*****************************************************************************************

#ifndef INTEGRATED_TESTS
!*****************************************************************************************
program jf_test_47

!! 47th unit test.

use jf_test_47_mod , only: test_47
implicit none
integer :: n_errors
n_errors = 0
call test_47(n_errors)
if (n_errors /= 0) stop 1

end program jf_test_47
!*****************************************************************************************
#endif
6 changes: 6 additions & 0 deletions visual_studio/jsonfortrantest/jsonfortrantest.f90
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ program jsonfortrantest
use jf_test_40_mod , only: test_40
use jf_test_41_mod , only: test_41
use jf_test_42_mod , only: test_42
use jf_test_43_mod , only: test_43
use jf_test_44_mod , only: test_44
use jf_test_45_mod , only: test_45
use jf_test_46_mod , only: test_46
use jf_test_47_mod , only: test_47

implicit none

Expand Down Expand Up @@ -102,6 +107,7 @@ program jsonfortrantest
call test_44(n_errors); if (n_errors /= 0) stop 1
call test_45(n_errors); if (n_errors /= 0) stop 1
call test_46(n_errors); if (n_errors /= 0) stop 1
call test_47(n_errors); if (n_errors /= 0) stop 1

end program jsonfortrantest
!*****************************************************************************************
Expand Down
1 change: 1 addition & 0 deletions visual_studio/jsonfortrantest/jsonfortrantest.vfproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,6 @@
<File RelativePath="..\..\src\tests\jf_test_44.F90"/>
<File RelativePath="..\..\src\tests\jf_test_45.F90"/>
<File RelativePath="..\..\src\tests\jf_test_46.F90"/>
<File RelativePath="..\..\src\tests\jf_test_47.F90"/>
<File RelativePath=".\jsonfortrantest.f90"/></Filter></Files>
<Globals/></VisualStudioProject>

0 comments on commit 8c12e7a

Please sign in to comment.