stdlib: Add a pointer equality function to the standard library and a test case
This commit is contained in:
parent
5dbf554bb3
commit
735435bf96
8
src/lib/Box.rs
Normal file
8
src/lib/Box.rs
Normal file
@ -0,0 +1,8 @@
|
||||
export rustrt;
|
||||
|
||||
native "rust" mod rustrt {
|
||||
fn rust_ptr_eq[T](@T a, @T b) -> int;
|
||||
}
|
||||
|
||||
fn ptr_eq[T](@T a, @T b) -> bool { ret rustrt.rust_ptr_eq[T](a, b) != 0; }
|
||||
|
@ -69,6 +69,7 @@ mod sha1;
|
||||
mod ebml;
|
||||
mod UFind;
|
||||
mod ExtFmt;
|
||||
mod Box;
|
||||
|
||||
// Local Variables:
|
||||
// mode: rust;
|
||||
|
@ -468,6 +468,11 @@ rust_file_is_dir(rust_task *task, rust_str *path) {
|
||||
extern "C" CDECL FILE* rust_get_stdin() {return stdin;}
|
||||
extern "C" CDECL FILE* rust_get_stdout() {return stdout;}
|
||||
|
||||
extern "C" CDECL int
|
||||
rust_ptr_eq(rust_task *task, type_desc *t, rust_box *a, rust_box *b) {
|
||||
return a == b;
|
||||
}
|
||||
|
||||
//
|
||||
// Local Variables:
|
||||
// mode: C++
|
||||
|
@ -19,6 +19,7 @@ rust_get_stdin
|
||||
rust_get_stdout
|
||||
rust_list_files
|
||||
rust_process_wait
|
||||
rust_ptr_eq
|
||||
rust_run_program
|
||||
rust_start
|
||||
size_of
|
||||
|
12
src/test/run-pass/lib-box.rs
Normal file
12
src/test/run-pass/lib-box.rs
Normal file
@ -0,0 +1,12 @@
|
||||
use std;
|
||||
import std.Box;
|
||||
|
||||
fn main() {
|
||||
auto x = @3;
|
||||
auto y = @3;
|
||||
check (Box.ptr_eq[int](x, x));
|
||||
check (Box.ptr_eq[int](y, y));
|
||||
check (!Box.ptr_eq[int](x, y));
|
||||
check (!Box.ptr_eq[int](y, x));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user