Skip to content

Commit 415dfff

Browse files
committed
---
yaml --- r: 30918 b: refs/heads/incoming c: 9b4db17 h: refs/heads/master v: v3
1 parent 9de7cc6 commit 415dfff

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 1229d1c2ce7cc97ec63a86668e0b12fabaa63e06
9+
refs/heads/incoming: 9b4db176307e91e85361270b667fb22885a21b8b
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libcore/os.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,30 @@ pub fn set_exit_status(code: int) {
732732
rustrt::rust_set_exit_status(code as libc::intptr_t);
733733
}
734734

735+
/**
736+
* Returns the command line arguments
737+
*
738+
* Returns a list of the command line arguments.
739+
*/
740+
#[cfg(target_os = "macos")]
741+
pub fn args() -> ~[~str] {
742+
unsafe {
743+
let (argc, argv) = (*_NSGetArgc() as uint, *_NSGetArgv());
744+
let mut args = ~[];
745+
for uint::range(0, argc) |i| {
746+
vec::push(&mut args, str::raw::from_c_str(*argv.offset(i)));
747+
}
748+
return args;
749+
}
750+
}
751+
752+
#[cfg(target_os = "macos")]
753+
extern {
754+
// These functions are in crt_externs.h.
755+
pub fn _NSGetArgc() -> *c_int;
756+
pub fn _NSGetArgv() -> ***c_char;
757+
}
758+
735759
#[cfg(unix)]
736760
pub fn family() -> ~str { ~"unix" }
737761

branches/incoming/src/libcore/ptr.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,23 @@ pub pure fn mut_addr_of<T>(val: &T) -> *mut T {
4747

4848
/// Calculate the offset from a pointer
4949
#[inline(always)]
50-
pub fn offset<T>(ptr: *T, count: uint) -> *T {
50+
pub pure fn offset<T>(ptr: *T, count: uint) -> *T {
5151
unsafe {
5252
(ptr as uint + count * sys::size_of::<T>()) as *T
5353
}
5454
}
5555

5656
/// Calculate the offset from a const pointer
5757
#[inline(always)]
58-
pub fn const_offset<T>(ptr: *const T, count: uint) -> *const T {
58+
pub pure fn const_offset<T>(ptr: *const T, count: uint) -> *const T {
5959
unsafe {
6060
(ptr as uint + count * sys::size_of::<T>()) as *T
6161
}
6262
}
6363

6464
/// Calculate the offset from a mut pointer
6565
#[inline(always)]
66-
pub fn mut_offset<T>(ptr: *mut T, count: uint) -> *mut T {
66+
pub pure fn mut_offset<T>(ptr: *mut T, count: uint) -> *mut T {
6767
(ptr as uint + count * sys::size_of::<T>()) as *mut T
6868
}
6969

@@ -176,18 +176,25 @@ pub fn ref_eq<T>(thing: &a/T, other: &b/T) -> bool {
176176
to_uint(thing) == to_uint(other)
177177
}
178178

179-
pub trait Ptr {
179+
pub trait Ptr<T> {
180180
pure fn is_null() -> bool;
181181
pure fn is_not_null() -> bool;
182+
pure fn offset(count: uint) -> self;
182183
}
183184

184185
/// Extension methods for pointers
185-
impl<T> *T: Ptr {
186+
impl<T> *T: Ptr<T> {
186187
/// Returns true if the pointer is equal to the null pointer.
188+
#[inline(always)]
187189
pure fn is_null() -> bool { is_null(self) }
188190

189191
/// Returns true if the pointer is not equal to the null pointer.
192+
#[inline(always)]
190193
pure fn is_not_null() -> bool { is_not_null(self) }
194+
195+
/// Calculates the offset from a pointer.
196+
#[inline(always)]
197+
pure fn offset(count: uint) -> *T { offset(self, count) }
191198
}
192199

193200
// Equality for pointers

0 commit comments

Comments
 (0)