Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/libcore/unstable/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub unsafe fn fail_borrowed() {

// FIXME #4942: Make these signatures agree with exchange_alloc's signatures
#[lang="exchange_malloc"]
#[inline(always)]
pub unsafe fn exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
transmute(exchange_alloc::malloc(transmute(td), transmute(size)))
}
Expand All @@ -72,11 +73,13 @@ pub unsafe fn exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
// inside a landing pad may corrupt the state of the exception handler. If a
// problem occurs, call exit instead.
#[lang="exchange_free"]
#[inline(always)]
pub unsafe fn exchange_free(ptr: *c_char) {
exchange_alloc::free(transmute(ptr))
}

#[lang="malloc"]
#[inline(always)]
pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
return rustrt::rust_upcall_malloc(td, size);
}
Expand All @@ -85,6 +88,7 @@ pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
// inside a landing pad may corrupt the state of the exception handler. If a
// problem occurs, call exit instead.
#[lang="free"]
#[inline(always)]
pub unsafe fn local_free(ptr: *c_char) {
rustrt::rust_upcall_free(ptr);
}
Expand Down Expand Up @@ -117,6 +121,7 @@ pub unsafe fn check_not_borrowed(a: *u8) {
}

#[lang="strdup_uniq"]
#[inline(always)]
pub unsafe fn strdup_uniq(ptr: *c_uchar, len: uint) -> ~str {
str::raw::from_buf_len(ptr, len)
}
Expand Down
12 changes: 6 additions & 6 deletions src/libstd/ebml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,13 @@ pub mod reader {
}

#[cfg(stage0)]
fn read_option<T>(&self, f: &fn() -> T) -> Option<T> {
fn read_option<T>(&self, f: &fn(bool) -> T) -> T {
debug!("read_option()");
do self.read_enum("Option") || {
do self.read_enum_variant |idx| {
match idx {
0 => None,
1 => Some(f()),
0 => f(false),
1 => f(true),
_ => fail!(),
}
}
Expand All @@ -427,13 +427,13 @@ pub mod reader {
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn read_option<T>(&self, f: &fn() -> T) -> Option<T> {
fn read_option<T>(&self, f: &fn(bool) -> T) -> T {
debug!("read_option()");
do self.read_enum("Option") || {
do self.read_enum_variant(["None", "Some"]) |idx| {
match idx {
0 => None,
1 => Some(f()),
0 => f(false),
1 => f(true),
_ => fail!(),
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,10 +980,10 @@ impl<'self> serialize::Decoder for Decoder<'self> {
}
}

fn read_option<T>(&self, f: &fn() -> T) -> Option<T> {
fn read_option<T>(&self, f: &fn(bool) -> T) -> T {
match *self.peek() {
Null => { self.pop(); None }
_ => Some(f()),
Null => { self.pop(); f(false) }
_ => f(true),
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/libstd/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub trait Decoder {
fn read_tup_elt<T>(&self, idx: uint, f: &fn() -> T) -> T;

// Specialized types:
fn read_option<T>(&self, f: &fn() -> T) -> Option<T>;
fn read_option<T>(&self, f: &fn(bool) -> T) -> T;
}

pub trait Encodable<S:Encoder> {
Expand Down Expand Up @@ -395,7 +395,13 @@ impl<S:Encoder,T:Encodable<S>> Encodable<S> for Option<T> {

impl<D:Decoder,T:Decodable<D>> Decodable<D> for Option<T> {
fn decode(d: &D) -> Option<T> {
d.read_option(|| Decodable::decode(d))
do d.read_option |b| {
if b {
Some(Decodable::decode(d))
} else {
None
}
}
}
}

Expand Down