Skip to content

Commit 856a544

Browse files
committed
Remove native types from stdlib
1 parent c6aead7 commit 856a544

14 files changed

+87
-101
lines changed

src/libcore/comm.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ export recv;
2929
export chan::{};
3030
export port::{};
3131

32+
enum rust_port {}
33+
3234
#[abi = "cdecl"]
3335
native mod rustrt {
34-
type rust_port;
35-
3636
fn chan_id_send<T: send>(t: *sys::type_desc,
3737
target_task: task::task, target_port: port_id,
3838
data: T) -> ctypes::uintptr_t;
@@ -72,7 +72,7 @@ enum chan<T: send> {
7272
chan_t(task::task, port_id)
7373
}
7474

75-
resource port_ptr<T: send>(po: *rustrt::rust_port) {
75+
resource port_ptr<T: send>(po: *rust_port) {
7676
// Once the port is detached it's guaranteed not to receive further
7777
// messages
7878
rustrt::rust_port_detach(po);
@@ -127,13 +127,13 @@ fn recv<T: send>(p: port<T>) -> T { recv_(***p) }
127127
#[doc(
128128
brief = "Receive on a raw port pointer"
129129
)]
130-
fn recv_<T: send>(p: *rustrt::rust_port) -> T {
130+
fn recv_<T: send>(p: *rust_port) -> T {
131131
// FIXME: Due to issue 1185 we can't use a return pointer when
132132
// calling C code, and since we can't create our own return
133133
// pointer on the stack, we're going to call a little intrinsic
134134
// that will grab the value of the return pointer, then call this
135135
// function, which we will then use to call the runtime.
136-
fn recv(dptr: *uint, port: *rustrt::rust_port,
136+
fn recv(dptr: *uint, port: *rust_port,
137137
yield: *ctypes::uintptr_t,
138138
killed: *ctypes::uintptr_t) unsafe {
139139
rustrt::port_recv(dptr, port, yield, killed);

src/libcore/ctypes.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,7 @@ type uint32_t = u32;
7575
but using pointers to this type when interoperating \
7676
with C void pointers can help in documentation."
7777
)]
78-
enum void {
79-
// Making the only variant reference itself makes it impossible to
80-
// construct. Not exporting it makes it impossible to destructure.
81-
void_private(@void),
82-
// FIXME: #881
83-
void_private2(@void),
84-
}
78+
enum void {}
8579

8680
#[doc(
8781
brief = "A float value with the same size as a C `float`."

src/libstd/freebsd_os.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import core::ctypes::*;
1010
export libc;
1111
export libc_constants;
1212
export pipe;
13-
export fd_FILE;
13+
export FILE, fd_FILE;
1414
export close;
1515
export fclose;
1616
export waitpid;
@@ -24,16 +24,20 @@ export fsync_fd;
2424
// FIXME Somehow merge stuff duplicated here and macosx_os.rs. Made difficult
2525
// by https://github.com/graydon/rust/issues#issue/268
2626

27+
enum FILE_opaque {}
28+
type FILE = *FILE_opaque;
29+
enum dir {}
30+
enum dirent {}
31+
2732
#[nolink]
2833
#[abi = "cdecl"]
2934
native mod libc {
3035
fn read(fd: fd_t, buf: *u8, count: size_t) -> ssize_t;
3136
fn write(fd: fd_t, buf: *u8, count: size_t) -> ssize_t;
32-
fn fread(buf: *u8, size: size_t, n: size_t, f: libc::FILE) -> size_t;
33-
fn fwrite(buf: *u8, size: size_t, n: size_t, f: libc::FILE) -> size_t;
37+
fn fread(buf: *u8, size: size_t, n: size_t, f: FILE) -> size_t;
38+
fn fwrite(buf: *u8, size: size_t, n: size_t, f: FILE) -> size_t;
3439
fn open(s: str::sbuf, flags: c_int, mode: unsigned) -> fd_t;
3540
fn close(fd: fd_t) -> c_int;
36-
type FILE;
3741
fn fopen(path: str::sbuf, mode: str::sbuf) -> FILE;
3842
fn fdopen(fd: fd_t, mode: str::sbuf) -> FILE;
3943
fn fclose(f: FILE);
@@ -45,11 +49,9 @@ native mod libc {
4549
fn feof(f: FILE) -> c_int;
4650
fn fseek(f: FILE, offset: long, whence: c_int) -> c_int;
4751
fn ftell(f: FILE) -> long;
48-
type dir;
49-
fn opendir(d: str::sbuf) -> dir;
50-
fn closedir(d: dir) -> c_int;
51-
type dirent;
52-
fn readdir(d: dir) -> dirent;
52+
fn opendir(d: str::sbuf) -> *dir;
53+
fn closedir(d: *dir) -> c_int;
54+
fn readdir(d: *dir) -> *dirent;
5355
fn getenv(n: str::sbuf) -> str::sbuf;
5456
fn setenv(n: str::sbuf, v: str::sbuf, overwrite: c_int) -> c_int;
5557
fn unsetenv(n: str::sbuf) -> c_int;
@@ -90,15 +92,15 @@ fn pipe() -> {in: fd_t, out: fd_t} {
9092
ret {in: fds.in, out: fds.out};
9193
}
9294

93-
fn fd_FILE(fd: fd_t) -> libc::FILE {
95+
fn fd_FILE(fd: fd_t) -> FILE {
9496
ret str::as_buf("r", {|modebuf| libc::fdopen(fd, modebuf) });
9597
}
9698

9799
fn close(fd: fd_t) -> c_int {
98100
libc::close(fd)
99101
}
100102

101-
fn fclose(file: libc::FILE) {
103+
fn fclose(file: FILE) {
102104
libc::fclose(file)
103105
}
104106

src/libstd/io.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import core::ctypes::c_int;
99

1010
#[abi = "cdecl"]
1111
native mod rustrt {
12-
fn rust_get_stdin() -> os::libc::FILE;
13-
fn rust_get_stdout() -> os::libc::FILE;
14-
fn rust_get_stderr() -> os::libc::FILE;
12+
fn rust_get_stdin() -> os::FILE;
13+
fn rust_get_stdout() -> os::FILE;
14+
fn rust_get_stderr() -> os::FILE;
1515
}
1616

1717
// Reading
@@ -166,7 +166,7 @@ fn convert_whence(whence: seek_style) -> i32 {
166166
};
167167
}
168168

169-
impl of reader for os::libc::FILE {
169+
impl of reader for os::FILE {
170170
fn read_bytes(len: uint) -> [u8] unsafe {
171171
let buf = [];
172172
vec::reserve(buf, len);
@@ -195,9 +195,9 @@ impl <T: reader, C> of reader for {base: T, cleanup: C} {
195195
fn tell() -> uint { self.base.tell() }
196196
}
197197

198-
resource FILE_res(f: os::libc::FILE) { os::libc::fclose(f); }
198+
resource FILE_res(f: os::FILE) { os::libc::fclose(f); }
199199

200-
fn FILE_reader(f: os::libc::FILE, cleanup: bool) -> reader {
200+
fn FILE_reader(f: os::FILE, cleanup: bool) -> reader {
201201
if cleanup {
202202
{base: f, cleanup: FILE_res(f)} as reader
203203
} else {
@@ -282,7 +282,7 @@ impl <T: writer, C> of writer for {base: T, cleanup: C} {
282282
fn flush() -> int { self.base.flush() }
283283
}
284284

285-
impl of writer for os::libc::FILE {
285+
impl of writer for os::FILE {
286286
fn write(v: [const u8]) unsafe {
287287
let len = vec::len(v);
288288
let vbuf = vec::unsafe::to_ptr(v);
@@ -296,7 +296,7 @@ impl of writer for os::libc::FILE {
296296
fn flush() -> int { os::libc::fflush(self) as int }
297297
}
298298

299-
fn FILE_writer(f: os::libc::FILE, cleanup: bool) -> writer {
299+
fn FILE_writer(f: os::FILE, cleanup: bool) -> writer {
300300
if cleanup {
301301
{base: f, cleanup: FILE_res(f)} as writer
302302
} else {
@@ -532,10 +532,10 @@ mod fsync {
532532
// fsync file after executing blk
533533
// FIXME find better way to create resources within lifetime of outer res
534534
fn FILE_res_sync(&&file: FILE_res, opt_level: option<level>,
535-
blk: fn(&&res<os::libc::FILE>)) {
535+
blk: fn(&&res<os::FILE>)) {
536536
blk(res({
537537
val: *file, opt_level: opt_level,
538-
fsync_fn: fn@(&&file: os::libc::FILE, l: level) -> int {
538+
fsync_fn: fn@(&&file: os::FILE, l: level) -> int {
539539
ret os::fsync_fd(os::libc::fileno(file), l) as int;
540540
}
541541
}));

src/libstd/linux_os.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import core::ctypes::*;
1010
export libc;
1111
export libc_constants;
1212
export pipe;
13-
export fd_FILE;
13+
export FILE, fd_FILE;
1414
export close;
1515
export fclose;
1616
export waitpid;
@@ -24,16 +24,20 @@ export fsync_fd;
2424
// FIXME Somehow merge stuff duplicated here and macosx_os.rs. Made difficult
2525
// by https://github.com/graydon/rust/issues#issue/268
2626

27+
enum FILE_opaque {}
28+
type FILE = *FILE_opaque;
29+
enum dir {}
30+
enum dirent {}
31+
2732
#[nolink]
2833
#[abi = "cdecl"]
2934
native mod libc {
3035
fn read(fd: fd_t, buf: *u8, count: size_t) -> ssize_t;
3136
fn write(fd: fd_t, buf: *u8, count: size_t) -> ssize_t;
32-
fn fread(buf: *u8, size: size_t, n: size_t, f: libc::FILE) -> size_t;
33-
fn fwrite(buf: *u8, size: size_t, n: size_t, f: libc::FILE) -> size_t;
37+
fn fread(buf: *u8, size: size_t, n: size_t, f: FILE) -> size_t;
38+
fn fwrite(buf: *u8, size: size_t, n: size_t, f: FILE) -> size_t;
3439
fn open(s: str::sbuf, flags: c_int, mode: unsigned) -> fd_t;
3540
fn close(fd: fd_t) -> c_int;
36-
type FILE;
3741
fn fopen(path: str::sbuf, mode: str::sbuf) -> FILE;
3842
fn fdopen(fd: fd_t, mode: str::sbuf) -> FILE;
3943
fn fclose(f: FILE);
@@ -46,11 +50,9 @@ native mod libc {
4650
fn feof(f: FILE) -> c_int;
4751
fn fseek(f: FILE, offset: long, whence: c_int) -> c_int;
4852
fn ftell(f: FILE) -> long;
49-
type dir;
50-
fn opendir(d: str::sbuf) -> dir;
51-
fn closedir(d: dir) -> c_int;
52-
type dirent;
53-
fn readdir(d: dir) -> dirent;
53+
fn opendir(d: str::sbuf) -> *dir;
54+
fn closedir(d: *dir) -> c_int;
55+
fn readdir(d: *dir) -> *dirent;
5456
fn getenv(n: str::sbuf) -> str::sbuf;
5557
fn setenv(n: str::sbuf, v: str::sbuf, overwrite: c_int) -> c_int;
5658
fn unsetenv(n: str::sbuf) -> c_int;
@@ -83,15 +85,15 @@ fn pipe() -> {in: fd_t, out: fd_t} {
8385
ret {in: fds.in, out: fds.out};
8486
}
8587

86-
fn fd_FILE(fd: fd_t) -> libc::FILE {
88+
fn fd_FILE(fd: fd_t) -> FILE {
8789
ret str::as_buf("r", {|modebuf| libc::fdopen(fd, modebuf) });
8890
}
8991

9092
fn close(fd: fd_t) -> c_int {
9193
libc::close(fd)
9294
}
9395

94-
fn fclose(file: libc::FILE) {
96+
fn fclose(file: FILE) {
9597
libc::fclose(file)
9698
}
9799

src/libstd/macos_os.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import core::ctypes::*;
44
export libc;
55
export libc_constants;
66
export pipe;
7-
export fd_FILE;
7+
export FILE, fd_FILE;
88
export close;
99
export fclose;
1010
export waitpid;
@@ -18,16 +18,20 @@ export fsync_fd;
1818
// FIXME Refactor into unix_os module or some such. Doesn't
1919
// seem to work right now.
2020

21+
enum FILE_opaque {}
22+
type FILE = *FILE_opaque;
23+
enum dir {}
24+
enum dirent {}
25+
2126
#[nolink]
2227
#[abi = "cdecl"]
2328
native mod libc {
2429
fn read(fd: fd_t, buf: *u8, count: size_t) -> ssize_t;
2530
fn write(fd: fd_t, buf: *u8, count: size_t) -> ssize_t;
26-
fn fread(buf: *u8, size: size_t, n: size_t, f: libc::FILE) -> size_t;
27-
fn fwrite(buf: *u8, size: size_t, n: size_t, f: libc::FILE) -> size_t;
31+
fn fread(buf: *u8, size: size_t, n: size_t, f: FILE) -> size_t;
32+
fn fwrite(buf: *u8, size: size_t, n: size_t, f: FILE) -> size_t;
2833
fn open(s: str::sbuf, flags: c_int, mode: unsigned) -> fd_t;
2934
fn close(fd: fd_t) -> c_int;
30-
type FILE;
3135
fn fopen(path: str::sbuf, mode: str::sbuf) -> FILE;
3236
fn fdopen(fd: fd_t, mode: str::sbuf) -> FILE;
3337
fn fflush(f: FILE) -> c_int;
@@ -39,11 +43,9 @@ native mod libc {
3943
fn feof(f: FILE) -> c_int;
4044
fn fseek(f: FILE, offset: long, whence: c_int) -> c_int;
4145
fn ftell(f: FILE) -> long;
42-
type dir;
43-
fn opendir(d: str::sbuf) -> dir;
44-
fn closedir(d: dir) -> c_int;
45-
type dirent;
46-
fn readdir(d: dir) -> dirent;
46+
fn opendir(d: str::sbuf) -> *dir;
47+
fn closedir(d: *dir) -> c_int;
48+
fn readdir(d: *dir) -> *dirent;
4749
fn getenv(n: str::sbuf) -> str::sbuf;
4850
fn setenv(n: str::sbuf, v: str::sbuf, overwrite: c_int) -> c_int;
4951
fn unsetenv(n: str::sbuf) -> c_int;
@@ -80,15 +82,15 @@ fn pipe() -> {in: fd_t, out: fd_t} {
8082
ret {in: fds.in, out: fds.out};
8183
}
8284

83-
fn fd_FILE(fd: fd_t) -> libc::FILE {
85+
fn fd_FILE(fd: fd_t) -> FILE {
8486
ret str::as_buf("r", {|modebuf| libc::fdopen(fd, modebuf) });
8587
}
8688

8789
fn close(fd: fd_t) -> c_int {
8890
libc::close(fd)
8991
}
9092

91-
fn fclose(file: libc::FILE) {
93+
fn fclose(file: FILE) {
9294
libc::fclose(file)
9395
}
9496

src/libstd/rand.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ Module: rand
33
44
Random number generation
55
*/
6+
7+
enum rctx {}
8+
69
#[abi = "cdecl"]
710
native mod rustrt {
8-
type rctx;
9-
fn rand_new() -> rctx;
10-
fn rand_next(c: rctx) -> u32;
11-
fn rand_free(c: rctx);
11+
fn rand_new() -> *rctx;
12+
fn rand_next(c: *rctx) -> u32;
13+
fn rand_free(c: *rctx);
1214
}
1315

1416
/* Section: Types */
@@ -48,7 +50,7 @@ iface rng {
4850
fn gen_bytes(len: uint) -> [u8];
4951
}
5052

51-
resource rand_res(c: rustrt::rctx) { rustrt::rand_free(c); }
53+
resource rand_res(c: *rctx) { rustrt::rand_free(c); }
5254

5355
/* Section: Operations */
5456

src/libstd/run_program.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ fn start_program(prog: str, args: [str]) -> program {
171171

172172
type prog_repr = {pid: pid_t,
173173
mutable in_fd: fd_t,
174-
out_file: os::libc::FILE,
175-
err_file: os::libc::FILE,
174+
out_file: os::FILE,
175+
err_file: os::FILE,
176176
mutable finished: bool};
177177

178178
fn close_repr_input(r: prog_repr) {

0 commit comments

Comments
 (0)