Skip to content

Commit

Permalink
Auto merge of #1008 - AndrewGaspar:underscore-identifier, r=fitzgen
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors-servo authored Sep 21, 2017
2 parents a8f4bc9 + aa11524 commit 5b49548
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,8 @@ impl BindgenContext {
"where" |
"while" |
"yield" |
"bool" => true,
"bool" |
"_" => true,
_ => false,
}
{
Expand Down
40 changes: 40 additions & 0 deletions tests/expectations/tests/underscore.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


pub const __: ::std::os::raw::c_int = 10;
#[repr(C)]
#[derive(Debug, Default, Copy)]
pub struct ptr_t {
pub __: [::std::os::raw::c_uchar; 8usize],
}
#[test]
fn bindgen_test_layout_ptr_t() {
assert_eq!(
::std::mem::size_of::<ptr_t>(),
8usize,
concat!("Size of: ", stringify!(ptr_t))
);
assert_eq!(
::std::mem::align_of::<ptr_t>(),
1usize,
concat!("Alignment of ", stringify!(ptr_t))
);
assert_eq!(
unsafe { &(*(0 as *const ptr_t)).__ as *const _ as usize },
0usize,
concat!(
"Alignment of field: ",
stringify!(ptr_t),
"::",
stringify!(__)
)
);
}
impl Clone for ptr_t {
fn clone(&self) -> Self {
*self
}
}
3 changes: 3 additions & 0 deletions tests/headers/underscore.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const int _ = 10;

typedef struct { unsigned char _[8]; } ptr_t;

0 comments on commit 5b49548

Please sign in to comment.