|
3 | 3 |
|
4 | 4 | #include "assert_macros.h" |
5 | 5 |
|
| 6 | +module caf_prif_co_max_helper |
| 7 | + !! F23 C1807: bind(c) callbacks written in Fortran must appear in a top-level module |
| 8 | + use iso_c_binding, only: c_ptr, c_size_t, c_char, c_f_pointer |
| 9 | + implicit none |
| 10 | + |
| 11 | +contains |
| 12 | + |
| 13 | + subroutine caf_char_max_wrapper(arg1, arg2_and_out, count, cdata) bind(C) |
| 14 | + type(c_ptr), intent(in), value :: arg1, arg2_and_out |
| 15 | + integer(c_size_t), intent(in), value :: count |
| 16 | + type(c_ptr), intent(in), value :: cdata |
| 17 | + |
| 18 | + integer(c_size_t), pointer :: char_len |
| 19 | + integer(c_size_t) :: i |
| 20 | + |
| 21 | + if (count == 0) return |
| 22 | + call c_f_pointer(cdata, char_len) |
| 23 | + block |
| 24 | + character(len=char_len,kind=c_char), pointer :: lhs(:), rhs_and_result(:) |
| 25 | + call c_f_pointer(arg1, lhs, [count]) |
| 26 | + call c_f_pointer(arg2_and_out, rhs_and_result, [count]) |
| 27 | + do i = 1, count |
| 28 | + if (lhs(i) >= rhs_and_result(i)) rhs_and_result(i) = lhs(i) |
| 29 | + end do |
| 30 | + end block |
| 31 | + end subroutine |
| 32 | + |
| 33 | +end module |
| 34 | + |
6 | 35 | submodule(prif:prif_private_s) co_max_s |
7 | 36 | ! DO NOT ADD USE STATEMENTS HERE |
8 | 37 | ! All use statements belong in prif_private_s.F90 |
@@ -34,32 +63,13 @@ subroutine contiguous_co_max(a, result_image, stat, errmsg, errmsg_alloc) |
34 | 63 | current_team%info%gex_team) |
35 | 64 | end subroutine |
36 | 65 |
|
37 | | - subroutine char_max_wrapper(arg1, arg2_and_out, count, cdata) bind(C) |
38 | | - type(c_ptr), intent(in), value :: arg1, arg2_and_out |
39 | | - integer(c_size_t), intent(in), value :: count |
40 | | - type(c_ptr), intent(in), value :: cdata |
41 | | - |
42 | | - integer(c_size_t), pointer :: char_len |
43 | | - integer(c_size_t) :: i |
44 | | - |
45 | | - if (count == 0) return |
46 | | - call c_f_pointer(cdata, char_len) |
47 | | - block |
48 | | - character(len=char_len,kind=c_char), pointer :: lhs(:), rhs_and_result(:) |
49 | | - call c_f_pointer(arg1, lhs, [count]) |
50 | | - call c_f_pointer(arg2_and_out, rhs_and_result, [count]) |
51 | | - do i = 1, count |
52 | | - if (lhs(i) >= rhs_and_result(i)) rhs_and_result(i) = lhs(i) |
53 | | - end do |
54 | | - end block |
55 | | - end subroutine |
56 | | - |
57 | 66 | module procedure prif_co_max_character |
| 67 | + use caf_prif_co_max_helper |
58 | 68 | integer(c_size_t), target :: char_len |
59 | 69 | procedure(prif_operation_wrapper_interface), pointer :: op |
60 | 70 |
|
61 | 71 | char_len = len(a) |
62 | | - op => char_max_wrapper |
| 72 | + op => caf_char_max_wrapper |
63 | 73 | #if defined(__GFORTRAN__) && 0 |
64 | 74 | ! gfortran 13.2 (sometimes?) crashes on the call below |
65 | 75 | ! internal compiler error: in make_decl_rtl, at varasm.cc:1442 |
|
0 commit comments