Skip to content

Commit 7b1703e

Browse files
fix build and runtime issues with hash tests usinc c/c++ (fortran-lang#988)
2 parents 52fa5bf + d8a90aa commit 7b1703e

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

src/stdlib_strings.fypp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,21 @@ contains
302302

303303
last = len(string)
304304
nsub = len(substring)
305-
if (nsub > 0) then
306-
do while(string(last-nsub+1:last) == substring)
307-
last = last - nsub
305+
if (nsub > 0 .and. nsub <= last) then
306+
do while(last >= nsub)
307+
if (string(last-nsub+1:last) == substring) then
308+
last = last - nsub
309+
else
310+
exit
311+
end if
308312
end do
309313
end if
310-
chomped_string = string(1:last)
314+
315+
if (last <= 0) then
316+
chomped_string = ''
317+
else
318+
chomped_string = string(1:last)
319+
end if
311320

312321
end function chomp_substring_char_char
313322

test/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ if (NOT TARGET "test-drive::test-drive")
22
find_package("test-drive" REQUIRED)
33
endif()
44

5+
if(WIN32)
6+
if(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
7+
add_link_options(/Qoption,link,/STACK:8388608)
8+
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
9+
add_link_options(-Wl,--stack,8388608)
10+
endif()
11+
endif()
12+
513
macro(ADDTEST name)
614
add_executable(test_${name} test_${name}.f90)
715
target_link_libraries(test_${name} "${PROJECT_NAME}" "test-drive::test-drive")

test/hash_functions/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ if(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
2323
set(CMAKE_CXX_EXTENSIONS OFF)
2424

2525
set_target_properties(test_hash_functions PROPERTIES LINKER_LANGUAGE Fortran)
26+
27+
if(WIN32)
28+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL$<$<CONFIG:Debug>:Debug>")
29+
target_compile_options(
30+
test_hash_functions
31+
PRIVATE
32+
$<$<COMPILE_LANGUAGE:Fortran>:/libs:dll> )
33+
if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR "RelWithDebInfo")
34+
target_link_options(test_hash_functions
35+
PRIVATE
36+
/Qoption,link,/NODEFAULTLIB:libcmt
37+
/Qoption,link,/NODEFAULTLIB:msvcrt.lib
38+
/Qoption,link,/NODEFAULTLIB:libifcoremt.lib )
39+
endif()
40+
endif()
2641
endif()
2742

2843
if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU AND CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 10.0)

test/string/test_string_strip_chomp.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ subroutine test_chomp_substring_char(error)
151151
call check(error, chomp("hellooooo", "oo") == "hello")
152152
if (allocated(error)) return
153153
call check(error, chomp("hellooooo", substring="oo") == "hello")
154+
if (allocated(error)) return
155+
call check(error, chomp("helhel", substring="hel") == "")
154156
end subroutine test_chomp_substring_char
155157

156158
subroutine test_chomp_substring_string(error)

0 commit comments

Comments
 (0)