diff options
| author | bors <bors@rust-lang.org> | 2013-06-02 16:55:33 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-06-02 16:55:33 -0700 |
| commit | c40baf68cb3306f1beaf1d5443bb2433043b7da7 (patch) | |
| tree | 964b03a12db214c3a63fbed78ca50ec8fb973819 /src/libstd | |
| parent | dad945646fe7ec6592adfdf21b4bc464ac5c1fe7 (diff) | |
| parent | 454133127a78e14ae4922d96579f1d1a433fa54c (diff) | |
| download | rust-c40baf68cb3306f1beaf1d5443bb2433043b7da7.tar.gz rust-c40baf68cb3306f1beaf1d5443bb2433043b7da7.zip | |
auto merge of #6905 : thestinger/rust/ptr, r=catamorphism
The ptr module is intended to be for raw pointers. Closes #3111
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/borrow.rs | 60 | ||||
| -rw-r--r-- | src/libstd/core.rc | 1 | ||||
| -rw-r--r-- | src/libstd/ptr.rs | 46 | ||||
| -rw-r--r-- | src/libstd/rt/task.rs | 5 |
4 files changed, 64 insertions, 48 deletions
diff --git a/src/libstd/borrow.rs b/src/libstd/borrow.rs new file mode 100644 index 00000000000..703011aea7f --- /dev/null +++ b/src/libstd/borrow.rs @@ -0,0 +1,60 @@ +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Borrowed pointer utilities + +#[cfg(not(test))] +use prelude::*; + +/// Cast a region pointer - &T - to a uint. +#[inline(always)] +pub fn to_uint<T>(thing: &T) -> uint { + thing as *T as uint +} + +/// Determine if two borrowed pointers point to the same thing. +#[inline(always)] +pub fn ref_eq<'a, 'b, T>(thing: &'a T, other: &'b T) -> bool { + to_uint(thing) == to_uint(other) +} + +// Equality for region pointers +#[cfg(not(test))] +impl<'self, T: Eq> Eq for &'self T { + #[inline(always)] + fn eq(&self, other: & &'self T) -> bool { + *(*self) == *(*other) + } + #[inline(always)] + fn ne(&self, other: & &'self T) -> bool { + *(*self) != *(*other) + } +} + +// Comparison for region pointers +#[cfg(not(test))] +impl<'self, T: Ord> Ord for &'self T { + #[inline(always)] + fn lt(&self, other: & &'self T) -> bool { + *(*self) < *(*other) + } + #[inline(always)] + fn le(&self, other: & &'self T) -> bool { + *(*self) <= *(*other) + } + #[inline(always)] + fn ge(&self, other: & &'self T) -> bool { + *(*self) >= *(*other) + } + #[inline(always)] + fn gt(&self, other: & &'self T) -> bool { + *(*self) > *(*other) + } +} diff --git a/src/libstd/core.rc b/src/libstd/core.rc index 82e0d4b54d2..e629db9244d 100644 --- a/src/libstd/core.rc +++ b/src/libstd/core.rc @@ -125,6 +125,7 @@ pub mod ascii; pub mod ptr; pub mod owned; pub mod managed; +pub mod borrow; /* Core language traits */ diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs index ebc0a4b1e96..1d9a9b9be36 100644 --- a/src/libstd/ptr.rs +++ b/src/libstd/ptr.rs @@ -255,18 +255,6 @@ pub fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T { thing as *mut T } -/// Cast a region pointer - &T - to a uint. -#[inline(always)] -pub fn to_uint<T>(thing: &T) -> uint { - thing as *T as uint -} - -/// Determine if two borrowed pointers point to the same thing. -#[inline(always)] -pub fn ref_eq<'a,'b,T>(thing: &'a T, other: &'b T) -> bool { - to_uint(thing) == to_uint(other) -} - /** Given a **T (pointer to an array of pointers), iterate through each *T, up to the provided `len`, @@ -411,40 +399,6 @@ impl<T> Ord for *const T { } } -// Equality for region pointers -#[cfg(not(test))] -impl<'self,T:Eq> Eq for &'self T { - #[inline(always)] - fn eq(&self, other: & &'self T) -> bool { - *(*self) == *(*other) - } - #[inline(always)] - fn ne(&self, other: & &'self T) -> bool { - *(*self) != *(*other) - } -} - -// Comparison for region pointers -#[cfg(not(test))] -impl<'self,T:Ord> Ord for &'self T { - #[inline(always)] - fn lt(&self, other: & &'self T) -> bool { - *(*self) < *(*other) - } - #[inline(always)] - fn le(&self, other: & &'self T) -> bool { - *(*self) <= *(*other) - } - #[inline(always)] - fn ge(&self, other: & &'self T) -> bool { - *(*self) >= *(*other) - } - #[inline(always)] - fn gt(&self, other: & &'self T) -> bool { - *(*self) > *(*other) - } -} - #[cfg(test)] pub mod ptr_tests { use super::*; diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index eb7282bae05..620efed99ca 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -13,6 +13,7 @@ //! local storage, and logging. Even a 'freestanding' Rust would likely want //! to implement this. +use borrow; use cast::transmute; use libc::{c_void, uintptr_t}; use ptr; @@ -64,7 +65,7 @@ impl Task { // This is just an assertion that `run` was called unsafely // and this instance of Task is still accessible. do Local::borrow::<Task> |task| { - assert!(ptr::ref_eq(task, self)); + assert!(borrow::ref_eq(task, self)); } match self.unwinder { @@ -89,7 +90,7 @@ impl Task { // This is just an assertion that `destroy` was called unsafely // and this instance of Task is still accessible. do Local::borrow::<Task> |task| { - assert!(ptr::ref_eq(task, self)); + assert!(borrow::ref_eq(task, self)); } match self.storage { LocalStorage(ptr, Some(ref dtor)) => { |
