Fixes for recent stdlib changes

This commit is contained in:
Andrew Poelstra 2014-08-14 15:20:39 -07:00
parent 6d4861b472
commit d9d7416e32
5 changed files with 21 additions and 24 deletions

View File

@ -129,7 +129,9 @@ impl SignatureHashType {
/// A structure that can hold either a slice or vector, as necessary /// A structure that can hold either a slice or vector, as necessary
#[deriving(Clone, Show)] #[deriving(Clone, Show)]
pub enum MaybeOwned<'a> { pub enum MaybeOwned<'a> {
/// Freshly allocated memory
Owned(Vec<u8>), Owned(Vec<u8>),
/// Pointer into the original script
Slice(&'a [u8]) Slice(&'a [u8])
} }
@ -140,7 +142,7 @@ impl<'a> PartialEq for MaybeOwned<'a> {
impl<'a> Eq for MaybeOwned<'a> {} impl<'a> Eq for MaybeOwned<'a> {}
impl<'a> Vector<u8> for MaybeOwned<'a> { impl<'a> Slice<u8> for MaybeOwned<'a> {
#[inline] #[inline]
fn as_slice<'a>(&'a self) -> &'a [u8] { fn as_slice<'a>(&'a self) -> &'a [u8] {
match *self { match *self {

View File

@ -209,20 +209,14 @@ let tx = unsafe {&*tx};
match txo { match txo {
Some(txo) => { Some(txo) => {
let mut stack = Vec::with_capacity(6); let mut stack = Vec::with_capacity(6);
match input.script_sig.evaluate(&mut stack, Some((tx, n))) { if input.script_sig.evaluate(&mut stack, Some((tx, n))).is_err() {
Ok(_) => {}
Err(e) => {
println!("txid was {}", tx.bitcoin_hash()); println!("txid was {}", tx.bitcoin_hash());
return false; return false;
} }
} if txo.script_pubkey.evaluate(&mut stack, Some((tx, n))).is_err() {
match txo.script_pubkey.evaluate(&mut stack, Some((tx, n))) {
Ok(_) => {},
Err(e) => {
println!("txid was {}", tx.bitcoin_hash()); println!("txid was {}", tx.bitcoin_hash());
return false; return false;
} }
}
match stack.pop() { match stack.pop() {
Some(v) => { Some(v) => {
if !read_scriptbool(v.as_slice()) { if !read_scriptbool(v.as_slice()) {

View File

@ -20,6 +20,7 @@
use std::io::{IoResult, standard_error, ConnectionFailed}; use std::io::{IoResult, standard_error, ConnectionFailed};
use std::io::timer; use std::io::timer;
use std::time::Duration;
use network::constants::Network; use network::constants::Network;
use network::message::{NetworkMessage, Verack}; use network::message::{NetworkMessage, Verack};
@ -78,7 +79,7 @@ pub trait Listener {
} }
Err(e) => { Err(e) => {
println!("Received error {:} when decoding message. Pausing for 5 seconds then reconnecting.", e); println!("Received error {:} when decoding message. Pausing for 5 seconds then reconnecting.", e);
timer::sleep(5000); timer::sleep(Duration::seconds(5));
// Reconnect // Reconnect
sock.reconnect() sock.reconnect()
// Create version message // Create version message

View File

@ -41,7 +41,7 @@ impl<S:SimpleEncoder<E>, E> ConsensusEncodable<S, E> for CommandString {
fn consensus_encode(&self, s: &mut S) -> Result<(), E> { fn consensus_encode(&self, s: &mut S) -> Result<(), E> {
let &CommandString(ref inner_str) = self; let &CommandString(ref inner_str) = self;
let mut rawbytes = [0u8, ..12]; let mut rawbytes = [0u8, ..12];
rawbytes.copy_from(inner_str.as_bytes().as_slice()); rawbytes.clone_from_slice(inner_str.as_bytes().as_slice());
rawbytes.consensus_encode(s) rawbytes.consensus_encode(s)
} }
} }

View File

@ -20,7 +20,7 @@
//! //!
use alloc::heap::{allocate, reallocate, deallocate}; use alloc::heap::{allocate, reallocate, deallocate};
use std::raw::Slice; use std::raw;
use std::slice::{Items, MutItems}; use std::slice::{Items, MutItems};
use std::{fmt, mem, ptr}; use std::{fmt, mem, ptr};
use std::u32; use std::u32;
@ -76,7 +76,7 @@ impl<T> ThinVec<T> {
/// Get vector as mutable slice /// Get vector as mutable slice
#[inline] #[inline]
pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] { pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] {
unsafe { mem::transmute(Slice { data: self.ptr as *const T, len: self.cap as uint }) } unsafe { mem::transmute(raw::Slice { data: self.ptr as *const T, len: self.cap as uint }) }
} }
/// Accessor /// Accessor
@ -166,16 +166,16 @@ impl<T:Clone> ThinVec<T> {
for i in range(0, other.len()) { for i in range(0, other.len()) {
unsafe { unsafe {
ptr::write(self.as_mut_slice().unsafe_mut_ref(old_cap + i), ptr::write(self.as_mut_slice().unsafe_mut_ref(old_cap + i),
other.unsafe_ref(i).clone()); other.unsafe_get(i).clone());
} }
} }
} }
} }
impl<T> Vector<T> for ThinVec<T> { impl<T> Slice<T> for ThinVec<T> {
#[inline] #[inline]
fn as_slice<'a>(&'a self) -> &'a [T] { fn as_slice<'a>(&'a self) -> &'a [T] {
unsafe { mem::transmute(Slice { data: self.ptr as *const T, len: self.cap as uint }) } unsafe { mem::transmute(raw::Slice { data: self.ptr as *const T, len: self.cap as uint }) }
} }
} }
@ -187,7 +187,7 @@ impl<T:Clone> Clone for ThinVec<T> {
// if T is Copy // if T is Copy
for i in range(0, self.len()) { for i in range(0, self.len()) {
ptr::write(ret.as_mut_slice().unsafe_mut_ref(i), ptr::write(ret.as_mut_slice().unsafe_mut_ref(i),
self.as_slice().unsafe_ref(i).clone()); self.as_slice().unsafe_get(i).clone());
} }
ret ret
} }