Skip to content

Commit 9068410

Browse files
xavi-ocemilio
authored andcommitted
Fix #1085 - Incorrect detection of duplicated constants
1 parent d6437ef commit 9068410

13 files changed

+208
-2
lines changed

src/bindgen/ir/constant.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,15 @@ impl Constant {
546546
documentation: Documentation,
547547
associated_to: Option<Path>,
548548
) -> Self {
549-
let export_name = path.name().to_owned();
549+
let export_name = match associated_to.clone() {
550+
Some(associated_to) => path
551+
.name()
552+
.strip_suffix(associated_to.name())
553+
.unwrap()
554+
.to_owned(),
555+
None => path.name().to_owned(),
556+
};
557+
550558
Self {
551559
path,
552560
export_name,

src/bindgen/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ impl Parse {
795795
return;
796796
}
797797

798-
let path = Path::new(item.ident.unraw().to_string());
798+
let path = Path::new(item.ident.unraw().to_string() + impl_path.name());
799799
match Constant::load(
800800
path,
801801
mod_cfg,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
root;
3+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
typedef struct {
7+
uint32_t field;
8+
} Foo;
9+
#define Foo_FIELD_RELATED_CONSTANT 0
10+
11+
typedef struct {
12+
uint32_t field;
13+
} Bar;
14+
#define Bar_FIELD_RELATED_CONSTANT 0
15+
16+
void root(Foo a, Bar b);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
typedef struct {
7+
uint32_t field;
8+
} Foo;
9+
#define Foo_FIELD_RELATED_CONSTANT 0
10+
11+
typedef struct {
12+
uint32_t field;
13+
} Bar;
14+
#define Bar_FIELD_RELATED_CONSTANT 0
15+
16+
#ifdef __cplusplus
17+
extern "C" {
18+
#endif // __cplusplus
19+
20+
void root(Foo a, Bar b);
21+
22+
#ifdef __cplusplus
23+
} // extern "C"
24+
#endif // __cplusplus
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <cstdarg>
2+
#include <cstdint>
3+
#include <cstdlib>
4+
#include <ostream>
5+
#include <new>
6+
7+
struct Foo {
8+
uint32_t field;
9+
};
10+
constexpr static const uint32_t Foo_FIELD_RELATED_CONSTANT = 0;
11+
12+
struct Bar {
13+
uint32_t field;
14+
};
15+
constexpr static const uint32_t Bar_FIELD_RELATED_CONSTANT = 0;
16+
17+
extern "C" {
18+
19+
void root(Foo a, Bar b);
20+
21+
} // extern "C"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t
2+
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t
3+
cdef extern from *:
4+
ctypedef bint bool
5+
ctypedef struct va_list
6+
7+
cdef extern from *:
8+
9+
ctypedef struct Foo:
10+
uint32_t field;
11+
const uint32_t Foo_FIELD_RELATED_CONSTANT # = 0
12+
13+
ctypedef struct Bar:
14+
uint32_t field;
15+
const uint32_t Bar_FIELD_RELATED_CONSTANT # = 0
16+
17+
void root(Foo a, Bar b);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
typedef struct Foo {
7+
uint32_t field;
8+
} Foo;
9+
#define Foo_FIELD_RELATED_CONSTANT 0
10+
11+
typedef struct Bar {
12+
uint32_t field;
13+
} Bar;
14+
#define Bar_FIELD_RELATED_CONSTANT 0
15+
16+
void root(struct Foo a, struct Bar b);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
typedef struct Foo {
7+
uint32_t field;
8+
} Foo;
9+
#define Foo_FIELD_RELATED_CONSTANT 0
10+
11+
typedef struct Bar {
12+
uint32_t field;
13+
} Bar;
14+
#define Bar_FIELD_RELATED_CONSTANT 0
15+
16+
#ifdef __cplusplus
17+
extern "C" {
18+
#endif // __cplusplus
19+
20+
void root(struct Foo a, struct Bar b);
21+
22+
#ifdef __cplusplus
23+
} // extern "C"
24+
#endif // __cplusplus
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
struct Foo {
7+
uint32_t field;
8+
};
9+
#define Foo_FIELD_RELATED_CONSTANT 0
10+
11+
struct Bar {
12+
uint32_t field;
13+
};
14+
#define Bar_FIELD_RELATED_CONSTANT 0
15+
16+
void root(struct Foo a, struct Bar b);

0 commit comments

Comments
 (0)