diff options
author | Ellie Huxtable <e@elm.sh> | 2021-05-17 19:51:09 +0100 |
---|---|---|
committer | Ellie Huxtable <e@elm.sh> | 2021-05-17 19:51:09 +0100 |
commit | d0215a937a7889a97e11778ee4b0f9a12de01278 (patch) | |
tree | 5a8fd5ad62e6b5a4c218746ff2d4bd97373a48de /vendor/httparse-1.4.0 | |
parent | 802a2258cbd839c5b82d24f74d7aebe4a27d8dc5 (diff) |
Vendor dependenciesvendor
Just testing how CI works with this. I tend to prefer vendoring, as it
means that if you have a copy of the code *you can always build it*.
Even if you're 20 years in the future
This is the output of
```
cargo vendor --versioned-dirs
```
Diffstat (limited to 'vendor/httparse-1.4.0')
-rw-r--r-- | vendor/httparse-1.4.0/.cargo-checksum.json | 1 | ||||
-rw-r--r-- | vendor/httparse-1.4.0/Cargo.toml | 34 | ||||
-rw-r--r-- | vendor/httparse-1.4.0/LICENSE-APACHE | 201 | ||||
-rw-r--r-- | vendor/httparse-1.4.0/LICENSE-MIT | 20 | ||||
-rw-r--r-- | vendor/httparse-1.4.0/README.md | 38 | ||||
-rw-r--r-- | vendor/httparse-1.4.0/benches/parse.rs | 122 | ||||
-rw-r--r-- | vendor/httparse-1.4.0/build.rs | 165 | ||||
-rw-r--r-- | vendor/httparse-1.4.0/src/iter.rs | 216 | ||||
-rw-r--r-- | vendor/httparse-1.4.0/src/lib.rs | 1267 | ||||
-rw-r--r-- | vendor/httparse-1.4.0/src/macros.rs | 59 | ||||
-rw-r--r-- | vendor/httparse-1.4.0/src/simd/avx2.rs | 161 | ||||
-rw-r--r-- | vendor/httparse-1.4.0/src/simd/fallback.rs | 8 | ||||
-rw-r--r-- | vendor/httparse-1.4.0/src/simd/mod.rs | 284 | ||||
-rw-r--r-- | vendor/httparse-1.4.0/src/simd/sse42.rs | 137 | ||||
-rw-r--r-- | vendor/httparse-1.4.0/tests/uri.rs | 3693 |
15 files changed, 6406 insertions, 0 deletions
diff --git a/vendor/httparse-1.4.0/.cargo-checksum.json b/vendor/httparse-1.4.0/.cargo-checksum.json new file mode 100644 index 00000000..4ef6e4ca --- /dev/null +++ b/vendor/httparse-1.4.0/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"Cargo.toml":"f74022ff35b4b95fc1bd5d61c4b11680ff011b9896bc912d41e9ccb9adf87ba9","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"d1e7f8223db09ae257ac95039ab91b95676c1ac7e55c7a6e996fd76e01fb3453","README.md":"b45dbfa9aa0361b8a574333cbc9cc996d96682b3e46420287fe3a2944ce5abcf","benches/parse.rs":"caabd31cbcb00172bb7f31a1398dbed27a3bf36b01d69729c3d6fbd9a4008e05","build.rs":"b73e269376b98ce6bafdce52d1f17ec0ad3156260f0834cb3efc24ab53c43cf4","src/iter.rs":"979746a1f7e497c4125aeac2270c69b3b3797ff35a2b39799d4aa30598a7df38","src/lib.rs":"6829270202c8346ee4628d668a567043a373ac3723629b1e2bd52683d5da54ad","src/macros.rs":"25de190f894eefb48a6992f9dc3d039d9065f908f381d683f0395d568d992275","src/simd/avx2.rs":"e4e71ff55ec3871a7bb079a1e171aba5e0668810a2969e3e0dda42add57377ca","src/simd/fallback.rs":"0234cc11459f3225d6e3d329068a01206e39625a538bdc292e0d1beaa06a37e5","src/simd/mod.rs":"ca87046ad5d50a8fb9309d526aa97b9a793f6bd227ebd6777dc0c3b5ccf020aa","src/simd/sse42.rs":"8194dd091fbb1bba8116ab3c8fe825194050b5ed68b7932dff382a7b501f9872","tests/uri.rs":"7991575f1caeeff05ba83828ec73c11a17d51dc7d1df20f3a65c6e3940dee67c"},"package":"4a1ce40d6fc9764887c2fdc7305c3dcc429ba11ff981c1509416afd5697e4437"}
\ No newline at end of file diff --git a/vendor/httparse-1.4.0/Cargo.toml b/vendor/httparse-1.4.0/Cargo.toml new file mode 100644 index 00000000..70457817 --- /dev/null +++ b/vendor/httparse-1.4.0/Cargo.toml @@ -0,0 +1,34 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies +# +# If you believe there's an error in this file please file an +# issue against the rust-lang/cargo repository. If you're +# editing this file be aware that the upstream Cargo.toml +# will likely look very different (and much more reasonable) + +[package] +name = "httparse" +version = "1.4.0" +authors = ["Sean McArthur <sean@seanmonstar.com>"] +build = "build.rs" +description = "A tiny, safe, speedy, zero-copy HTTP/1.x parser." +documentation = "https://docs.rs/httparse" +readme = "README.md" +keywords = ["http", "parser", "no_std"] +categories = ["network-programming", "no-std", "parser-implementations", "web-programming"] +license = "MIT/Apache-2.0" +repository = "https://github.com/seanmonstar/httparse" +[profile.bench] +opt-level = 3 +lto = true +codegen-units = 1 +[dev-dependencies.pico-sys] +version = "0.0.1" + +[features] +default = ["std"] +std = [] diff --git a/vendor/httparse-1.4.0/LICENSE-APACHE b/vendor/httparse-1.4.0/LICENSE-APACHE new file mode 100644 index 00000000..16fe87b0 --- /dev/null +++ b/vendor/httparse-1.4.0/LICENSE-APACHE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/vendor/httparse-1.4.0/LICENSE-MIT b/vendor/httparse-1.4.0/LICENSE-MIT new file mode 100644 index 00000000..3485e00b --- /dev/null +++ b/vendor/httparse-1.4.0/LICENSE-MIT @@ -0,0 +1,20 @@ +Copyright (c) 2015-2021 Sean McArthur + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/vendor/httparse-1.4.0/README.md b/vendor/httparse-1.4.0/README.md new file mode 100644 index 00000000..011228a3 --- /dev/null +++ b/vendor/httparse-1.4.0/README.md @@ -0,0 +1,38 @@ +# httparse + +[![Build Status](https://travis-ci.org/seanmonstar/httparse.svg?branch=master)](https://travis-ci.org/seanmonstar/httparse) +[![Coverage Status](https://coveralls.io/repos/seanmonstar/httparse/badge.svg)](https://coveralls.io/r/seanmonstar/httparse) +[![crates.io](https://img.shields.io/crates/v/httparse.svg)](https://crates.io/crates/httparse) + +A push parser for the HTTP 1.x protocol. Avoids allocations. No copy. **Fast.** + +Works with `no_std`, simply disable the `std` Cargo feature. + +[Documentation](https://docs.rs/httparse) +[Changelog](https://github.com/seanmonstar/httparse/releases) + +## Usage + +```rust +let mut headers = [httparse::EMPTY_HEADER; 16]; +let mut req = httparse::Request::new(&mut headers); + +let buf = b"GET /index.html HTTP/1.1\r\nHost"; +assert!(req.parse(buf)?.is_partial()); + +// a partial request, so we try again once we have more data + +let buf = b"GET /index.html HTTP/1.1\r\nHost: example.domain\r\n\r\n"; +assert!(req.parse(buf)?.is_complete()); +``` + +## License + +Licensed under either of + +- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or https://apache.org/licenses/LICENSE-2.0) +- MIT license ([LICENSE-MIT](LICENSE-MIT) or https://opensource.org/licenses/MIT) + +### Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/vendor/httparse-1.4.0/benches/parse.rs b/vendor/httparse-1.4.0/benches/parse.rs new file mode 100644 index 00000000..38e8b585 --- /dev/null +++ b/vendor/httparse-1.4.0/benches/parse.rs @@ -0,0 +1,122 @@ +#![feature(test)] + +extern crate pico_sys as pico; +extern crate httparse; + +extern crate test; + +const REQ_SHORT: &'static [u8] = b"\ +GET / HTTP/1.0\r\n\ +Host: example.com\r\n\ +Cookie: session=60; user_id=1\r\n\r\n"; + +const REQ: &'static [u8] = b"\ +GET /wp-content/uploads/2010/03/hello-kitty-darth-vader-pink.jpg HTTP/1.1\r\n\ +Host: www.kittyhell.com\r\n\ +User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; ja-JP-mac; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 Pathtraq/0.9\r\n\ +Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n\ +Accept-Language: ja,en-us;q=0.7,en;q=0.3\r\n\ +Accept-Encoding: gzip,deflate\r\n\ +Accept-Charset: Shift_JIS,utf-8;q=0.7,*;q=0.7\r\n\ +Keep-Alive: 115\r\n\ +Connection: keep-alive\r\n\ +Cookie: wp_ozh_wsa_visits=2; wp_ozh_wsa_visit_lasttime=xxxxxxxxxx; __utma=xxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.x; __utmz=xxxxxxxxx.xxxxxxxxxx.x.x.utmccn=(referral)|utmcsr=reader.livedoor.com|utmcct=/reader/|utmcmd=referral|padding=under256\r\n\r\n"; + + +#[bench] +fn bench_pico(b: &mut test::Bencher) { + use std::mem; + + #[repr(C)] + #[derive(Clone, Copy)] + struct Header<'a>(&'a [u8], &'a [u8]); + + + #[repr(C)] + struct Headers<'a>(&'a mut [Header<'a>]); + let method = [0i8; 16]; + let path = [0i8; 16]; + let mut minor_version = 0; + let mut h = [Header(&[], &[]); 16]; + let mut h_len = h.len(); + let headers = Headers(&mut h); + let prev_buf_len = 0; + + b.iter(|| { + let ret = unsafe { + pico::ffi::phr_parse_request( + REQ.as_ptr() as *const _, + REQ.len(), + &mut method.as_ptr(), + &mut 16, + &mut path.as_ptr(), + &mut 16, + &mut minor_version, + mem::transmute::<*mut Header, *mut pico::ffi::phr_header>(headers.0.as_mut_ptr()), + &mut h_len as *mut usize as *mut _, + prev_buf_len + ) + }; + assert_eq!(ret, REQ.len() as i32); + }); + b.bytes = REQ.len() as u64; +} + +#[bench] +fn bench_httparse(b: &mut test::Bencher) { + let mut headers = [httparse::Header{ name: "", value: &[] }; 16]; + let mut req = httparse::Request::new(&mut headers); + b.iter(|| { + assert_eq!(req.parse(REQ).unwrap(), httparse::Status::Complete(REQ.len())); + }); + b.bytes = REQ.len() as u64; +} + +#[bench] +fn bench_pico_short(b: &mut test::Bencher) { + use std::mem; + + #[repr(C)] + #[derive(Clone, Copy)] + struct Header<'a>(&'a [u8], &'a [u8]); + + + #[repr(C)] + struct Headers<'a>(&'a mut [Header<'a>]); + let method = [0i8; 16]; + let path = [0i8; 16]; + let mut minor_version = 0; + let mut h = [Header(&[], &[]); 16]; + let mut h_len = h.len(); + let headers = Headers(&mut h); + let prev_buf_len = 0; + + b.iter(|| { + let ret = unsafe { + pico::ffi::phr_parse_request( + REQ_SHORT.as_ptr() as *const _, + REQ_SHORT.len(), + &mut method.as_ptr(), + &mut 16, + &mut path.as_ptr(), + &mut 16, + &mut minor_version, + mem::transmute::<*mut Header, *mut pico::ffi::phr_header>(headers.0.as_mut_ptr()), + &mut h_len as *mut usize as *mut _, + prev_buf_len + ) + }; + assert_eq!(ret, REQ_SHORT.len() as i32); + }); + b.bytes = REQ_SHORT.len() as u64; +} + +#[bench] +fn bench_httparse_short(b: &mut test::Bencher) { + let mut headers = [httparse::Header{ name: "", value: &[] }; 16]; + let mut req = httparse::Request::new(&mut headers); + b.iter(|| { + assert_eq!(req.parse(REQ_SHORT).unwrap(), httparse::Status::Complete(REQ_SHORT.len())); + }); + b.bytes = REQ_SHORT.len() as u64; +} diff --git a/vendor/httparse-1.4.0/build.rs b/vendor/httparse-1.4.0/build.rs new file mode 100644 index 00000000..600a180d --- /dev/null +++ b/vendor/httparse-1.4.0/build.rs @@ -0,0 +1,165 @@ +use std::env; +use std::ffi::OsString; +use std::process::Command; + +fn main() { + let rustc = env::var_os("RUSTC").unwrap_or(OsString::from("rustc")); + let output = Command::new(&rustc) + .arg("--version") + .output() + .expect("failed to check 'rustc --version'") + .stdout; + + let version = String::from_utf8(output) + .expect("rustc version output should be utf-8"); + + enable_new_features(&version); +} + +fn enable_new_features(raw_version: &str) { + let version = match Version::parse(raw_version) { + Ok(version) => version, + Err(err) => { + println!("cargo:warning=failed to parse `rustc --version`: {}", err); + return; + } + }; + + let min_rust2018_version = Version { + major: 1, + minor: 31, + patch: 0, + }; + + if version >= min_rust2018_version { + println!("cargo:rustc-cfg=httparse_min_2018"); + } + + enable_simd(version); +} + +fn enable_simd(version: Version) { + if env::var_os("CARGO_FEATURE_STD").is_none() { + println!("cargo:warning=building for no_std disables httparse SIMD"); + return; + } + + let env_disable = "CARGO_CFG_HTTPARSE_DISABLE_SIMD"; + if env::var_os(env_disable).is_some() { + println!("cargo:warning=detected {} environment variable, disabling SIMD", env_disable); + return; + } + + let min_simd_version = Version { + major: 1, + minor: 27, + patch: 0, + }; + + if version >= min_simd_version { + println!("cargo:rustc-cfg=httparse_simd"); + } + + // cfg(target_feature) isn't stable yet, but CARGO_CFG_TARGET_FEATURE has + // a list... We aren't doing anything unsafe, since the is_x86_feature_detected + // macro still checks in the actual lib, BUT! + // + // By peeking at the list here, we can change up slightly how we do feature + // detection in the lib. If our features aren't in the feature list, we + // stick with a cached runtime detection strategy. + // + // But if the features *are* in the list, we benefit from removing our cache, + // since the compiler will eliminate several branches with its internal + // cfg(target_feature) usage. + + + let env_runtime_only = "CARGO_CFG_HTTPARSE_DISABLE_SIMD_COMPILETIME"; + if env::var_os(env_runtime_only).is_some() { + println!("cargo:warning=detected {} environment variable, using runtime SIMD detection only", env_runtime_only); + return; + } + let feature_list = match env::var_os("CARGO_CFG_TARGET_FEATURE") { + Some(var) => match var.into_string() { + Ok(s) => s, + Err(_) => { + println!("cargo:warning=CARGO_CFG_TARGET_FEATURE was not valid utf-8"); + return; + }, + }, + None => { + println!("cargo:warning=CARGO_CFG_TARGET_FEATURE was not set"); + return + }, + }; + + let mut saw_sse42 = false; + let mut saw_avx2 = false; + + for feature in feature_list.split(',') { + let feature = feature.trim(); + if !saw_sse42 && feature == "sse4.2" { + saw_sse42 = true; + println!("cargo:rustc-cfg=httparse_simd_target_feature_sse42"); + } + + if !saw_avx2 && feature == "avx2" { + saw_avx2 = true; + println!("cargo:rustc-cfg=httparse_simd_target_feature_avx2"); + } + } +} + +#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)] +struct Version { + major: u32, + minor: u32, + patch: u32, +} + +impl Version { + fn parse(mut s: &str) -> Result<Version, String> { + if !s.starts_with("rustc ") { + return Err(format!("unrecognized version string: {}", s)); + } + s = &s["rustc ".len()..]; + + let parts: Vec<&str> = s.split(".").collect(); + if parts.len() < 3 { + return Err(format!("not enough version parts: {:?}", parts)); + } + + let mut num = String::new(); + for c in parts[0].chars() { + if !c.is_digit(10) { + break; + } + num.push(c); + } + let major = try!(num.parse::<u32>().map_err(|e| e.to_string())); + + num.clear(); + for c in parts[1].chars() { + if !c.is_digit(10) { + break; + } + num.push(c); + } + let minor = try!(num.parse::<u32>().map_err(|e| e.to_string())); + + num.clear(); + for c in parts[2].chars() { + if !c.is_digit(10) { + break; + } + num.push(c); + } + let patch = try!(num.parse::<u32>().map_err(|e| e.to_string())); + + Ok(Version { + major: major, + minor: minor, + patch: patch, + }) + } +} + diff --git a/vendor/httparse-1.4.0/src/iter.rs b/vendor/httparse-1.4.0/src/iter.rs new file mode 100644 index 00000000..d4c7e1c2 --- /dev/null +++ b/vendor/httparse-1.4.0/src/iter.rs @@ -0,0 +1,216 @@ +use core::slice; + +pub struct Bytes<'a> { + slice: &'a [u8], + pos: usize +} + +impl<'a> Bytes<'a> { + #[inline] + pub fn new(slice: &'a [u8]) -> Bytes<'a> { + Bytes { + slice: slice, + pos: 0 + } + } + + #[inline] + pub fn pos(&self) -> usize { + self.pos + } + + #[inline] + pub fn peek(&self) -> Option<u8> { + self.slice.get(self.pos).cloned() + } + + #[inline] + pub unsafe fn bump(&mut self) { + debug_assert!(self.pos + 1 <= self.slice.len(), "overflow"); + self.pos += 1; + } + + #[allow(unused)] + #[inline] + pub unsafe fn advance(&mut self, n: usize) { + debug_assert!(self.pos + n <= self.slice.len(), "overflow"); + self.pos += n; + } + + #[inline] + pub fn len(&self) -> usize { + self.slice.len() + } + + #[inline] + pub fn slice(&mut self) -> &'a [u8] { + // not moving position at all, so it's safe + unsafe { + self.slice_skip(0) + } + } + + #[inline] + pub unsafe fn slice_skip(&mut self, skip: usize) -> &'a [u8] { + debug_assert!(self.pos >= skip); + let head_pos = self.pos - skip; + let ptr = self.slice.as_ptr(); + let head = slice::from_raw_parts(ptr, head_pos); + let tail = slice::from_raw_parts(ptr.offset(self.pos as isize), self.slice.len() - self.pos); + self.pos = 0; + self.slice = tail; + head + } + + #[inline] + pub fn next_8<'b>(&'b mut self) -> Option<Bytes8<'b, 'a>> { + if self.slice.len() >= self.pos + 8 { + Some(Bytes8::new(self)) + } else { + None + } + } +} + +impl<'a> AsRef<[u8]> for Bytes<'a> { + #[inline] + fn as_ref(&self) -> &[u8] { + &self.slice[self.pos..] + } +} + +impl<'a> Iterator for Bytes<'a> { + type Item = u8; + + #[inline] + fn next(&mut self) -> Option<u8> { + if self.slice.len() > self.pos { + let b = unsafe { *self.slice.get_unchecked(self.pos) }; + self.pos += 1; + Some(b) + } else { + None + } + } +} + +pub struct Bytes8<'a, 'b: 'a> { + bytes: &'a mut Bytes<'b>, + #[cfg(debug_assertions)] + pos: usize +} + +macro_rules! bytes8_methods { + ($f:ident, $pos:expr) => { + #[inline] + pub fn $f(&mut self) -> u8 { + self.assert_pos($pos); + let b = unsafe { *self.bytes.slice.get_unchecked(self.bytes.pos) }; + self.bytes.pos += 1; + b + } + }; + () => { + bytes8_methods!(_0, 0); + bytes8_methods!(_1, 1); + bytes8_methods!(_2, 2); + bytes8_methods!(_3, 3); + bytes8_methods!(_4, 4); + bytes8_methods!(_5, 5); + bytes8_methods!(_6, 6); + bytes8_methods!(_7, 7); + } +} + +impl<'a, 'b: 'a> Bytes8<'a, 'b> { + bytes8_methods! {} + + #[cfg(not(debug_assertions))] + #[inline] + fn new(bytes: &'a mut Bytes<'b>) -> Bytes8<'a, 'b> { + Bytes8 { + bytes: bytes, + } + } + + #[cfg(debug_assertions)] + #[inline] + fn new(bytes: &'a mut Bytes<'b>) -> Bytes8<'a, 'b> { + Bytes8 { + bytes: bytes, + pos: 0, + } + } + + #[cfg(not(debug_assertions))] + #[inline] + fn assert_pos(&mut self, _pos: usize) { + } + + #[cfg(debug_assertions)] + #[inline] + fn assert_pos(&mut self, pos: usize) { + assert!(self.pos == pos); + self.po |