Skip to content

Some general clean-up of std::vec::raw #10984

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

Closed
wants to merge 6 commits into from
Closed
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
14 changes: 7 additions & 7 deletions doc/po/ja/tutorial-ffi.md.po
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ msgid ""
"~~~~ {.xfail-test}\n"
"pub fn validate_compressed_buffer(src: &[u8]) -> bool {\n"
" unsafe {\n"
" snappy_validate_compressed_buffer(vec::raw::to_ptr(src), src.len() as size_t) == 0\n"
" snappy_validate_compressed_buffer(src.as_ptr(), src.len() as size_t) == 0\n"
" }\n"
"}\n"
"~~~~\n"
Expand Down Expand Up @@ -207,7 +207,7 @@ msgid ""
"pub fn compress(src: &[u8]) -> ~[u8] {\n"
" unsafe {\n"
" let srclen = src.len() as size_t;\n"
" let psrc = vec::raw::to_ptr(src);\n"
" let psrc = src.as_ptr();\n"
msgstr ""

#. type: Plain text
Expand All @@ -216,15 +216,15 @@ msgstr ""
msgid ""
" let mut dstlen = snappy_max_compressed_length(srclen);\n"
" let mut dst = vec::with_capacity(dstlen as uint);\n"
" let pdst = vec::raw::to_mut_ptr(dst);\n"
" let pdst = dst.as_mut_ptr();\n"
msgstr ""

#. type: Plain text
#: doc/tutorial-ffi.md:113
#, no-wrap
msgid ""
" snappy_compress(psrc, srclen, pdst, &mut dstlen);\n"
" vec::raw::set_len(&mut dst, dstlen as uint);\n"
" dst.set_len(dstlen as uint);\n"
" dst\n"
" }\n"
"}\n"
Expand All @@ -247,7 +247,7 @@ msgid ""
"pub fn uncompress(src: &[u8]) -> Option<~[u8]> {\n"
" unsafe {\n"
" let srclen = src.len() as size_t;\n"
" let psrc = vec::raw::to_ptr(src);\n"
" let psrc = src.as_ptr();\n"
msgstr ""

#. type: Plain text
Expand All @@ -263,15 +263,15 @@ msgstr ""
#, no-wrap
msgid ""
" let mut dst = vec::with_capacity(dstlen as uint);\n"
" let pdst = vec::raw::to_mut_ptr(dst);\n"
" let pdst = dst.as_mut_ptr();\n"
msgstr ""

#. type: Plain text
#: doc/tutorial-ffi.md:138
#, no-wrap
msgid ""
" if snappy_uncompress(psrc, srclen, pdst, &mut dstlen) == 0 {\n"
" vec::raw::set_len(&mut dst, dstlen as uint);\n"
" dst.set_len(dstlen as uint);\n"
" Some(dst)\n"
" } else {\n"
" None // SNAPPY_INVALID_INPUT\n"
Expand Down
14 changes: 7 additions & 7 deletions doc/po/tutorial-ffi.md.pot
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ msgid ""
"~~~~ {.xfail-test}\n"
"pub fn validate_compressed_buffer(src: &[u8]) -> bool {\n"
" unsafe {\n"
" snappy_validate_compressed_buffer(vec::raw::to_ptr(src), src.len() as size_t) == 0\n"
" snappy_validate_compressed_buffer(src.as_ptr(), src.len() as size_t) == 0\n"
" }\n"
"}\n"
"~~~~\n"
Expand Down Expand Up @@ -207,7 +207,7 @@ msgid ""
"pub fn compress(src: &[u8]) -> ~[u8] {\n"
" unsafe {\n"
" let srclen = src.len() as size_t;\n"
" let psrc = vec::raw::to_ptr(src);\n"
" let psrc = src.as_ptr();\n"
msgstr ""

#. type: Plain text
Expand All @@ -216,15 +216,15 @@ msgstr ""
msgid ""
" let mut dstlen = snappy_max_compressed_length(srclen);\n"
" let mut dst = vec::with_capacity(dstlen as uint);\n"
" let pdst = vec::raw::to_mut_ptr(dst);\n"
" let pdst = dst.as_mut_ptr();\n"
msgstr ""

#. type: Plain text
#: doc/tutorial-ffi.md:113
#, no-wrap
msgid ""
" snappy_compress(psrc, srclen, pdst, &mut dstlen);\n"
" vec::raw::set_len(&mut dst, dstlen as uint);\n"
" dst.set_len(dstlen as uint);\n"
" dst\n"
" }\n"
"}\n"
Expand All @@ -247,7 +247,7 @@ msgid ""
"pub fn uncompress(src: &[u8]) -> Option<~[u8]> {\n"
" unsafe {\n"
" let srclen = src.len() as size_t;\n"
" let psrc = vec::raw::to_ptr(src);\n"
" let psrc = src.as_ptr();\n"
msgstr ""

#. type: Plain text
Expand All @@ -263,15 +263,15 @@ msgstr ""
#, no-wrap
msgid ""
" let mut dst = vec::with_capacity(dstlen as uint);\n"
" let pdst = vec::raw::to_mut_ptr(dst);\n"
" let pdst = dst.as_mut_ptr();\n"
msgstr ""

#. type: Plain text
#: doc/tutorial-ffi.md:138
#, no-wrap
msgid ""
" if snappy_uncompress(psrc, srclen, pdst, &mut dstlen) == 0 {\n"
" vec::raw::set_len(&mut dst, dstlen as uint);\n"
" dst.set_len(dstlen as uint);\n"
" Some(dst)\n"
" } else {\n"
" None // SNAPPY_INVALID_INPUT\n"
Expand Down
14 changes: 7 additions & 7 deletions doc/tutorial-ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ the allocated memory. The length is less than or equal to the capacity.
~~~~ {.xfail-test}
pub fn validate_compressed_buffer(src: &[u8]) -> bool {
unsafe {
snappy_validate_compressed_buffer(vec::raw::to_ptr(src), src.len() as size_t) == 0
snappy_validate_compressed_buffer(src.as_ptr(), src.len() as size_t) == 0
}
}
~~~~
Expand All @@ -100,14 +100,14 @@ the true length after compression for setting the length.
pub fn compress(src: &[u8]) -> ~[u8] {
unsafe {
let srclen = src.len() as size_t;
let psrc = vec::raw::to_ptr(src);
let psrc = src.as_ptr();

let mut dstlen = snappy_max_compressed_length(srclen);
let mut dst = vec::with_capacity(dstlen as uint);
let pdst = vec::raw::to_mut_ptr(dst);
let pdst = dst.as_mut_ptr();

snappy_compress(psrc, srclen, pdst, &mut dstlen);
vec::raw::set_len(&mut dst, dstlen as uint);
dst.set_len(dstlen as uint);
dst
}
}
Expand All @@ -120,16 +120,16 @@ format and `snappy_uncompressed_length` will retrieve the exact buffer size requ
pub fn uncompress(src: &[u8]) -> Option<~[u8]> {
unsafe {
let srclen = src.len() as size_t;
let psrc = vec::raw::to_ptr(src);
let psrc = src.as_ptr();

let mut dstlen: size_t = 0;
snappy_uncompressed_length(psrc, srclen, &mut dstlen);

let mut dst = vec::with_capacity(dstlen as uint);
let pdst = vec::raw::to_mut_ptr(dst);
let pdst = dst.as_mut_ptr();

if snappy_uncompress(psrc, srclen, pdst, &mut dstlen) == 0 {
vec::raw::set_len(&mut dst, dstlen as uint);
dst.set_len(dstlen as uint);
Some(dst)
} else {
None // SNAPPY_INVALID_INPUT
Expand Down
7 changes: 3 additions & 4 deletions src/libextra/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ use std::num;
use std::ptr;
use std::mem;
use std::uint;
use std::vec;
use std::unstable::intrinsics;
use std::unstable::intrinsics::{TyDesc, get_tydesc};

Expand Down Expand Up @@ -115,7 +114,7 @@ fn round_up_to(base: uint, align: uint) -> uint {
// in it.
unsafe fn destroy_chunk(chunk: &Chunk) {
let mut idx = 0;
let buf = vec::raw::to_ptr(chunk.data);
let buf = chunk.data.as_ptr();
let fill = chunk.fill;

while idx < fill {
Expand Down Expand Up @@ -179,7 +178,7 @@ impl Arena {
//debug!("idx = {}, size = {}, align = {}, fill = {}",
// start, n_bytes, align, head.fill);

ptr::offset(vec::raw::to_ptr(this.pod_head.data), start as int)
ptr::offset(this.pod_head.data.as_ptr(), start as int)
}
}

Expand Down Expand Up @@ -235,7 +234,7 @@ impl Arena {
//debug!("idx = {}, size = {}, align = {}, fill = {}",
// start, n_bytes, align, head.fill);

let buf = vec::raw::to_ptr(self.head.data);
let buf = self.head.data.as_ptr();
return (ptr::offset(buf, tydesc_start as int), ptr::offset(buf, start as int));
}
}
Expand Down
14 changes: 5 additions & 9 deletions src/libextra/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl Uuid {
pub fn new_v4() -> Uuid {
let ub = rand::task_rng().gen_vec(16);
let mut uuid = Uuid{ bytes: [0, .. 16] };
vec::bytes::copy_memory(uuid.bytes, ub, 16);
vec::bytes::copy_memory(uuid.bytes, ub);
uuid.set_variant(VariantRFC4122);
uuid.set_version(Version4Random);
uuid
Expand All @@ -202,7 +202,7 @@ impl Uuid {
fields.data1 = to_be32(d1 as i32) as u32;
fields.data2 = to_be16(d2 as i16) as u16;
fields.data3 = to_be16(d3 as i16) as u16;
vec::bytes::copy_memory(fields.data4, d4, 8);
vec::bytes::copy_memory(fields.data4, d4);

unsafe {
transmute(fields)
Expand All @@ -220,7 +220,7 @@ impl Uuid {

let mut uuid = Uuid{ bytes: [0, .. 16] };
unsafe {
vec::raw::copy_memory(uuid.bytes, b, 16);
vec::raw::copy_memory(uuid.bytes, b);
}
Some(uuid)
}
Expand Down Expand Up @@ -442,11 +442,7 @@ impl Zero for Uuid {

impl Clone for Uuid {
/// Returns a copy of the UUID
fn clone(&self) -> Uuid {
let mut clone = Uuid{ bytes: [0, .. 16] };
vec::bytes::copy_memory(clone.bytes, self.bytes, 16);
clone
}
fn clone(&self) -> Uuid { *self }
}

impl FromStr for Uuid {
Expand Down Expand Up @@ -509,7 +505,7 @@ impl rand::Rand for Uuid {
fn rand<R: rand::Rng>(rng: &mut R) -> Uuid {
let ub = rng.gen_vec(16);
let mut uuid = Uuid{ bytes: [0, .. 16] };
vec::bytes::copy_memory(uuid.bytes, ub, 16);
vec::bytes::copy_memory(uuid.bytes, ub);
uuid.set_variant(VariantRFC4122);
uuid.set_version(Version4Random);
uuid
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use metadata::cstore;
use util::common::time;

use std::libc;
use std::vec;

pub fn run(sess: session::Session, llmod: ModuleRef,
tm: TargetMachineRef, reachable: &[~str]) {
Expand Down Expand Up @@ -48,7 +47,7 @@ pub fn run(sess: session::Session, llmod: ModuleRef,
debug!("reading {}", name);
let bc = time(sess.time_passes(), format!("read {}.bc", name), (), |_|
archive.read(format!("{}.bc", name)));
let ptr = vec::raw::to_ptr(bc);
let ptr = bc.as_ptr();
debug!("linking {}", name);
time(sess.time_passes(), format!("ll link {}", name), (), |()| unsafe {
if !llvm::LLVMRustLinkInExternalBitcode(llmod,
Expand All @@ -62,7 +61,7 @@ pub fn run(sess: session::Session, llmod: ModuleRef,
// Internalize everything but the reachable symbols of the current module
let cstrs = reachable.map(|s| s.to_c_str());
let arr = cstrs.map(|c| c.with_ref(|p| p));
let ptr = vec::raw::to_ptr(arr);
let ptr = arr.as_ptr();
unsafe {
llvm::LLVMRustRunRestrictionPass(llmod, ptr as **libc::c_char,
arr.len() as libc::size_t);
Expand Down
17 changes: 8 additions & 9 deletions src/librustc/middle/trans/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use middle::trans::type_::Type;
use std::cast;
use std::hashmap::HashMap;
use std::libc::{c_uint, c_ulonglong, c_char};
use std::vec;
use syntax::codemap::Span;
use std::ptr::is_not_null;

Expand Down Expand Up @@ -118,7 +117,7 @@ impl Builder {
pub fn aggregate_ret(&self, ret_vals: &[ValueRef]) {
unsafe {
llvm::LLVMBuildAggregateRet(self.llbuilder,
vec::raw::to_ptr(ret_vals),
ret_vals.as_ptr(),
ret_vals.len() as c_uint);
}
}
Expand Down Expand Up @@ -161,7 +160,7 @@ impl Builder {
unsafe {
let v = llvm::LLVMBuildInvoke(self.llbuilder,
llfn,
vec::raw::to_ptr(args),
args.as_ptr(),
args.len() as c_uint,
then,
catch,
Expand Down Expand Up @@ -500,7 +499,7 @@ impl Builder {
pub fn gep(&self, ptr: ValueRef, indices: &[ValueRef]) -> ValueRef {
self.count_insn("gep");
unsafe {
llvm::LLVMBuildGEP(self.llbuilder, ptr, vec::raw::to_ptr(indices),
llvm::LLVMBuildGEP(self.llbuilder, ptr, indices.as_ptr(),
indices.len() as c_uint, noname())
}
}
Expand Down Expand Up @@ -528,7 +527,7 @@ impl Builder {
self.count_insn("inboundsgep");
unsafe {
llvm::LLVMBuildInBoundsGEP(
self.llbuilder, ptr, vec::raw::to_ptr(indices), indices.len() as c_uint, noname())
self.llbuilder, ptr, indices.as_ptr(), indices.len() as c_uint, noname())
}
}

Expand Down Expand Up @@ -716,8 +715,8 @@ impl Builder {
let phi = self.empty_phi(ty);
self.count_insn("addincoming");
unsafe {
llvm::LLVMAddIncoming(phi, vec::raw::to_ptr(vals),
vec::raw::to_ptr(bbs),
llvm::LLVMAddIncoming(phi, vals.as_ptr(),
bbs.as_ptr(),
vals.len() as c_uint);
phi
}
Expand Down Expand Up @@ -775,7 +774,7 @@ impl Builder {
attributes: &[(uint, lib::llvm::Attribute)]) -> ValueRef {
self.count_insn("call");
unsafe {
let v = llvm::LLVMBuildCall(self.llbuilder, llfn, vec::raw::to_ptr(args),
let v = llvm::LLVMBuildCall(self.llbuilder, llfn, args.as_ptr(),
args.len() as c_uint, noname());
for &(idx, attr) in attributes.iter() {
llvm::LLVMAddInstrAttribute(v, idx as c_uint, attr as c_uint);
Expand Down Expand Up @@ -885,7 +884,7 @@ impl Builder {
let args: &[ValueRef] = [];
self.count_insn("trap");
llvm::LLVMBuildCall(
self.llbuilder, T, vec::raw::to_ptr(args), args.len() as c_uint, noname());
self.llbuilder, T, args.as_ptr(), args.len() as c_uint, noname());
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ pub fn C_zero_byte_arr(size: uint) -> ValueRef {
let mut elts: ~[ValueRef] = ~[];
while i < size { elts.push(C_u8(0u)); i += 1u; }
return llvm::LLVMConstArray(Type::i8().to_ref(),
vec::raw::to_ptr(elts), elts.len() as c_uint);
elts.as_ptr(), elts.len() as c_uint);
}
}

Expand All @@ -968,13 +968,13 @@ pub fn C_named_struct(T: Type, elts: &[ValueRef]) -> ValueRef {

pub fn C_array(ty: Type, elts: &[ValueRef]) -> ValueRef {
unsafe {
return llvm::LLVMConstArray(ty.to_ref(), vec::raw::to_ptr(elts), elts.len() as c_uint);
return llvm::LLVMConstArray(ty.to_ref(), elts.as_ptr(), elts.len() as c_uint);
}
}

pub fn C_bytes(bytes: &[u8]) -> ValueRef {
unsafe {
let ptr = cast::transmute(vec::raw::to_ptr(bytes));
let ptr = cast::transmute(bytes.as_ptr());
return llvm::LLVMConstStringInContext(base::task_llcx(), ptr, bytes.len() as c_uint, True);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/trans/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use util::sha2::Sha256;
use std::c_str::ToCStr;
use std::hashmap::{HashMap, HashSet};
use std::local_data;
use std::vec;
use std::libc::c_uint;
use syntax::ast;

Expand Down Expand Up @@ -261,7 +260,7 @@ impl CrateContext {
indices.iter().map(|i| C_i32(*i as i32)).collect();
unsafe {
llvm::LLVMConstInBoundsGEP(pointer,
vec::raw::to_ptr(v),
v.as_ptr(),
indices.len() as c_uint)
}
}
Expand Down
Loading