Skip to content

Commit 770c78d

Browse files
committed
---
yaml --- r: 10664 b: refs/heads/snap-stage3 c: fee78d2 h: refs/heads/master v: v3
1 parent 1d070be commit 770c78d

File tree

5 files changed

+46
-25
lines changed

5 files changed

+46
-25
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 5281771a07ba6d437bcdd9d94343c04ea1ed7221
4+
refs/heads/snap-stage3: fee78d296c66e0b10600c7fefbbe07f33406fe97
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/src/libcore/io.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,11 @@ impl <T: reader, C> of reader for {base: T, cleanup: C} {
224224
fn tell() -> uint { self.base.tell() }
225225
}
226226

227-
resource FILE_res(f: *libc::FILE) { libc::fclose(f); }
227+
class FILE_res {
228+
let f: *libc::FILE;
229+
new(f: *libc::FILE) { self.f = f; }
230+
drop { libc::fclose(self.f); }
231+
}
228232

229233
fn FILE_reader(f: *libc::FILE, cleanup: bool) -> reader {
230234
if cleanup {
@@ -383,7 +387,11 @@ impl of writer for fd_t {
383387
fn flush() -> int { 0 }
384388
}
385389

386-
resource fd_res(fd: fd_t) { libc::close(fd); }
390+
class fd_res {
391+
let fd: fd_t;
392+
new(fd: fd_t) { self.fd = fd; }
393+
drop { libc::close(self.fd); }
394+
}
387395

388396
fn fd_writer(fd: fd_t, cleanup: bool) -> writer {
389397
if cleanup {
@@ -695,13 +703,17 @@ mod fsync {
695703
}
696704

697705

698-
// Resource of artifacts that need to fsync on destruction
699-
resource res<t>(arg: arg<t>) {
700-
alt arg.opt_level {
701-
option::none { }
702-
option::some(level) {
703-
// fail hard if not succesful
704-
assert(arg.fsync_fn(arg.val, level) != -1);
706+
// Artifacts that need to fsync on destruction
707+
class res<t> {
708+
let arg: arg<t>;
709+
new(-arg: arg<t>) { self.arg <- arg; }
710+
drop {
711+
alt self.arg.opt_level {
712+
option::none { }
713+
option::some(level) {
714+
// fail hard if not succesful
715+
assert(self.arg.fsync_fn(self.arg.val, level) != -1);
716+
}
705717
}
706718
}
707719
}
@@ -718,7 +730,7 @@ mod fsync {
718730
fn FILE_res_sync(&&file: FILE_res, opt_level: option<level>,
719731
blk: fn(&&res<*libc::FILE>)) {
720732
blk(res({
721-
val: *file, opt_level: opt_level,
733+
val: file.f, opt_level: opt_level,
722734
fsync_fn: fn@(&&file: *libc::FILE, l: level) -> int {
723735
ret os::fsync_fd(libc::fileno(file), l) as int;
724736
}
@@ -729,7 +741,7 @@ mod fsync {
729741
fn fd_res_sync(&&fd: fd_res, opt_level: option<level>,
730742
blk: fn(&&res<fd_t>)) {
731743
blk(res({
732-
val: *fd, opt_level: opt_level,
744+
val: fd.fd, opt_level: opt_level,
733745
fsync_fn: fn@(&&fd: fd_t, l: level) -> int {
734746
ret os::fsync_fd(fd, l) as int;
735747
}

branches/snap-stage3/src/libcore/option.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ fn test_unwrap_str() {
140140

141141
#[test]
142142
fn test_unwrap_resource() {
143-
resource r(i: @mut int) {
144-
*i += 1;
143+
class r {
144+
let i: @mut int;
145+
new(i: @mut int) { self.i = i; }
146+
drop { *(self.i) += 1; }
145147
}
146148
let i = @mut 0;
147149
{

branches/snap-stage3/src/libcore/sys.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,20 @@ pure fn log_str<T>(t: T) -> str {
8585
}
8686
}
8787

88-
resource lock_and_signal(lock: rust_cond_lock) {
89-
rustrt::rust_destroy_cond_lock(lock);
88+
class lock_and_signal {
89+
let lock: rust_cond_lock;
90+
new(lock: rust_cond_lock) { self.lock = lock; }
91+
drop { rustrt::rust_destroy_cond_lock(self.lock); }
9092
}
9193

9294
enum condition {
9395
condition_(rust_cond_lock)
9496
}
9597

96-
resource unlock(lock: rust_cond_lock) {
97-
rustrt::rust_unlock_cond_lock(lock);
98+
class unlock {
99+
let lock: rust_cond_lock;
100+
new(lock: rust_cond_lock) { self.lock = lock; }
101+
drop { rustrt::rust_unlock_cond_lock(self.lock); }
98102
}
99103

100104
fn create_lock() -> lock_and_signal {
@@ -103,15 +107,15 @@ fn create_lock() -> lock_and_signal {
103107

104108
impl methods for lock_and_signal {
105109
fn lock<T>(f: fn() -> T) -> T {
106-
rustrt::rust_lock_cond_lock(*self);
107-
let _r = unlock(*self);
110+
rustrt::rust_lock_cond_lock(self.lock);
111+
let _r = unlock(self.lock);
108112
f()
109113
}
110114

111115
fn lock_cond<T>(f: fn(condition) -> T) -> T {
112-
rustrt::rust_lock_cond_lock(*self);
113-
let _r = unlock(*self);
114-
f(condition_(*self))
116+
rustrt::rust_lock_cond_lock(self.lock);
117+
let _r = unlock(self.lock);
118+
f(condition_(self.lock))
115119
}
116120
}
117121

branches/snap-stage3/src/libcore/task.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,12 @@ Temporarily make the task unkillable
482482
483483
"]
484484
unsafe fn unkillable(f: fn()) {
485-
resource allow_failure(_i: ()) {
486-
rustrt::rust_task_allow_kill();
485+
class allow_failure {
486+
let i: (); // since a class must have at least one field
487+
new(_i: ()) { self.i = (); }
488+
drop { rustrt::rust_task_allow_kill(); }
487489
}
490+
488491
let _allow_failure = allow_failure(());
489492
rustrt::rust_task_inhibit_kill();
490493
f();

0 commit comments

Comments
 (0)