Skip to content

Commit ef24bad

Browse files
committed
Avoid -Wtrampolines warnings
1 parent 83fb99e commit ef24bad

File tree

4 files changed

+214
-205
lines changed

4 files changed

+214
-205
lines changed

examples/fortran/lhapdf_example-deprecated.f90

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,6 @@
1-
program lhapdf_example
2-
use iso_c_binding
3-
use pineappl
4-
1+
module callbacks2
52
implicit none
6-
7-
integer, parameter :: dp = kind(0.0d0)
8-
9-
type(pineappl_grid) :: grid
10-
type(pineappl_lumi) :: lumi
11-
type(pineappl_keyval) :: key_vals
12-
13-
type(pineappl_xfx) :: xfx
14-
type(pineappl_alphas) :: alphas
15-
16-
integer, target :: alphas_flags(2)
17-
18-
lumi = pineappl_lumi_new()
19-
call pineappl_lumi_add(lumi, 3, [0, 0, 1, -1, 2, -2], [1.0_dp, 1.0_dp, 1.0_dp])
20-
21-
key_vals = pineappl_keyval_new()
22-
grid = pineappl_grid_new(lumi, 1, [2, 0, 0, 0], 2, [0.0_dp, 1.0_dp, 2.0_dp], key_vals)
23-
24-
call pineappl_grid_fill_all(grid, 0.5_dp, 0.5_dp, 100.0_dp, 0, 0.5_dp, [0.5_dp, 0.5_dp, 0.5_dp])
25-
call pineappl_grid_fill_all(grid, 0.5_dp, 0.5_dp, 100.0_dp, 0, 1.5_dp, [1.5_dp, 1.5_dp, 1.5_dp])
26-
27-
call setlhaparm("SILENT")
28-
call lhapdf_initpdfset_byname(0, "NNPDF31_nlo_as_0118_luxqed")
29-
call lhapdf_initpdfset_byname(1, "MSHT20nnlo_as118")
30-
31-
! calling pineappl_grid_convolve without any flags
32-
xfx = pineappl_xfx(xfx_test1)
33-
alphas = pineappl_alphas(alphas_test1)
34-
write(*, *) "first pineappl_grid_convolve_with_one:"
35-
write(*, *) pineappl_grid_convolve_with_one(grid, 2212, xfx, alphas, &
36-
[.true.], [.true.], 1.0_dp, 1.0_dp)
37-
38-
! calling pineappl_grid_convolve with two integer flags that are used in xfx_test2 and alphas_test2 to determine the set and member indices
39-
xfx = pineappl_xfx(xfx_test2)
40-
alphas = pineappl_alphas(alphas_test2)
41-
alphas_flags = [1, 0]
42-
write(*, *) "second pineappl_grid_convolve_with_one:"
43-
write(*, *) pineappl_grid_convolve_with_one(grid, 2212, xfx, alphas, &
44-
[.true.], [.true.], 1.0_dp, 1.0_dp, c_loc(alphas_flags(1)))
45-
46-
call pineappl_lumi_delete(lumi)
47-
call pineappl_grid_delete(grid)
483
contains
49-
504
! Passing a Fortran procedure to C needs the iso_c_binding
515
function xfx_test1(pdg_id, x, q2, state) bind(c)
526
use iso_c_binding
@@ -111,5 +65,54 @@ function alphas_test2(q2, state) bind(c)
11165

11266
call lhapdf_alphasq2(flags(1), flags(2), q2, alphas_test2)
11367
end function
68+
end module
11469

70+
program lhapdf_example
71+
use iso_c_binding
72+
use pineappl
73+
use callbacks2
74+
75+
implicit none
76+
77+
integer, parameter :: dp = kind(0.0d0)
78+
79+
type(pineappl_grid) :: grid
80+
type(pineappl_lumi) :: lumi
81+
type(pineappl_keyval) :: key_vals
82+
83+
type(pineappl_xfx) :: xfx
84+
type(pineappl_alphas) :: alphas
85+
86+
integer, target :: alphas_flags(2)
87+
88+
lumi = pineappl_lumi_new()
89+
call pineappl_lumi_add(lumi, 3, [0, 0, 1, -1, 2, -2], [1.0_dp, 1.0_dp, 1.0_dp])
90+
91+
key_vals = pineappl_keyval_new()
92+
grid = pineappl_grid_new(lumi, 1, [2, 0, 0, 0], 2, [0.0_dp, 1.0_dp, 2.0_dp], key_vals)
93+
94+
call pineappl_grid_fill_all(grid, 0.5_dp, 0.5_dp, 100.0_dp, 0, 0.5_dp, [0.5_dp, 0.5_dp, 0.5_dp])
95+
call pineappl_grid_fill_all(grid, 0.5_dp, 0.5_dp, 100.0_dp, 0, 1.5_dp, [1.5_dp, 1.5_dp, 1.5_dp])
96+
97+
call setlhaparm("SILENT")
98+
call lhapdf_initpdfset_byname(0, "NNPDF31_nlo_as_0118_luxqed")
99+
call lhapdf_initpdfset_byname(1, "MSHT20nnlo_as118")
100+
101+
! calling pineappl_grid_convolve without any flags
102+
xfx = pineappl_xfx(xfx_test1)
103+
alphas = pineappl_alphas(alphas_test1)
104+
write(*, *) "first pineappl_grid_convolve_with_one:"
105+
write(*, *) pineappl_grid_convolve_with_one(grid, 2212, xfx, alphas, &
106+
[.true.], [.true.], 1.0_dp, 1.0_dp)
107+
108+
! calling pineappl_grid_convolve with two integer flags that are used in xfx_test2 and alphas_test2 to determine the set and member indices
109+
xfx = pineappl_xfx(xfx_test2)
110+
alphas = pineappl_alphas(alphas_test2)
111+
alphas_flags = [1, 0]
112+
write(*, *) "second pineappl_grid_convolve_with_one:"
113+
write(*, *) pineappl_grid_convolve_with_one(grid, 2212, xfx, alphas, &
114+
[.true.], [.true.], 1.0_dp, 1.0_dp, c_loc(alphas_flags(1)))
115+
116+
call pineappl_lumi_delete(lumi)
117+
call pineappl_grid_delete(grid)
115118
end program lhapdf_example

examples/fortran/lhapdf_example.f90

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
1+
module callbacks4
2+
implicit none
3+
contains
4+
function wrap_xfx(pdg_id, x, q2, state) bind(c)
5+
use iso_c_binding
6+
7+
implicit none
8+
9+
integer(c_int32_t), value, intent(in) :: pdg_id
10+
real(c_double), value, intent(in) :: x, q2
11+
type(c_ptr), value, intent(in) :: state
12+
real(c_double) :: wrap_xfx
13+
integer, pointer :: state_array(:)
14+
15+
call c_f_pointer(state, state_array, [2])
16+
call lhapdf_xfxq2(state_array(1), state_array(2), pdg_id, x, q2, wrap_xfx)
17+
end function
18+
19+
function wrap_alphasq2(q2, state) bind(c)
20+
use iso_c_binding
21+
22+
implicit none
23+
24+
real(c_double), value, intent(in) :: q2
25+
type(c_ptr), value, intent(in) :: state
26+
real(c_double) :: wrap_alphasq2
27+
integer, pointer :: state_array(:)
28+
29+
call c_f_pointer(state, state_array, [2])
30+
call lhapdf_alphasq2(state_array(1), state_array(2), q2, wrap_alphasq2)
31+
end function
32+
end module
33+
134
program lhapdf_example
235
use iso_c_binding
336
use pineappl
37+
use callbacks4
438

539
implicit none
640

@@ -106,35 +140,4 @@ program lhapdf_example
106140
! call pineappl_grid_write(grid, 'test.pineappl.lz4')
107141
call pineappl_channels_delete(channels)
108142
call pineappl_grid_delete(grid)
109-
contains
110-
111-
function wrap_xfx(pdg_id, x, q2, state) bind(c)
112-
use iso_c_binding
113-
114-
implicit none
115-
116-
integer(c_int32_t), value, intent(in) :: pdg_id
117-
real(c_double), value, intent(in) :: x, q2
118-
type(c_ptr), value, intent(in) :: state
119-
real(c_double) :: wrap_xfx
120-
integer, pointer :: state_array(:)
121-
122-
call c_f_pointer(state, state_array, [2])
123-
call lhapdf_xfxq2(state_array(1), state_array(2), pdg_id, x, q2, wrap_xfx)
124-
end function
125-
126-
function wrap_alphasq2(q2, state) bind(c)
127-
use iso_c_binding
128-
129-
implicit none
130-
131-
real(c_double), value, intent(in) :: q2
132-
type(c_ptr), value, intent(in) :: state
133-
real(c_double) :: wrap_alphasq2
134-
integer, pointer :: state_array(:)
135-
136-
call c_f_pointer(state, state_array, [2])
137-
call lhapdf_alphasq2(state_array(1), state_array(2), q2, wrap_alphasq2)
138-
end function
139-
140143
end program lhapdf_example

examples/fortran/test-deprecated.f90

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,62 @@
1+
module callbacks3
2+
implicit none
3+
contains
4+
function xfx1_test(pdg_id, x, q2, state) bind(c)
5+
use iso_c_binding
6+
7+
implicit none
8+
9+
integer(c_int32_t), value, intent(in) :: pdg_id
10+
real(c_double), value, intent(in) :: x, q2
11+
type(c_ptr), value, intent(in) :: state
12+
real(c_double) :: xfx1_test
13+
14+
! ignore unused arguments
15+
associate(pdg_id => pdg_id); end associate
16+
associate(q2 => q2); end associate
17+
associate(state => state); end associate
18+
19+
xfx1_test = x
20+
end function
21+
22+
function xfx2_test(pdg_id, x, q2, state) bind(c)
23+
use iso_c_binding
24+
25+
implicit none
26+
27+
integer(c_int32_t), value, intent(in) :: pdg_id
28+
real(c_double), value, intent(in) :: x, q2
29+
type(c_ptr), value, intent(in) :: state
30+
real(c_double) :: xfx2_test
31+
32+
! ignore unused arguments
33+
associate(pdg_id => pdg_id); end associate
34+
associate(q2 => q2); end associate
35+
associate(state => state); end associate
36+
37+
xfx2_test = -x
38+
end function
39+
40+
function alphas_test(q2, state) bind(c)
41+
use iso_c_binding
42+
43+
implicit none
44+
45+
real(c_double), value, intent(in) :: q2
46+
type(c_ptr), value, intent(in) :: state
47+
real(c_double) :: alphas_test
48+
49+
! ignore unused argument
50+
associate(state => state); end associate
51+
52+
alphas_test = q2
53+
end function
54+
end module
55+
156
program test_pineappl
257
use pineappl
358
use iso_c_binding
59+
use callbacks3
460

561
implicit none
662

@@ -177,58 +233,4 @@ program test_pineappl
177233
call pineappl_lumi_delete(lumi)
178234

179235
call pineappl_grid_delete(grid)
180-
181-
contains
182-
183-
function xfx1_test(pdg_id, x, q2, state) bind(c)
184-
use iso_c_binding
185-
186-
implicit none
187-
188-
integer(c_int32_t), value, intent(in) :: pdg_id
189-
real(c_double), value, intent(in) :: x, q2
190-
type(c_ptr), value, intent(in) :: state
191-
real(c_double) :: xfx1_test
192-
193-
! ignore unused arguments
194-
associate(pdg_id => pdg_id); end associate
195-
associate(q2 => q2); end associate
196-
associate(state => state); end associate
197-
198-
xfx1_test = x
199-
end function
200-
201-
function xfx2_test(pdg_id, x, q2, state) bind(c)
202-
use iso_c_binding
203-
204-
implicit none
205-
206-
integer(c_int32_t), value, intent(in) :: pdg_id
207-
real(c_double), value, intent(in) :: x, q2
208-
type(c_ptr), value, intent(in) :: state
209-
real(c_double) :: xfx2_test
210-
211-
! ignore unused arguments
212-
associate(pdg_id => pdg_id); end associate
213-
associate(q2 => q2); end associate
214-
associate(state => state); end associate
215-
216-
xfx2_test = -x
217-
end function
218-
219-
function alphas_test(q2, state) bind(c)
220-
use iso_c_binding
221-
222-
implicit none
223-
224-
real(c_double), value, intent(in) :: q2
225-
type(c_ptr), value, intent(in) :: state
226-
real(c_double) :: alphas_test
227-
228-
! ignore unused argument
229-
associate(state => state); end associate
230-
231-
alphas_test = q2
232-
end function
233-
234236
end program test_pineappl

0 commit comments

Comments
 (0)