Skip to content

Commit cc8ed87

Browse files
committed
Represent block pointers as *mut c_void instead.
Signed-off-by: Emilio Cobos Álvarez <[email protected]>
1 parent dd45e45 commit cc8ed87

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/codegen/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ impl CodeGenerator for Type {
311311
TypeKind::Float(..) |
312312
TypeKind::Array(..) |
313313
TypeKind::Pointer(..) |
314+
TypeKind::BlockPointer |
314315
TypeKind::Reference(..) |
315316
TypeKind::TemplateRef(..) |
316317
TypeKind::Function(..) |
@@ -1382,6 +1383,10 @@ impl ToRustTy for Type {
13821383

13831384
utils::build_templated_path(item, ctx, false)
13841385
}
1386+
TypeKind::BlockPointer => {
1387+
let void = raw!(c_void);
1388+
void.to_ptr(/* is_const = */ false, ctx.span())
1389+
}
13851390
TypeKind::Pointer(inner) |
13861391
TypeKind::Reference(inner) => {
13871392
let inner = ctx.resolve_item(inner);

src/ir/ty.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ impl Type {
9090
TypeKind::Array(..) |
9191
TypeKind::Reference(..) |
9292
TypeKind::Pointer(..) |
93+
TypeKind::BlockPointer |
9394
TypeKind::Int(..) |
9495
TypeKind::Float(..) |
9596
TypeKind::Named(..) => true,
@@ -124,8 +125,9 @@ impl Type {
124125
TypeKind::Comp(ref ci)
125126
=> ci.layout(type_resolver),
126127
// FIXME(emilio): This is a hack for anonymous union templates.
127-
// Use the actual pointer size!
128-
TypeKind::Pointer(..)
128+
// Use the actual pointer size!
129+
TypeKind::Pointer(..) |
130+
TypeKind::BlockPointer
129131
=> Some(Layout::new(mem::size_of::<*mut ()>(), mem::align_of::<*mut ()>())),
130132
TypeKind::ResolvedTypeRef(inner)
131133
=> type_resolver.resolve_type(inner).layout(type_resolver),
@@ -286,6 +288,7 @@ impl Type {
286288
TypeKind::Reference(..) |
287289
TypeKind::Void |
288290
TypeKind::NullPtr |
291+
TypeKind::BlockPointer |
289292
TypeKind::Pointer(..) => self,
290293

291294
TypeKind::ResolvedTypeRef(inner) |
@@ -334,6 +337,8 @@ pub enum TypeKind {
334337
/// A pointer to a type. The bool field represents whether it's const or
335338
/// not.
336339
Pointer(ItemId),
340+
/// A pointer to an Apple block.
341+
BlockPointer,
337342
/// A reference to a type, as in: int& foo().
338343
Reference(ItemId),
339344
/// A reference to a template, with different template parameter names. To
@@ -376,6 +381,7 @@ impl Type {
376381
TypeKind::Enum(..) |
377382
TypeKind::Reference(..) |
378383
TypeKind::NullPtr |
384+
TypeKind::BlockPointer |
379385
TypeKind::Pointer(..) => false,
380386

381387
TypeKind::UnresolvedTypeRef(..)
@@ -485,13 +491,15 @@ impl Type {
485491
// We might need to, though, if the context is already in the
486492
// process of resolving them.
487493
CXType_MemberPointer |
488-
CXType_BlockPointer |
489494
CXType_Pointer => {
490495
let inner =
491496
Item::from_ty_or_ref(ty.pointee_type(), location,
492497
parent_id, ctx);
493498
TypeKind::Pointer(inner)
494499
}
500+
CXType_BlockPointer => {
501+
TypeKind::BlockPointer
502+
}
495503
// XXX: RValueReference is most likely wrong, but I don't think we
496504
// can even add bindings for that, so huh.
497505
CXType_RValueReference |

tests/expectations/blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66

77
extern "C" {
8-
pub fn atexit_b(arg1: ::std::option::Option<unsafe extern "C" fn()>);
8+
pub fn atexit_b(arg1: *mut ::std::os::raw::c_void);
99
}

0 commit comments

Comments
 (0)