Skip to content

Commit e8c002b

Browse files
committed
Merge pull request chris-morgan#8 from larsbergstrom/rust_20140224
Rust upgrade 20140224
2 parents 1a9a23b + 5dff177 commit e8c002b

35 files changed

+742
-684
lines changed

.travis.yml

+6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
env:
2+
global:
3+
- secure: SkhFtAUkRRrDYHr6z6YhWtGouw6jsys7dBKLojA+M3M68EM9U1VG9oNHMasCdFUt0a+TdPte9JccufbhvZABnlo7+yU6hQ94jhsyQ9qSL5y7V+2eyWBkQZDqyFt3jgLyrrSV2Nkk22xI4UAm2iGRKel6lXWi7i0i9hDT+3W0dK4=
14
before_install:
25
- yes | sudo add-apt-repository ppa:hansjorg/rust
36
- sudo apt-get update
47
install:
58
- sudo apt-get install rust-nightly
69
script:
710
- make check
11+
- make docs
12+
after_script:
13+
- curl http://www.rust-ci.org/artifacts/put?t=$RUSTCI_TOKEN | sh

Makefile

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
RUSTC ?= rustc
22
RUSTDOC ?= rustdoc
33
RUSTPKG ?= rustpkg
4-
RUSTFLAGS ?= -O -Z debug-info
5-
RUSTLIBFLAGS ?= --dylib --rlib
4+
RUSTFLAGS ?= -O
65
RUST_REPOSITORY ?= ../rust
76
RUST_CTAGS ?= $(RUST_REPOSITORY)/src/etc/ctags.rust
87
VERSION=0.1-pre
@@ -31,15 +30,18 @@ http: $(libhttp_so)
3130

3231
$(libhttp_so): $(http_files)
3332
mkdir -p build/
34-
$(RUSTC) $(RUSTFLAGS) $(RUSTLIBFLAGS) src/http/lib.rs --out-dir=build
33+
$(RUSTC) $(RUSTFLAGS) src/http/lib.rs --out-dir=build
3534

3635
all: http examples docs
3736

3837
build/codegen: $(codegen_files)
3938
mkdir -p build/
40-
$(RUSTC) $(RUSTFLAGS) src/codegen/main.rs --out-dir=build
39+
$(RUSTC) src/codegen/main.rs --out-dir=build
4140

42-
src/http/generated/%.rs: build/codegen
41+
src/http/generated:
42+
mkdir -p src/http/generated
43+
44+
src/http/generated/%.rs: build/codegen src/http/generated
4345
build/codegen $(patsubst src/http/generated/%,%,$@) src/http/generated/
4446

4547
build/%:: src/%/main.rs $(libhttp_so)

Makefile.in

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ all: libhttp.dummy
1515
codegen: $(wildcard $(VPATH)/src/codegen/*.rs)
1616
$(RUSTC) $(HOST_RUSTFLAGS) $(VPATH)/src/codegen/main.rs -o codegen
1717

18-
$(VPATH)/src/http/generated/%.rs: codegen
18+
$(VPATH)/src/http/generated:
19+
mkdir -p $(VPATH)/src/http/generated
20+
21+
$(VPATH)/src/http/generated/%.rs: codegen $(VPATH)/src/http/generated
1922
./codegen $(patsubst $(VPATH)/src/http/generated/%,%,$@) $(VPATH)/src/http/generated/
2023

2124
libhttp.dummy: $(libhttp_files)
22-
$(RUSTC) $(RUSTFLAGS) $(VPATH)/src/http/lib.rs --out-dir . --lib
25+
$(RUSTC) $(RUSTFLAGS) $(VPATH)/src/http/lib.rs --out-dir .
2326
touch $@
2427

2528
check: tests

README.rst

+11-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ This project has two parts:
1313
Both are in progress; both have basic, low-level implementations in place.
1414
Neither is complete nor yet compliant in any way.
1515

16+
Rust versions
17+
-------------
18+
19+
I urge you to track Rust master as rust-http does, but if you really are set on
20+
using Rust 0.9, you can use the [`rust-0.9-compatible`
21+
branch](https://github.com/chris-morgan/rust-http/commits/rust-0.9-compatible).
22+
It is not maintained, however; it's just the last commit that *will* work on
23+
Rust 0.9.
24+
1625
Goals
1726
-----
1827

@@ -48,11 +57,11 @@ Build everything::
4857

4958
Run one of the servers::
5059

51-
build/examples/apache_fake
60+
build/examples/server/apache_fake
5261

5362
To run the client example, start one of the servers and run::
5463

55-
build/examples/client/client
64+
build/examples/client http://127.0.0.1:8001/
5665

5766
At present, all of the example servers serve to http://127.0.0.1:8001/.
5867

doc/client-plan.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ probably be a wrapper about a ``Reader``.
3939
The initial API will be very simple, with ``Request::new(Method, Url)`` and the
4040
use of string typing for headers::
4141

42-
extern mod http;
42+
extern crate http;
4343
use http::client::Request;
4444
use http::method::Get;
4545
use extra::url::Url;
4646

47-
let mut request = Request::new(Get, FromStr::from_str("http://rust-lang.org"));
47+
let mut request = Request::new(Get, from_str("http://rust-lang.org"));
4848
request.headers.insert(~"Connection", ~"close");
4949
request.headers.insert(~"Referer", ~"https://google.com/");
5050
let mut response = request.send();

src/codegen/branchify.rs

+49-43
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[macro_escape];
22

3-
use std::str::CharIterator;
4-
use std::io::Writer;
3+
use std::str::Chars;
4+
use std::io::IoResult;
55

66
struct ParseBranch {
77
matches: ~[u8],
@@ -22,7 +22,7 @@ impl ParseBranch {
2222
pub fn branchify(options: &[(&str, &str)], case_sensitive: bool) -> ~[ParseBranch] {
2323
let mut root = ParseBranch::new();
2424

25-
fn go_down_moses(branch: &mut ParseBranch, mut chariter: CharIterator, result: &str, case_sensitive: bool) {
25+
fn go_down_moses(branch: &mut ParseBranch, mut chariter: Chars, result: &str, case_sensitive: bool) {
2626
match chariter.next() {
2727
Some(c) => {
2828
let first_case = if case_sensitive { c as u8 } else { c.to_ascii().to_upper().to_byte() };
@@ -85,60 +85,66 @@ pub fn generate_branchified_method(
8585
end: &str,
8686
max_len: &str,
8787
valid: &str,
88-
unknown: &str) {
88+
unknown: &str) -> IoResult<()> {
8989

9090
fn r(writer: &mut Writer, branch: &ParseBranch, prefix: &str, indent: uint, read_call: &str,
91-
end: &str, max_len: &str, valid: &str, unknown: &str) {
91+
end: &str, max_len: &str, valid: &str, unknown: &str) -> IoResult<()> {
9292
let indentstr = " ".repeat(indent * 4);
93-
let w = |s: &str| {
94-
writer.write(indentstr.as_bytes());
95-
writer.write(s.as_bytes());
96-
writer.write(bytes!("\n"));
97-
};
93+
macro_rules! w (
94+
($s:expr) => {
95+
try!(write!(writer, "{}{}\n", indentstr, $s))
96+
}
97+
)
9898
for &c in branch.matches.iter() {
9999
let next_prefix = format!("{}{}", prefix, c as char);
100-
w(format!("Some(b) if b == '{}' as u8 => match {} \\{", c as char, read_call));
100+
w!(format!("Ok(b) if b == '{}' as u8 => match {} \\{", c as char, read_call));
101101
for b in branch.children.iter() {
102-
r(writer, b, next_prefix, indent + 1, read_call, end, max_len, valid, unknown);
102+
try!(r(writer, b, next_prefix, indent + 1, read_call, end, max_len, valid, unknown));
103103
}
104104
match branch.result {
105-
Some(ref result) => w(format!(" Some(b) if b == SP => return Some({}),", *result)),
106-
None => w(format!(" Some(b) if b == SP => return Some({}),",
105+
Some(ref result) =>
106+
w!(format!(" Ok(b) if b == SP => return Ok({}),", *result)),
107+
None => w!(format!(" Ok(b) if b == SP => return Ok({}),",
107108
unknown.replace("{}", format!("~\"{}\"", next_prefix)))),
108109
}
109-
w(format!(" Some(b) if {} => (\"{}\", b),", valid, next_prefix));
110-
w(" _ => return None,");
111-
w("},");
110+
w!(format!(" Ok(b) if {} => (\"{}\", b),", valid, next_prefix));
111+
w!(" Ok(_) => return Err(::std::io::IoError { kind: ::std::io::OtherIoError, desc: \"bad value\", detail: None }),");
112+
w!(" Err(err) => return Err(err),");
113+
w!("},");
112114
}
115+
Ok(())
113116
}
114117
let indentstr = " ".repeat(indent * 4);
115-
let w = |s: &str| {
116-
writer.write(indentstr.as_bytes());
117-
writer.write(s.as_bytes());
118-
writer.write(bytes!("\n"));
119-
};
118+
macro_rules! w (
119+
($s:expr) => {
120+
try!(write!(writer, "{}{}\n", indentstr, $s))
121+
}
122+
)
120123

121-
w(format!("let (s, next_byte) = match {} \\{", read_call));
124+
w!(format!("let (s, next_byte) = match {} \\{", read_call));
122125
for b in branches.iter() {
123-
r(writer, b, "", indent + 1, read_call, end, max_len, valid, unknown);
126+
try!(r(writer, b, "", indent + 1, read_call, end, max_len, valid, unknown));
124127
}
125-
w(format!(" Some(b) if {} => (\"\", b),", valid));
126-
w( (" _ => return None,"));
127-
w( ("};"));
128-
w( ("// OK, that didn't pan out. Let's read the rest and see what we get."));
129-
w( ("let mut s = s.to_owned();"));
130-
w( ("s.push_char(next_byte as char);"));
131-
w( ("loop {"));
132-
w(format!(" match {} \\{", read_call));
133-
w(format!(" Some(b) if b == {} => return Some({}),", end, unknown.replace("{}", "s")));
134-
w(format!(" Some(b) if {} => \\{", valid));
135-
w(format!(" if s.len() == {} \\{", max_len));
136-
w( (" // Too long; bad request"));
137-
w( (" return None;"));
138-
w( (" }"));
139-
w( (" s.push_char(b as char);"));
140-
w( (" },"));
141-
w( (" _ => return None,"));
142-
w( (" }"));
143-
w( ("}"));
128+
w!(format!(" Ok(b) if {} => (\"\", b),", valid));
129+
w!( (" Ok(_) => return Err(::std::io::IoError { kind: ::std::io::OtherIoError, desc: \"bad value\", detail: None }),"));
130+
w!( (" Err(err) => return Err(err),"));
131+
w!( ("};"));
132+
w!( ("// OK, that didn't pan out. Let's read the rest and see what we get."));
133+
w!( ("let mut s = s.to_owned();"));
134+
w!( ("s.push_char(next_byte as char);"));
135+
w!( ("loop {"));
136+
w!(format!(" match {} \\{", read_call));
137+
w!(format!(" Ok(b) if b == {} => return Ok({}),", end, unknown.replace("{}", "s")));
138+
w!(format!(" Ok(b) if {} => \\{", valid));
139+
w!(format!(" if s.len() == {} \\{", max_len));
140+
w!( (" // Too long; bad request"));
141+
w!( (" return Err(::std::io::IoError { kind: ::std::io::OtherIoError, desc: \"too long, bad request\", detail: None });"));
142+
w!( (" }"));
143+
w!( (" s.push_char(b as char);"));
144+
w!( (" },"));
145+
w!( (" Ok(_) => return Err(::std::io::IoError { kind: ::std::io::OtherIoError, desc: \"bad value\", detail: None }),"));
146+
w!( (" Err(err) => return Err(err),"));
147+
w!( (" }"));
148+
w!( ("}"));
149+
Ok(())
144150
}

src/codegen/main.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
#[feature(macro_rules)];
44

5-
use std::io;
6-
use std::io::{File, Truncate, Write, fs};
5+
extern crate collections;
6+
7+
use std::io::{File, Truncate, Write};
78
use std::os;
89

910
pub mod branchify;
@@ -14,27 +15,23 @@ fn main() {
1415
let args = os::args();
1516
match args.len() {
1617
0 => {
17-
println("usage: codegen [read_method|status].rs <output-dir>");
18-
os::set_exit_status(1);
18+
println!("usage: codegen [read_method|status].rs <output-dir>");
19+
os::set_exit_status(1);
1920
},
2021
3 => {
2122
let output_dir = Path::new(args[2].as_slice());
22-
// TODO: maybe not 0777?
23-
if !output_dir.exists() {
24-
fs::mkdir(&output_dir, 0b111_111_111);
25-
}
2623

2724
match args[1] {
28-
~"read_method.rs" => read_method::generate(&output_dir),
29-
~"status.rs" => status::generate(&output_dir),
25+
~"read_method.rs" => read_method::generate(&output_dir).unwrap(),
26+
~"status.rs" => status::generate(&output_dir).unwrap(),
3027
s => {
3128
println!("unknown thing-to-generate '{}'", s);
3229
os::set_exit_status(1);
3330
}
3431
}
3532
},
3633
_ => {
37-
println!("usage: {} [read_method|status].rs", args[0]);
34+
println!("usage: {} [read_method|status].rs <output-dir>", args[0]);
3835
os::set_exit_status(1);
3936
}
4037
}
@@ -43,7 +40,7 @@ fn main() {
4340
pub fn get_writer(output_dir: &Path, filename: &str) -> ~Writer {
4441
let mut output_file = output_dir.clone();
4542
output_file.push(filename);
46-
match io::result(|| File::open_mode(&output_file, Truncate, Write)) {
43+
match File::open_mode(&output_file, Truncate, Write) {
4744
Ok(writer) => ~writer as ~Writer,
4845
Err(e) => fail!("Unable to write file: {}", e.desc),
4946
}

src/codegen/read_method.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
use super::branchify::generate_branchified_method;
22
use super::get_writer;
3-
use std::io::Writer;
3+
use std::io::IoResult;
44

5-
pub fn generate(output_dir: &Path) {
5+
pub fn generate(output_dir: &Path) -> IoResult<()> {
66
let mut writer = get_writer(output_dir, "read_method.rs");
7-
writer.write(bytes!("\
7+
try!(writer.write(bytes!("\
88
// This automatically generated file is included in request.rs.
99
{
1010
use method::{Connect, Delete, Get, Head, Options, Patch, Post, Put, Trace, ExtensionMethod};
1111
use server::request::MAX_METHOD_LEN;
1212
use rfc2616::{SP, is_token_item};
1313
14-
"));
14+
")));
1515

16-
generate_branchified_method(
16+
try!(generate_branchified_method(
1717
writer,
1818
branchify!(case sensitive,
1919
"CONNECT" => Connect,
@@ -31,6 +31,6 @@ pub fn generate(output_dir: &Path) {
3131
"SP",
3232
"MAX_METHOD_LEN",
3333
"is_token_item(b)",
34-
"ExtensionMethod({})");
35-
writer.write(bytes!("}\n"));
34+
"ExtensionMethod({})"));
35+
writer.write(bytes!("}\n"))
3636
}

0 commit comments

Comments
 (0)