Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename *T to *const T #15208

Merged
merged 2 commits into from
Jun 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub mod common;
pub mod errors;

#[start]
fn start(argc: int, argv: **u8) -> int {
fn start(argc: int, argv: *const *const u8) -> int {
green::start(argc, argv, rustuv::event_loop, main)
}

Expand Down
22 changes: 11 additions & 11 deletions src/doc/guide-ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ use libc::{c_int, size_t};

#[link(name = "snappy")]
extern {
fn snappy_compress(input: *u8,
fn snappy_compress(input: *const u8,
input_length: size_t,
compressed: *mut u8,
compressed_length: *mut size_t) -> c_int;
fn snappy_uncompress(compressed: *u8,
fn snappy_uncompress(compressed: *const u8,
compressed_length: size_t,
uncompressed: *mut u8,
uncompressed_length: *mut size_t) -> c_int;
fn snappy_max_compressed_length(source_length: size_t) -> size_t;
fn snappy_uncompressed_length(compressed: *u8,
fn snappy_uncompressed_length(compressed: *const u8,
compressed_length: size_t,
result: *mut size_t) -> c_int;
fn snappy_validate_compressed_buffer(compressed: *u8,
fn snappy_validate_compressed_buffer(compressed: *const u8,
compressed_length: size_t) -> c_int;
}
# fn main() {}
Expand All @@ -82,7 +82,7 @@ the allocated memory. The length is less than or equal to the capacity.
~~~~
# extern crate libc;
# use libc::{c_int, size_t};
# unsafe fn snappy_validate_compressed_buffer(_: *u8, _: size_t) -> c_int { 0 }
# unsafe fn snappy_validate_compressed_buffer(_: *const u8, _: size_t) -> c_int { 0 }
# fn main() {}
pub fn validate_compressed_buffer(src: &[u8]) -> bool {
unsafe {
Expand All @@ -106,7 +106,7 @@ the true length after compression for setting the length.
~~~~
# extern crate libc;
# use libc::{size_t, c_int};
# unsafe fn snappy_compress(a: *u8, b: size_t, c: *mut u8,
# unsafe fn snappy_compress(a: *const u8, b: size_t, c: *mut u8,
# d: *mut size_t) -> c_int { 0 }
# unsafe fn snappy_max_compressed_length(a: size_t) -> size_t { a }
# fn main() {}
Expand All @@ -132,11 +132,11 @@ format and `snappy_uncompressed_length` will retrieve the exact buffer size requ
~~~~
# extern crate libc;
# use libc::{size_t, c_int};
# unsafe fn snappy_uncompress(compressed: *u8,
# unsafe fn snappy_uncompress(compressed: *const u8,
# compressed_length: size_t,
# uncompressed: *mut u8,
# uncompressed_length: *mut size_t) -> c_int { 0 }
# unsafe fn snappy_uncompressed_length(compressed: *u8,
# unsafe fn snappy_uncompressed_length(compressed: *const u8,
# compressed_length: size_t,
# result: *mut size_t) -> c_int { 0 }
# fn main() {}
Expand Down Expand Up @@ -418,7 +418,7 @@ Unsafe functions, on the other hand, advertise it to the world. An unsafe functi
this:

~~~~
unsafe fn kaboom(ptr: *int) -> int { *ptr }
unsafe fn kaboom(ptr: *const int) -> int { *ptr }
~~~~

This function can only be called from an `unsafe` block or another `unsafe` function.
Expand Down Expand Up @@ -453,7 +453,7 @@ use std::ptr;

#[link(name = "readline")]
extern {
static mut rl_prompt: *libc::c_char;
static mut rl_prompt: *const libc::c_char;
}

fn main() {
Expand All @@ -478,7 +478,7 @@ extern crate libc;
#[link(name = "kernel32")]
#[allow(non_snake_case_functions)]
extern "stdcall" {
fn SetEnvironmentVariableA(n: *u8, v: *u8) -> libc::c_int;
fn SetEnvironmentVariableA(n: *const u8, v: *const u8) -> libc::c_int;
}
# fn main() { }
~~~~
Expand Down
6 changes: 4 additions & 2 deletions src/doc/guide-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ extern crate green;
extern crate rustuv;

#[start]
fn start(argc: int, argv: **u8) -> int {
fn start(argc: int, argv: *const *const u8) -> int {
green::start(argc, argv, rustuv::event_loop, main)
}

Expand All @@ -261,7 +261,9 @@ inside of an OS thread.
extern crate native;

#[start]
fn start(argc: int, argv: **u8) -> int { native::start(argc, argv, main) }
fn start(argc: int, argv: *const *const u8) -> int {
native::start(argc, argv, main)
}

fn main() {}
~~~
Expand Down
32 changes: 16 additions & 16 deletions src/doc/guide-unsafe.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ let ref_2: &mut u8 = unsafe { mem::transmute(&mut *ref_1) };
## Raw pointers

Rust offers two additional pointer types "raw pointers", written as
`*T` and `*mut T`. They're an approximation of C's `const T*` and `T*`
`*const T` and `*mut T`. They're an approximation of C's `const T*` and `T*`
respectively; indeed, one of their most common uses is for FFI,
interfacing with external C libraries.

Expand All @@ -100,7 +100,7 @@ offered by the Rust language and libraries. For example, they
- lack any form of lifetimes, unlike `&`, and so the compiler cannot
reason about dangling pointers; and
- have no guarantees about aliasing or mutability other than mutation
not being allowed directly through a `*T`.
not being allowed directly through a `*const T`.

Fortunately, they come with a redeeming feature: the weaker guarantees
mean weaker restrictions. The missing restrictions make raw pointers
Expand Down Expand Up @@ -131,13 +131,13 @@ unsafe, and neither is converting to an integer.

At runtime, a raw pointer `*` and a reference pointing to the same
piece of data have an identical representation. In fact, an `&T`
reference will implicitly coerce to an `*T` raw pointer in safe code
reference will implicitly coerce to an `*const T` raw pointer in safe code
and similarly for the `mut` variants (both coercions can be performed
explicitly with, respectively, `value as *T` and `value as *mut T`).
explicitly with, respectively, `value as *const T` and `value as *mut T`).

Going the opposite direction, from `*` to a reference `&`, is not
Going the opposite direction, from `*const` to a reference `&`, is not
safe. A `&T` is always valid, and so, at a minimum, the raw pointer
`*T` has to be a valid to a valid instance of type `T`. Furthermore,
`*const T` has to be a valid to a valid instance of type `T`. Furthermore,
the resulting pointer must satisfy the aliasing and mutability laws of
references. The compiler assumes these properties are true for any
references, no matter how they are created, and so any conversion from
Expand All @@ -149,7 +149,7 @@ The recommended method for the conversion is
```
let i: u32 = 1;
// explicit cast
let p_imm: *u32 = &i as *u32;
let p_imm: *const u32 = &i as *const u32;
let mut m: u32 = 2;
// implicit coercion
let p_mut: *mut u32 = &mut m;
Expand Down Expand Up @@ -256,7 +256,7 @@ impl<T: Send> Drop for Unique<T> {
// Copy the object out from the pointer onto the stack,
// where it is covered by normal Rust destructor semantics
// and cleans itself up, if necessary
ptr::read(self.ptr as *T);
ptr::read(self.ptr as *const T);

// clean-up our allocation
free(self.ptr as *mut c_void)
Expand Down Expand Up @@ -457,7 +457,7 @@ extern crate libc;

// Entry point for this program
#[start]
fn start(_argc: int, _argv: **u8) -> int {
fn start(_argc: int, _argv: *const *const u8) -> int {
0
}

Expand All @@ -482,7 +482,7 @@ compiler's name mangling too:
extern crate libc;

#[no_mangle] // ensure that this symbol is called `main` in the output
pub extern fn main(argc: int, argv: **u8) -> int {
pub extern fn main(argc: int, argv: *const *const u8) -> int {
0
}

Expand Down Expand Up @@ -540,8 +540,8 @@ use core::mem;
use core::raw::Slice;

#[no_mangle]
pub extern fn dot_product(a: *u32, a_len: u32,
b: *u32, b_len: u32) -> u32 {
pub extern fn dot_product(a: *const u32, a_len: u32,
b: *const u32, b_len: u32) -> u32 {
// Convert the provided arrays into Rust slices.
// The core::raw module guarantees that the Slice
// structure has the same memory layout as a &[T]
Expand Down Expand Up @@ -573,7 +573,7 @@ extern fn begin_unwind(args: &core::fmt::Arguments,

#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
# #[start] fn start(argc: int, argv: **u8) -> int { 0 }
# #[start] fn start(argc: int, argv: *const *const u8) -> int { 0 }
# fn main() {}
```

Expand All @@ -595,7 +595,7 @@ standard library itself.
> parts of the language may never be full specified and so details may
> differ wildly between implementations (and even versions of `rustc`
> itself).
>
>
> Furthermore, this is just an overview; the best form of
> documentation for specific instances of these features are their
> definitions and uses in `std`.
Expand Down Expand Up @@ -627,7 +627,7 @@ via a declaration like
extern "rust-intrinsic" {
fn transmute<T, U>(x: T) -> U;

fn offset<T>(dst: *T, offset: int) -> *T;
fn offset<T>(dst: *const T, offset: int) -> *const T;
}
```

Expand Down Expand Up @@ -677,7 +677,7 @@ unsafe fn deallocate(ptr: *mut u8, _size: uint, _align: uint) {
}

#[start]
fn main(argc: int, argv: **u8) -> int {
fn main(argc: int, argv: *const *const u8) -> int {
let x = box 1;

0
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,7 @@ extern crate libc;
use libc::{c_char, FILE};

extern {
fn fopen(filename: *c_char, mode: *c_char) -> *FILE;
fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE;
}
# fn main() {}
~~~~
Expand Down
11 changes: 6 additions & 5 deletions src/liballoc/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub static mut EMPTY: uint = 12345;
#[inline]
unsafe fn exchange_malloc(size: uint, align: uint) -> *mut u8 {
if size == 0 {
&EMPTY as *uint as *mut u8
&EMPTY as *const uint as *mut u8
} else {
allocate(size, align)
}
Expand Down Expand Up @@ -144,9 +144,10 @@ mod imp {
flags: c_int) -> size_t;
fn je_dallocx(ptr: *mut c_void, flags: c_int);
fn je_nallocx(size: size_t, flags: c_int) -> size_t;
fn je_malloc_stats_print(write_cb: Option<extern "C" fn(cbopaque: *mut c_void, *c_char)>,
fn je_malloc_stats_print(write_cb: Option<extern "C" fn(cbopaque: *mut c_void,
*const c_char)>,
cbopaque: *mut c_void,
opts: *c_char);
opts: *const c_char);
}

// -lpthread needs to occur after -ljemalloc, the earlier argument isn't enough
Expand Down Expand Up @@ -226,7 +227,7 @@ mod imp {
// a block of memory, so we special case everything under `*uint` to
// just pass it to malloc, which is guaranteed to align to at least the
// size of `*uint`.
if align < mem::size_of::<*uint>() {
if align < mem::size_of::<uint>() {
libc_heap::malloc_raw(size)
} else {
let mut out = 0 as *mut libc::c_void;
Expand All @@ -244,7 +245,7 @@ mod imp {
pub unsafe fn reallocate(ptr: *mut u8, size: uint, align: uint,
old_size: uint) -> *mut u8 {
let new_ptr = allocate(size, align);
ptr::copy_memory(new_ptr, ptr as *u8, old_size);
ptr::copy_memory(new_ptr, ptr as *const u8, old_size);
deallocate(ptr, old_size, align);
return new_ptr;
}
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@

#![no_std]
#![feature(lang_items, phase, unsafe_destructor)]
#![allow(unknown_features)] // NOTE: remove after a stage0 snap

#[phase(plugin, link)]
extern crate core;
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub static HEAP: () = ();

/// A type that represents a uniquely-owned value.
#[lang="owned_box"]
pub struct Box<T>(*T);
pub struct Box<T>(*mut T);

impl<T: Default> Default for Box<T> {
fn default() -> Box<T> { box Default::default() }
Expand Down
Loading