Skip to content

Commit

Permalink
Add support for NonZero<T> and simplify handling of int primitives
Browse files Browse the repository at this point in the history
Closes #964.
  • Loading branch information
scovich authored and emilio committed May 26, 2024
1 parent c6012a0 commit ad84541
Show file tree
Hide file tree
Showing 11 changed files with 489 additions and 354 deletions.
361 changes: 122 additions & 239 deletions src/bindgen/ir/ty.rs

Large diffs are not rendered by default.

51 changes: 38 additions & 13 deletions tests/expectations/nonzero.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,41 @@ typedef struct {
int64_t h;
int64_t i;
const Option_i64 *j;
} NonZeroTest;

void root(NonZeroTest test,
uint8_t a,
uint16_t b,
uint32_t c,
uint64_t d,
int8_t e,
int16_t f,
int32_t g,
int64_t h,
int64_t i,
const Option_i64 *j);
} NonZeroAliases;

typedef struct {
uint8_t a;
uint16_t b;
uint32_t c;
uint64_t d;
int8_t e;
int16_t f;
int32_t g;
int64_t h;
int64_t i;
const Option_i64 *j;
} NonZeroGenerics;

void root_nonzero_aliases(NonZeroAliases test,
uint8_t a,
uint16_t b,
uint32_t c,
uint64_t d,
int8_t e,
int16_t f,
int32_t g,
int64_t h,
int64_t i,
const Option_i64 *j);

void root_nonzero_generics(NonZeroGenerics test,
uint8_t a,
uint16_t b,
uint32_t c,
uint64_t d,
int8_t e,
int16_t f,
int32_t g,
int64_t h,
int64_t i,
const Option_i64 *j);
49 changes: 37 additions & 12 deletions tests/expectations/nonzero.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,48 @@ typedef struct {
int64_t h;
int64_t i;
const Option_i64 *j;
} NonZeroTest;
} NonZeroAliases;

typedef struct {
uint8_t a;
uint16_t b;
uint32_t c;
uint64_t d;
int8_t e;
int16_t f;
int32_t g;
int64_t h;
int64_t i;
const Option_i64 *j;
} NonZeroGenerics;

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void root(NonZeroTest test,
uint8_t a,
uint16_t b,
uint32_t c,
uint64_t d,
int8_t e,
int16_t f,
int32_t g,
int64_t h,
int64_t i,
const Option_i64 *j);
void root_nonzero_aliases(NonZeroAliases test,
uint8_t a,
uint16_t b,
uint32_t c,
uint64_t d,
int8_t e,
int16_t f,
int32_t g,
int64_t h,
int64_t i,
const Option_i64 *j);

void root_nonzero_generics(NonZeroGenerics test,
uint8_t a,
uint16_t b,
uint32_t c,
uint64_t d,
int8_t e,
int16_t f,
int32_t g,
int64_t h,
int64_t i,
const Option_i64 *j);

#ifdef __cplusplus
} // extern "C"
Expand Down
49 changes: 37 additions & 12 deletions tests/expectations/nonzero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@ struct NonZeroI64;
template<typename T = void>
struct Option;

struct NonZeroTest {
struct NonZeroAliases {
uint8_t a;
uint16_t b;
uint32_t c;
uint64_t d;
int8_t e;
int16_t f;
int32_t g;
int64_t h;
int64_t i;
const Option<int64_t> *j;
};

struct NonZeroGenerics {
uint8_t a;
uint16_t b;
uint32_t c;
Expand All @@ -35,16 +48,28 @@ struct NonZeroTest {

extern "C" {

void root(NonZeroTest test,
uint8_t a,
uint16_t b,
uint32_t c,
uint64_t d,
int8_t e,
int16_t f,
int32_t g,
int64_t h,
int64_t i,
const Option<int64_t> *j);
void root_nonzero_aliases(NonZeroAliases test,
uint8_t a,
uint16_t b,
uint32_t c,
uint64_t d,
int8_t e,
int16_t f,
int32_t g,
int64_t h,
int64_t i,
const Option<int64_t> *j);

void root_nonzero_generics(NonZeroGenerics test,
uint8_t a,
uint16_t b,
uint32_t c,
uint64_t d,
int8_t e,
int16_t f,
int32_t g,
int64_t h,
int64_t i,
const Option<int64_t> *j);

} // extern "C"
48 changes: 36 additions & 12 deletions tests/expectations/nonzero.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cdef extern from *:
ctypedef struct Option_i64:
pass

ctypedef struct NonZeroTest:
ctypedef struct NonZeroAliases:
uint8_t a;
uint16_t b;
uint32_t c;
Expand All @@ -34,14 +34,38 @@ cdef extern from *:
int64_t i;
const Option_i64 *j;

void root(NonZeroTest test,
uint8_t a,
uint16_t b,
uint32_t c,
uint64_t d,
int8_t e,
int16_t f,
int32_t g,
int64_t h,
int64_t i,
const Option_i64 *j);
ctypedef struct NonZeroGenerics:
uint8_t a;
uint16_t b;
uint32_t c;
uint64_t d;
int8_t e;
int16_t f;
int32_t g;
int64_t h;
int64_t i;
const Option_i64 *j;

void root_nonzero_aliases(NonZeroAliases test,
uint8_t a,
uint16_t b,
uint32_t c,
uint64_t d,
int8_t e,
int16_t f,
int32_t g,
int64_t h,
int64_t i,
const Option_i64 *j);

void root_nonzero_generics(NonZeroGenerics test,
uint8_t a,
uint16_t b,
uint32_t c,
uint64_t d,
int8_t e,
int16_t f,
int32_t g,
int64_t h,
int64_t i,
const Option_i64 *j);
53 changes: 39 additions & 14 deletions tests/expectations/nonzero_both.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct NonZeroI64;

typedef struct Option_i64 Option_i64;

typedef struct NonZeroTest {
typedef struct NonZeroAliases {
uint8_t a;
uint16_t b;
uint32_t c;
Expand All @@ -29,16 +29,41 @@ typedef struct NonZeroTest {
int64_t h;
int64_t i;
const struct Option_i64 *j;
} NonZeroTest;

void root(struct NonZeroTest test,
uint8_t a,
uint16_t b,
uint32_t c,
uint64_t d,
int8_t e,
int16_t f,
int32_t g,
int64_t h,
int64_t i,
const struct Option_i64 *j);
} NonZeroAliases;

typedef struct NonZeroGenerics {
uint8_t a;
uint16_t b;
uint32_t c;
uint64_t d;
int8_t e;
int16_t f;
int32_t g;
int64_t h;
int64_t i;
const struct Option_i64 *j;
} NonZeroGenerics;

void root_nonzero_aliases(struct NonZeroAliases test,
uint8_t a,
uint16_t b,
uint32_t c,
uint64_t d,
int8_t e,
int16_t f,
int32_t g,
int64_t h,
int64_t i,
const struct Option_i64 *j);

void root_nonzero_generics(struct NonZeroGenerics test,
uint8_t a,
uint16_t b,
uint32_t c,
uint64_t d,
int8_t e,
int16_t f,
int32_t g,
int64_t h,
int64_t i,
const struct Option_i64 *j);
51 changes: 38 additions & 13 deletions tests/expectations/nonzero_both.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct NonZeroI64;

typedef struct Option_i64 Option_i64;

typedef struct NonZeroTest {
typedef struct NonZeroAliases {
uint8_t a;
uint16_t b;
uint32_t c;
Expand All @@ -29,23 +29,48 @@ typedef struct NonZeroTest {
int64_t h;
int64_t i;
const struct Option_i64 *j;
} NonZeroTest;
} NonZeroAliases;

typedef struct NonZeroGenerics {
uint8_t a;
uint16_t b;
uint32_t c;
uint64_t d;
int8_t e;
int16_t f;
int32_t g;
int64_t h;
int64_t i;
const struct Option_i64 *j;
} NonZeroGenerics;

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void root(struct NonZeroTest test,
uint8_t a,
uint16_t b,
uint32_t c,
uint64_t d,
int8_t e,
int16_t f,
int32_t g,
int64_t h,
int64_t i,
const struct Option_i64 *j);
void root_nonzero_aliases(struct NonZeroAliases test,
uint8_t a,
uint16_t b,
uint32_t c,
uint64_t d,
int8_t e,
int16_t f,
int32_t g,
int64_t h,
int64_t i,
const struct Option_i64 *j);

void root_nonzero_generics(struct NonZeroGenerics test,
uint8_t a,
uint16_t b,
uint32_t c,
uint64_t d,
int8_t e,
int16_t f,
int32_t g,
int64_t h,
int64_t i,
const struct Option_i64 *j);

#ifdef __cplusplus
} // extern "C"
Expand Down
Loading

0 comments on commit ad84541

Please sign in to comment.