diff options
| author | Graydon Hoare <graydon@mozilla.com> | 2011-12-13 16:25:51 -0800 |
|---|---|---|
| committer | Graydon Hoare <graydon@mozilla.com> | 2011-12-13 16:34:50 -0800 |
| commit | fa9ad984fb2f013baebdbe01a42baa3b9101dd84 (patch) | |
| tree | 49115690e45ca322337b93f25308cd618f85b013 /src/libcore/ptr.rs | |
| parent | 32087f5c2a35bf8050067c22a57fd60269633a60 (diff) | |
| download | rust-fa9ad984fb2f013baebdbe01a42baa3b9101dd84.tar.gz rust-fa9ad984fb2f013baebdbe01a42baa3b9101dd84.zip | |
Copy first batch of material from libstd to libcore.
Diffstat (limited to 'src/libcore/ptr.rs')
| -rw-r--r-- | src/libcore/ptr.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs new file mode 100644 index 00000000000..0372b17cdf1 --- /dev/null +++ b/src/libcore/ptr.rs @@ -0,0 +1,52 @@ +/* +Module: ptr + +Unsafe pointer utility functions +*/ +#[abi = "rust-intrinsic"] +native mod rusti { + fn addr_of<T>(val: T) -> *T; + fn ptr_offset<T>(ptr: *T, count: uint) -> *T; +} + +/* +Function: addr_of + +Get an unsafe pointer to a value +*/ +fn addr_of<T>(val: T) -> *T { ret rusti::addr_of(val); } + +/* +Function: mut_addr_of + +Get an unsafe mutable pointer to a value +*/ +fn mut_addr_of<T>(val: T) -> *mutable T unsafe { + ret unsafe::reinterpret_cast(rusti::addr_of(val)); +} + +/* +Function: offset + +Calculate the offset from a pointer +*/ +fn offset<T>(ptr: *T, count: uint) -> *T { + ret rusti::ptr_offset(ptr, count); +} + +/* +Function: mut_offset + +Calculate the offset from a mutable pointer +*/ +fn mut_offset<T>(ptr: *mutable T, count: uint) -> *mutable T { + ret rusti::ptr_offset(ptr as *T, count) as *mutable T; +} + + +/* +Function: null + +Create an unsafe null pointer +*/ +fn null<T>() -> *T unsafe { ret unsafe::reinterpret_cast(0u); } |
