librustc_back: use unboxed closures
This commit is contained in:
parent
d3d707c883
commit
451eef5c40
4 changed files with 38 additions and 18 deletions
|
|
@ -279,8 +279,9 @@ impl<'a> ArchiveBuilder<'a> {
|
|||
self.archive
|
||||
}
|
||||
|
||||
fn add_archive(&mut self, archive: &Path, name: &str,
|
||||
skip: |&str| -> bool) -> io::IoResult<()> {
|
||||
fn add_archive<F>(&mut self, archive: &Path, name: &str, mut skip: F) -> io::IoResult<()> where
|
||||
F: FnMut(&str) -> bool,
|
||||
{
|
||||
let loc = TempDir::new("rsar").unwrap();
|
||||
|
||||
// First, extract the contents of the archive to a temporary directory.
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#![allow(unknown_features)]
|
||||
#![feature(globs, phase, macro_rules, slicing_syntax)]
|
||||
#![feature(unboxed_closures)]
|
||||
|
||||
#[phase(plugin, link)]
|
||||
extern crate log;
|
||||
|
|
|
|||
|
|
@ -14,17 +14,22 @@ use std::os;
|
|||
use std::io::IoError;
|
||||
use syntax::ast;
|
||||
|
||||
pub struct RPathConfig<'a> {
|
||||
pub struct RPathConfig<F, G> where
|
||||
F: FnOnce() -> Path,
|
||||
G: FnMut(&Path) -> Result<Path, IoError>,
|
||||
{
|
||||
pub used_crates: Vec<(ast::CrateNum, Option<Path>)>,
|
||||
pub out_filename: Path,
|
||||
pub is_like_osx: bool,
|
||||
pub has_rpath: bool,
|
||||
pub get_install_prefix_lib_path: ||:'a -> Path,
|
||||
pub realpath: |&Path|:'a -> Result<Path, IoError>
|
||||
pub get_install_prefix_lib_path: F,
|
||||
pub realpath: G,
|
||||
}
|
||||
|
||||
pub fn get_rpath_flags(config: RPathConfig) -> Vec<String> {
|
||||
|
||||
pub fn get_rpath_flags<F, G>(config: RPathConfig<F, G>) -> Vec<String> where
|
||||
F: FnOnce() -> Path,
|
||||
G: FnMut(&Path) -> Result<Path, IoError>,
|
||||
{
|
||||
// No rpath on windows
|
||||
if !config.has_rpath {
|
||||
return Vec::new();
|
||||
|
|
@ -52,8 +57,10 @@ fn rpaths_to_flags(rpaths: &[String]) -> Vec<String> {
|
|||
return ret;
|
||||
}
|
||||
|
||||
fn get_rpaths(mut config: RPathConfig,
|
||||
libs: &[Path]) -> Vec<String> {
|
||||
fn get_rpaths<F, G>(mut config: RPathConfig<F, G>, libs: &[Path]) -> Vec<String> where
|
||||
F: FnOnce() -> Path,
|
||||
G: FnMut(&Path) -> Result<Path, IoError>,
|
||||
{
|
||||
debug!("output: {}", config.out_filename.display());
|
||||
debug!("libs:");
|
||||
for libpath in libs.iter() {
|
||||
|
|
@ -86,13 +93,18 @@ fn get_rpaths(mut config: RPathConfig,
|
|||
return rpaths;
|
||||
}
|
||||
|
||||
fn get_rpaths_relative_to_output(config: &mut RPathConfig,
|
||||
libs: &[Path]) -> Vec<String> {
|
||||
fn get_rpaths_relative_to_output<F, G>(config: &mut RPathConfig<F, G>,
|
||||
libs: &[Path]) -> Vec<String> where
|
||||
F: FnOnce() -> Path,
|
||||
G: FnMut(&Path) -> Result<Path, IoError>,
|
||||
{
|
||||
libs.iter().map(|a| get_rpath_relative_to_output(config, a)).collect()
|
||||
}
|
||||
|
||||
fn get_rpath_relative_to_output(config: &mut RPathConfig,
|
||||
lib: &Path) -> String {
|
||||
fn get_rpath_relative_to_output<F, G>(config: &mut RPathConfig<F, G>, lib: &Path) -> String where
|
||||
F: FnOnce() -> Path,
|
||||
G: FnMut(&Path) -> Result<Path, IoError>,
|
||||
{
|
||||
use std::os;
|
||||
|
||||
// Mac doesn't appear to support $ORIGIN
|
||||
|
|
@ -114,7 +126,10 @@ fn get_rpath_relative_to_output(config: &mut RPathConfig,
|
|||
relative.as_str().expect("non-utf8 component in path"))
|
||||
}
|
||||
|
||||
fn get_install_prefix_rpath(config: RPathConfig) -> String {
|
||||
fn get_install_prefix_rpath<F, G>(config: RPathConfig<F, G>) -> String where
|
||||
F: FnOnce() -> Path,
|
||||
G: FnMut(&Path) -> Result<Path, IoError>,
|
||||
{
|
||||
let path = (config.get_install_prefix_lib_path)();
|
||||
let path = os::make_absolute(&path).unwrap();
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
|
|
|
|||
|
|
@ -82,7 +82,8 @@ fn add_bytes_to_bits<T: Int + ToBits>(bits: T, bytes: T) -> T {
|
|||
trait FixedBuffer {
|
||||
/// Input a vector of bytes. If the buffer becomes full, process it with the provided
|
||||
/// function and then clear the buffer.
|
||||
fn input(&mut self, input: &[u8], func: |&[u8]|);
|
||||
fn input<F>(&mut self, input: &[u8], func: F) where
|
||||
F: FnMut(&[u8]);
|
||||
|
||||
/// Reset the buffer.
|
||||
fn reset(&mut self);
|
||||
|
|
@ -125,7 +126,9 @@ impl FixedBuffer64 {
|
|||
}
|
||||
|
||||
impl FixedBuffer for FixedBuffer64 {
|
||||
fn input(&mut self, input: &[u8], func: |&[u8]|) {
|
||||
fn input<F>(&mut self, input: &[u8], mut func: F) where
|
||||
F: FnMut(&[u8]),
|
||||
{
|
||||
let mut i = 0;
|
||||
|
||||
let size = self.size();
|
||||
|
|
@ -201,11 +204,11 @@ trait StandardPadding {
|
|||
/// guaranteed to have exactly rem remaining bytes when it returns. If there are not at least
|
||||
/// rem bytes available, the buffer will be zero padded, processed, cleared, and then filled
|
||||
/// with zeros again until only rem bytes are remaining.
|
||||
fn standard_padding(&mut self, rem: uint, func: |&[u8]|);
|
||||
fn standard_padding<F>(&mut self, rem: uint, func: F) where F: FnMut(&[u8]);
|
||||
}
|
||||
|
||||
impl <T: FixedBuffer> StandardPadding for T {
|
||||
fn standard_padding(&mut self, rem: uint, func: |&[u8]|) {
|
||||
fn standard_padding<F>(&mut self, rem: uint, mut func: F) where F: FnMut(&[u8]) {
|
||||
let size = self.size();
|
||||
|
||||
self.next(1)[0] = 128;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue