Skip to content

Commit d87aeae

Browse files
committed
---
yaml --- r: 24318 b: refs/heads/master c: 9b4db17 h: refs/heads/master v: v3
1 parent 818538d commit d87aeae

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
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 1229d1c2ce7cc97ec63a86668e0b12fabaa63e06
2+
refs/heads/master: 9b4db176307e91e85361270b667fb22885a21b8b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/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

trunk/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)