Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Rust 1.0pre compat #195

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions codegen/branchify.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![macro_escape]
#![macro_use]

use std::str::Chars;
use std::vec::Vec;
Expand Down Expand Up @@ -104,13 +104,13 @@ pub fn generate_branchified_method(
let next_prefix = format!("{}{}", prefix, c as char);
w!(format!("Ok(b'{}') => match {} {{", c as char, read_call));
for b in branch.children.iter() {
try!(r(writer, b, next_prefix[], indent + 1, read_call, end, max_len, valid, unknown));
try!(r(writer, b, next_prefix.as_slice(), indent + 1, read_call, end, max_len, valid, unknown));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The better transformation here is &next_prefix[].

}
match branch.result {
Some(ref result) =>
w!(format!(" Ok(b' ') => return Ok({}),", *result)),
None => w!(format!(" Ok(b' ') => return Ok({}),",
unknown.replace("{}", format!("String::from_str(\"{}\")", next_prefix)[]))),
unknown.replace("{}", format!("String::from_str(\"{}\")", next_prefix).as_slice()))),
}
w!(format!(" Ok(b) if {} => (\"{}\", b),", valid, next_prefix));
w!(" Ok(_) => return Err(::std::io::IoError { kind: ::std::io::OtherIoError, desc: \"bad value\", detail: None }),");
Expand Down
4 changes: 2 additions & 2 deletions codegen/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(macro_rules, slicing_syntax)]
#![feature(slicing_syntax, box_syntax, int_uint)]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be better to update these as appropriate rather than use the gates.


use std::io::{File, Truncate, Write};
use std::os;
Expand All @@ -12,7 +12,7 @@ fn main() {
Thread::spawn(move || {
let output_dir = Path::new(os::getenv("OUT_DIR").unwrap());
read_method::generate(output_dir).unwrap();
}).detach();
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

I think what is actually desired here is to .join() the guard at the end of the function. Or just ditch the threading, it's probably a silly idea anyway.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, right now this will totally detach the thread and can leave things undone when main exits and all threads are killed. Either we should use let join = Thread::scope(..) and let join drop at the end of main, or we should just drop the threading altogether.


let output_dir = Path::new(os::getenv("OUT_DIR").unwrap());
status::generate(output_dir).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion codegen/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl HttpStatus {

fn padded_ident(&self) -> String {
let mut s = self.ident();
s.push_str(self.reason_padding_spaces()[]);
s.push_str(self.reason_padding_spaces().as_slice());
s
}

Expand Down
2 changes: 1 addition & 1 deletion src/http/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl<T: Reader> BufferedStream<T> {
(0, _) => panic!("poke called when buffer is full"),
(_, _) => self.read_pos -= 1,
}
self.read_buffer[mut][self.read_pos] = byte;
self.read_buffer[self.read_pos] = byte;
}

#[inline]
Expand Down
20 changes: 10 additions & 10 deletions src/http/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const ASCII_UPPER_F: u8 = b'F';
*
* Should everything work as designed (i.e. none of these conditions occur) a `Some` is returned.
*/
pub fn read_decimal<R: Reader, N: UnsignedInt + NumCast + Int>
(reader: &mut R, expected_end: |u8| -> bool)
pub fn read_decimal<R: Reader, N: UnsignedInt + NumCast + Int, F: FnMut(u8) -> bool>
(reader: &mut R, mut expected_end: F)
-> IoResult<N> {
// Here and in `read_hexadecimal` there is the possibility of infinite sequence of zeroes. The
// spec allows this, but it may not be a good thing to allow. It's not a particularly good
Expand Down Expand Up @@ -89,8 +89,8 @@ pub fn read_decimal<R: Reader, N: UnsignedInt + NumCast + Int>
*
* Should everything work as designed (i.e. none of these conditions occur) a `Some` is returned.
*/
pub fn read_hexadecimal<R: Reader, N: UnsignedInt + NumCast + Int>
(reader: &mut R, expected_end: |u8| -> bool)
pub fn read_hexadecimal<R: Reader, N: UnsignedInt + NumCast + Int, F: FnMut(u8) -> bool>
(reader: &mut R, mut expected_end: F)
-> IoResult<N> {
let mut n: N = Int::zero();
let mut got_content = false;
Expand Down Expand Up @@ -142,8 +142,8 @@ pub fn read_hexadecimal<R: Reader, N: UnsignedInt + NumCast + Int>
* - A `Some`, if all goes well.
*/
#[inline]
pub fn read_http_version<R: Reader>
(reader: &mut R, expected_end: |u8| -> bool)
pub fn read_http_version<R: Reader, F: FnMut(u8) -> bool>
(reader: &mut R, mut expected_end: F)
-> IoResult<(uint, uint)> {
// I'd read into a [0u8, ..5], but that buffer is not guaranteed to be
// filled, so I must read it byte by byte to guarantee correctness.
Expand All @@ -169,7 +169,7 @@ pub fn read_http_version<R: Reader>

// I couldn't think what to call it. Ah well. It's just trivial syntax sugar, anyway.
macro_rules! test_reads {
($func:ident $($value:expr => $expected:expr),*) => {{
($func:ident, $($value:expr => $expected:expr),*) => {{
$(
assert_eq!(
concat_idents!(read_, $func)(&mut MemReader::new($value.bytes().collect::<Vec<_>>()),
Expand All @@ -181,7 +181,7 @@ macro_rules! test_reads {

#[test]
fn test_read_http_version() {
test_reads!(http_version
test_reads!(http_version,
"HTTP/25.17\0" => Some((25, 17)),
"http/1.0\0" => Some((1, 0)),
"http 1.0\0" => None,
Expand All @@ -192,7 +192,7 @@ fn test_read_http_version() {

#[test]
fn test_read_decimal() {
test_reads!(decimal
test_reads!(decimal,
"0\0" => Some(0u),
"0\0" => Some(0u8),
"0\0" => Some(0u64),
Expand All @@ -219,7 +219,7 @@ fn test_read_decimal() {

#[test]
fn test_read_hexadecimal() {
test_reads!(hexadecimal
test_reads!(hexadecimal,
"0\0" => Some(0u),
"0\0" => Some(0u8),
"0\0" => Some(0u64),
Expand Down
9 changes: 2 additions & 7 deletions src/http/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@

#![allow(unknown_features)]
#![feature(slicing_syntax)]
#![feature(default_type_params)]
#![feature(macro_rules)]
#![feature(phase)]
#![feature(globs)]
#![feature(associated_types)]
#![feature(old_orphan_check)]
//#![feature(old_orphan_check)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be actually deleted.


#[phase(plugin, link)] extern crate log;
#[macro_use] extern crate log;
extern crate url;
extern crate time;
extern crate collections;
Expand Down