Skip to content

Commit

Permalink
Merge pull request #2484 from GEOS-ESM/hotfix/nag-dangling-pointers
Browse files Browse the repository at this point in the history
Hotfix/nag dangling pointers
  • Loading branch information
mathomp4 authored Dec 11, 2023
2 parents 9e0f2d1 + 8b771ee commit ed117a2
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 49 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Deprecated

## [2.42.4] - 2023-12-10

### Changed

- Improved error message for missing labels in GridManager.

### Fixed

- Corrected some unit tests (and test utilities) to fix dangling pointers detected by NAG. Most (possibly all) of these changes are already on release/MAPL-v3, but it was getting annoying to have NAG fail unit tests with develop branch.
- Fix for CMake an Apple. Needs to set `__DARWIN` as an fpp flag. (Only used by NAG, but ...)

## [2.42.3] - 2023-12-06

### Fixed
Expand Down
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ endif ()

project (
MAPL
VERSION 2.42.3
VERSION 2.42.4
LANGUAGES Fortran CXX C) # Note - CXX is required for ESMF

# Set the possible values of build type for cmake-gui
Expand Down Expand Up @@ -220,6 +220,9 @@ include(CheckCompilerCapabilities)
if(SUPPORT_FOR_MPI_IERROR_KEYWORD)
add_compile_definitions(SUPPORT_FOR_MPI_IERROR_KEYWORD)
endif()
if (APPLE)
add_compile_definitions("-D__DARWIN")
endif()

add_subdirectory (pfio)
add_subdirectory (profiler)
Expand All @@ -242,6 +245,7 @@ if (PFUNIT_FOUND)
add_subdirectory (pfunit EXCLUDE_FROM_ALL)
endif ()


# Support for automated code generation
include(mapl_acg)
include(mapl_create_stub_component)
Expand Down
3 changes: 2 additions & 1 deletion base/MAPL_Config.F90
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ function MAPL_ConfigCreate(unusable, rc) result(config)
#endif
character, parameter :: NUL = achar(00) !! what it says

_UNUSED_DUMMY(unusable)
config = ESMF_ConfigCreate(rc=rc)
config%cptr%buffer(1:1) = EOL
config%cptr%buffer(2:2) = EOB
config%cptr%nbuf = 2
config%cptr%next_line = 1
config%cptr%value_begin = 1

_RETURN(_SUCCESS)
_UNUSED_DUMMY(unusable)
end function MAPL_ConfigCreate

!------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion base/MAPL_GridManager.F90
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ function make_grid_from_config(this, config, unusable, prefix, rc) result(grid)
end if

call ESMF_ConfigGetAttribute(config, label=label, value=grid_type, rc=status)
_ASSERT(status==0,'label not found')
_ASSERT(status==0,'label ['//label//'] not found')

allocate(factory, source=this%make_factory(trim(grid_type), config, prefix=prefix, rc=status))
_VERIFY(status)
Expand Down
2 changes: 1 addition & 1 deletion base/tests/Test_GridManager.pf
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ contains
if (status == 0) then
call grid_manager%delete(grid)
end if
@assertExceptionRaised('label not found')
@assertExceptionRaised('label [GRID_TYPE:] not found')

! Check that it actually failed
@assertFalse(0 == status, 'made a grid even though there is no prototype')
Expand Down
4 changes: 2 additions & 2 deletions base/tests/mapl_bundleio_test.F90
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function create_cf(grid_name,im_world,jm_world,nx,ny,lm,cs_stretch_param,rc) res
call MAPL_ConfigSetAttribute(cf,value=dateline, label=trim(grid_name)//".DATELINE:",_RC)
end if


_RETURN(_SUCCESS)
end function create_cf

function create_gridname(im,jm,date,pole) result(gridname)
Expand Down Expand Up @@ -260,7 +260,7 @@ program ut_ReGridding
call UnpackGridName(Gridname,im_world_new,jm_world_new,dateline_new,pole_new)

lm_world=3
cfoutput = create_cf(gridname,im_world_new,jm_world_new,nx,ny,lm_world,cs_stretch_param,_RC)
cfoutput = create_cf(trim(gridname),im_world_new,jm_world_new,nx,ny,lm_world,cs_stretch_param,_RC)
grid_new=grid_manager%make_grid(cfoutput,prefix=trim(gridname)//".",_RC)
bundle=ESMF_FieldBundleCreate(name="cfio_bundle",_RC)
call ESMF_FieldBundleSet(bundle,grid=grid_new,_RC)
Expand Down
16 changes: 9 additions & 7 deletions gridcomps/ExtData2G/ExtDataConfig.F90
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,22 @@ recursive subroutine new_ExtDataConfig_from_yaml(ext_config,config_file,current_

if (ESMF_HConfigIsDefined(input_config,keyString="Samplings")) then
temp_configs = ESMF_HConfigCreateAt(input_config,keyString="Samplings",_RC)
hconfigIter = ESMF_HConfigIterBegin(temp_configs)
hconfigIterBegin = ESMF_HConfigIterBegin(temp_configs)
hconfigIter = hconfigIterBegin
hconfigIterEnd = ESMF_HConfigIterEnd(temp_configs)
do while (ESMF_HConfigIterLoop(hconfigIter,hconfigIterBegin,hconfigIterEnd))
hconfig_key = ESMF_HConfigAsStringMapKey(hconfigIter,_RC)
single_sample = ESMF_HConfigCreateAtMapVal(hconfigIter,_RC)
ts = ExtDataTimeSample(single_sample,_RC)
call ext_config%sample_map%insert(trim(hconfig_key),ts)
enddo
call ESMF_HConfigDestroy(temp_configs)
end if

if (ESMF_HConfigIsDefined(input_config,keyString="Collections")) then
temp_configs = ESMF_HConfigCreateAt(input_config,keyString="Collections",_RC)
hconfigIter = ESMF_HConfigIterBegin(temp_configs)
hconfigIterBegin = ESMF_HConfigIterBegin(temp_configs)
hconfigIter = hconfigIterBegin
hconfigIterEnd = ESMF_HConfigIterEnd(temp_configs)
do while (ESMF_HConfigIterLoop(hconfigIter,hconfigIterBegin,hconfigIterEnd))
hconfig_key = ESMF_HConfigAsStringMapKey(hconfigIter,_RC)
Expand All @@ -111,12 +112,13 @@ recursive subroutine new_ExtDataConfig_from_yaml(ext_config,config_file,current_
ds = ExtDataFileStream(single_collection,current_time,_RC)
call ext_config%file_stream_map%insert(trim(hconfig_key),ds)
enddo
call ESMF_HConfigDestroy(temp_configs)
end if

if (ESMF_HConfigIsDefined(input_config,keyString="Exports")) then
temp_configs = ESMF_HConfigCreateAt(input_config,keyString="Exports",_RC)
hconfigIter = ESMF_HConfigIterBegin(temp_configs)
hconfigIterBegin = ESMF_HConfigIterBegin(temp_configs)
hconfigIter = hconfigIterBegin
hconfigIterEnd = ESMF_HConfigIterEnd(temp_configs)
do while (ESMF_HConfigIterLoop(hconfigIter,hconfigIterBegin,hconfigIterEnd))
hconfig_key = ESMF_HConfigAsStringMapKey(hconfigIter,_RC)
Expand All @@ -140,8 +142,8 @@ recursive subroutine new_ExtDataConfig_from_yaml(ext_config,config_file,current_

if (ESMF_HConfigIsDefined(input_config,keyString="Derived")) then
temp_configs = ESMF_HConfigCreateAt(input_config,keyString="Derived",_RC)
hconfigIter = ESMF_HConfigIterBegin(temp_configs)
hconfigIterBegin = ESMF_HConfigIterBegin(temp_configs)
hconfigIter = hconfigIterBegin
hconfigIterEnd = ESMF_HConfigIterEnd(temp_configs)
do while (ESMF_HConfigIterLoop(hconfigIter,hconfigIterBegin,hconfigIterEnd))
hconfig_key = ESMF_HConfigAsStringMapKey(hconfigIter,_RC)
Expand All @@ -162,7 +164,7 @@ end subroutine new_ExtDataConfig_from_yaml

function count_rules_for_item(this,item_name,rc) result(number_of_rules)
integer :: number_of_rules
class(ExtDataConfig), intent(in) :: this
class(ExtDataConfig), target, intent(in) :: this
character(len=*), intent(in) :: item_name
integer, optional, intent(out) :: rc

Expand All @@ -187,7 +189,7 @@ end function count_rules_for_item

function get_time_range(this,item_name,rc) result(time_range)
type(ESMF_Time), allocatable :: time_range(:)
class(ExtDataConfig), intent(in) :: this
class(ExtDataConfig), target, intent(in) :: this
character(len=*), intent(in) :: item_name
integer, optional, intent(out) :: rc

Expand Down Expand Up @@ -265,7 +267,7 @@ function sort_rules_by_start(hconfig_sequence,rc) result(sorted_index)
end function sort_rules_by_start

function get_item_type(this,item_name,unusable,rc) result(item_type)
class(ExtDataConfig), intent(inout) :: this
class(ExtDataConfig), target, intent(inout) :: this
character(len=*), intent(in) :: item_name
class(KeywordEnforcer), optional, intent(in) :: unusable
integer, optional, intent(out) :: rc
Expand Down
6 changes: 3 additions & 3 deletions gridcomps/ExtData2G/ExtDataGridCompNG.F90
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ SUBROUTINE Initialize_ ( GC, IMPORT, EXPORT, CLOCK, rc )
integer :: idx
type(MAPL_MetaComp),pointer :: MAPLSTATE

type(ExtDataOldTypesCreator),target :: config_yaml
type(ExtDataOldTypesCreator), target :: config_yaml
character(len=ESMF_MAXSTR) :: new_rc_file
logical :: found_in_config
integer :: num_primary,num_derived,num_rules
Expand Down Expand Up @@ -308,7 +308,7 @@ SUBROUTINE Initialize_ ( GC, IMPORT, EXPORT, CLOCK, rc )
_RETURN(ESMF_SUCCESS)
end if

config_yaml = ExtDataOldTypesCreator(new_rc_file,time,_RC)
call new_ExtDataOldTypesCreator(config_yaml, new_rc_file, time, _RC)

allocate(ITEMNAMES(ITEMCOUNT), STAT=STATUS)
_VERIFY(STATUS)
Expand Down Expand Up @@ -1449,7 +1449,7 @@ end subroutine createFileLevBracket

subroutine IOBundle_Add_Entry(IOBundles,item,entry_num,rc)
type(IOBundleNGVector), intent(inout) :: IOBundles
type(primaryExport), intent(inout) :: item
type(primaryExport), target, intent(inout) :: item
integer, intent(in) :: entry_num
integer, intent(out), optional :: rc

Expand Down
37 changes: 19 additions & 18 deletions gridcomps/ExtData2G/ExtDataOldTypesCreator.F90
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ module MAPL_ExtDataOldTypesCreator
use MAPL_ExtDataTimeSample
use MAPL_ExtDataTimeSampleMap
implicit none

public :: ExtDataOldTypesCreator
public :: new_ExtDataOldTypesCreator

type, extends(ExtDataConfig) :: ExtDataOldTypesCreator
private
Expand All @@ -30,32 +32,31 @@ module MAPL_ExtDataOldTypesCreator
procedure :: fillin_derived
end type ExtDataOldTypesCreator

interface ExtDataOldTypesCreator
module procedure :: new_ExtDataOldTypesCreator
end interface
!# interface ExtDataOldTypesCreator
!# module procedure :: new_ExtDataOldTypesCreator
!# end interface

contains

function new_ExtDataOldTypesCreator(config_file,current_time,unusable,rc ) result(ExtDataObj)
character(len=*), intent(in) :: config_file
type(ESMF_Time), intent(in) :: current_time
class(KeywordEnforcer), optional, intent(in) :: unusable
integer, optional, intent(out) :: rc
subroutine new_ExtDataOldTypesCreator(extdataobj, config_file,current_time,unusable,rc )
type(ExtDataOldTypesCreator), target, intent(out) :: ExtDataObj
character(len=*), intent(in) :: config_file
type(ESMF_Time), intent(in) :: current_time
class(KeywordEnforcer), optional, intent(in) :: unusable
integer, optional, intent(out) :: rc

type(ExtDataOldTypesCreator) :: ExtDataObj

integer :: status

_UNUSED_DUMMY(unusable)
call ExtDataObj%ExtDataConfig%new_ExtDataConfig_from_yaml(config_file,current_time,rc=status)
_VERIFY(status)

_RETURN(_SUCCESS)
end function new_ExtDataOldTypesCreator
integer :: status

call ExtDataObj%ExtDataConfig%new_ExtDataConfig_from_yaml(config_file,current_time,_RC)

_RETURN(_SUCCESS)
_UNUSED_DUMMY(unusable)
end subroutine new_ExtDataOldTypesCreator


subroutine fillin_primary(this,item_name,base_name,primary_item,time,clock,unusable,rc)
class(ExtDataOldTypesCreator), intent(inout) :: this
class(ExtDataOldTypesCreator), target, intent(inout) :: this
character(len=*), intent(in) :: item_name
character(len=*), intent(in) :: base_name
type(PrimaryExport), intent(inout) :: primary_item
Expand Down
8 changes: 4 additions & 4 deletions griddedio/GriddedIO.F90
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ function new_MAPL_GriddedIO(metadata,input_bundle,output_bundle,write_collection
end function new_MAPL_GriddedIO

subroutine CreateFileMetaData(this,items,bundle,timeInfo,vdata,ogrid,global_attributes,rc)
class (MAPL_GriddedIO), intent(inout) :: this
class (MAPL_GriddedIO), target, intent(inout) :: this
type(GriddedIOitemVector), target, intent(inout) :: items
type(ESMF_FieldBundle), intent(inout) :: bundle
type(TimeData), intent(inout) :: timeInfo
type(VerticalData), intent(inout), optional :: vdata
type (ESMF_Grid), intent(inout), pointer, optional :: ogrid
type(StringStringMap), intent(in), optional :: global_attributes
type(StringStringMap), intent(in), target, optional :: global_attributes
integer, intent(out), optional :: rc

type(ESMF_Grid) :: input_grid
Expand Down Expand Up @@ -729,8 +729,8 @@ subroutine RegridVector(this,xName,yName,rc)
yptr3d => yptr3d_inter
end if
else
if (associated(xptr3d)) nullify(xptr3d)
if (associated(yptr3d)) nullify(yptr3d)
nullify(xptr3d)
nullify(yptr3d)
end if

call ESMF_FieldBundleGet(this%input_bundle,xname,field=xfield,rc=status)
Expand Down
6 changes: 3 additions & 3 deletions pfio/AbstractDirectoryService.F90
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ subroutine connect_to_client(this, port_name, server, rc)
import AbstractSocketVector
class (AbstractDirectoryService), target, intent(inout) :: this
character(*), intent(in) :: port_name
class (BaseServer), intent(inout) :: server
class (BaseServer), target, intent(inout) :: server
integer, optional, intent(out) :: rc
end subroutine connect_to_client

subroutine publish(this, port, server, rc)
use pFIO_BaseServerMod
import AbstractDirectoryService
import PortInfo
class (AbstractDirectoryService), intent(inout) :: this
class (AbstractDirectoryService), target, intent(inout) :: this
type(PortInfo), target, intent(in) :: port
class (BaseServer), intent(inout) :: server
class (BaseServer), intent(in) :: server
integer, optional, intent(out) :: rc
end subroutine

Expand Down
6 changes: 3 additions & 3 deletions pfio/DirectoryService.F90
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ end subroutine connect_to_server
subroutine connect_to_client(this, port_name, server, rc)
class (DirectoryService), target, intent(inout) :: this
character(*), intent(in) :: port_name
class (BaseServer), intent(inout) :: server
class (BaseServer), target, intent(inout) :: server
integer, optional, intent(out) :: rc

class (AbstractSocket), pointer :: sckt
Expand Down Expand Up @@ -422,9 +422,9 @@ end subroutine connect_to_client
! But it would allow future implementation to query for servers
! or possibly to allow servers to satisfy multiple clients.
subroutine publish(this, port, server, rc)
class (DirectoryService), intent(inout) :: this
class (DirectoryService), target,intent(inout) :: this
type(PortInfo),target, intent(in) :: port
class (BaseServer), intent(inout) :: server
class (BaseServer), intent(in) :: server
integer, optional, intent(out) :: rc
character(len=MAX_LEN_PORT_NAME) :: port_name
integer :: ierror
Expand Down
8 changes: 4 additions & 4 deletions pfio/MultiGroupServer.F90
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ subroutine start_back(this, rc)
integer, parameter :: stag = 6782

integer :: status
type (StringSet) :: FilesBeingWritten
type (StringSet), target :: FilesBeingWritten

allocate(this%serverthread_done_msgs(1))
this%serverthread_done_msgs(:) = .false.
Expand Down Expand Up @@ -625,10 +625,10 @@ subroutine start_back_writers(rc)
integer, pointer :: g_4d(:,:,:,:), l_4d(:,:,:,:), g_5d(:,:,:,:,:), l_5d(:,:,:,:,:)
integer :: d_rank, request_id
integer(kind=INT64) :: msize_word, s0, e0, s1, e1, s2, e2, s3, e3, s4, e4, s5, e5
type (StringAttributeMap) :: vars_map
type (StringAttributeMap), target :: vars_map
type (StringAttributeMapIterator) :: var_iter
type (IntegerMessageMap) :: msg_map
type (IntegerMessageMapIterator) :: msg_iter
type (IntegerMessageMap), target :: msg_map
type (IntegerMessageMapIterator) :: msg_iter

class (*), pointer :: x_ptr(:)
integer , allocatable :: buffer_v(:)
Expand Down
2 changes: 1 addition & 1 deletion pfio/tests/pfio_ctest_io.F90
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ program main
integer :: rank, npes, ierror, provided,required
integer :: status, color, key

class(BaseServer),allocatable :: iserver,oserver
class(BaseServer), target, allocatable :: iserver,oserver
class(AbstractDirectoryService), allocatable, target :: directory_service

type (CommandLineOptions0) :: options
Expand Down

0 comments on commit ed117a2

Please sign in to comment.