1
Fork 0

Remove all uses of native cdecl except for those that yield

This commit is contained in:
Brian Anderson 2011-11-08 11:09:40 -08:00
parent a727bbaf70
commit 0f1af17a60
14 changed files with 58 additions and 27 deletions

View file

@ -77,7 +77,7 @@ fn writeclose(fd: int, s: option::t<str>) {
writer.write_str(option::get(s)); writer.write_str(option::get(s));
} }
os::libc::close(fd); os::close(fd);
} }
fn readclose(fd: int) -> str { fn readclose(fd: int) -> str {
@ -89,7 +89,7 @@ fn readclose(fd: int) -> str {
let bytes = reader.read_bytes(4096u); let bytes = reader.read_bytes(4096u);
buf += str::unsafe_from_bytes(bytes); buf += str::unsafe_from_bytes(bytes);
} }
os::libc::fclose(file); os::fclose(file);
ret buf; ret buf;
} }
@ -134,13 +134,13 @@ fn worker(p: port<request>) {
pipe_in.in, pipe_out.out, pipe_err.out); pipe_in.in, pipe_out.out, pipe_err.out);
let pid = maybe_with_lib_path(execparms.lib_path, spawnproc); let pid = maybe_with_lib_path(execparms.lib_path, spawnproc);
os::libc::close(pipe_in.in); os::close(pipe_in.in);
os::libc::close(pipe_out.out); os::close(pipe_out.out);
os::libc::close(pipe_err.out); os::close(pipe_err.out);
if pid == -1 { if pid == -1 {
os::libc::close(pipe_in.out); os::close(pipe_in.out);
os::libc::close(pipe_out.in); os::close(pipe_out.in);
os::libc::close(pipe_err.in); os::close(pipe_err.in);
fail; fail;
} }

View file

@ -6,7 +6,7 @@ TODO: Restructure and document
// FIXME Somehow merge stuff duplicated here and macosx_os.rs. Made difficult // FIXME Somehow merge stuff duplicated here and macosx_os.rs. Made difficult
// by https://github.com/graydon/rust/issues#issue/268 // by https://github.com/graydon/rust/issues#issue/268
native "cdecl" mod libc = "" { native "c-stack-cdecl" mod libc = "" {
fn read(fd: int, buf: *u8, count: uint) -> int; fn read(fd: int, buf: *u8, count: uint) -> int;
fn write(fd: int, buf: *u8, count: uint) -> int; fn write(fd: int, buf: *u8, count: uint) -> int;
fn fread(buf: *u8, size: uint, n: uint, f: libc::FILE) -> uint; fn fread(buf: *u8, size: uint, n: uint, f: libc::FILE) -> uint;
@ -72,6 +72,14 @@ fn fd_FILE(fd: int) -> libc::FILE {
ret str::as_buf("r", {|modebuf| libc::fdopen(fd, modebuf) }); ret str::as_buf("r", {|modebuf| libc::fdopen(fd, modebuf) });
} }
fn close(fd: int) -> int {
libc::close(fd)
}
fn fclose(file: libc::FILE) {
libc::fclose(file)
}
fn waitpid(pid: int) -> int { fn waitpid(pid: int) -> int {
let status = 0; let status = 0;
assert (os::libc::waitpid(pid, status, 0) != -1); assert (os::libc::waitpid(pid, status, 0) != -1);

View file

@ -1,5 +1,5 @@
native "cdecl" mod libc = "" { native "c-stack-cdecl" mod libc = "" {
fn read(fd: int, buf: *u8, count: uint) -> int; fn read(fd: int, buf: *u8, count: uint) -> int;
fn write(fd: int, buf: *u8, count: uint) -> int; fn write(fd: int, buf: *u8, count: uint) -> int;
fn fread(buf: *u8, size: uint, n: uint, f: libc::FILE) -> uint; fn fread(buf: *u8, size: uint, n: uint, f: libc::FILE) -> uint;
@ -65,6 +65,14 @@ fn fd_FILE(fd: int) -> libc::FILE {
ret str::as_buf("r", {|modebuf| libc::fdopen(fd, modebuf) }); ret str::as_buf("r", {|modebuf| libc::fdopen(fd, modebuf) });
} }
fn close(fd: int) -> int {
libc::close(fd)
}
fn fclose(file: libc::FILE) {
libc::fclose(file)
}
fn waitpid(pid: int) -> int { fn waitpid(pid: int) -> int {
let status = 0; let status = 0;
assert (os::libc::waitpid(pid, status, 0) != -1); assert (os::libc::waitpid(pid, status, 0) != -1);

View file

@ -148,7 +148,7 @@ mod icu {
// FIXME: should be -1, change when compiler supports negative // FIXME: should be -1, change when compiler supports negative
// constants // constants
native "cdecl" mod libicu = "icuuc" { native "c-stack-cdecl" mod libicu = "icuuc" {
fn u_hasBinaryProperty(c: UChar32, which: UProperty) -> UBool; fn u_hasBinaryProperty(c: UChar32, which: UProperty) -> UBool;
} }
} }

View file

@ -1,5 +1,5 @@
native "cdecl" mod libc = "" { native "c-stack-cdecl" mod libc = "" {
fn read(fd: int, buf: *u8, count: uint) -> int; fn read(fd: int, buf: *u8, count: uint) -> int;
fn write(fd: int, buf: *u8, count: uint) -> int; fn write(fd: int, buf: *u8, count: uint) -> int;
fn fread(buf: *u8, size: uint, n: uint, f: libc::FILE) -> uint; fn fread(buf: *u8, size: uint, n: uint, f: libc::FILE) -> uint;
@ -79,6 +79,14 @@ fn fd_FILE(fd: int) -> libc::FILE {
ret str::as_buf("r", {|modebuf| libc::_fdopen(fd, modebuf) }); ret str::as_buf("r", {|modebuf| libc::_fdopen(fd, modebuf) });
} }
fn close(fd: int) -> int {
libc::close(fd)
}
fn fclose(file: libc::FILE) {
libc::fclose(file)
}
native "c-stack-cdecl" mod rustrt { native "c-stack-cdecl" mod rustrt {
fn rust_process_wait(handle: int) -> int; fn rust_process_wait(handle: int) -> int;
fn rust_getcwd() -> str; fn rust_getcwd() -> str;

View file

@ -1,6 +1,6 @@
// -*- rust -*- // -*- rust -*-
// error-pattern: safe function calls function marked unsafe // error-pattern: safe function calls function marked unsafe
native "cdecl" mod test { native "c-stack-cdecl" mod test {
unsafe fn free(); unsafe fn free();
} }

View file

@ -1,7 +1,7 @@
// -*- rust -*- // -*- rust -*-
// error-pattern: unsafe functions can only be called // error-pattern: unsafe functions can only be called
native "cdecl" mod test { native "c-stack-cdecl" mod test {
unsafe fn free(); unsafe fn free();
} }

View file

@ -2,7 +2,7 @@
Can we bind native things? Can we bind native things?
*/ */
native "cdecl" mod rustrt { native "c-stack-cdecl" mod rustrt {
fn task_yield(); fn task_yield();
} }

View file

@ -117,15 +117,17 @@ fn test_fn() {
assert (h1 >= h2); assert (h1 >= h2);
} }
native "cdecl" mod native_mod = "" { native "c-stack-cdecl" mod native_mod = "" {
fn do_gc(); fn do_gc();
fn unsupervise(); fn unsupervise();
} }
// FIXME: comparison of native fns // FIXME (#1058): comparison of native fns
fn test_native_fn() { fn test_native_fn() {
/*
assert (native_mod::do_gc == native_mod::do_gc); assert (native_mod::do_gc == native_mod::do_gc);
assert (native_mod::do_gc != native_mod::unsupervise); assert (native_mod::do_gc != native_mod::unsupervise);
*/
} }
fn test_obj() { fn test_obj() {

View file

@ -20,7 +20,7 @@ mod a1 {
// | | | // | | |
mod a2 { mod a2 {
// | | | // | | |
native "cdecl" mod b1 = "" { native "c-stack-cdecl" mod b1 = "" {
// | | | // | | |
import a1::b2::*; import a1::b2::*;
// | <-/ -/ // | <-/ -/

View file

@ -1,3 +1,8 @@
// xfail-test
// FIXME: This test is no longer testing what it was intended to. It should
// be testing spawning of a native function, but is actually testing
// spawning some other function, then executing a native function.
/* /*
A reduced test case for Issue #506, provided by Rob Arnold. A reduced test case for Issue #506, provided by Rob Arnold.
*/ */

View file

@ -1,6 +1,6 @@
native "cdecl" mod libc = "" { native "c-stack-cdecl" mod libc = "" {
type file_handle; type file_handle;
} }

View file

@ -6,12 +6,12 @@ native "c-stack-cdecl" mod rustrt {
native "c-stack-cdecl" mod bar = "" { } native "c-stack-cdecl" mod bar = "" { }
native "cdecl" mod zed = "" { } native "c-stack-cdecl" mod zed = "" { }
native "cdecl" mod libc = "" { native "c-stack-cdecl" mod libc = "" {
fn write(fd: int, buf: *u8, count: uint) -> int; fn write(fd: int, buf: *u8, count: uint) -> int;
} }
native "cdecl" mod baz = "" { } native "c-stack-cdecl" mod baz = "" { }
fn main(args: [str]) { } fn main(args: [str]) { }

View file

@ -22,9 +22,9 @@ fn test_pipes() unsafe {
let pid = let pid =
run::spawn_process("cat", [], pipe_in.in, pipe_out.out, pipe_err.out); run::spawn_process("cat", [], pipe_in.in, pipe_out.out, pipe_err.out);
os::libc::close(pipe_in.in); os::close(pipe_in.in);
os::libc::close(pipe_out.out); os::close(pipe_out.out);
os::libc::close(pipe_err.out); os::close(pipe_err.out);
if pid == -1 { fail; } if pid == -1 { fail; }
let expected = "test"; let expected = "test";
@ -41,7 +41,7 @@ fn test_pipes() unsafe {
let writer = io::new_writer(io::fd_buf_writer(fd, option::none)); let writer = io::new_writer(io::fd_buf_writer(fd, option::none));
writer.write_str(s); writer.write_str(s);
os::libc::close(fd); os::close(fd);
} }
fn readclose(fd: int) -> str unsafe { fn readclose(fd: int) -> str unsafe {
@ -53,7 +53,7 @@ fn test_pipes() unsafe {
let bytes = reader.read_bytes(4096u); let bytes = reader.read_bytes(4096u);
buf += str::unsafe_from_bytes(bytes); buf += str::unsafe_from_bytes(bytes);
} }
os::libc::fclose(file); os::fclose(file);
ret buf; ret buf;
} }
} }