| 1 |
#include <stdlib.h> |
| 2 |
#include <stdio.h> |
| 3 |
|
| 4 |
#include <ISO_Fortran_binding.h> |
| 5 |
#include "dump-descriptors.h" |
| 6 |
|
| 7 |
extern void ctest (CFI_cdesc_t *a, CFI_cdesc_t *b); |
| 8 |
extern void ftest2 (CFI_cdesc_t *a, CFI_cdesc_t *b); |
| 9 |
|
| 10 |
struct m { |
| 11 |
int i; |
| 12 |
int j; |
| 13 |
}; |
| 14 |
|
| 15 |
#define imax 10 |
| 16 |
#define jmax 5 |
| 17 |
|
| 18 |
void |
| 19 |
ctest (CFI_cdesc_t *a, CFI_cdesc_t *b) |
| 20 |
{ |
| 21 |
CFI_index_t i, j; |
| 22 |
CFI_index_t s[2]; |
| 23 |
struct m *mpa, *mpb; |
| 24 |
|
| 25 |
/* Dump the descriptor contents to test that we can access the fields |
| 26 |
correctly, etc. */ |
| 27 |
dump_CFI_cdesc_t (a); |
| 28 |
if (a->rank != 2) |
| 29 |
abort (); |
| 30 |
if (a->attribute != CFI_attribute_other) |
| 31 |
abort (); |
| 32 |
if (a->dim[0].lower_bound != 0) |
| 33 |
abort (); |
| 34 |
if (a->dim[0].extent != imax) |
| 35 |
abort (); |
| 36 |
if (a->dim[1].lower_bound != 0) |
| 37 |
abort (); |
| 38 |
if (a->dim[1].extent != jmax) |
| 39 |
abort (); |
| 40 |
|
| 41 |
dump_CFI_cdesc_t (b); |
| 42 |
if (b->rank != 2) |
| 43 |
abort (); |
| 44 |
if (b->attribute != CFI_attribute_other) |
| 45 |
abort (); |
| 46 |
if (b->dim[0].lower_bound != 0) |
| 47 |
abort (); |
| 48 |
if (b->dim[0].extent != jmax) |
| 49 |
abort (); |
| 50 |
if (b->dim[1].lower_bound != 0) |
| 51 |
abort (); |
| 52 |
if (b->dim[1].extent != imax) |
| 53 |
abort (); |
| 54 |
|
| 55 |
/* Call back into Fortran, passing both the a and b arrays. */ |
| 56 |
ftest2 (a, b); |
| 57 |
|
| 58 |
/* Check that we got a valid b array back. */ |
| 59 |
dump_CFI_cdesc_t (b); |
| 60 |
if (b->rank != 2) |
| 61 |
abort (); |
| 62 |
if (b->attribute != CFI_attribute_other) |
| 63 |
abort (); |
| 64 |
if (b->dim[0].lower_bound != 0) |
| 65 |
abort (); |
| 66 |
if (b->dim[0].extent != jmax) |
| 67 |
abort (); |
| 68 |
if (b->dim[1].lower_bound != 0) |
| 69 |
abort (); |
| 70 |
if (b->dim[1].extent != imax) |
| 71 |
abort (); |
| 72 |
|
| 73 |
for (j = 0; j < jmax; j++) |
| 74 |
for (i = 0; i < imax; i++) |
| 75 |
{ |
| 76 |
s[0] = i; |
| 77 |
s[1] = j; |
| 78 |
mpa = (struct m *) CFI_address (a, s); |
| 79 |
s[0] = j; |
| 80 |
s[1] = i; |
| 81 |
mpb = (struct m *) CFI_address (b, s); |
| 82 |
if (mpa->i != mpb->i) |
| 83 |
abort (); |
| 84 |
if (mpa->j != mpb->j) |
| 85 |
abort (); |
| 86 |
} |
| 87 |
} |