|
| 1 | +/* This file was autogenerated by ctest; do not modify directly */ |
| 2 | + |
| 3 | +#include <stdbool.h> |
| 4 | +#include <stddef.h> |
| 5 | +#include <stdint.h> |
| 6 | +#include <stdio.h> |
| 7 | + |
| 8 | +#define SUPPRESS_ERROR |
| 9 | +#include <macro.h> |
| 10 | +#undef SUPPRESS_ERROR |
| 11 | + |
| 12 | +#if defined(__cplusplus) |
| 13 | + #define CTEST_ALIGNOF(T) alignof(T) |
| 14 | + #define CTEST_EXTERN extern "C" |
| 15 | +#else |
| 16 | + #define CTEST_ALIGNOF(T) _Alignof(T) |
| 17 | + #define CTEST_EXTERN |
| 18 | +#endif |
| 19 | + |
| 20 | +typedef void (*ctest_void_func)(void); |
| 21 | + |
| 22 | +// Return the size of a type. |
| 23 | +CTEST_EXTERN uint64_t ctest_size_of__VecU8(void) { return sizeof(struct VecU8); } |
| 24 | + |
| 25 | +// Return the alignment of a type. |
| 26 | +CTEST_EXTERN uint64_t ctest_align_of__VecU8(void) { return CTEST_ALIGNOF(struct VecU8); } |
| 27 | + |
| 28 | +// Return the size of a type. |
| 29 | +CTEST_EXTERN uint64_t ctest_size_of__VecU16(void) { return sizeof(struct VecU16); } |
| 30 | + |
| 31 | +// Return the alignment of a type. |
| 32 | +CTEST_EXTERN uint64_t ctest_align_of__VecU16(void) { return CTEST_ALIGNOF(struct VecU16); } |
| 33 | + |
| 34 | +// Return the offset of a struct/union field. |
| 35 | +CTEST_EXTERN uint64_t ctest_offset_of__VecU8__x(void) { |
| 36 | + return offsetof(struct VecU8, x); |
| 37 | +} |
| 38 | + |
| 39 | +// Return the size of a struct/union field. |
| 40 | +CTEST_EXTERN uint64_t ctest_size_of__VecU8__x(void) { |
| 41 | + return sizeof(((struct VecU8){}).x); |
| 42 | +} |
| 43 | + |
| 44 | +// Return the offset of a struct/union field. |
| 45 | +CTEST_EXTERN uint64_t ctest_offset_of__VecU8__y(void) { |
| 46 | + return offsetof(struct VecU8, y); |
| 47 | +} |
| 48 | + |
| 49 | +// Return the size of a struct/union field. |
| 50 | +CTEST_EXTERN uint64_t ctest_size_of__VecU8__y(void) { |
| 51 | + return sizeof(((struct VecU8){}).y); |
| 52 | +} |
| 53 | + |
| 54 | +// Return the offset of a struct/union field. |
| 55 | +CTEST_EXTERN uint64_t ctest_offset_of__VecU16__x(void) { |
| 56 | + return offsetof(struct VecU16, x); |
| 57 | +} |
| 58 | + |
| 59 | +// Return the size of a struct/union field. |
| 60 | +CTEST_EXTERN uint64_t ctest_size_of__VecU16__x(void) { |
| 61 | + return sizeof(((struct VecU16){}).x); |
| 62 | +} |
| 63 | + |
| 64 | +// Return the offset of a struct/union field. |
| 65 | +CTEST_EXTERN uint64_t ctest_offset_of__VecU16__y(void) { |
| 66 | + return offsetof(struct VecU16, y); |
| 67 | +} |
| 68 | + |
| 69 | +// Return the size of a struct/union field. |
| 70 | +CTEST_EXTERN uint64_t ctest_size_of__VecU16__y(void) { |
| 71 | + return sizeof(((struct VecU16){}).y); |
| 72 | +} |
| 73 | + |
| 74 | +// Return a pointer to a struct/union field. |
| 75 | +// This field can have a normal data type, or it could be a function pointer or an array, which |
| 76 | +// have different syntax. A typedef is used for convenience, but the syntax must be precomputed. |
| 77 | +typedef uint8_t *ctest_field_ty__VecU8__x; |
| 78 | +CTEST_EXTERN ctest_field_ty__VecU8__x |
| 79 | +ctest_field_ptr__VecU8__x(struct VecU8 *b) { |
| 80 | + return &b->x; |
| 81 | +} |
| 82 | + |
| 83 | +// Return a pointer to a struct/union field. |
| 84 | +// This field can have a normal data type, or it could be a function pointer or an array, which |
| 85 | +// have different syntax. A typedef is used for convenience, but the syntax must be precomputed. |
| 86 | +typedef uint8_t *ctest_field_ty__VecU8__y; |
| 87 | +CTEST_EXTERN ctest_field_ty__VecU8__y |
| 88 | +ctest_field_ptr__VecU8__y(struct VecU8 *b) { |
| 89 | + return &b->y; |
| 90 | +} |
| 91 | + |
| 92 | +// Return a pointer to a struct/union field. |
| 93 | +// This field can have a normal data type, or it could be a function pointer or an array, which |
| 94 | +// have different syntax. A typedef is used for convenience, but the syntax must be precomputed. |
| 95 | +typedef uint16_t *ctest_field_ty__VecU16__x; |
| 96 | +CTEST_EXTERN ctest_field_ty__VecU16__x |
| 97 | +ctest_field_ptr__VecU16__x(struct VecU16 *b) { |
| 98 | + return &b->x; |
| 99 | +} |
| 100 | + |
| 101 | +// Return a pointer to a struct/union field. |
| 102 | +// This field can have a normal data type, or it could be a function pointer or an array, which |
| 103 | +// have different syntax. A typedef is used for convenience, but the syntax must be precomputed. |
| 104 | +typedef uint16_t *ctest_field_ty__VecU16__y; |
| 105 | +CTEST_EXTERN ctest_field_ty__VecU16__y |
| 106 | +ctest_field_ptr__VecU16__y(struct VecU16 *b) { |
| 107 | + return &b->y; |
| 108 | +} |
| 109 | + |
| 110 | +#ifdef _MSC_VER |
| 111 | + // Disable signed/unsigned conversion warnings on MSVC. |
| 112 | + // These trigger even if the conversion is explicit. |
| 113 | + #pragma warning(disable:4365) |
| 114 | +#endif |
| 115 | + |
| 116 | +#ifdef __GNUC__ |
| 117 | + // GCC emits a warning with `-Wextra` if we return a typedef to a type marked `volatile`. |
| 118 | + #pragma GCC diagnostic push |
| 119 | + #pragma GCC diagnostic ignored "-Wignored-qualifiers" |
| 120 | +#endif |
| 121 | + |
| 122 | +// Tests whether the struct/union/alias `x` when passed by value to C and back to Rust |
| 123 | +// remains unchanged. |
| 124 | +// It checks if the size is the same as well as if the padding bytes are all in the correct place. |
| 125 | +CTEST_EXTERN struct VecU8 ctest_roundtrip__VecU8( |
| 126 | + struct VecU8 value, |
| 127 | + const uint8_t is_padding_byte[sizeof(struct VecU8)], |
| 128 | + uint8_t value_bytes[sizeof(struct VecU8)] |
| 129 | +) { |
| 130 | + int size = (int)sizeof(struct VecU8); |
| 131 | + // Mark `p` as volatile so that the C compiler does not optimize away the pattern we create. |
| 132 | + // Otherwise the Rust side would not be able to see it. |
| 133 | + volatile uint8_t* p = (volatile uint8_t*)&value; |
| 134 | + int i = 0; |
| 135 | + for (i = 0; i < size; ++i) { |
| 136 | + // We skip padding bytes in both Rust and C because writing to it is undefined. |
| 137 | + // Instead we just make sure the the placement of the padding bytes remains the same. |
| 138 | + if (is_padding_byte[i]) { continue; } |
| 139 | + value_bytes[i] = p[i]; |
| 140 | + // After we check that the pattern remained unchanged from Rust to C, we invert the pattern |
| 141 | + // and send it back to Rust to make sure that it remains unchanged from C to Rust. |
| 142 | + uint8_t d = (uint8_t)(255) - (uint8_t)(i % 256); |
| 143 | + d = d == 0 ? 42: d; |
| 144 | + p[i] = d; |
| 145 | + } |
| 146 | + return value; |
| 147 | +} |
| 148 | + |
| 149 | +// Tests whether the struct/union/alias `x` when passed by value to C and back to Rust |
| 150 | +// remains unchanged. |
| 151 | +// It checks if the size is the same as well as if the padding bytes are all in the correct place. |
| 152 | +CTEST_EXTERN struct VecU16 ctest_roundtrip__VecU16( |
| 153 | + struct VecU16 value, |
| 154 | + const uint8_t is_padding_byte[sizeof(struct VecU16)], |
| 155 | + uint8_t value_bytes[sizeof(struct VecU16)] |
| 156 | +) { |
| 157 | + int size = (int)sizeof(struct VecU16); |
| 158 | + // Mark `p` as volatile so that the C compiler does not optimize away the pattern we create. |
| 159 | + // Otherwise the Rust side would not be able to see it. |
| 160 | + volatile uint8_t* p = (volatile uint8_t*)&value; |
| 161 | + int i = 0; |
| 162 | + for (i = 0; i < size; ++i) { |
| 163 | + // We skip padding bytes in both Rust and C because writing to it is undefined. |
| 164 | + // Instead we just make sure the the placement of the padding bytes remains the same. |
| 165 | + if (is_padding_byte[i]) { continue; } |
| 166 | + value_bytes[i] = p[i]; |
| 167 | + // After we check that the pattern remained unchanged from Rust to C, we invert the pattern |
| 168 | + // and send it back to Rust to make sure that it remains unchanged from C to Rust. |
| 169 | + uint8_t d = (uint8_t)(255) - (uint8_t)(i % 256); |
| 170 | + d = d == 0 ? 42: d; |
| 171 | + p[i] = d; |
| 172 | + } |
| 173 | + return value; |
| 174 | +} |
| 175 | + |
| 176 | +#ifdef __GNUC__ |
| 177 | + // Pop allow for `-Wignored-qualifiers` |
| 178 | + #pragma GCC diagnostic pop |
| 179 | +#endif |
| 180 | + |
| 181 | +#ifdef _MSC_VER |
| 182 | + // Pop allow for 4365 |
| 183 | + #pragma warning(default:4365) |
| 184 | +#endif |
| 185 | + |
| 186 | +#ifdef _MSC_VER |
| 187 | + // Disable function pointer type conversion warnings on MSVC. |
| 188 | + // The conversion may fail only if we call that function, however we only check its address. |
| 189 | + #pragma warning(disable:4191) |
| 190 | +#endif |
| 191 | + |
| 192 | +#ifdef _MSC_VER |
| 193 | + // Pop allow for 4191 |
| 194 | + #pragma warning(default:4191) |
| 195 | +#endif |
0 commit comments