Skip to content

Commit 5b49548

Browse files
author
bors-servo
authored
Auto merge of #1008 - AndrewGaspar:underscore-identifier, r=fitzgen
Translate _ as __ This change treats _ as a reserved identifier to resolve the bug reported in #631. I have one concern - if the header has both an `_` and `__` identifier in the global namespace, this will cause a conflict. However, it seems like we already don't handle that case for `keyword_` (e.g. `abstract_`, `alignof_`, etc.) so it doesn't seem like we need a solution specifically for `__` in this change. Fixes #631.
2 parents a8f4bc9 + aa11524 commit 5b49548

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

src/ir/context.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,8 @@ impl BindgenContext {
680680
"where" |
681681
"while" |
682682
"yield" |
683-
"bool" => true,
683+
"bool" |
684+
"_" => true,
684685
_ => false,
685686
}
686687
{
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
5+
6+
7+
pub const __: ::std::os::raw::c_int = 10;
8+
#[repr(C)]
9+
#[derive(Debug, Default, Copy)]
10+
pub struct ptr_t {
11+
pub __: [::std::os::raw::c_uchar; 8usize],
12+
}
13+
#[test]
14+
fn bindgen_test_layout_ptr_t() {
15+
assert_eq!(
16+
::std::mem::size_of::<ptr_t>(),
17+
8usize,
18+
concat!("Size of: ", stringify!(ptr_t))
19+
);
20+
assert_eq!(
21+
::std::mem::align_of::<ptr_t>(),
22+
1usize,
23+
concat!("Alignment of ", stringify!(ptr_t))
24+
);
25+
assert_eq!(
26+
unsafe { &(*(0 as *const ptr_t)).__ as *const _ as usize },
27+
0usize,
28+
concat!(
29+
"Alignment of field: ",
30+
stringify!(ptr_t),
31+
"::",
32+
stringify!(__)
33+
)
34+
);
35+
}
36+
impl Clone for ptr_t {
37+
fn clone(&self) -> Self {
38+
*self
39+
}
40+
}

tests/headers/underscore.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const int _ = 10;
2+
3+
typedef struct { unsigned char _[8]; } ptr_t;

0 commit comments

Comments
 (0)