Skip to content

Commit cb12105

Browse files
committed
---
yaml --- r: 44390 b: refs/heads/master c: 1d82d8d h: refs/heads/master v: v3
1 parent 02a5493 commit cb12105

23 files changed

+107
-258
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: 2180fe25520727a747c5a73b4d582a120ad116bd
2+
refs/heads/master: 1d82d8dd5def0713a78f864f47a4c9a65f8bf6cc
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d9689399d091c3265f00434a69c551a61c28dc
55
refs/heads/try: ef355f6332f83371e4acf04fc4eb940ab41d78d3

trunk/src/libcore/os.rs

Lines changed: 10 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ extern mod rustrt {
6262
unsafe fn rust_path_exists(path: *libc::c_char) -> c_int;
6363
unsafe fn rust_list_files2(&&path: ~str) -> ~[~str];
6464
unsafe fn rust_process_wait(handle: c_int) -> c_int;
65+
unsafe fn last_os_error() -> ~str;
6566
unsafe fn rust_set_exit_status(code: libc::intptr_t);
6667
}
6768

68-
pub const TMPBUF_SZ : uint = 1000u;
69+
pub const tmpbuf_sz : uint = 1000u;
6970

7071
pub fn getcwd() -> Path {
7172
unsafe {
@@ -79,7 +80,7 @@ pub fn as_c_charp<T>(s: &str, f: fn(*c_char) -> T) -> T {
7980

8081
pub fn fill_charp_buf(f: fn(*mut c_char, size_t) -> bool)
8182
-> Option<~str> {
82-
let buf = vec::cast_to_mut(vec::from_elem(TMPBUF_SZ, 0u8 as c_char));
83+
let buf = vec::cast_to_mut(vec::from_elem(tmpbuf_sz, 0u8 as c_char));
8384
do vec::as_mut_buf(buf) |b, sz| {
8485
if f(b, sz as size_t) {
8586
unsafe {
@@ -98,19 +99,19 @@ pub mod win32 {
9899
use str;
99100
use option::{None, Option};
100101
use option;
101-
use os::TMPBUF_SZ;
102+
use os::tmpbuf_sz;
102103
use libc::types::os::arch::extra::DWORD;
103104

104105
pub fn fill_utf16_buf_and_decode(f: fn(*mut u16, DWORD) -> DWORD)
105106
-> Option<~str> {
106107
unsafe {
107-
let mut n = TMPBUF_SZ as DWORD;
108+
let mut n = tmpbuf_sz as DWORD;
108109
let mut res = None;
109110
let mut done = false;
110111
while !done {
111112
let buf = vec::cast_to_mut(vec::from_elem(n as uint, 0u16));
112113
do vec::as_mut_buf(buf) |b, _sz| {
113-
let k : DWORD = f(b, TMPBUF_SZ as DWORD);
114+
let k : DWORD = f(b, tmpbuf_sz as DWORD);
114115
if k == (0 as DWORD) {
115116
done = true;
116117
} else if (k == n &&
@@ -386,11 +387,11 @@ pub fn self_exe_path() -> Option<Path> {
386387
unsafe {
387388
use libc::funcs::posix01::unistd::readlink;
388389

389-
let mut path_str = str::with_capacity(TMPBUF_SZ);
390+
let mut path_str = str::with_capacity(tmpbuf_sz);
390391
let len = do str::as_c_str(path_str) |buf| {
391392
let buf = buf as *mut c_char;
392393
do as_c_charp("/proc/self/exe") |proc_self_buf| {
393-
readlink(proc_self_buf, buf, TMPBUF_SZ as size_t)
394+
readlink(proc_self_buf, buf, tmpbuf_sz as size_t)
394395
}
395396
};
396397
if len == -1 {
@@ -765,136 +766,11 @@ pub fn remove_file(p: &Path) -> bool {
765766
}
766767
}
767768

768-
#[cfg(unix)]
769-
pub fn errno() -> int {
770-
#[cfg(target_os = "macos")]
771-
#[cfg(target_os = "freebsd")]
772-
fn errno_location() -> *c_int {
773-
#[nolink]
774-
extern {
775-
unsafe fn __error() -> *c_int;
776-
}
777-
unsafe {
778-
__error()
779-
}
780-
}
781-
782-
#[cfg(target_os = "linux")]
783-
#[cfg(target_os = "android")]
784-
fn errno_location() -> *c_int {
785-
#[nolink]
786-
extern {
787-
unsafe fn __errno_location() -> *c_int;
788-
}
789-
unsafe {
790-
__errno_location()
791-
}
792-
}
793-
794-
unsafe {
795-
(*errno_location()) as int
796-
}
797-
}
798-
799-
#[cfg(windows)]
800-
pub fn errno() -> uint {
801-
use libc::types::os::arch::extra::DWORD;
802-
803-
#[link_name = "kernel32"]
804-
#[abi = "stdcall"]
805-
extern {
806-
unsafe fn GetLastError() -> DWORD;
807-
}
808-
809-
unsafe {
810-
GetLastError() as uint
811-
}
812-
}
813-
814769
/// Get a string representing the platform-dependent last error
815770
pub fn last_os_error() -> ~str {
816-
#[cfg(unix)]
817-
fn strerror() -> ~str {
818-
#[cfg(target_os = "macos")]
819-
#[cfg(target_os = "android")]
820-
#[cfg(target_os = "freebsd")]
821-
fn strerror_r(errnum: c_int, buf: *c_char, buflen: size_t) -> c_int {
822-
#[nolink]
823-
extern {
824-
unsafe fn strerror_r(errnum: c_int, buf: *c_char,
825-
buflen: size_t) -> c_int;
826-
}
827-
unsafe {
828-
strerror_r(errnum, buf, buflen)
829-
}
830-
}
831-
832-
// GNU libc provides a non-compliant version of strerror_r by default
833-
// and requires macros to instead use the POSIX compliant variant.
834-
// So we just use __xpg_strerror_r which is always POSIX compliant
835-
#[cfg(target_os = "linux")]
836-
fn strerror_r(errnum: c_int, buf: *c_char, buflen: size_t) -> c_int {
837-
#[nolink]
838-
extern {
839-
unsafe fn __xpg_strerror_r(errnum: c_int, buf: *c_char,
840-
buflen: size_t) -> c_int;
841-
}
842-
unsafe {
843-
__xpg_strerror_r(errnum, buf, buflen)
844-
}
845-
}
846-
847-
let mut buf = [0 as c_char, ..TMPBUF_SZ];
848-
unsafe {
849-
let err = strerror_r(errno() as c_int, &buf[0],
850-
TMPBUF_SZ as size_t);
851-
if err < 0 {
852-
die!(~"strerror_r failure");
853-
}
854-
855-
str::raw::from_c_str(&buf[0])
856-
}
857-
}
858-
859-
#[cfg(windows)]
860-
fn strerror() -> ~str {
861-
use libc::types::os::arch::extra::DWORD;
862-
use libc::types::os::arch::extra::LPSTR;
863-
use libc::types::os::arch::extra::LPVOID;
864-
865-
#[link_name = "kernel32"]
866-
#[abi = "stdcall"]
867-
extern {
868-
unsafe fn FormatMessageA(flags: DWORD, lpSrc: LPVOID,
869-
msgId: DWORD, langId: DWORD,
870-
buf: LPSTR, nsize: DWORD,
871-
args: *c_void) -> DWORD;
872-
}
873-
874-
const FORMAT_MESSAGE_FROM_SYSTEM: DWORD = 0x00001000;
875-
const FORMAT_MESSAGE_IGNORE_INSERTS: DWORD = 0x00000200;
876-
877-
let mut buf = [0 as c_char, ..TMPBUF_SZ];
878-
879-
// This value is calculated from the macro
880-
// MAKELANGID(LANG_SYSTEM_DEFAULT, SUBLANG_SYS_DEFAULT)
881-
let langId = 0x0800 as DWORD;
882-
let err = errno() as DWORD;
883-
unsafe {
884-
let res = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
885-
FORMAT_MESSAGE_IGNORE_INSERTS,
886-
ptr::mut_null(), err, langId,
887-
&mut buf[0], TMPBUF_SZ as DWORD,
888-
ptr::null());
889-
if res == 0 {
890-
die!(fmt!("[%?] FormatMessage failure", errno()));
891-
}
892-
893-
str::raw::from_c_str(&buf[0])
894-
}
771+
unsafe {
772+
rustrt::last_os_error()
895773
}
896-
897-
strerror()
898774
}
899775

900776
/**

trunk/src/librustc/metadata/common.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,5 @@ pub const tag_lang_items_item: uint = 0x73;
153153
pub const tag_lang_items_item_id: uint = 0x74;
154154
pub const tag_lang_items_item_node_id: uint = 0x75;
155155

156-
pub const tag_item_unnamed_field: uint = 0x76;
157-
158156
pub type link_meta = {name: @str, vers: @str, extras_hash: @str};
159157

trunk/src/librustc/metadata/csearch.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,8 @@ pub fn get_item_attrs(cstore: @mut cstore::CStore,
166166
decoder::get_item_attrs(cdata, def_id.node, f)
167167
}
168168

169-
pub fn get_struct_fields(cstore: @mut cstore::CStore,
170-
def: ast::def_id)
171-
-> ~[ty::field_ty] {
169+
pub fn get_struct_fields(tcx: ty::ctxt, def: ast::def_id) -> ~[ty::field_ty] {
170+
let cstore = tcx.cstore;
172171
let cdata = cstore::get_crate_data(cstore, def.crate);
173172
decoder::get_struct_fields(cstore.intr, cdata, def.node)
174173
}

trunk/src/librustc/metadata/decoder.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use std::serialize::Decodable;
4242
use syntax::ast_map;
4343
use syntax::attr;
4444
use syntax::diagnostic::span_handler;
45-
use syntax::parse::token::{ident_interner, special_idents};
45+
use syntax::parse::token::ident_interner;
4646
use syntax::print::pprust;
4747
use syntax::{ast, ast_util};
4848
use syntax::codemap;
@@ -231,9 +231,7 @@ pub fn item_type(item_id: ast::def_id, item: ebml::Doc,
231231
let t = doc_type(item, tcx, cdata);
232232
if family_names_type(item_family(item)) {
233233
ty::mk_with_id(tcx, t, item_id)
234-
} else {
235-
t
236-
}
234+
} else { t }
237235
}
238236

239237
fn item_impl_traits(item: ebml::Doc, tcx: ty::ctxt, cdata: cmd) -> ~[ty::t] {
@@ -663,12 +661,11 @@ fn item_impl_methods(intr: @ident_interner, cdata: cmd, item: ebml::Doc,
663661
rslt
664662
}
665663

666-
pub fn get_impls_for_mod(intr: @ident_interner,
667-
cdata: cmd,
668-
m_id: ast::node_id,
669-
name: Option<ast::ident>,
670-
get_cdata: &fn(ast::crate_num) -> cmd)
664+
pub fn get_impls_for_mod(intr: @ident_interner, cdata: cmd,
665+
m_id: ast::node_id, name: Option<ast::ident>,
666+
get_cdata: fn(ast::crate_num) -> cmd)
671667
-> @~[@_impl] {
668+
672669
let data = cdata.data;
673670
let mod_item = lookup_item(m_id, data);
674671
let mut result = ~[];
@@ -890,15 +887,6 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id)
890887
});
891888
}
892889
}
893-
for reader::tagged_docs(item, tag_item_unnamed_field) |an_item| {
894-
let did = item_def_id(an_item, cdata);
895-
result.push(ty::field_ty {
896-
ident: special_idents::unnamed_field,
897-
id: did,
898-
vis: ast::inherited,
899-
mutability: ast::struct_immutable,
900-
});
901-
}
902890
result
903891
}
904892

trunk/src/librustc/metadata/encoder.rs

Lines changed: 22 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ use syntax::ast_map;
4646
use syntax::ast_util::*;
4747
use syntax::attr;
4848
use syntax::diagnostic::span_handler;
49-
use syntax::parse::token::special_idents;
5049
use syntax::print::pprust;
5150
use syntax::{ast_util, visit};
5251
use syntax;
@@ -329,7 +328,7 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: writer::Encoder,
329328
// Encode info about all the module children.
330329
for md.items.each |item| {
331330
match item.node {
332-
item_impl(*) => {
331+
item_impl(*) | item_struct(*) => {
333332
let (ident, did) = (item.ident, item.id);
334333
debug!("(encoding info for module) ... encoding impl %s \
335334
(%?/%?)",
@@ -433,28 +432,25 @@ fn encode_info_for_struct(ecx: @encode_ctxt, ebml_w: writer::Encoder,
433432
/* We encode both private and public fields -- need to include
434433
private fields to get the offsets right */
435434
for fields.each |field| {
436-
let (nm, mt, vis) = match field.node.kind {
437-
named_field(nm, mt, vis) => (nm, mt, vis),
438-
unnamed_field => (
439-
special_idents::unnamed_field,
440-
struct_immutable,
441-
inherited
442-
)
443-
};
444-
445-
let id = field.node.id;
446-
index.push({val: id, pos: ebml_w.writer.tell()});
447-
global_index.push({val: id, pos: ebml_w.writer.tell()});
448-
ebml_w.start_tag(tag_items_data_item);
449-
debug!("encode_info_for_struct: doing %s %d",
450-
tcx.sess.str_of(nm), id);
451-
encode_visibility(ebml_w, vis);
452-
encode_name(ecx, ebml_w, nm);
453-
encode_path(ecx, ebml_w, path, ast_map::path_name(nm));
454-
encode_type(ecx, ebml_w, node_id_to_type(tcx, id));
455-
encode_mutability(ebml_w, mt);
456-
encode_def_id(ebml_w, local_def(id));
457-
ebml_w.end_tag();
435+
match field.node.kind {
436+
named_field(nm, mt, vis) => {
437+
let id = field.node.id;
438+
index.push({val: id, pos: ebml_w.writer.tell()});
439+
global_index.push({val: id,
440+
pos: ebml_w.writer.tell()});
441+
ebml_w.start_tag(tag_items_data_item);
442+
debug!("encode_info_for_struct: doing %s %d",
443+
tcx.sess.str_of(nm), id);
444+
encode_visibility(ebml_w, vis);
445+
encode_name(ecx, ebml_w, nm);
446+
encode_path(ecx, ebml_w, path, ast_map::path_name(nm));
447+
encode_type(ecx, ebml_w, node_id_to_type(tcx, id));
448+
encode_mutability(ebml_w, mt);
449+
encode_def_id(ebml_w, local_def(id));
450+
ebml_w.end_tag();
451+
}
452+
unnamed_field => {}
453+
}
458454
}
459455
/*bad*/copy *index
460456
}
@@ -677,24 +673,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
677673
encode_def_id(ebml_w, local_def(item.id));
678674
encode_family(ebml_w, 'S');
679675
encode_type_param_bounds(ebml_w, ecx, tps);
680-
681-
// If this is a tuple- or enum-like struct, encode the type of the
682-
// constructor. Otherwise, encode the type of the struct.
683-
if struct_def.fields.len() > 0 &&
684-
struct_def.fields[0].node.kind == ast::unnamed_field {
685-
// Tuple- or enum-like struct.
686-
let ctor_id = match struct_def.ctor_id {
687-
Some(ctor_id) => ctor_id,
688-
None => ecx.tcx.sess.bug(~"struct def didn't have ctor id"),
689-
};
690-
encode_type(ecx, ebml_w, node_id_to_type(tcx, ctor_id));
691-
692-
// Also encode the symbol.
693-
encode_symbol(ecx, ebml_w, ctor_id);
694-
} else {
695-
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
696-
}
697-
676+
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
698677
encode_name(ecx, ebml_w, item.ident);
699678
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
700679
encode_region_param(ecx, ebml_w, item);
@@ -718,11 +697,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
718697
encode_def_id(ebml_w, local_def(f.node.id));
719698
ebml_w.end_tag();
720699
}
721-
unnamed_field => {
722-
ebml_w.start_tag(tag_item_unnamed_field);
723-
encode_def_id(ebml_w, local_def(f.node.id));
724-
ebml_w.end_tag();
725-
}
700+
unnamed_field => {}
726701
}
727702
}
728703

0 commit comments

Comments
 (0)