Skip to content

Commit 447afe1

Browse files
committed
bindgen: Change how opaque comp types are managed
So it's not awfully broken.
1 parent 9d3fccc commit 447afe1

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

src/gen.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,14 @@ fn gen_mod(mut ctx: &mut GenCtx,
376376
}
377377
}
378378

379+
// XXX: Replace the name-based lookup, or do it at parse-time,
380+
// to keep all the mess in the same place.
379381
fn type_opaque(ctx: &GenCtx, ty: &Type) -> bool {
382+
match *ty {
383+
TComp(ref ci) if ci.borrow().opaque => return true,
384+
_ => {}
385+
}
386+
380387
let ty_name = ty.name();
381388

382389
match ty_name {
@@ -389,6 +396,12 @@ fn type_opaque(ctx: &GenCtx, ty: &Type) -> bool {
389396
fn global_opaque(ctx: &GenCtx, global: &Global) -> bool {
390397
let global_name = global.name();
391398

399+
match *global {
400+
GCompDecl(ref ci) |
401+
GComp(ref ci) if ci.borrow().opaque => return true,
402+
_ => {}
403+
}
404+
392405
// Can't make an opaque type without layout
393406
global.layout().is_some() &&
394407
ctx.options.opaque_types.iter().any(|name| *name == global_name)

src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ fn visit_top(cursor: &Cursor,
902902
visit_composite(c, p, ctx_, &mut ci_)
903903
});
904904
if anno.opaque {
905-
ci.borrow_mut().members = vec!();
905+
ci.borrow_mut().opaque = true;
906906
}
907907
if anno.hide {
908908
ci.borrow_mut().hide = true;

src/types.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,11 @@ pub struct CompInfo {
308308
pub has_destructor: bool,
309309
pub has_nonempty_base: bool,
310310
pub hide: bool,
311+
/// If this struct should be replaced by an opaque blob.
312+
///
313+
/// This is useful if for some reason we can't generate
314+
/// the correct layout.
315+
pub opaque: bool,
311316
pub base_members: usize,
312317
pub layout: Layout,
313318
/// Typedef'd types names, that we'll resolve early to avoid name conflicts
@@ -347,6 +352,7 @@ impl CompInfo {
347352
has_destructor: false,
348353
has_nonempty_base: false,
349354
hide: false,
355+
opaque: false,
350356
base_members: 0,
351357
layout: layout,
352358
typedefs: vec!(),

tests/headers/annotation_hide.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@
33
* <div rustbindgen="true" hide="true"></div>
44
*/
55
struct C;
6+
7+
/**
8+
* <div rustbindgen opaque></div>
9+
*/
10+
struct D {
11+
int a;
12+
};

0 commit comments

Comments
 (0)