2014-02-10 15:36:31 +01:00
|
|
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
2012-12-04 01:48:01 +01:00
|
|
|
// 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.
|
|
|
|
|
2014-03-22 02:05:05 +01:00
|
|
|
#![allow(non_camel_case_types)]
|
2013-01-07 23:16:52 +01:00
|
|
|
|
2011-07-08 03:39:44 +02:00
|
|
|
// The crate store - a central repo for information collected about external
|
|
|
|
// crates and libraries
|
|
|
|
|
2014-11-06 09:05:53 +01:00
|
|
|
pub use self::MetadataBlob::*;
|
|
|
|
|
2015-11-24 23:00:26 +01:00
|
|
|
use creader;
|
|
|
|
use decoder;
|
|
|
|
use index;
|
|
|
|
use loader;
|
|
|
|
|
|
|
|
use rustc::back::svh::Svh;
|
2016-03-16 10:50:38 +01:00
|
|
|
use rustc::middle::cstore::{ExternCrate};
|
2015-11-24 23:00:26 +01:00
|
|
|
use rustc::util::nodemap::{FnvHashMap, NodeMap, NodeSet};
|
2012-12-23 23:41:37 +01:00
|
|
|
|
2015-06-25 19:07:01 +02:00
|
|
|
use std::cell::{RefCell, Ref, Cell};
|
2014-03-27 18:28:38 +01:00
|
|
|
use std::rc::Rc;
|
2015-02-27 06:00:43 +01:00
|
|
|
use std::path::PathBuf;
|
2014-11-25 22:28:35 +01:00
|
|
|
use flate::Bytes;
|
2013-03-26 21:38:07 +01:00
|
|
|
use syntax::ast;
|
2015-09-14 11:58:20 +02:00
|
|
|
use syntax::attr;
|
2015-02-11 18:29:49 +01:00
|
|
|
use syntax::codemap;
|
2014-01-09 14:05:33 +01:00
|
|
|
use syntax::parse::token::IdentInterner;
|
2015-11-24 23:00:26 +01:00
|
|
|
|
|
|
|
pub use middle::cstore::{NativeLibraryKind, LinkagePreference};
|
|
|
|
pub use middle::cstore::{NativeStatic, NativeFramework, NativeUnknown};
|
|
|
|
pub use middle::cstore::{CrateSource, LinkMeta};
|
2011-07-08 03:00:16 +02:00
|
|
|
|
2011-07-08 21:08:43 +02:00
|
|
|
// A map from external crate numbers (as decoded from some crate file) to
|
|
|
|
// local crate numbers (as generated during this session). Each external
|
|
|
|
// crate may refer to types in other external crates, and each has their
|
|
|
|
// own crate numbers.
|
2014-11-09 23:59:56 +01:00
|
|
|
pub type cnum_map = FnvHashMap<ast::CrateNum, ast::CrateNum>;
|
2011-07-08 21:08:43 +02:00
|
|
|
|
2013-12-18 23:10:28 +01:00
|
|
|
pub enum MetadataBlob {
|
2014-11-25 22:28:35 +01:00
|
|
|
MetadataVec(Bytes),
|
2013-12-17 05:58:21 +01:00
|
|
|
MetadataArchive(loader::ArchiveMetadata),
|
2013-12-18 23:10:28 +01:00
|
|
|
}
|
|
|
|
|
2015-02-11 18:29:49 +01:00
|
|
|
/// Holds information about a codemap::FileMap imported from another crate.
|
|
|
|
/// See creader::import_codemap() for more information.
|
|
|
|
pub struct ImportedFileMap {
|
|
|
|
/// This FileMap's byte-offset within the codemap of its original crate
|
|
|
|
pub original_start_pos: codemap::BytePos,
|
|
|
|
/// The end of this FileMap within the codemap of its original crate
|
|
|
|
pub original_end_pos: codemap::BytePos,
|
|
|
|
/// The imported FileMap's representation within the local codemap
|
|
|
|
pub translated_filemap: Rc<codemap::FileMap>
|
|
|
|
}
|
|
|
|
|
2013-02-19 08:40:42 +01:00
|
|
|
pub struct crate_metadata {
|
2014-05-23 01:57:53 +02:00
|
|
|
pub name: String,
|
2016-03-16 10:50:38 +01:00
|
|
|
|
|
|
|
/// Information about the extern crate that caused this crate to
|
|
|
|
/// be loaded. If this is `None`, then the crate was injected
|
|
|
|
/// (e.g., by the allocator)
|
|
|
|
pub extern_crate: Cell<Option<ExternCrate>>,
|
|
|
|
|
2014-03-28 18:05:27 +01:00
|
|
|
pub data: MetadataBlob,
|
2015-06-25 19:07:01 +02:00
|
|
|
pub cnum_map: RefCell<cnum_map>,
|
2014-03-28 18:05:27 +01:00
|
|
|
pub cnum: ast::CrateNum,
|
2015-05-22 15:15:21 +02:00
|
|
|
pub codemap_import_info: RefCell<Vec<ImportedFileMap>>,
|
2015-06-25 19:07:01 +02:00
|
|
|
pub staged_api: bool,
|
2015-09-17 15:04:18 +02:00
|
|
|
|
2015-09-03 00:22:31 +02:00
|
|
|
pub index: index::Index,
|
2015-09-17 15:04:18 +02:00
|
|
|
pub xref_index: index::DenseIndex,
|
2015-06-25 19:07:01 +02:00
|
|
|
|
|
|
|
/// Flag if this crate is required by an rlib version of this crate, or in
|
|
|
|
/// other words whether it was explicitly linked to. An example of a crate
|
|
|
|
/// where this is false is when an allocator crate is injected into the
|
|
|
|
/// dependency list, and therefore isn't actually needed to link an rlib.
|
|
|
|
pub explicitly_linked: Cell<bool>,
|
2013-02-19 08:40:42 +01:00
|
|
|
}
|
2011-07-08 03:00:16 +02:00
|
|
|
|
2013-02-04 23:02:01 +01:00
|
|
|
pub struct CStore {
|
2014-11-09 23:59:56 +01:00
|
|
|
metas: RefCell<FnvHashMap<ast::CrateNum, Rc<crate_metadata>>>,
|
|
|
|
/// Map from NodeId's of local extern crate statements to crate numbers
|
|
|
|
extern_mod_crate_map: RefCell<NodeMap<ast::CrateNum>>,
|
2014-03-28 18:05:27 +01:00
|
|
|
used_crate_sources: RefCell<Vec<CrateSource>>,
|
librustc: Make `Copy` opt-in.
This change makes the compiler no longer infer whether types (structures
and enumerations) implement the `Copy` trait (and thus are implicitly
copyable). Rather, you must implement `Copy` yourself via `impl Copy for
MyType {}`.
A new warning has been added, `missing_copy_implementations`, to warn
you if a non-generic public type has been added that could have
implemented `Copy` but didn't.
For convenience, you may *temporarily* opt out of this behavior by using
`#![feature(opt_out_copy)]`. Note though that this feature gate will never be
accepted and will be removed by the time that 1.0 is released, so you should
transition your code away from using it.
This breaks code like:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
Change this code to:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
impl Copy for Point2D {}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
This is the backwards-incompatible part of #13231.
Part of RFC #3.
[breaking-change]
2014-12-06 02:01:33 +01:00
|
|
|
used_libraries: RefCell<Vec<(String, NativeLibraryKind)>>,
|
2014-05-23 01:57:53 +02:00
|
|
|
used_link_args: RefCell<Vec<String>>,
|
2015-07-30 23:20:36 +02:00
|
|
|
statically_included_foreign_items: RefCell<NodeSet>,
|
2014-03-28 18:05:27 +01:00
|
|
|
pub intr: Rc<IdentInterner>,
|
2013-02-04 23:02:01 +01:00
|
|
|
}
|
2011-07-10 07:56:12 +02:00
|
|
|
|
2013-12-25 21:08:04 +01:00
|
|
|
impl CStore {
|
2014-03-27 18:28:38 +01:00
|
|
|
pub fn new(intr: Rc<IdentInterner>) -> CStore {
|
2013-12-25 21:08:04 +01:00
|
|
|
CStore {
|
2015-01-16 23:27:43 +01:00
|
|
|
metas: RefCell::new(FnvHashMap()),
|
|
|
|
extern_mod_crate_map: RefCell::new(FnvHashMap()),
|
2014-03-04 19:02:49 +01:00
|
|
|
used_crate_sources: RefCell::new(Vec::new()),
|
|
|
|
used_libraries: RefCell::new(Vec::new()),
|
|
|
|
used_link_args: RefCell::new(Vec::new()),
|
2015-07-30 23:20:36 +02:00
|
|
|
intr: intr,
|
|
|
|
statically_included_foreign_items: RefCell::new(NodeSet()),
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
|
|
|
}
|
2011-07-08 03:00:16 +02:00
|
|
|
|
2014-04-07 21:14:33 +02:00
|
|
|
pub fn next_crate_num(&self) -> ast::CrateNum {
|
|
|
|
self.metas.borrow().len() as ast::CrateNum + 1
|
|
|
|
}
|
|
|
|
|
2014-04-17 14:06:25 +02:00
|
|
|
pub fn get_crate_data(&self, cnum: ast::CrateNum) -> Rc<crate_metadata> {
|
2015-03-22 02:15:47 +01:00
|
|
|
self.metas.borrow().get(&cnum).unwrap().clone()
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2011-07-08 03:00:16 +02:00
|
|
|
|
2014-02-25 04:45:20 +01:00
|
|
|
pub fn get_crate_hash(&self, cnum: ast::CrateNum) -> Svh {
|
2013-12-25 21:08:04 +01:00
|
|
|
let cdata = self.get_crate_data(cnum);
|
|
|
|
decoder::get_crate_hash(cdata.data())
|
|
|
|
}
|
2012-04-06 12:45:49 +02:00
|
|
|
|
2014-04-17 14:06:25 +02:00
|
|
|
pub fn set_crate_data(&self, cnum: ast::CrateNum, data: Rc<crate_metadata>) {
|
2014-03-21 03:49:20 +01:00
|
|
|
self.metas.borrow_mut().insert(cnum, data);
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2011-07-08 03:00:16 +02:00
|
|
|
|
2014-12-09 02:26:43 +01:00
|
|
|
pub fn iter_crate_data<I>(&self, mut i: I) where
|
2015-06-25 19:07:01 +02:00
|
|
|
I: FnMut(ast::CrateNum, &Rc<crate_metadata>),
|
2014-12-09 02:26:43 +01:00
|
|
|
{
|
2015-06-11 14:56:07 +02:00
|
|
|
for (&k, v) in self.metas.borrow().iter() {
|
2015-06-25 19:07:01 +02:00
|
|
|
i(k, v);
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2013-02-04 23:02:01 +01:00
|
|
|
}
|
2011-07-08 03:00:16 +02:00
|
|
|
|
2014-04-25 18:06:49 +02:00
|
|
|
/// Like `iter_crate_data`, but passes source paths (if available) as well.
|
2014-12-09 02:26:43 +01:00
|
|
|
pub fn iter_crate_data_origins<I>(&self, mut i: I) where
|
|
|
|
I: FnMut(ast::CrateNum, &crate_metadata, Option<CrateSource>),
|
|
|
|
{
|
2015-06-11 14:56:07 +02:00
|
|
|
for (&k, v) in self.metas.borrow().iter() {
|
2015-11-25 16:02:59 +01:00
|
|
|
let origin = self.opt_used_crate_source(k);
|
2014-04-25 18:06:49 +02:00
|
|
|
origin.as_ref().map(|cs| { assert!(k == cs.cnum); });
|
2016-02-09 21:37:21 +01:00
|
|
|
i(k, &v, origin);
|
2014-04-25 18:06:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-21 05:00:58 +01:00
|
|
|
pub fn add_used_crate_source(&self, src: CrateSource) {
|
2013-12-21 04:50:13 +01:00
|
|
|
let mut used_crate_sources = self.used_crate_sources.borrow_mut();
|
2014-03-21 03:49:20 +01:00
|
|
|
if !used_crate_sources.contains(&src) {
|
|
|
|
used_crate_sources.push(src);
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2011-07-08 03:25:56 +02:00
|
|
|
}
|
|
|
|
|
2015-11-25 16:02:59 +01:00
|
|
|
pub fn opt_used_crate_source(&self, cnum: ast::CrateNum)
|
|
|
|
-> Option<CrateSource> {
|
2014-03-21 03:49:20 +01:00
|
|
|
self.used_crate_sources.borrow_mut()
|
2015-02-13 08:33:44 +01:00
|
|
|
.iter().find(|source| source.cnum == cnum).cloned()
|
2013-12-25 19:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn reset(&self) {
|
2014-03-21 03:55:52 +01:00
|
|
|
self.metas.borrow_mut().clear();
|
|
|
|
self.extern_mod_crate_map.borrow_mut().clear();
|
|
|
|
self.used_crate_sources.borrow_mut().clear();
|
|
|
|
self.used_libraries.borrow_mut().clear();
|
|
|
|
self.used_link_args.borrow_mut().clear();
|
2015-07-30 23:20:36 +02:00
|
|
|
self.statically_included_foreign_items.borrow_mut().clear();
|
2013-12-25 19:10:33 +01:00
|
|
|
}
|
|
|
|
|
2014-03-14 02:47:43 +01:00
|
|
|
// This method is used when generating the command line to pass through to
|
|
|
|
// system linker. The linker expects undefined symbols on the left of the
|
|
|
|
// command line to be defined in libraries on the right, not the other way
|
|
|
|
// around. For more info, see some comments in the add_used_library function
|
|
|
|
// below.
|
|
|
|
//
|
|
|
|
// In order to get this left-to-right dependency ordering, we perform a
|
|
|
|
// topological sort of all crates putting the leaves at the right-most
|
|
|
|
// positions.
|
2015-11-21 00:08:09 +01:00
|
|
|
pub fn do_get_used_crates(&self, prefer: LinkagePreference)
|
|
|
|
-> Vec<(ast::CrateNum, Option<PathBuf>)> {
|
2014-03-14 02:47:43 +01:00
|
|
|
let mut ordering = Vec::new();
|
|
|
|
fn visit(cstore: &CStore, cnum: ast::CrateNum,
|
|
|
|
ordering: &mut Vec<ast::CrateNum>) {
|
2014-11-27 19:53:34 +01:00
|
|
|
if ordering.contains(&cnum) { return }
|
2014-03-14 02:47:43 +01:00
|
|
|
let meta = cstore.get_crate_data(cnum);
|
2015-06-25 19:07:01 +02:00
|
|
|
for (_, &dep) in meta.cnum_map.borrow().iter() {
|
2014-03-14 02:47:43 +01:00
|
|
|
visit(cstore, dep, ordering);
|
|
|
|
}
|
|
|
|
ordering.push(cnum);
|
2015-10-21 18:20:46 +02:00
|
|
|
}
|
2015-06-11 14:56:07 +02:00
|
|
|
for (&num, _) in self.metas.borrow().iter() {
|
2014-03-14 02:47:43 +01:00
|
|
|
visit(self, num, &mut ordering);
|
|
|
|
}
|
2015-06-25 19:07:01 +02:00
|
|
|
info!("topological ordering: {:?}", ordering);
|
2014-11-27 22:47:48 +01:00
|
|
|
ordering.reverse();
|
2014-03-21 03:49:20 +01:00
|
|
|
let mut libs = self.used_crate_sources.borrow()
|
2013-12-21 04:50:13 +01:00
|
|
|
.iter()
|
2013-12-25 21:08:04 +01:00
|
|
|
.map(|src| (src.cnum, match prefer {
|
2015-11-24 23:00:26 +01:00
|
|
|
LinkagePreference::RequireDynamic => src.dylib.clone().map(|p| p.0),
|
|
|
|
LinkagePreference::RequireStatic => src.rlib.clone().map(|p| p.0),
|
2013-12-25 21:08:04 +01:00
|
|
|
}))
|
2015-01-06 17:46:07 +01:00
|
|
|
.collect::<Vec<_>>();
|
2014-03-14 02:47:43 +01:00
|
|
|
libs.sort_by(|&(a, _), &(b, _)| {
|
2015-07-08 17:33:13 +02:00
|
|
|
let a = ordering.iter().position(|x| *x == a);
|
|
|
|
let b = ordering.iter().position(|x| *x == b);
|
|
|
|
a.cmp(&b)
|
2014-03-14 02:47:43 +01:00
|
|
|
});
|
|
|
|
libs
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
|
|
|
|
librustc: Make `Copy` opt-in.
This change makes the compiler no longer infer whether types (structures
and enumerations) implement the `Copy` trait (and thus are implicitly
copyable). Rather, you must implement `Copy` yourself via `impl Copy for
MyType {}`.
A new warning has been added, `missing_copy_implementations`, to warn
you if a non-generic public type has been added that could have
implemented `Copy` but didn't.
For convenience, you may *temporarily* opt out of this behavior by using
`#![feature(opt_out_copy)]`. Note though that this feature gate will never be
accepted and will be removed by the time that 1.0 is released, so you should
transition your code away from using it.
This breaks code like:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
Change this code to:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
impl Copy for Point2D {}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
This is the backwards-incompatible part of #13231.
Part of RFC #3.
[breaking-change]
2014-12-06 02:01:33 +01:00
|
|
|
pub fn add_used_library(&self, lib: String, kind: NativeLibraryKind) {
|
2013-12-25 21:08:04 +01:00
|
|
|
assert!(!lib.is_empty());
|
2014-03-21 03:49:20 +01:00
|
|
|
self.used_libraries.borrow_mut().push((lib, kind));
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2011-07-08 03:25:56 +02:00
|
|
|
|
2013-12-21 04:54:01 +01:00
|
|
|
pub fn get_used_libraries<'a>(&'a self)
|
librustc: Make `Copy` opt-in.
This change makes the compiler no longer infer whether types (structures
and enumerations) implement the `Copy` trait (and thus are implicitly
copyable). Rather, you must implement `Copy` yourself via `impl Copy for
MyType {}`.
A new warning has been added, `missing_copy_implementations`, to warn
you if a non-generic public type has been added that could have
implemented `Copy` but didn't.
For convenience, you may *temporarily* opt out of this behavior by using
`#![feature(opt_out_copy)]`. Note though that this feature gate will never be
accepted and will be removed by the time that 1.0 is released, so you should
transition your code away from using it.
This breaks code like:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
Change this code to:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
impl Copy for Point2D {}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
This is the backwards-incompatible part of #13231.
Part of RFC #3.
[breaking-change]
2014-12-06 02:01:33 +01:00
|
|
|
-> &'a RefCell<Vec<(String,
|
|
|
|
NativeLibraryKind)>> {
|
2013-12-21 04:54:01 +01:00
|
|
|
&self.used_libraries
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2011-07-08 03:33:59 +02:00
|
|
|
|
2013-12-21 05:00:58 +01:00
|
|
|
pub fn add_used_link_args(&self, args: &str) {
|
2014-07-07 18:54:38 +02:00
|
|
|
for s in args.split(' ').filter(|s| !s.is_empty()) {
|
2014-05-25 12:17:19 +02:00
|
|
|
self.used_link_args.borrow_mut().push(s.to_string());
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
|
|
|
}
|
2011-07-08 03:33:59 +02:00
|
|
|
|
2014-05-23 01:57:53 +02:00
|
|
|
pub fn get_used_link_args<'a>(&'a self) -> &'a RefCell<Vec<String> > {
|
2013-12-21 04:56:29 +01:00
|
|
|
&self.used_link_args
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2011-07-08 03:33:59 +02:00
|
|
|
|
2013-12-21 05:00:58 +01:00
|
|
|
pub fn add_extern_mod_stmt_cnum(&self,
|
2013-12-25 21:08:04 +01:00
|
|
|
emod_id: ast::NodeId,
|
|
|
|
cnum: ast::CrateNum) {
|
2014-03-21 03:49:20 +01:00
|
|
|
self.extern_mod_crate_map.borrow_mut().insert(emod_id, cnum);
|
2013-03-24 07:51:18 +01:00
|
|
|
}
|
2011-07-08 03:38:42 +02:00
|
|
|
|
2015-07-30 23:20:36 +02:00
|
|
|
pub fn add_statically_included_foreign_item(&self, id: ast::NodeId) {
|
|
|
|
self.statically_included_foreign_items.borrow_mut().insert(id);
|
|
|
|
}
|
|
|
|
|
2015-11-21 20:39:05 +01:00
|
|
|
pub fn do_is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool {
|
2015-07-30 23:20:36 +02:00
|
|
|
self.statically_included_foreign_items.borrow().contains(&id)
|
|
|
|
}
|
2015-11-25 16:02:59 +01:00
|
|
|
|
|
|
|
pub fn do_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<ast::CrateNum>
|
|
|
|
{
|
|
|
|
self.extern_mod_crate_map.borrow().get(&emod_id).cloned()
|
|
|
|
}
|
2013-07-02 21:47:32 +02:00
|
|
|
}
|
|
|
|
|
2013-12-18 23:10:28 +01:00
|
|
|
impl crate_metadata {
|
|
|
|
pub fn data<'a>(&'a self) -> &'a [u8] { self.data.as_slice() }
|
2016-03-01 14:19:00 +01:00
|
|
|
pub fn name(&self) -> &str { decoder::get_crate_name(self.data()) }
|
2014-04-07 21:14:33 +02:00
|
|
|
pub fn hash(&self) -> Svh { decoder::get_crate_hash(self.data()) }
|
2016-02-26 22:25:25 +01:00
|
|
|
pub fn disambiguator(&self) -> &str {
|
|
|
|
decoder::get_crate_disambiguator(self.data())
|
|
|
|
}
|
2015-05-22 15:15:21 +02:00
|
|
|
pub fn imported_filemaps<'a>(&'a self, codemap: &codemap::CodeMap)
|
|
|
|
-> Ref<'a, Vec<ImportedFileMap>> {
|
|
|
|
let filemaps = self.codemap_import_info.borrow();
|
|
|
|
if filemaps.is_empty() {
|
|
|
|
drop(filemaps);
|
|
|
|
let filemaps = creader::import_codemap(codemap, &self.data);
|
|
|
|
|
|
|
|
// This shouldn't borrow twice, but there is no way to downgrade RefMut to Ref.
|
|
|
|
*self.codemap_import_info.borrow_mut() = filemaps;
|
|
|
|
self.codemap_import_info.borrow()
|
|
|
|
} else {
|
|
|
|
filemaps
|
|
|
|
}
|
2015-08-01 16:14:45 +02:00
|
|
|
}
|
2015-06-25 19:07:01 +02:00
|
|
|
|
|
|
|
pub fn is_allocator(&self) -> bool {
|
|
|
|
let attrs = decoder::get_crate_attributes(self.data());
|
|
|
|
attr::contains_name(&attrs, "allocator")
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn needs_allocator(&self) -> bool {
|
|
|
|
let attrs = decoder::get_crate_attributes(self.data());
|
|
|
|
attr::contains_name(&attrs, "needs_allocator")
|
|
|
|
}
|
2013-12-18 23:10:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl MetadataBlob {
|
|
|
|
pub fn as_slice<'a>(&'a self) -> &'a [u8] {
|
2014-12-05 06:32:34 +01:00
|
|
|
let slice = match *self {
|
2015-03-18 17:14:54 +01:00
|
|
|
MetadataVec(ref vec) => &vec[..],
|
2013-12-17 05:58:21 +01:00
|
|
|
MetadataArchive(ref ar) => ar.as_slice(),
|
2014-12-05 06:32:34 +01:00
|
|
|
};
|
|
|
|
if slice.len() < 4 {
|
2014-12-13 03:00:17 +01:00
|
|
|
&[] // corrupt metadata
|
2014-12-05 06:32:34 +01:00
|
|
|
} else {
|
2014-12-13 03:00:17 +01:00
|
|
|
let len = (((slice[0] as u32) << 24) |
|
|
|
|
((slice[1] as u32) << 16) |
|
|
|
|
((slice[2] as u32) << 8) |
|
2015-03-26 01:06:52 +01:00
|
|
|
((slice[3] as u32) << 0)) as usize;
|
2014-12-13 03:00:17 +01:00
|
|
|
if len + 4 <= slice.len() {
|
2015-01-18 01:15:52 +01:00
|
|
|
&slice[4.. len + 4]
|
2014-12-13 03:00:17 +01:00
|
|
|
} else {
|
|
|
|
&[] // corrupt or old metadata
|
|
|
|
}
|
2013-12-18 23:10:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|