Skip to content

Commit 91387a0

Browse files
authored
Check for equality between Fortran and C logicals (#692)
1 parent 8eaf156 commit 91387a0

File tree

7 files changed

+32
-2
lines changed

7 files changed

+32
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ endif()
5959

6060
list(
6161
APPEND fyppFlags
62+
"-DWITH_CBOOL=$<BOOL:${WITH_CBOOL}>"
6263
"-DWITH_QP=$<BOOL:${WITH_QP}>"
6364
"-DWITH_XDP=$<BOOL:${WITH_XDP}>"
6465
"-DPROJECT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}"

config/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE)
1616
# Check for available features
1717
# Note: users can overwrite the automatic check by setting the value at configure time
1818
include(CheckFortranSourceRuns)
19+
if (NOT DEFINED WITH_CBOOL)
20+
check_fortran_source_runs(
21+
"use, intrinsic :: iso_c_binding, only: c_bool; integer, parameter :: lk = kind(.true.)
22+
if (c_bool == lk) stop 1
23+
end"
24+
WITH_CBOOL
25+
)
26+
set(WITH_CBOOL ${WITH_CBOOL} PARENT_SCOPE)
27+
endif()
1928
if (NOT DEFINED WITH_QP)
2029
check_fortran_source_runs(
2130
"if (selected_real_kind(33) == -1) stop 1; end"

config/template.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@PACKAGE_INIT@
22

3+
set("@PROJECT_NAME@_WITH_CBOOL" @WITH_CBOOL@)
34
set("@PROJECT_NAME@_WITH_QP" @WITH_QP@)
45
set("@PROJECT_NAME@_WITH_XDP" @WITH_XDP@)
56

src/common.fypp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
#! Project version number
44
#:set PROJECT_VERSION = "{}.{}.{}".format(PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR, PROJECT_VERSION_PATCH)
55

6+
#! Support for C_BOOL logical
7+
#:if not defined("WITH_CBOOL")
8+
#:set WITH_CBOOL = False
9+
#:endif
10+
611
#! Support for quadruple precision floating point numbers
712
#:if not defined("WITH_QP")
813
#:set WITH_QP = False
@@ -53,7 +58,10 @@
5358
#:set INT_KINDS_TYPES = list(zip(INT_KINDS, INT_TYPES))
5459

5560
#! Logical kinds to be considered during templating
56-
#:set LOG_KINDS = ["lk", "c_bool"]
61+
#:set LOG_KINDS = ["lk"]
62+
#:if WITH_CBOOL
63+
#:set LOG_KINDS = LOG_KINDS + ["c_bool"]
64+
#:endif
5765

5866
#! Logical types to be considered during templating
5967
#:set LOG_TYPES = ["logical({})".format(k) for k in LOG_KINDS]

test/ascii/test_ascii.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module test_ascii
66
is_digit, is_octal_digit, is_hex_digit, is_white, is_blank, &
77
is_control, is_punctuation, is_graphical, is_printable, is_ascii, &
88
to_lower, to_upper, to_title, to_sentence, reverse, LF, TAB, NUL, DEL
9-
use stdlib_kinds, only : int8, int16, int32, int64, lk, c_bool
9+
use stdlib_kinds, only : int8, int16, int32, int64, lk
1010
implicit none
1111
private
1212

test/string/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
#### Pre-process: .fpp -> .f90 via Fypp
2+
3+
# Create a list of the files to be preprocessed
4+
set(fppFiles
5+
test_string_assignment.fypp
6+
)
7+
8+
fypp_f90("${fyppFlags}" "${fppFiles}" outFiles)
9+
110
ADDTEST(string_assignment)
211
ADDTEST(string_operator)
312
ADDTEST(string_intrinsic)

test/string/test_string_assignment.f90 renamed to test/string/test_string_assignment.fypp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ subroutine test_constructor(error)
7979
call check(error, string_type(.false.) == trim(flc))
8080
if (allocated(error)) return
8181

82+
#:if WITH_CBOOL
8283
write(flc, '(g0)') .false._c_bool
8384
call check(error, string_type(.false._c_bool) == trim(flc))
8485
if (allocated(error)) return
86+
#:endif
8587

8688
write(flc, '(g0)') .true._lk
8789
call check(error, string_type(.true._lk) == trim(flc))

0 commit comments

Comments
 (0)