Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement mangling for arrays #1022

Merged
merged 2 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/bindgen/mangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ enum Separator {
BeginFn,
BetweenFnArg,
EndFn,
BeginArray,
BetweenArray,
}

struct Mangler<'a> {
Expand Down Expand Up @@ -128,12 +130,11 @@ impl<'a> Mangler<'a> {
self.push(Separator::EndFn);
}
}
Type::Array(..) => {
unimplemented!(
"Unable to mangle generic parameter {:?} for '{}'",
ty,
self.input
);
Type::Array(ref ty, ref len) => {
self.push(Separator::BeginArray);
self.append_mangled_type(ty, false);
self.push(Separator::BetweenArray);
self.append_mangled_argument(&GenericArgument::Const(len.clone()), last);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/expectations/generic_pointer.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ typedef struct {

typedef Foo_____u8 Boo;

typedef struct {
uint8_t a[4];
} Foo__________u8__________4;

void root(Boo x);

void my_function(Foo__________u8__________4 x);
6 changes: 6 additions & 0 deletions tests/expectations/generic_pointer.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ typedef struct {

typedef Foo_____u8 Boo;

typedef struct {
uint8_t a[4];
} Foo__________u8__________4;

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

void root(Boo x);

void my_function(Foo__________u8__________4 x);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
2 changes: 2 additions & 0 deletions tests/expectations/generic_pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ extern "C" {

void root(Boo x);

void my_function(Foo<uint8_t[4]> x);

} // extern "C"
5 changes: 5 additions & 0 deletions tests/expectations/generic_pointer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ cdef extern from *:

ctypedef Foo_____u8 Boo;

ctypedef struct Foo__________u8__________4:
uint8_t a[4];

void root(Boo x);

void my_function(Foo__________u8__________4 x);
6 changes: 6 additions & 0 deletions tests/expectations/generic_pointer_both.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ typedef struct Foo_____u8 {

typedef struct Foo_____u8 Boo;

typedef struct Foo__________u8__________4 {
uint8_t a[4];
} Foo__________u8__________4;

void root(Boo x);

void my_function(struct Foo__________u8__________4 x);
6 changes: 6 additions & 0 deletions tests/expectations/generic_pointer_both.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ typedef struct Foo_____u8 {

typedef struct Foo_____u8 Boo;

typedef struct Foo__________u8__________4 {
uint8_t a[4];
} Foo__________u8__________4;

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

void root(Boo x);

void my_function(struct Foo__________u8__________4 x);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
6 changes: 6 additions & 0 deletions tests/expectations/generic_pointer_tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ struct Foo_____u8 {

typedef struct Foo_____u8 Boo;

struct Foo__________u8__________4 {
uint8_t a[4];
};

void root(Boo x);

void my_function(struct Foo__________u8__________4 x);
6 changes: 6 additions & 0 deletions tests/expectations/generic_pointer_tag.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ struct Foo_____u8 {

typedef struct Foo_____u8 Boo;

struct Foo__________u8__________4 {
uint8_t a[4];
};

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

void root(Boo x);

void my_function(struct Foo__________u8__________4 x);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
5 changes: 5 additions & 0 deletions tests/expectations/generic_pointer_tag.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ cdef extern from *:

ctypedef Foo_____u8 Boo;

cdef struct Foo__________u8__________4:
uint8_t a[4];

void root(Boo x);

void my_function(Foo__________u8__________4 x);
3 changes: 3 additions & 0 deletions tests/rust/generic_pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ pub type Boo = Foo<*mut u8>;
pub extern "C" fn root(
x: Boo,
) { }

#[no_mangle]
pub extern "C" fn my_function(x: Foo<[u8; 4]>) {}
Loading