Skip to content

Commit 4cd749f

Browse files
committed
Merge branch 'release/0.8.0'
* release/0.8.0: Version 0.8.0 FCKIT-28 Only apply previous commit for flang compiler FCKIT-28 Fix fctest compilation with flang Fix char sizes (#12) Fixup that prevents inexplicable segfaults with PGI Fortran Fixup last commit to support older CMake versions Fix warnings with -Wall FCKIT-27 Reenable c_ptr() for compilers that support it Pass used compilers during build to be used during ctest coding norms Set string array in configuration Add directory label for CDash Add a constructor for fckit_mpi_comm Remove developer-only warnings from release builds
2 parents 5a9ad88 + 0eb8b92 commit 4cd749f

26 files changed

+383
-147
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ find_package( ecbuild 3.0.0 REQUIRED )
2121

2222
project( fckit LANGUAGES C CXX Fortran )
2323

24+
set(CMAKE_DIRECTORY_LABELS "fckit")
2425
set(CMAKE_CXX_STANDARD 11)
2526
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2627

@@ -35,7 +36,11 @@ ecbuild_enable_fortran( REQUIRED MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/module )
3536
ecbuild_check_fortran( FEATURES finalization )
3637

3738
set( FEATURE_FINAL_DEFAULT ON )
39+
set( PGIBUG_ATLAS_197 0 )
3840
if( CMAKE_Fortran_COMPILER_ID MATCHES "PGI" )
41+
if( ${CMAKE_Fortran_COMPILER_VERSION} VERSION_LESS 19.4 )
42+
set( PGIBUG_ATLAS_197 1 )
43+
endif()
3944
if( ${CMAKE_Fortran_COMPILER_VERSION} VERSION_LESS 19.10 )
4045
# Compilation works, but runtime segmentation faults occur (tested with pgi/17.7)
4146
set( FEATURE_FINAL_DEFAULT OFF )

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.7.0
1+
0.8.0

cmake/add_fctest.cmake

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ cmake_policy( SET CMP0064 NEW ) # Recognize ``TEST`` as operator for the ``if()`
8383
target_sources( ${_PAR_TARGET} PUBLIC ${TESTRUNNER} )
8484

8585
### Add dependencies
86-
target_include_directories( ${_PAR_TARGET} PUBLIC ${FCKIT_INCLUDE_DIRS} )
8786
target_link_libraries( ${_PAR_TARGET} fckit )
8887
if( TEST ${_PAR_TARGET} )
8988
set_property( TEST ${_PAR_TARGET} APPEND PROPERTY LABELS "fortran" )
@@ -100,6 +99,17 @@ cmake_policy( SET CMP0064 NEW ) # Recognize ``TEST`` as operator for the ``if()`
10099
set_source_files_properties( ${TESTRUNNER} PROPERTIES ${_prop} ${TESTSUITE_PROPERTY} )
101100
endif()
102101
endforeach()
102+
if(${CMAKE_Fortran_COMPILER_ID} MATCHES GNU)
103+
#Disable developer-only pre-processor warnings when not compiling for Debug configurations
104+
target_compile_options(${_PAR_TARGET} PRIVATE $<$<NOT:$<CONFIG:Debug>>:-Wno-cpp>)
105+
endif()
106+
107+
### Workaround Flang issue, not able to include absolute path. Adding -I/ seems a workaround
108+
# but results in warning for other compilers (intel)
109+
if( ${CMAKE_Fortran_COMPILER_ID} MATCHES Flang )
110+
target_include_directories( ${_PAR_TARGET} PUBLIC ${FCKIT_INCLUDE_DIRS} "/" )
111+
endif()
112+
103113

104114
add_custom_target( ${_PAR_TARGET}_testsuite SOURCES ${TESTSUITE} )
105115
endif()

src/fckit/Log.F90

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88

99
! Callback function, used from C++ side
1010
subroutine fckit_write_to_fortran_unit(unit,msg_cptr) bind(C)
11-
use, intrinsic :: iso_c_binding, only: c_int32_t, c_ptr, c_char
12-
use fckit_c_interop_module, only : c_ptr_to_string
11+
use, intrinsic :: iso_c_binding, only: c_int32_t, c_ptr, c_char, c_associated
12+
use fckit_c_interop_module, only : copy_c_ptr_to_string
1313
integer(c_int32_t), value, intent(in) :: unit
1414
type(c_ptr), value, intent(in) :: msg_cptr
1515
character(kind=c_char,len=:), allocatable :: msg
16-
msg = c_ptr_to_string(msg_cptr)
17-
write(unit,'(A)') msg
16+
if( c_associated(msg_cptr) ) then
17+
call copy_c_ptr_to_string( msg_cptr, msg )
18+
write(unit,'(A)') msg
19+
endif
1820
end subroutine
1921

2022
function fckit_fortranunit_stdout() result(stdout) bind(C)

src/fckit/fckit.h.in

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,23 @@ does it submit to any jurisdiction.
3737
associate( unused_ => X ); \
3838
end associate
3939

40-
#define PGIBUG_ATLAS_197 1
40+
#define PGIBUG_ATLAS_197 @PGIBUG_ATLAS_197@
4141
#if 0
4242
Following is to workaround PGI bug which prevents the use of function c_ptr()
43+
PGI bug present from version 17.10, fixed since version 19.4
4344
#endif
4445
#if PGIBUG_ATLAS_197
4546
#define CPTR_PGIBUG_A cpp_object_ptr
4647
#define CPTR_PGIBUG_B shared_object_%cpp_object_ptr
47-
#define PGIBUG_ATLAS_197_DEBUG 0
4848
#else
4949
#define CPTR_PGIBUG_A c_ptr()
5050
#define CPTR_PGIBUG_B c_ptr()
51+
#endif
52+
5153
#define PGIBUG_ATLAS_197_DEBUG 0
54+
#if 0
55+
When above PGIBUG_ATLAS_197_DEBUG==1 then the c_ptr() member functions are disabled from compilation,
56+
to detect possible dangerous use cases when the PGI bug ATLAS-197 is present.
5257
#endif
5358

5459
#define XLBUG_FCKIT_14 1

src/fckit/module/fckit_C_interop.F90

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ module fckit_C_interop_module
2121
public :: get_c_commandline_arguments
2222
public :: c_str_to_string
2323
public :: c_ptr_to_string
24+
public :: copy_c_ptr_to_string
25+
public :: copy_c_str_to_string
2426
public :: c_str
2527
public :: c_str_no_trim
2628
public :: c_str_right_trim
@@ -157,14 +159,45 @@ function c_str_to_string(s) result(string)
157159

158160
! =============================================================================
159161

162+
subroutine copy_c_str_to_string(s,string)
163+
use, intrinsic :: iso_c_binding
164+
character(kind=c_char,len=1), intent(in) :: s(*)
165+
character(len=:), allocatable :: string
166+
integer i, nchars
167+
i = 1
168+
do
169+
if (s(i) == c_null_char) exit
170+
i = i + 1
171+
enddo
172+
nchars = i - 1 ! Exclude null character from Fortran string
173+
FCKIT_ALLOCATE_CHARACTER(string,nchars)
174+
do i=1,nchars
175+
string(i:i) = s(i)
176+
enddo
177+
end subroutine
178+
179+
! =============================================================================
180+
181+
subroutine copy_c_ptr_to_string(cptr,string)
182+
use, intrinsic :: iso_c_binding
183+
type(c_ptr), intent(in) :: cptr
184+
character(kind=c_char,len=:), allocatable :: string
185+
character(kind=c_char), dimension(:), pointer :: s
186+
integer(c_int), parameter :: MAX_STR_LEN = 255
187+
call c_f_pointer ( cptr , s, (/MAX_STR_LEN/) )
188+
call copy_c_str_to_string( s, string )
189+
end subroutine
190+
191+
! =============================================================================
192+
160193
function c_ptr_to_string(cptr) result(string)
161194
use, intrinsic :: iso_c_binding
162195
type(c_ptr), intent(in) :: cptr
163196
character(kind=c_char,len=:), allocatable :: string
164197
character(kind=c_char), dimension(:), pointer :: s
165198
integer(c_int), parameter :: MAX_STR_LEN = 255
166199
call c_f_pointer ( cptr , s, (/MAX_STR_LEN/) )
167-
string = c_str_to_string(s)
200+
call copy_c_str_to_string( s, string )
168201
end function
169202

170203
! =============================================================================

0 commit comments

Comments
 (0)