Skip to content

Commit

Permalink
Merge branch 'release/0.8.0'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
wdeconinck committed Jul 9, 2020
2 parents 5a9ad88 + 0eb8b92 commit 4cd749f
Show file tree
Hide file tree
Showing 26 changed files with 383 additions and 147 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ find_package( ecbuild 3.0.0 REQUIRED )

project( fckit LANGUAGES C CXX Fortran )

set(CMAKE_DIRECTORY_LABELS "fckit")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

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

set( FEATURE_FINAL_DEFAULT ON )
set( PGIBUG_ATLAS_197 0 )
if( CMAKE_Fortran_COMPILER_ID MATCHES "PGI" )
if( ${CMAKE_Fortran_COMPILER_VERSION} VERSION_LESS 19.4 )
set( PGIBUG_ATLAS_197 1 )
endif()
if( ${CMAKE_Fortran_COMPILER_VERSION} VERSION_LESS 19.10 )
# Compilation works, but runtime segmentation faults occur (tested with pgi/17.7)
set( FEATURE_FINAL_DEFAULT OFF )
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.0
0.8.0
12 changes: 11 additions & 1 deletion cmake/add_fctest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ cmake_policy( SET CMP0064 NEW ) # Recognize ``TEST`` as operator for the ``if()`
target_sources( ${_PAR_TARGET} PUBLIC ${TESTRUNNER} )

### Add dependencies
target_include_directories( ${_PAR_TARGET} PUBLIC ${FCKIT_INCLUDE_DIRS} )
target_link_libraries( ${_PAR_TARGET} fckit )
if( TEST ${_PAR_TARGET} )
set_property( TEST ${_PAR_TARGET} APPEND PROPERTY LABELS "fortran" )
Expand All @@ -100,6 +99,17 @@ cmake_policy( SET CMP0064 NEW ) # Recognize ``TEST`` as operator for the ``if()`
set_source_files_properties( ${TESTRUNNER} PROPERTIES ${_prop} ${TESTSUITE_PROPERTY} )
endif()
endforeach()
if(${CMAKE_Fortran_COMPILER_ID} MATCHES GNU)
#Disable developer-only pre-processor warnings when not compiling for Debug configurations
target_compile_options(${_PAR_TARGET} PRIVATE $<$<NOT:$<CONFIG:Debug>>:-Wno-cpp>)
endif()

### Workaround Flang issue, not able to include absolute path. Adding -I/ seems a workaround
# but results in warning for other compilers (intel)
if( ${CMAKE_Fortran_COMPILER_ID} MATCHES Flang )
target_include_directories( ${_PAR_TARGET} PUBLIC ${FCKIT_INCLUDE_DIRS} "/" )
endif()


add_custom_target( ${_PAR_TARGET}_testsuite SOURCES ${TESTSUITE} )
endif()
Expand Down
10 changes: 6 additions & 4 deletions src/fckit/Log.F90
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@

! Callback function, used from C++ side
subroutine fckit_write_to_fortran_unit(unit,msg_cptr) bind(C)
use, intrinsic :: iso_c_binding, only: c_int32_t, c_ptr, c_char
use fckit_c_interop_module, only : c_ptr_to_string
use, intrinsic :: iso_c_binding, only: c_int32_t, c_ptr, c_char, c_associated
use fckit_c_interop_module, only : copy_c_ptr_to_string
integer(c_int32_t), value, intent(in) :: unit
type(c_ptr), value, intent(in) :: msg_cptr
character(kind=c_char,len=:), allocatable :: msg
msg = c_ptr_to_string(msg_cptr)
write(unit,'(A)') msg
if( c_associated(msg_cptr) ) then
call copy_c_ptr_to_string( msg_cptr, msg )
write(unit,'(A)') msg
endif
end subroutine

function fckit_fortranunit_stdout() result(stdout) bind(C)
Expand Down
9 changes: 7 additions & 2 deletions src/fckit/fckit.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,23 @@ does it submit to any jurisdiction.
associate( unused_ => X ); \
end associate

#define PGIBUG_ATLAS_197 1
#define PGIBUG_ATLAS_197 @PGIBUG_ATLAS_197@
#if 0
Following is to workaround PGI bug which prevents the use of function c_ptr()
PGI bug present from version 17.10, fixed since version 19.4
#endif
#if PGIBUG_ATLAS_197
#define CPTR_PGIBUG_A cpp_object_ptr
#define CPTR_PGIBUG_B shared_object_%cpp_object_ptr
#define PGIBUG_ATLAS_197_DEBUG 0
#else
#define CPTR_PGIBUG_A c_ptr()
#define CPTR_PGIBUG_B c_ptr()
#endif

#define PGIBUG_ATLAS_197_DEBUG 0
#if 0
When above PGIBUG_ATLAS_197_DEBUG==1 then the c_ptr() member functions are disabled from compilation,
to detect possible dangerous use cases when the PGI bug ATLAS-197 is present.
#endif

#define XLBUG_FCKIT_14 1
Expand Down
35 changes: 34 additions & 1 deletion src/fckit/module/fckit_C_interop.F90
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module fckit_C_interop_module
public :: get_c_commandline_arguments
public :: c_str_to_string
public :: c_ptr_to_string
public :: copy_c_ptr_to_string
public :: copy_c_str_to_string
public :: c_str
public :: c_str_no_trim
public :: c_str_right_trim
Expand Down Expand Up @@ -157,14 +159,45 @@ function c_str_to_string(s) result(string)

! =============================================================================

subroutine copy_c_str_to_string(s,string)
use, intrinsic :: iso_c_binding
character(kind=c_char,len=1), intent(in) :: s(*)
character(len=:), allocatable :: string
integer i, nchars
i = 1
do
if (s(i) == c_null_char) exit
i = i + 1
enddo
nchars = i - 1 ! Exclude null character from Fortran string
FCKIT_ALLOCATE_CHARACTER(string,nchars)
do i=1,nchars
string(i:i) = s(i)
enddo
end subroutine

! =============================================================================

subroutine copy_c_ptr_to_string(cptr,string)
use, intrinsic :: iso_c_binding
type(c_ptr), intent(in) :: cptr
character(kind=c_char,len=:), allocatable :: string
character(kind=c_char), dimension(:), pointer :: s
integer(c_int), parameter :: MAX_STR_LEN = 255
call c_f_pointer ( cptr , s, (/MAX_STR_LEN/) )
call copy_c_str_to_string( s, string )
end subroutine

! =============================================================================

function c_ptr_to_string(cptr) result(string)
use, intrinsic :: iso_c_binding
type(c_ptr), intent(in) :: cptr
character(kind=c_char,len=:), allocatable :: string
character(kind=c_char), dimension(:), pointer :: s
integer(c_int), parameter :: MAX_STR_LEN = 255
call c_f_pointer ( cptr , s, (/MAX_STR_LEN/) )
string = c_str_to_string(s)
call copy_c_str_to_string( s, string )
end function

! =============================================================================
Expand Down
Loading

0 comments on commit 4cd749f

Please sign in to comment.