Skip to content

Commit be85e12

Browse files
committed
---
yaml --- r: 95959 b: refs/heads/dist-snap c: 7bb668d h: refs/heads/master i: 95957: 1a8e67b 95955: f573d85 95951: 8e7cb90 v: v3
1 parent 9b21bb7 commit be85e12

File tree

16 files changed

+209
-13
lines changed

16 files changed

+209
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: b60de8a1f6fe343f99203036e39ec82c3c6fd1b9
9+
refs/heads/dist-snap: 7bb668defdabb39a4e15bb3a49f9d16e31767fb0
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libextra/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Rust extras are part of the standard Rust distribution.
2121
*/
2222

2323
#[link(name = "extra",
24+
package_id = "extra",
2425
vers = "0.9-pre",
2526
uuid = "122bed0b-c19b-4b82-b0b7-7ae8aead7297",
2627
url = "https://github.com/mozilla/rust/tree/master/src/libextra")];

branches/dist-snap/src/librustc/back/link.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,18 @@ pub fn build_link_meta(sess: Session,
634634
}
635635
}
636636

637+
fn crate_meta_pkgid(sess: Session, name: @str, opt_pkg_id: Option<@str>)
638+
-> @str {
639+
match opt_pkg_id {
640+
Some(v) if !v.is_empty() => v,
641+
_ => {
642+
let pkg_id = name.clone();
643+
warn_missing(sess, "package_id", pkg_id);
644+
pkg_id
645+
}
646+
}
647+
}
648+
637649
let ProvidedMetas {
638650
name: opt_name,
639651
vers: opt_vers,
@@ -642,15 +654,16 @@ pub fn build_link_meta(sess: Session,
642654
} = provided_link_metas(sess, c);
643655
let name = crate_meta_name(sess, output, opt_name);
644656
let vers = crate_meta_vers(sess, opt_vers);
657+
let pkg_id = crate_meta_pkgid(sess, name, opt_pkg_id);
645658
let dep_hashes = cstore::get_dep_hashes(sess.cstore);
646659
let extras_hash =
647660
crate_meta_extras_hash(symbol_hasher, cmh_items,
648-
dep_hashes, opt_pkg_id);
661+
dep_hashes, Some(pkg_id));
649662

650663
LinkMeta {
651664
name: name,
652665
vers: vers,
653-
package_id: opt_pkg_id,
666+
package_id: Some(pkg_id),
654667
extras_hash: extras_hash
655668
}
656669
}

branches/dist-snap/src/librustc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#[link(name = "rustc",
12+
package_id = "rustc",
1213
vers = "0.9-pre",
1314
uuid = "0ce89b41-2f92-459e-bbc1-8f5fe32f16cf",
1415
url = "https://github.com/mozilla/rust/tree/master/src/rustc")];

branches/dist-snap/src/librustc/metadata/encoder.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,8 +1487,8 @@ fn encode_attributes(ebml_w: &mut writer::Encoder, attrs: &[Attribute]) {
14871487

14881488
// So there's a special crate attribute called 'link' which defines the
14891489
// metadata that Rust cares about for linking crates. This attribute requires
1490-
// 'name' and 'vers' items, so if the user didn't provide them we will throw
1491-
// them in anyway with default values.
1490+
// 'name', 'vers' and 'package_id' items, so if the user didn't provide them we
1491+
// will throw them in anyway with default values.
14921492
fn synthesize_crate_attrs(ecx: &EncodeContext,
14931493
crate: &Crate) -> ~[Attribute] {
14941494

@@ -1505,9 +1505,20 @@ fn synthesize_crate_attrs(ecx: &EncodeContext,
15051505
attr::mk_name_value_item_str(@"vers",
15061506
ecx.link_meta.vers);
15071507

1508-
let mut meta_items = ~[name_item, vers_item];
1508+
let pkgid_item = match ecx.link_meta.package_id {
1509+
Some(pkg_id) => attr::mk_name_value_item_str(@"package_id",
1510+
pkg_id),
1511+
// uses package_id equal to name;
1512+
// this should never happen here but package_id is an Option
1513+
// FIXME (#10370): change package_id in LinkMeta to @str instead of Option<@str>
1514+
_ => attr::mk_name_value_item_str(@"package_id",
1515+
ecx.link_meta.name)
1516+
};
1517+
1518+
let mut meta_items = ~[name_item, vers_item, pkgid_item];
15091519

1510-
for &mi in items.iter().filter(|mi| "name" != mi.name() && "vers" != mi.name()) {
1520+
for &mi in items.iter().filter(|mi| "name" != mi.name() && "vers" != mi.name() &&
1521+
"package_id" != mi.name()) {
15111522
meta_items.push(mi);
15121523
}
15131524
let link_item = attr::mk_list_item(@"link", meta_items);

branches/dist-snap/src/librustdoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#[link(name = "rustdoc",
12+
package_id = "rustdoc",
1213
vers = "0.9-pre",
1314
uuid = "8c6e4598-1596-4aa5-a24c-b811914bbbc6",
1415
url = "https://github.com/mozilla/rust/tree/master/src/librustdoc")];

branches/dist-snap/src/librustpkg/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// rustpkg - a package manager and build system for Rust
1212

1313
#[link(name = "rustpkg",
14+
package_id = "rustpkg",
1415
vers = "0.9-pre",
1516
uuid = "25de5e6e-279e-4a20-845c-4cabae92daaf",
1617
url = "https://github.com/mozilla/rust/tree/master/src/librustpkg")];

branches/dist-snap/src/librustuv/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ via `close` and `delete` methods.
3535
*/
3636

3737
#[link(name = "rustuv",
38+
package_id = "rustuv",
3839
vers = "0.9-pre",
3940
uuid = "f3719011-0459-9b86-b11c-29265c0d0864",
4041
url = "https://github.com/mozilla/rust/tree/master/src/librustuv")];

branches/dist-snap/src/libstd/any.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use cast::transmute;
1515
use cmp::Eq;
1616
use option::{Option, Some, None};
17+
use to_bytes::{IterBytes, Cb};
1718
use to_str::ToStr;
1819
use unstable::intrinsics;
1920
use util::Void;
@@ -42,6 +43,12 @@ impl Eq for TypeId {
4243
}
4344
}
4445

46+
impl IterBytes for TypeId {
47+
fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
48+
self.t.iter_bytes(lsb0, f)
49+
}
50+
}
51+
4552
///////////////////////////////////////////////////////////////////////////////
4653
// Any trait
4754
///////////////////////////////////////////////////////////////////////////////
@@ -175,6 +182,7 @@ mod tests {
175182
use super::*;
176183
use super::AnyRefExt;
177184
use option::{Some, None};
185+
use hash::Hash;
178186

179187
#[deriving(Eq)]
180188
struct Test;
@@ -197,6 +205,13 @@ mod tests {
197205
assert_eq!(c, f);
198206
}
199207

208+
#[test]
209+
fn type_id_hash() {
210+
let (a, b) = (TypeId::of::<uint>(), TypeId::of::<uint>::());
211+
212+
assert_eq!(a.hash(), b.hash());
213+
}
214+
200215
#[test]
201216
fn any_as_void_ptr() {
202217
let (a, b, c) = (~5u as ~Any, ~TEST as ~Any, ~Test as ~Any);

branches/dist-snap/src/libstd/clone.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,27 @@ pub trait Clone {
2929
/// are copied to maintain uniqueness, while the contents of
3030
/// managed pointers are not copied.
3131
fn clone(&self) -> Self;
32+
33+
/// Perform copy-assignment from `source`.
34+
///
35+
/// `a.clone_from(&b)` is equivalent to `a = b.clone()` in functionality,
36+
/// but can be overriden to reuse the resources of `a` to avoid unnecessary
37+
/// allocations.
38+
#[inline(always)]
39+
fn clone_from(&mut self, source: &Self) {
40+
*self = source.clone()
41+
}
3242
}
3343

3444
impl<T: Clone> Clone for ~T {
35-
/// Return a deep copy of the owned box.
45+
/// Return a copy of the owned box.
3646
#[inline]
3747
fn clone(&self) -> ~T { ~(**self).clone() }
48+
49+
/// Perform copy-assignment from `source` by reusing the existing allocation.
50+
fn clone_from(&mut self, source: &~T) {
51+
**self = (**source).clone()
52+
}
3853
}
3954

4055
impl<T> Clone for @T {
@@ -118,16 +133,31 @@ extern_fn_clone!(A, B, C, D, E, F, G, H)
118133

119134
/// A trait distinct from `Clone` which represents "deep copies" of things like
120135
/// managed boxes which would otherwise not be copied.
121-
pub trait DeepClone {
136+
pub trait DeepClone: Clone {
122137
/// Return a deep copy of the value. Unlike `Clone`, the contents of shared pointer types
123138
/// *are* copied.
124139
fn deep_clone(&self) -> Self;
140+
141+
/// Perform deep copy-assignment from `source`.
142+
///
143+
/// `a.deep_clone_from(&b)` is equivalent to `a = b.deep_clone()` in
144+
/// functionality, but can be overriden to reuse the resources of `a` to
145+
/// avoid unnecessary allocations.
146+
#[inline(always)]
147+
fn deep_clone_from(&mut self, source: &Self) {
148+
*self = source.deep_clone()
149+
}
125150
}
126151

127152
impl<T: DeepClone> DeepClone for ~T {
128153
/// Return a deep copy of the owned box.
129154
#[inline]
130155
fn deep_clone(&self) -> ~T { ~(**self).deep_clone() }
156+
157+
/// Perform deep copy-assignment from `source` by reusing the existing allocation.
158+
fn deep_clone_from(&mut self, source: &~T) {
159+
**self = (**source).deep_clone()
160+
}
131161
}
132162

133163
// FIXME: #6525: should also be implemented for `T: Send + DeepClone`
@@ -234,6 +264,22 @@ fn test_borrowed_clone() {
234264
assert_eq!(*z, 5);
235265
}
236266

267+
#[test]
268+
fn test_clone_from() {
269+
let a = ~5;
270+
let mut b = ~10;
271+
b.clone_from(&a);
272+
assert_eq!(*b, 5);
273+
}
274+
275+
#[test]
276+
fn test_deep_clone_from() {
277+
let a = ~5;
278+
let mut b = ~10;
279+
b.deep_clone_from(&a);
280+
assert_eq!(*b, 5);
281+
}
282+
237283
#[test]
238284
fn test_extern_fn_clone() {
239285
trait Empty {}

branches/dist-snap/src/libstd/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
//! use std::prelude::*;
4545
4646
#[link(name = "std",
47+
package_id = "std",
4748
vers = "0.9-pre",
4849
uuid = "c70c24a7-5551-4f73-8e37-380b11d80be8",
4950
url = "https://github.com/mozilla/rust/tree/master/src/libstd")];

branches/dist-snap/src/libstd/os.rs

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -913,41 +913,81 @@ pub fn page_size() -> uint {
913913
}
914914
}
915915

916+
/// A memory mapped file or chunk of memory. This is a very system-specific interface to the OS's
917+
/// memory mapping facilities (`mmap` on POSIX, `VirtualAlloc`/`CreateFileMapping` on win32). It
918+
/// makes no attempt at abstracting platform differences, besides in error values returned. Consider
919+
/// yourself warned.
920+
///
921+
/// The memory map is released (unmapped) when the destructor is run, so don't let it leave scope by
922+
/// accident if you want it to stick around.
916923
pub struct MemoryMap {
924+
/// Pointer to the memory created or modified by this map.
917925
data: *mut u8,
926+
/// Number of bytes this map applies to
918927
len: size_t,
928+
/// Type of mapping
919929
kind: MemoryMapKind
920930
}
921931

932+
/// Type of memory map
922933
pub enum MemoryMapKind {
934+
/// Memory-mapped file. On Windows, the inner pointer is a handle to the mapping, and
935+
/// corresponds to `CreateFileMapping`. Elsewhere, it is null.
923936
MapFile(*c_void),
937+
/// Virtual memory map. Usually used to change the permissions of a given chunk of memory.
938+
/// Corresponds to `VirtualAlloc` on Windows.
924939
MapVirtual
925940
}
926941

942+
/// Options the memory map is created with
927943
pub enum MapOption {
944+
/// The memory should be readable
928945
MapReadable,
946+
/// The memory should be writable
929947
MapWritable,
948+
/// The memory should be executable
930949
MapExecutable,
950+
/// Create a map for a specific address range. Corresponds to `MAP_FIXED` on POSIX.
931951
MapAddr(*c_void),
952+
/// Create a memory mapping for a file with a given fd.
932953
MapFd(c_int),
954+
/// When using `MapFd`, the start of the map is `uint` bytes from the start of the file.
933955
MapOffset(uint)
934956
}
935957

958+
/// Possible errors when creating a map.
936959
pub enum MapError {
937-
// Linux-specific errors
960+
/// ## The following are POSIX-specific
961+
///
962+
/// fd was not open for reading or, if using `MapWritable`, was not open for writing.
938963
ErrFdNotAvail,
964+
/// fd was not valid
939965
ErrInvalidFd,
966+
/// Either the address given by `MapAddr` or offset given by `MapOffset` was not a multiple of
967+
/// `MemoryMap::granularity` (unaligned to page size).
940968
ErrUnaligned,
969+
/// With `MapFd`, the fd does not support mapping.
941970
ErrNoMapSupport,
971+
/// If using `MapAddr`, the address + `min_len` was outside of the process's address space. If
972+
/// using `MapFd`, the target of the fd didn't have enough resources to fulfill the request.
942973
ErrNoMem,
974+
/// Unrecognized error. The inner value is the unrecognized errno.
943975
ErrUnknown(libc::c_int),
944-
945-
// Windows-specific errors
976+
/// ## The following are win32-specific
977+
///
978+
/// Unsupported combination of protection flags (`MapReadable`/`MapWritable`/`MapExecutable`).
946979
ErrUnsupProt,
980+
/// When using `MapFd`, `MapOffset` was given (Windows does not support this at all)
947981
ErrUnsupOffset,
982+
/// When using `MapFd`, there was already a mapping to the file.
948983
ErrAlreadyExists,
984+
/// Unrecognized error from `VirtualAlloc`. The inner value is the return value of GetLastError.
949985
ErrVirtualAlloc(uint),
986+
/// Unrecognized error from `CreateFileMapping`. The inner value is the return value of
987+
/// `GetLastError`.
950988
ErrCreateFileMappingW(uint),
989+
/// Unrecognized error from `MapViewOfFile`. The inner value is the return value of
990+
/// `GetLastError`.
951991
ErrMapViewOfFile(uint)
952992
}
953993

@@ -973,6 +1013,7 @@ impl to_str::ToStr for MapError {
9731013

9741014
#[cfg(unix)]
9751015
impl MemoryMap {
1016+
/// Create a new mapping with the given `options`, at least `min_len` bytes long.
9761017
pub fn new(min_len: uint, options: &[MapOption]) -> Result<MemoryMap, MapError> {
9771018
#[fixed_stack_segment]; #[inline(never)];
9781019

@@ -1028,13 +1069,15 @@ impl MemoryMap {
10281069
}
10291070
}
10301071

1072+
/// Granularity that the offset or address must be for `MapOffset` and `MapAddr` respectively.
10311073
pub fn granularity() -> uint {
10321074
page_size()
10331075
}
10341076
}
10351077

10361078
#[cfg(unix)]
10371079
impl Drop for MemoryMap {
1080+
/// Unmap the mapping. Fails the task if `munmap` fails.
10381081
fn drop(&mut self) {
10391082
#[fixed_stack_segment]; #[inline(never)];
10401083

@@ -1053,6 +1096,7 @@ impl Drop for MemoryMap {
10531096

10541097
#[cfg(windows)]
10551098
impl MemoryMap {
1099+
/// Create a new mapping with the given `options`, at least `min_len` bytes long.
10561100
pub fn new(min_len: uint, options: &[MapOption]) -> Result<MemoryMap, MapError> {
10571101
#[fixed_stack_segment]; #[inline(never)];
10581102

@@ -1161,6 +1205,8 @@ impl MemoryMap {
11611205

11621206
#[cfg(windows)]
11631207
impl Drop for MemoryMap {
1208+
/// Unmap the mapping. Fails the task if any of `VirtualFree`, `UnmapViewOfFile`, or
1209+
/// `CloseHandle` fail.
11641210
fn drop(&mut self) {
11651211
#[fixed_stack_segment]; #[inline(never)];
11661212

0 commit comments

Comments
 (0)