Skip to content

Commit ce55116

Browse files
committed
---
yaml --- r: 1450 b: refs/heads/master c: a172f5a h: refs/heads/master v: v3
1 parent e3c7ec1 commit ce55116

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 4ac4d03f0cac829650f7a297162d070de53c6455
2+
refs/heads/master: a172f5aef5f7d26fba9dbf94a1ade60d6d62ba74

trunk/src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ TEST_XFAILS_RUSTC := $(CONST_TAG_XFAILS) \
491491
mlist-cycle.rs \
492492
mlist.rs \
493493
mutable-alias-vec.rs \
494+
native2.rs \
494495
native-opaque-type.rs \
495496
obj-as.rs \
496497
obj-dtor.rs \

trunk/src/comp/middle/trans.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4395,6 +4395,12 @@ fn decl_fn_and_pair(@crate_ctxt cx,
43954395

43964396
// Declare the global constant pair that points to it.
43974397
let str ps = cx.names.next("_rust_" + kind + "_pair") + sep() + name;
4398+
4399+
register_fn_pair(cx, ps, llpairty, llfn, id);
4400+
}
4401+
4402+
fn register_fn_pair(@crate_ctxt cx, str ps, TypeRef llpairty, ValueRef llfn,
4403+
ast.def_id id) {
43984404
let ValueRef gvar = llvm.LLVMAddGlobal(cx.llmod, llpairty,
43994405
_str.buf(ps));
44004406
auto pair = C_struct(vec(llfn,
@@ -4410,16 +4416,34 @@ fn decl_fn_and_pair(@crate_ctxt cx,
44104416
cx.fn_pairs.insert(id, gvar);
44114417
}
44124418

4419+
fn native_fn_wrapper_type(@crate_ctxt cx, &ast.ann ann) -> TypeRef {
4420+
auto x = node_ann_type(cx, ann);
4421+
alt (x.struct) {
4422+
case (ty.ty_native_fn(?abi, ?args, ?out)) {
4423+
ret type_of_fn(cx, ast.proto_fn, args, out);
4424+
}
4425+
}
4426+
fail;
4427+
}
4428+
44134429
fn decl_native_fn_and_pair(@crate_ctxt cx,
44144430
str name,
44154431
&ast.ann ann,
44164432
ast.def_id id) {
4433+
// Declare the wrapper.
4434+
auto wrapper_type = native_fn_wrapper_type(cx, ann);
4435+
let str s = cx.names.next("_rust_wrapper") + sep() + name;
4436+
let ValueRef wrapper_fn = decl_fastcall_fn(cx.llmod, s, wrapper_type);
44174437

4418-
auto llpairty = node_type(cx, ann);
4419-
auto llfty = get_pair_fn_ty(llpairty);
4438+
// Declare the global constant pair that points to it.
4439+
auto wrapper_pair_type = T_fn_pair(cx.tn, wrapper_type);
4440+
let str ps = cx.names.next("_rust_wrapper_pair") + sep() + name;
44204441

4421-
let ValueRef llfn = decl_cdecl_fn(cx.llmod, name, llfty);
4422-
cx.item_ids.insert(id, llfn);
4442+
register_fn_pair(cx, ps, wrapper_pair_type, wrapper_fn, id);
4443+
4444+
// Declare the function itself.
4445+
auto llfty = get_pair_fn_ty(node_type(cx, ann));
4446+
decl_cdecl_fn(cx.llmod, name, llfty);
44234447
}
44244448

44254449
fn collect_native_item(&@crate_ctxt cx, @ast.native_item i) -> @crate_ctxt {

0 commit comments

Comments
 (0)