Skip to content

Commit 399da76

Browse files
committed
---
yaml --- r: 6219 b: refs/heads/master c: 4a4d31c h: refs/heads/master i: 6217: d148593 6215: 91b1db6 v: v3
1 parent 73d62d7 commit 399da76

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
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: ae2ce0926704be87cdc64c5721a926ffef846154
2+
refs/heads/master: 4a4d31cf0e6941dbffd86ac811714f0c5c1f6ee1

trunk/src/comp/middle/trans.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3840,6 +3840,7 @@ fn trans_c_stack_native_call(bcx: @block_ctxt, f: @ast::expr,
38403840
let ccx = bcx_ccx(bcx);
38413841
let f_res = trans_callee(bcx, f);
38423842
let llfn = f_res.val, bcx = f_res.bcx;
3843+
let llfn = BitCast(bcx, llfn, T_ptr(T_fn([], bcx_ccx(bcx).int_type)));
38433844

38443845
// Translate the callee.
38453846
let { params: _, ty: fn_ty } = ty::expr_ty_params_and_ty(bcx_tcx(bcx), f);
@@ -5651,8 +5652,22 @@ fn register_native_fn(ccx: @crate_ctxt, sp: span, path: [str], name: str,
56515652
ret;
56525653
}
56535654
ast::native_abi_c_stack_stdcall. {
5655+
// The name of stdcall functions depend on their argument count
5656+
// so we have to declare them correctly
5657+
let fn_args_tys = ty::ty_fn_args(ccx.tcx, fn_type);
5658+
let fn_ret_ty = ty::ty_fn_ret(ccx.tcx, fn_type);
5659+
let ll_args_tys = [];
5660+
for arg in fn_args_tys {
5661+
let arg_ty = arg.ty;
5662+
check type_has_static_size(ccx, arg_ty);
5663+
ll_args_tys += [type_of(ccx, sp, arg_ty)];
5664+
}
5665+
check type_has_static_size(ccx, fn_ret_ty);
5666+
let ll_ret_ty = type_of(ccx, sp, fn_ret_ty);
5667+
let native_fn_ty = T_fn(ll_args_tys, ll_ret_ty);
5668+
56545669
let llfn = decl_fn(ccx.llmod, name, lib::llvm::LLVMX86StdcallCallConv,
5655-
T_fn([], ccx.int_type));
5670+
native_fn_ty);
56565671
ccx.item_ids.insert(id, llfn);
56575672
ccx.item_symbols.insert(id, name);
56585673
ret;

trunk/src/test/run-pass/x86stdcall.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
// GetLastError doesn't seem to work with stack switching
2+
// xfail-test
3+
14
#[cfg(target_os = "win32")]
2-
native "x86stdcall" mod kernel32 {
5+
native "c-stack-stdcall" mod kernel32 {
36
fn SetLastError(err: uint);
47
fn GetLastError() -> uint;
58
}
69

10+
711
#[cfg(target_os = "win32")]
812
fn main() {
9-
let expected = 10u;
13+
let expected = 1234u;
1014
kernel32::SetLastError(expected);
1115
let actual = kernel32::GetLastError();
16+
log_err actual;
1217
assert (expected == actual);
1318
}
1419

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
type HANDLE = u32;
2+
type DWORD = u32;
3+
type SIZE_T = u32;
4+
type LPVOID = uint;
5+
type BOOL = u8;
6+
7+
#[cfg(target_os = "win32")]
8+
native "c-stack-stdcall" mod kernel32 {
9+
fn GetProcessHeap() -> HANDLE;
10+
fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) -> LPVOID;
11+
fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) -> BOOL;
12+
}
13+
14+
15+
#[cfg(target_os = "win32")]
16+
fn main() {
17+
let heap = kernel32::GetProcessHeap();
18+
let mem = kernel32::HeapAlloc(heap, 0u32, 100u32);
19+
assert mem != 0u;
20+
let res = kernel32::HeapFree(heap, 0u32, mem);
21+
assert res != 0u8;
22+
}
23+
24+
#[cfg(target_os = "macos")]
25+
#[cfg(target_os = "linux")]
26+
fn main() { }

0 commit comments

Comments
 (0)