This file was deleted.

@@ -75,24 +75,11 @@ use ptr::RawPtr;
use ptr;
use str::StrSlice;
use str;
use vec::{CloneableVector, ImmutableVector, MutableVector};
use vec::{ImmutableVector, MutableVector};
use vec;
use unstable::intrinsics;
use rt::global_heap::malloc_raw;

/// Resolution options for the `null_byte` condition
pub enum NullByteResolution {
/// Truncate at the null byte
Truncate,
/// Use a replacement byte
ReplaceWith(libc::c_char)
}

condition! {
// This should be &[u8] but there's a lifetime issue (#5370).
pub null_byte: (~[u8]) -> NullByteResolution;
}

/// The representation of a C String.
///
/// This structure wraps a `*libc::c_char`, and will automatically free the
@@ -252,7 +239,7 @@ pub trait ToCStr {
///
/// # Failure
///
/// Raises the `null_byte` condition if the receiver has an interior null.
/// Fails the task if the receiver has an interior null.
fn to_c_str(&self) -> CString;

/// Unsafe variant of `to_c_str()` that doesn't check for nulls.
@@ -273,7 +260,7 @@ pub trait ToCStr {
///
/// # Failure
///
/// Raises the `null_byte` condition if the receiver has an interior null.
/// Fails the task if the receiver has an interior null.
#[inline]
fn with_c_str<T>(&self, f: |*libc::c_char| -> T) -> T {
self.to_c_str().with_ref(f)
@@ -362,12 +349,7 @@ fn check_for_null(v: &[u8], buf: *mut libc::c_char) {
for i in range(0, v.len()) {
unsafe {
let p = buf.offset(i as int);
if *p == 0 {
match null_byte::cond.raise(v.to_owned()) {
Truncate => break,
ReplaceWith(c) => *p = c
}
}
assert!(*p != 0);
}
}
}
@@ -541,29 +523,9 @@ mod tests {

#[test]
fn test_to_c_str_fail() {
use c_str::null_byte::cond;

use task;
let mut error_happened = false;
cond.trap(|err| {
assert_eq!(err, bytes!("he", 0, "llo").to_owned())
error_happened = true;
Truncate
}).inside(|| "he\x00llo".to_c_str());
assert!(error_happened);

cond.trap(|_| {
ReplaceWith('?' as libc::c_char)
}).inside(|| "he\x00llo".to_c_str()).with_ref(|buf| {
unsafe {
assert_eq!(*buf.offset(0), 'h' as libc::c_char);
assert_eq!(*buf.offset(1), 'e' as libc::c_char);
assert_eq!(*buf.offset(2), '?' as libc::c_char);
assert_eq!(*buf.offset(3), 'l' as libc::c_char);
assert_eq!(*buf.offset(4), 'l' as libc::c_char);
assert_eq!(*buf.offset(5), 'o' as libc::c_char);
assert_eq!(*buf.offset(6), 0);
}
})
assert!(task::try(proc() { "he\x00llo".to_c_str() }).is_err());
}

#[test]

This file was deleted.

@@ -19,8 +19,6 @@ use prelude::*;
use char;
use str;

condition! { pub parse_error: ~str -> (); }

/// A piece is a portion of the format string which represents the next part to
/// emit. These are emitted as a stream by the `Parser` class.
#[deriving(Eq)]
@@ -170,6 +168,8 @@ pub struct Parser<'a> {
priv input: &'a str,
priv cur: str::CharOffsets<'a>,
priv depth: uint,
/// Error messages accumulated during parsing
errors: ~[~str],
}

impl<'a> Iterator<Piece<'a>> for Parser<'a> {
@@ -207,14 +207,15 @@ impl<'a> Parser<'a> {
input: s,
cur: s.char_indices(),
depth: 0,
errors: ~[],
}
}

/// Notifies of an error. The message doesn't actually need to be of type
/// ~str, but I think it does when this eventually uses conditions so it
/// might as well start using it now.
fn err(&self, msg: &str) {
parse_error::cond.raise("invalid format string: " + msg);
fn err(&mut self, msg: &str) {
self.errors.push(msg.to_owned());
}

/// Optionally consumes the specified character. If the character is not at
@@ -671,7 +672,9 @@ mod tests {
}

fn musterr(s: &str) {
Parser::new(s).next();
let mut p = Parser::new(s);
p.next();
assert!(p.errors.len() != 0);
}

#[test]
@@ -684,12 +687,12 @@ mod tests {
same("\\}", ~[String("}")]);
}

#[test] #[should_fail] fn invalid01() { musterr("{") }
#[test] #[should_fail] fn invalid02() { musterr("\\") }
#[test] #[should_fail] fn invalid03() { musterr("\\a") }
#[test] #[should_fail] fn invalid04() { musterr("{3a}") }
#[test] #[should_fail] fn invalid05() { musterr("{:|}") }
#[test] #[should_fail] fn invalid06() { musterr("{:>>>}") }
#[test] fn invalid01() { musterr("{") }
#[test] fn invalid02() { musterr("\\") }
#[test] fn invalid03() { musterr("\\a") }
#[test] fn invalid04() { musterr("{3a}") }
#[test] fn invalid05() { musterr("{:|}") }
#[test] fn invalid06() { musterr("{:>>>}") }

#[test]
fn format_nothing() {
@@ -916,36 +919,16 @@ mod tests {
})]);
}

#[test] #[should_fail] fn badselect01() {
musterr("{select, }")
}
#[test] #[should_fail] fn badselect02() {
musterr("{1, select}")
}
#[test] #[should_fail] fn badselect03() {
musterr("{1, select, }")
}
#[test] #[should_fail] fn badselect04() {
musterr("{1, select, a {}}")
}
#[test] #[should_fail] fn badselect05() {
musterr("{1, select, other }}")
}
#[test] #[should_fail] fn badselect06() {
musterr("{1, select, other {}")
}
#[test] #[should_fail] fn badselect07() {
musterr("{select, other {}")
}
#[test] #[should_fail] fn badselect08() {
musterr("{1 select, other {}")
}
#[test] #[should_fail] fn badselect09() {
musterr("{:d select, other {}")
}
#[test] #[should_fail] fn badselect10() {
musterr("{1:d select, other {}")
}
#[test] fn badselect01() { musterr("{select, }") }
#[test] fn badselect02() { musterr("{1, select}") }
#[test] fn badselect03() { musterr("{1, select, }") }
#[test] fn badselect04() { musterr("{1, select, a {}}") }
#[test] fn badselect05() { musterr("{1, select, other }}") }
#[test] fn badselect06() { musterr("{1, select, other {}") }
#[test] fn badselect07() { musterr("{select, other {}") }
#[test] fn badselect08() { musterr("{1 select, other {}") }
#[test] fn badselect09() { musterr("{:d select, other {}") }
#[test] fn badselect10() { musterr("{1:d select, other {}") }

#[test]
fn plural_simple() {
@@ -178,8 +178,6 @@ pub mod run;
pub mod cast;
pub mod fmt;
pub mod cleanup;
#[deprecated]
pub mod condition;
pub mod logging;
pub mod util;
pub mod mem;
@@ -216,7 +214,6 @@ mod std {
pub use clone;
pub use cmp;
pub use comm;
pub use condition;
pub use fmt;
pub use io;
pub use kinds;
@@ -123,50 +123,6 @@ macro_rules! unreachable (() => (
fail!("internal error: entered unreachable code");
))

#[macro_export]
macro_rules! condition (

{ pub $c:ident: $input:ty -> $out:ty; } => {

pub mod $c {
#[allow(unused_imports)];
#[allow(non_uppercase_statics)];
#[allow(missing_doc)];

use super::*;

local_data_key!(key: @::std::condition::Handler<$input, $out>)

pub static cond :
::std::condition::Condition<$input,$out> =
::std::condition::Condition {
name: stringify!($c),
key: key
};
}
};

{ $c:ident: $input:ty -> $out:ty; } => {

mod $c {
#[allow(unused_imports)];
#[allow(non_uppercase_statics)];
#[allow(dead_code)];

use super::*;

local_data_key!(key: @::std::condition::Handler<$input, $out>)

pub static cond :
::std::condition::Condition<$input,$out> =
::std::condition::Condition {
name: stringify!($c),
key: key
};
}
}
)

#[macro_export]
macro_rules! format(($($arg:tt)*) => (
format_args!(::std::fmt::format, $($arg)*)
@@ -147,31 +147,20 @@ pub use is_sep_byte = self::windows::is_sep_byte;
pub mod posix;
pub mod windows;

// Condition that is raised when a NUL is found in a byte vector given to a Path function
condition! {
// this should be a &[u8] but there's a lifetime issue
null_byte: ~[u8] -> ~[u8];
}

/// A trait that represents the generic operations available on paths
pub trait GenericPath: Clone + GenericPathUnsafe {
/// Creates a new Path from a byte vector or string.
/// The resulting Path will always be normalized.
///
/// # Failure
///
/// Raises the `null_byte` condition if the path contains a NUL.
/// Fails the task if the path contains a NUL.
///
/// See individual Path impls for additional restrictions.
#[inline]
fn new<T: BytesContainer>(path: T) -> Self {
if contains_nul(path.container_as_bytes()) {
let path = self::null_byte::cond.raise(path.container_into_owned_bytes());
assert!(!contains_nul(path));
unsafe { GenericPathUnsafe::new_unchecked(path) }
} else {
unsafe { GenericPathUnsafe::new_unchecked(path) }
}
assert!(!contains_nul(path.container_as_bytes()));
unsafe { GenericPathUnsafe::new_unchecked(path) }
}

/// Creates a new Path from a byte vector or string, if possible.
@@ -283,16 +272,11 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
///
/// # Failure
///
/// Raises the `null_byte` condition if the filename contains a NUL.
/// Fails the task if the filename contains a NUL.
#[inline]
fn set_filename<T: BytesContainer>(&mut self, filename: T) {
if contains_nul(filename.container_as_bytes()) {
let filename = self::null_byte::cond.raise(filename.container_into_owned_bytes());
assert!(!contains_nul(filename));
unsafe { self.set_filename_unchecked(filename) }
} else {
unsafe { self.set_filename_unchecked(filename) }
}
assert!(!contains_nul(filename.container_as_bytes()));
unsafe { self.set_filename_unchecked(filename) }
}
/// Replaces the extension with the given byte vector or string.
/// If there is no extension in `self`, this adds one.
@@ -301,8 +285,9 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
///
/// # Failure
///
/// Raises the `null_byte` condition if the extension contains a NUL.
/// Fails the task if the extension contains a NUL.
fn set_extension<T: BytesContainer>(&mut self, extension: T) {
assert!(!contains_nul(extension.container_as_bytes()));
// borrowck causes problems here too
let val = {
match self.filename() {
@@ -315,21 +300,11 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
None
} else {
let mut v;
if contains_nul(extension.container_as_bytes()) {
let ext = extension.container_into_owned_bytes();
let extension = self::null_byte::cond.raise(ext);
assert!(!contains_nul(extension));
v = vec::with_capacity(name.len() + extension.len() + 1);
v.push_all(name);
v.push(dot);
v.push_all(extension);
} else {
let extension = extension.container_as_bytes();
v = vec::with_capacity(name.len() + extension.len() + 1);
v.push_all(name);
v.push(dot);
v.push_all(extension);
}
let extension = extension.container_as_bytes();
v = vec::with_capacity(name.len() + extension.len() + 1);
v.push_all(name);
v.push(dot);
v.push_all(extension);
Some(v)
}
}
@@ -338,19 +313,10 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
Some(name.slice_to(idx).to_owned())
} else {
let mut v;
if contains_nul(extension.container_as_bytes()) {
let ext = extension.container_into_owned_bytes();
let extension = self::null_byte::cond.raise(ext);
assert!(!contains_nul(extension));
v = vec::with_capacity(idx + extension.len() + 1);
v.push_all(name.slice_to(idx+1));
v.push_all(extension);
} else {
let extension = extension.container_as_bytes();
v = vec::with_capacity(idx + extension.len() + 1);
v.push_all(name.slice_to(idx+1));
v.push_all(extension);
}
let extension = extension.container_as_bytes();
v = vec::with_capacity(idx + extension.len() + 1);
v.push_all(name.slice_to(idx+1));
v.push_all(extension);
Some(v)
}
}
@@ -370,7 +336,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
///
/// # Failure
///
/// Raises the `null_byte` condition if the filename contains a NUL.
/// Fails the task if the filename contains a NUL.
#[inline]
fn with_filename<T: BytesContainer>(&self, filename: T) -> Self {
let mut p = self.clone();
@@ -383,7 +349,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
///
/// # Failure
///
/// Raises the `null_byte` condition if the extension contains a NUL.
/// Fails the task if the extension contains a NUL.
#[inline]
fn with_extension<T: BytesContainer>(&self, extension: T) -> Self {
let mut p = self.clone();
@@ -408,16 +374,11 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
///
/// # Failure
///
/// Raises the `null_byte` condition if the path contains a NUL.
/// Fails the task if the path contains a NUL.
#[inline]
fn push<T: BytesContainer>(&mut self, path: T) {
if contains_nul(path.container_as_bytes()) {
let path = self::null_byte::cond.raise(path.container_into_owned_bytes());
assert!(!contains_nul(path));
unsafe { self.push_unchecked(path) }
} else {
unsafe { self.push_unchecked(path) }
}
assert!(!contains_nul(path.container_as_bytes()));
unsafe { self.push_unchecked(path) }
}
/// Pushes multiple paths (as byte vectors or strings) onto `self`.
/// See `push` for details.
@@ -445,7 +406,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
///
/// # Failure
///
/// Raises the `null_byte` condition if the path contains a NUL.
/// Fails the task if the path contains a NUL.
#[inline]
fn join<T: BytesContainer>(&self, path: T) -> Self {
let mut p = self.clone();
@@ -318,7 +318,7 @@ impl Path {
///
/// # Failure
///
/// Raises the `null_byte` condition if the vector contains a NUL.
/// Fails the task if the vector contains a NUL.
#[inline]
pub fn new<T: BytesContainer>(path: T) -> Path {
GenericPath::new(path)
@@ -527,83 +527,21 @@ mod tests {

#[test]
fn test_null_byte() {
use path::null_byte::cond;

let mut handled = false;
let mut p = cond.trap(|v| {
handled = true;
assert_eq!(v.as_slice(), b!("foo/bar", 0));
(b!("/bar").to_owned())
}).inside(|| {
use task;
let result = task::try(proc() {
Path::new(b!("foo/bar", 0))
});
assert!(handled);
assert_eq!(p.as_vec(), b!("/bar"));

handled = false;
cond.trap(|v| {
handled = true;
assert_eq!(v.as_slice(), b!("f", 0, "o"));
(b!("foo").to_owned())
}).inside(|| {
p.set_filename(b!("f", 0, "o"))
});
assert!(handled);
assert_eq!(p.as_vec(), b!("/foo"));

handled = false;
cond.trap(|v| {
handled = true;
assert_eq!(v.as_slice(), b!("f", 0, "o"));
(b!("foo").to_owned())
}).inside(|| {
p.push(b!("f", 0, "o"));
});
assert!(handled);
assert_eq!(p.as_vec(), b!("/foo/foo"));
}

#[test]
fn test_null_byte_fail() {
use path::null_byte::cond;
use task;
assert!(result.is_err());

macro_rules! t(
($name:expr => $code:expr) => (
{
let mut t = task::task();
t.name($name);
let res = t.try(proc() $code);
assert!(res.is_err());
}
)
)
let result = task::try(proc() {
Path::new("test").set_filename(b!("f", 0, "o"))
});
assert!(result.is_err());

t!(~"new() w/nul" => {
cond.trap(|_| {
(b!("null", 0).to_owned())
}).inside(|| {
Path::new(b!("foo/bar", 0))
});
})

t!(~"set_filename w/nul" => {
let mut p = Path::new(b!("foo/bar"));
cond.trap(|_| {
(b!("null", 0).to_owned())
}).inside(|| {
p.set_filename(b!("foo", 0))
});
})

t!(~"push w/nul" => {
let mut p = Path::new(b!("foo/bar"));
cond.trap(|_| {
(b!("null", 0).to_owned())
}).inside(|| {
p.push(b!("foo", 0))
});
})
let result = task::try(proc() {
Path::new("test").push(b!("f", 0, "o"));
});
assert!(result.is_err());
}

#[test]
@@ -590,7 +590,7 @@ impl Path {
///
/// # Failure
///
/// Raises the `null_byte` condition if the vector contains a NUL.
/// Fails the task if the vector contains a NUL.
/// Fails if invalid UTF-8.
#[inline]
pub fn new<T: BytesContainer>(path: T) -> Path {
@@ -1248,83 +1248,21 @@ mod tests {

#[test]
fn test_null_byte() {
use path::null_byte::cond;

let mut handled = false;
let mut p = cond.trap(|v| {
handled = true;
assert_eq!(v.as_slice(), b!("foo\\bar", 0));
(b!("\\bar").to_owned())
}).inside(|| {
Path::new(b!("foo\\bar", 0))
});
assert!(handled);
assert_eq!(p.as_vec(), b!("\\bar"));

handled = false;
cond.trap(|v| {
handled = true;
assert_eq!(v.as_slice(), b!("f", 0, "o"));
(b!("foo").to_owned())
}).inside(|| {
p.set_filename(b!("f", 0, "o"))
});
assert!(handled);
assert_eq!(p.as_vec(), b!("\\foo"));

handled = false;
cond.trap(|v| {
handled = true;
assert_eq!(v.as_slice(), b!("f", 0, "o"));
(b!("foo").to_owned())
}).inside(|| {
p.push(b!("f", 0, "o"));
});
assert!(handled);
assert_eq!(p.as_vec(), b!("\\foo\\foo"));
}

#[test]
fn test_null_byte_fail() {
use path::null_byte::cond;
use task;
let result = task::try(proc() {
Path::new(b!("foo/bar", 0))
});
assert!(result.is_err());

macro_rules! t(
($name:expr => $code:expr) => (
{
let mut t = task::task();
t.name($name);
let res = t.try(proc() $code);
assert!(res.is_err());
}
)
)

t!(~"from_vec() w\\nul" => {
cond.trap(|_| {
(b!("null", 0).to_owned())
}).inside(|| {
Path::new(b!("foo\\bar", 0))
});
})

t!(~"set_filename w\\nul" => {
let mut p = Path::new(b!("foo\\bar"));
cond.trap(|_| {
(b!("null", 0).to_owned())
}).inside(|| {
p.set_filename(b!("foo", 0))
});
})
let result = task::try(proc() {
Path::new("test").set_filename(b!("f", 0, "o"))
});
assert!(result.is_err());

t!(~"push w\\nul" => {
let mut p = Path::new(b!("foo\\bar"));
cond.trap(|_| {
(b!("null", 0).to_owned())
}).inside(|| {
p.push(b!("foo", 0))
});
})
let result = task::try(proc() {
Path::new("test").push(b!("f", 0, "o"));
});
assert!(result.is_err());
}

#[test]
@@ -44,7 +44,6 @@ Several modules in `core` are clients of `rt`:
* `std::local_data` - The interface to local data.
* `std::gc` - The garbage collector.
* `std::unstable::lang` - Miscellaneous lang items, some of which rely on `std::rt`.
* `std::condition` - Uses local data.
* `std::cleanup` - Local heap destruction.
* `std::io` - In the future `std::io` will use an `rt` implementation.
* `std::logging`
@@ -786,22 +786,25 @@ pub fn expand_args(ecx: &mut ExtCtxt, sp: Span,
None => return MacResult::dummy_expr()
};

let mut err = false;
parse::parse_error::cond.trap(|m| {
if !err {
err = true;
cx.ecx.span_err(efmt.span, m);
}
}).inside(|| {
for piece in parse::Parser::new(fmt.get()) {
if !err {
let mut parser = parse::Parser::new(fmt.get());
loop {
match parser.next() {
Some(piece) => {
if parser.errors.len() > 0 { break }
cx.verify_piece(&piece);
let piece = cx.trans_piece(&piece);
cx.pieces.push(piece);
}
None => break
}
}
match parser.errors.shift() {
Some(error) => {
cx.ecx.span_err(efmt.span, "invalid format string: " + error);
return MRExpr(efmt);
}
});
if err { return MRExpr(efmt) }
None => {}
}

// Make sure that all arguments were used and all arguments have types.
for (i, ty) in cx.arg_types.iter().enumerate() {

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -24,9 +24,3 @@ pub fn verify_same2(a: &'static int) {
let b = global2 as *int as uint;
assert_eq!(a, b);
}

condition!{ pub test: int -> (); }

pub fn raise() {
test::cond.raise(3);
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -18,11 +18,4 @@ use other = xcrate_static_addresses;
pub fn main() {
other::verify_same(&other::global);
other::verify_same2(other::global2);

// Previously this fail'd because there were two addresses that were being
// used when declaring constants.
other::test::cond.trap(|_| {
}).inside(|| {
other::raise();
})
}