Bug 1660745 - Update encoding_rs to 0.8.31 and packed_simd to 0.3.7. r=hsivonen

Differential Revision: https://phabricator.services.mozilla.com/D88002
This commit is contained in:
Mike Hommey 2022-04-20 06:24:28 +00:00
parent ee81fcef78
commit 6b078d7de3
261 changed files with 3215 additions and 1551 deletions

View file

@ -70,7 +70,7 @@ rev = "746743227485a83123784df0c53227ab466612ed"
[source."https://github.com/hsivonen/packed_simd"] [source."https://github.com/hsivonen/packed_simd"]
git = "https://github.com/hsivonen/packed_simd" git = "https://github.com/hsivonen/packed_simd"
replace-with = "vendored-sources" replace-with = "vendored-sources"
rev = "8b4bd7d8229660a749dbe419a57ea01df9de5453" rev = "c149d0a519bf878567c7630096737669ec2ff15f"
[source."https://github.com/hsivonen/chardetng_c"] [source."https://github.com/hsivonen/chardetng_c"]
git = "https://github.com/hsivonen/chardetng_c" git = "https://github.com/hsivonen/chardetng_c"

17
Cargo.lock generated
View file

@ -1427,12 +1427,12 @@ dependencies = [
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.22" version = "0.8.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd8d03faa7fe0c1431609dfad7bbe827af30f82e1e2ae6f7ee4fca6bd764bc28" checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b"
dependencies = [ dependencies = [
"cfg-if 0.1.10", "cfg-if 1.0.0",
"packed_simd", "packed_simd_2",
] ]
[[package]] [[package]]
@ -3790,12 +3790,11 @@ dependencies = [
] ]
[[package]] [[package]]
name = "packed_simd" name = "packed_simd_2"
version = "0.3.4" version = "0.3.7"
source = "git+https://github.com/hsivonen/packed_simd?rev=8b4bd7d8229660a749dbe419a57ea01df9de5453#8b4bd7d8229660a749dbe419a57ea01df9de5453" source = "git+https://github.com/hsivonen/packed_simd?rev=c149d0a519bf878567c7630096737669ec2ff15f#c149d0a519bf878567c7630096737669ec2ff15f"
dependencies = [ dependencies = [
"cfg-if 0.1.10", "cfg-if 1.0.0",
"rustc_version",
] ]
[[package]] [[package]]

View file

@ -109,7 +109,7 @@ chardetng = { git = "https://github.com/hsivonen/chardetng", rev="3484d3e3ebdc89
chardetng_c = { git = "https://github.com/hsivonen/chardetng_c", rev="ed8a4c6f900a90d4dbc1d64b856e61490a1c3570" } chardetng_c = { git = "https://github.com/hsivonen/chardetng_c", rev="ed8a4c6f900a90d4dbc1d64b856e61490a1c3570" }
coremidi = { git = "https://github.com/chris-zen/coremidi.git", rev="fc68464b5445caf111e41f643a2e69ccce0b4f83" } coremidi = { git = "https://github.com/chris-zen/coremidi.git", rev="fc68464b5445caf111e41f643a2e69ccce0b4f83" }
libudev-sys = { path = "dom/webauthn/libudev-sys" } libudev-sys = { path = "dom/webauthn/libudev-sys" }
packed_simd = { git = "https://github.com/hsivonen/packed_simd", rev="8b4bd7d8229660a749dbe419a57ea01df9de5453" } packed_simd = { package = "packed_simd_2", git = "https://github.com/hsivonen/packed_simd", rev="c149d0a519bf878567c7630096737669ec2ff15f" }
midir = { git = "https://github.com/mozilla/midir.git", rev = "4c11f0ffb5d6a10de4aff40a7b81218b33b94e6f" } midir = { git = "https://github.com/mozilla/midir.git", rev = "4c11f0ffb5d6a10de4aff40a7b81218b33b94e6f" }
minidump_writer_linux = { git = "https://github.com/msirringhaus/minidump_writer_linux.git", rev = "029ac0d54b237f27dc7d8d4e51bc0fb076e5e852" } minidump_writer_linux = { git = "https://github.com/msirringhaus/minidump_writer_linux.git", rev = "029ac0d54b237f27dc7d8d4e51bc0fb076e5e852" }

View file

@ -248,7 +248,7 @@ endif
ifndef RUSTC_BOOTSTRAP ifndef RUSTC_BOOTSTRAP
RUSTC_BOOTSTRAP := mozglue_static,qcms RUSTC_BOOTSTRAP := mozglue_static,qcms
ifdef MOZ_RUST_SIMD ifdef MOZ_RUST_SIMD
RUSTC_BOOTSTRAP := $(RUSTC_BOOTSTRAP),encoding_rs,packed_simd RUSTC_BOOTSTRAP := $(RUSTC_BOOTSTRAP),encoding_rs,packed_simd_2
endif endif
export RUSTC_BOOTSTRAP export RUSTC_BOOTSTRAP
endif endif

View file

@ -346,6 +346,13 @@ Please commit or stash these changes before vendoring, or re-run with `--ignore-
we will abort if that is detected. We'll handle `/` and OR as we will abort if that is detected. We'll handle `/` and OR as
equivalent and approve is any is in our approved list.""" equivalent and approve is any is in our approved list."""
# This specific AND combination has been reviewed for encoding_rs.
if (
license_string == "(Apache-2.0 OR MIT) AND BSD-3-Clause"
and package == "encoding_rs"
):
return True
if re.search(r"\s+AND", license_string): if re.search(r"\s+AND", license_string):
return False return False

View file

@ -1,57 +0,0 @@
[textdecoder-labels.any.html]
[unicode11utf8 => UTF-8]
expected: FAIL
[ucs-2 => UTF-16LE]
expected: FAIL
[unicodefffe => UTF-16BE]
expected: FAIL
[unicode => UTF-16LE]
expected: FAIL
[csunicode => UTF-16LE]
expected: FAIL
[x-unicode20utf8 => UTF-8]
expected: FAIL
[iso-10646-ucs-2 => UTF-16LE]
expected: FAIL
[unicodefeff => UTF-16LE]
expected: FAIL
[unicode20utf8 => UTF-8]
expected: FAIL
[textdecoder-labels.any.worker.html]
[unicode11utf8 => UTF-8]
expected: FAIL
[ucs-2 => UTF-16LE]
expected: FAIL
[unicodefffe => UTF-16BE]
expected: FAIL
[unicode => UTF-16LE]
expected: FAIL
[csunicode => UTF-16LE]
expected: FAIL
[x-unicode20utf8 => UTF-8]
expected: FAIL
[iso-10646-ucs-2 => UTF-16LE]
expected: FAIL
[unicodefeff => UTF-16LE]
expected: FAIL
[unicode20utf8 => UTF-8]
expected: FAIL

File diff suppressed because one or more lines are too long

View file

@ -29,8 +29,9 @@ Please do not contribute implementations of encodings that are not specified
in the [Encoding Standard](https://encoding.spec.whatwg.org/). in the [Encoding Standard](https://encoding.spec.whatwg.org/).
For example, an implementation of UTF-7 is explicitly out of scope for this For example, an implementation of UTF-7 is explicitly out of scope for this
crate and is, therefore, provided by the [charset](https://crates.io/crates/charset) crate and is, therefore, provided by the [`charset`](https://crates.io/crates/charset)
crate instead. crate instead. For single-byte DOS encodings, please see the
[`oem_cp`](https://crates.io/crates/oem_cp) crate.
## Compatibility with Stable Rust ## Compatibility with Stable Rust

View file

@ -1,4 +1,4 @@
encoding_rs is copyright 2013-2016 Mozilla Foundation. encoding_rs is copyright Mozilla Foundation.
Licensed under the Apache License, Version 2.0 Licensed under the Apache License, Version 2.0
<LICENSE-APACHE or <LICENSE-APACHE or
@ -8,5 +8,10 @@ at your option. All files in the project carrying such
notice may not be copied, modified, or distributed except notice may not be copied, modified, or distributed except
according to those terms. according to those terms.
This crate includes data derived from the data files supplied
with the WHATWG Encoding Standard, which, when incorporated into
source code, are licensed under the BSD 3-Clause License
<LICENSE-WHATWG>.
Test code within encoding_rs is dedicated to the Public Domain when so Test code within encoding_rs is dedicated to the Public Domain when so
designated (see the individual files for PD/CC0-dedicated sections). designated (see the individual files for PD/CC0-dedicated sections).

View file

@ -3,37 +3,51 @@
# When uploading crates to the registry Cargo will automatically # When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility # "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies # with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies # to registry (e.g., crates.io) dependencies.
# #
# If you believe there's an error in this file please file an # If you are reading this file be aware that the original Cargo.toml
# issue against the rust-lang/cargo repository. If you're # will likely look very different (and much more reasonable).
# editing this file be aware that the upstream Cargo.toml # See Cargo.toml.orig for the original contents.
# will likely look very different (and much more reasonable)
[package] [package]
edition = "2018"
name = "encoding_rs" name = "encoding_rs"
version = "0.8.22" version = "0.8.31"
authors = ["Henri Sivonen <hsivonen@hsivonen.fi>"] authors = ["Henri Sivonen <hsivonen@hsivonen.fi>"]
description = "A Gecko-oriented implementation of the Encoding Standard" description = "A Gecko-oriented implementation of the Encoding Standard"
homepage = "https://docs.rs/encoding_rs/" homepage = "https://docs.rs/encoding_rs/"
documentation = "https://docs.rs/encoding_rs/" documentation = "https://docs.rs/encoding_rs/"
readme = "README.md" readme = "README.md"
keywords = ["encoding", "web", "unicode", "charset"] keywords = [
categories = ["text-processing", "encoding", "web-programming", "internationalization"] "encoding",
license = "MIT/Apache-2.0" "web",
"unicode",
"charset",
]
categories = [
"text-processing",
"encoding",
"web-programming",
"internationalization",
]
license = "(Apache-2.0 OR MIT) AND BSD-3-Clause"
repository = "https://github.com/hsivonen/encoding_rs" repository = "https://github.com/hsivonen/encoding_rs"
[profile.release] [profile.release]
lto = true lto = true
[dependencies.cfg-if] [dependencies.cfg-if]
version = "0.1.0" version = "1.0"
[dependencies.packed_simd] [dependencies.packed_simd]
version = "0.3.3" version = "0.3.4"
optional = true optional = true
package = "packed_simd_2"
[dependencies.serde] [dependencies.serde]
version = "1.0" version = "1.0"
optional = true optional = true
[dev-dependencies.bincode] [dev-dependencies.bincode]
version = "1.0" version = "1.0"
@ -44,15 +58,27 @@ version = "1.0"
version = "1.0" version = "1.0"
[features] [features]
alloc = []
default = ["alloc"]
fast-big5-hanzi-encode = [] fast-big5-hanzi-encode = []
fast-gb-hanzi-encode = [] fast-gb-hanzi-encode = []
fast-hangul-encode = [] fast-hangul-encode = []
fast-hanja-encode = [] fast-hanja-encode = []
fast-kanji-encode = [] fast-kanji-encode = []
fast-legacy-encode = ["fast-hangul-encode", "fast-hanja-encode", "fast-kanji-encode", "fast-gb-hanzi-encode", "fast-big5-hanzi-encode"] fast-legacy-encode = [
"fast-hangul-encode",
"fast-hanja-encode",
"fast-kanji-encode",
"fast-gb-hanzi-encode",
"fast-big5-hanzi-encode",
]
less-slow-big5-hanzi-encode = [] less-slow-big5-hanzi-encode = []
less-slow-gb-hanzi-encode = [] less-slow-gb-hanzi-encode = []
less-slow-kanji-encode = [] less-slow-kanji-encode = []
simd-accel = ["packed_simd", "packed_simd/into_bits"] simd-accel = [
"packed_simd",
"packed_simd/into_bits",
]
[badges.travis-ci] [badges.travis-ci]
repository = "hsivonen/encoding_rs" repository = "hsivonen/encoding_rs"

View file

@ -1,4 +1,4 @@
Copyright (c) 2013-2016 Mozilla Foundation Copyright Mozilla Foundation
Permission is hereby granted, free of charge, to any Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated person obtaining a copy of this software and associated

View file

@ -0,0 +1,26 @@
Copyright © WHATWG (Apple, Google, Mozilla, Microsoft).
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View file

@ -1,13 +1,18 @@
# encoding_rs # encoding_rs
[![Build Status](https://travis-ci.org/hsivonen/encoding_rs.svg?branch=master)](https://travis-ci.org/hsivonen/encoding_rs) [![Build Status](https://travis-ci.org/hsivonen/encoding_rs.svg?branch=master)](https://travis-ci.org/hsivonen/encoding_rs)
[![crates.io](https://meritbadge.herokuapp.com/encoding_rs)](https://crates.io/crates/encoding_rs) [![crates.io](https://img.shields.io/crates/v/encoding_rs.svg)](https://crates.io/crates/encoding_rs)
[![docs.rs](https://docs.rs/encoding_rs/badge.svg)](https://docs.rs/encoding_rs/) [![docs.rs](https://docs.rs/encoding_rs/badge.svg)](https://docs.rs/encoding_rs/)
[![Apache 2 / MIT dual-licensed](https://img.shields.io/badge/license-Apache%202%20%2F%20MIT-blue.svg)](https://github.com/hsivonen/encoding_rs/blob/master/COPYRIGHT)
encoding_rs an implementation of the (non-JavaScript parts of) the encoding_rs an implementation of the (non-JavaScript parts of) the
[Encoding Standard](https://encoding.spec.whatwg.org/) written in Rust and [Encoding Standard](https://encoding.spec.whatwg.org/) written in Rust.
used in Gecko (starting with Firefox 56).
The Encoding Standard defines the Web-compatible set of character encodings,
which means this crate can be used to decode Web content. encoding_rs is
used in Gecko starting with Firefox 56. Due to the notable overlap between
the legacy encodings on the Web and the legacy encodings used on Windows,
this crate may be of use for non-Web-related situations as well; see below
for links to adjacent crates.
Additionally, the `mem` module provides various operations for dealing with Additionally, the `mem` module provides various operations for dealing with
in-RAM text (as opposed to data that's coming from or going to an IO boundary). in-RAM text (as opposed to data that's coming from or going to an IO boundary).
@ -75,6 +80,13 @@ a `std::io::Read`, decode it into UTF-8 and presenting the result via
`std::io::Read`. The [`encoding_rs_io`](https://crates.io/crates/encoding_rs_io) `std::io::Read`. The [`encoding_rs_io`](https://crates.io/crates/encoding_rs_io)
crate provides that capability. crate provides that capability.
## `no_std` Environment
The crate works in a `no_std` environment. By default, the `alloc` feature,
which assumes that an allocator is present is enabled. For a no-allocator
environment, the default features (i.e. `alloc`) can be turned off. This
makes the part of the API that returns `Vec`/`String`/`Cow` unavailable.
## Decoding Email ## Decoding Email
For decoding character encodings that occur in email, use the For decoding character encodings that occur in email, use the
@ -86,6 +98,11 @@ one directly. (It wraps this crate and adds UTF-7 decoding.)
For mappings to and from Windows code page identifiers, use the For mappings to and from Windows code page identifiers, use the
[`codepage`](https://crates.io/crates/codepage) crate. [`codepage`](https://crates.io/crates/codepage) crate.
## DOS Encodings
This crate does not support single-byte DOS encodings that aren't required by
the Web Platform, but the [`oem_cp`](https://crates.io/crates/oem_cp) crate does.
## Preparing Text for the Encoders ## Preparing Text for the Encoders
Normalizing text into Unicode Normalization Form C prior to encoding text into Normalizing text into Unicode Normalization Form C prior to encoding text into
@ -100,9 +117,20 @@ characters. Vietnamese tone marks can be decomposed using the
## Licensing ## Licensing
TL;DR: `(Apache-2.0 OR MIT) AND BSD-3-Clause` for the code and data combination.
Please see the file named Please see the file named
[COPYRIGHT](https://github.com/hsivonen/encoding_rs/blob/master/COPYRIGHT). [COPYRIGHT](https://github.com/hsivonen/encoding_rs/blob/master/COPYRIGHT).
The non-test code that isn't generated from the WHATWG data in this crate is
under Apache-2.0 OR MIT. Test code is under CC0.
This crate contains code/data generated from WHATWG-supplied data. The WHATWG
upstream changed its license for portions of specs incorporated into source code
from CC0 to BSD-3-Clause between the initial release of this crate and the present
version of this crate. The in-source licensing legends have been updated for the
parts of the generated code that have changed since the upstream license change.
## Documentation ## Documentation
Generated [API documentation](https://docs.rs/encoding_rs/) is available Generated [API documentation](https://docs.rs/encoding_rs/) is available
@ -139,7 +167,7 @@ There are currently these optional cargo features:
### `simd-accel` ### `simd-accel`
Enables SIMD acceleration using the nightly-dependent `packed_simd` crate. Enables SIMD acceleration using the nightly-dependent `packed_simd_2` crate.
This is an opt-in feature, because enabling this feature _opts out_ of Rust's This is an opt-in feature, because enabling this feature _opts out_ of Rust's
guarantees of future compilers compiling old code (aka. "stability story"). guarantees of future compilers compiling old code (aka. "stability story").
@ -160,7 +188,7 @@ feature.
_Note!_ If you are compiling for a target that does not have 128-bit SIMD _Note!_ If you are compiling for a target that does not have 128-bit SIMD
enabled as part of the target definition and you are enabling 128-bit SIMD enabled as part of the target definition and you are enabling 128-bit SIMD
using `-C target_feature`, you need to enable the `core_arch` Cargo feature using `-C target_feature`, you need to enable the `core_arch` Cargo feature
for `packed_simd` to compile a crates.io snapshot of `core_arch` instead of for `packed_simd_2` to compile a crates.io snapshot of `core_arch` instead of
using the standard-library copy of `core::arch`, because the `core::arch` using the standard-library copy of `core::arch`, because the `core::arch`
module of the pre-compiled standard library has been compiled with the module of the pre-compiled standard library has been compiled with the
assumption that the CPU doesn't have 128-bit SIMD. At present this applies assumption that the CPU doesn't have 128-bit SIMD. At present this applies
@ -345,16 +373,16 @@ A framework for measuring performance is [available separately][2].
## Rust Version Compatibility ## Rust Version Compatibility
It is a goal to support the latest stable Rust, the latest nightly Rust and It is a goal to support the latest stable Rust, the latest nightly Rust and
the version of Rust that's used for Firefox Nightly (currently 1.29.0). the version of Rust that's used for Firefox Nightly.
These are tested on Travis.
Additionally, beta and the oldest known to work Rust version (currently At this time, there is no firm commitment to support a version older than
1.29.0) are tested on Travis. The oldest Rust known to work is tested as what's required by Firefox, and there is no commitment to treat MSRV changes
a canary so that when the oldest known to work no longer works, the change as semver-breaking, because this crate depends on `cfg-if`, which doesn't
can be documented here. At this time, there is no firm commitment to support appear to treat MSRV changes as semver-breaking, so it would be useless for
a version older than what's required by Firefox. The oldest supported Rust this crate to treat MSRV changes as semver-breaking.
is expected to move forward rapidly when `packed_simd` can replace the `simd`
crate without performance regression. As of 2021-02-04, MSRV appears to be Rust 1.36.0 for using the crate and
1.42.0 for doc tests to pass without errors about the global allocator.
## Compatibility with rust-encoding ## Compatibility with rust-encoding
@ -376,7 +404,10 @@ To regenerate the generated code:
next to the `encoding_rs` directory. next to the `encoding_rs` directory.
* Clone [`https://github.com/whatwg/encoding`](https://github.com/whatwg/encoding) * Clone [`https://github.com/whatwg/encoding`](https://github.com/whatwg/encoding)
next to the `encoding_rs` directory. next to the `encoding_rs` directory.
* Checkout revision `f381389` of the `encoding` repo. * Checkout revision `be3337450e7df1c49dca7872153c4c4670dd8256` of the `encoding` repo.
(Note: `f381389` was the revision of `encoding` used from before the `encoding` repo
license change. So far, only output changed since then has been updated to
the new license legend.)
* With the `encoding_rs` directory as the working directory, run * With the `encoding_rs` directory as the working directory, run
`python generate-encoding-data.py`. `python generate-encoding-data.py`.
@ -414,14 +445,56 @@ To regenerate the generated code:
adapted to Rust in rust-encoding.~ adapted to Rust in rust-encoding.~
- [x] Add actually fast CJK encode options. - [x] Add actually fast CJK encode options.
- [ ] ~Investigate [Bob Steagall's lookup table acceleration for UTF-8](https://github.com/BobSteagall/CppNow2018/blob/master/FastConversionFromUTF-8/Fast%20Conversion%20From%20UTF-8%20with%20C%2B%2B%2C%20DFAs%2C%20and%20SSE%20Intrinsics%20-%20Bob%20Steagall%20-%20C%2B%2BNow%202018.pdf).~ - [ ] ~Investigate [Bob Steagall's lookup table acceleration for UTF-8](https://github.com/BobSteagall/CppNow2018/blob/master/FastConversionFromUTF-8/Fast%20Conversion%20From%20UTF-8%20with%20C%2B%2B%2C%20DFAs%2C%20and%20SSE%20Intrinsics%20-%20Bob%20Steagall%20-%20C%2B%2BNow%202018.pdf).~
- [ ] Provide a build mode that works without `alloc` (with lesser API surface).
- [ ] Migrate to `std::simd` once it is stable and declare 1.0.
## Release Notes ## Release Notes
## 0.8.22 ### 0.8.31
* Use SPDX with parentheses now that crates.io supports parentheses.
### 0.8.30
* Update the licensing information to take into account the WHATWG data license change.
### 0.8.29
* Make the parts that use an allocator optional.
### 0.8.28
* Fix error in Serde support introduced as part of `no_std` support.
### 0.8.27
* Make the crate works in a `no_std` environment (with `alloc`).
### 0.8.26
* Fix oversights in edition 2018 migration that broke the `simd-accel` feature.
### 0.8.25
* Do pointer alignment checks in a way where intermediate steps aren't defined to be Undefined Behavior.
* Update the `packed_simd` dependency to `packed_simd_2`.
* Update the `cfg-if` dependency to 1.0.
* Address warnings that have been introduced by newer Rust versions along the way.
* Update to edition 2018, since even prior to 1.0 `cfg-if` updated to edition 2018 without a semver break.
### 0.8.24
* Avoid computing an intermediate (not dereferenced) pointer value in a manner designated as Undefined Behavior when computing pointer alignment.
### 0.8.23
* Remove year from copyright notices. (No features or bug fixes.)
### 0.8.22
* Formatting fix and new unit test. (No features or bug fixes.) * Formatting fix and new unit test. (No features or bug fixes.)
## 0.8.21 ### 0.8.21
* Fixed a panic with invalid UTF-16[BE|LE] input at the end of the stream. * Fixed a panic with invalid UTF-16[BE|LE] input at the end of the stream.

14
third_party/rust/encoding_rs/ci/miri.sh vendored Normal file
View file

@ -0,0 +1,14 @@
set -ex
# Install Miri.
MIRI_NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri)
echo "Installing latest nightly with Miri: $MIRI_NIGHTLY"
rustup default "$MIRI_NIGHTLY"
rustup component add miri
# Run tests.
# Stacked Borrows is disabled as it costs too much RAM (due to our large tables).
MIRIFLAGS="-Zmiri-disable-stacked-borrows" cargo miri test
# Restore old state in case Travis uses this cache for other jobs.
rustup default nightly

View file

@ -1,6 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
# Copyright 2013-2016 Mozilla Foundation. See the COPYRIGHT # Copyright Mozilla Foundation. See the COPYRIGHT
# file at the top-level directory of this distribution. # file at the top-level directory of this distribution.
# #
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -1171,7 +1171,7 @@ data_file.close()
# Variant # Variant
variant_file = open("src/variant.rs", "w") variant_file = open("src/variant.rs", "w")
variant_file.write('''// Copyright 2015-2016 Mozilla Foundation. See the COPYRIGHT variant_file.write('''// Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -1446,12 +1446,20 @@ single_byte_file.write("""
#[test] #[test]
fn test_single_byte_decode() {""") fn test_single_byte_decode() {""")
idx = 0 # for Miri, return after 2nd test
for name in preferred: for name in preferred:
if name == u"ISO-8859-8-I": if name == u"ISO-8859-8-I":
continue; continue;
if is_single_byte(name): if is_single_byte(name):
single_byte_file.write(""" single_byte_file.write("""
decode_single_byte(%s, &data::SINGLE_BYTE_DATA.%s);""" % (to_constant_name(name), to_snake_name(name))) decode_single_byte(%s, &data::SINGLE_BYTE_DATA.%s);""" % (to_constant_name(name), to_snake_name(name)))
idx += 1
if idx == 2:
single_byte_file.write("""
if cfg!(miri) {
// Miri is too slow
return;
}""")
single_byte_file.write(""" single_byte_file.write("""
} }
@ -1459,12 +1467,21 @@ single_byte_file.write("""
#[test] #[test]
fn test_single_byte_encode() {""") fn test_single_byte_encode() {""")
idx = 0 # for Miri, return after 2nd test
for name in preferred: for name in preferred:
if name == u"ISO-8859-8-I": if name == u"ISO-8859-8-I":
continue; continue;
if is_single_byte(name): if is_single_byte(name):
single_byte_file.write(""" single_byte_file.write("""
encode_single_byte(%s, &data::SINGLE_BYTE_DATA.%s);""" % (to_constant_name(name), to_snake_name(name))) encode_single_byte(%s, &data::SINGLE_BYTE_DATA.%s);""" % (to_constant_name(name), to_snake_name(name)))
idx += 1
if idx == 2:
single_byte_file.write("""
if cfg!(miri) {
// Miri is too slow
return;
}""")
single_byte_file.write(""" single_byte_file.write("""
@ -1476,7 +1493,7 @@ single_byte_file.close()
static_file = open("../encoding_c/include/encoding_rs_statics.h", "w") static_file = open("../encoding_c/include/encoding_rs_statics.h", "w")
static_file.write("""// Copyright 2016 Mozilla Foundation. See the COPYRIGHT static_file.write("""// Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or

View file

@ -1,4 +1,4 @@
// Copyright 2016 Mozilla Foundation. See the COPYRIGHT // Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -29,14 +29,14 @@
all(target_endian = "little", target_feature = "neon") all(target_endian = "little", target_feature = "neon")
) )
))] ))]
use simd_funcs::*; use crate::simd_funcs::*;
cfg_if! { cfg_if! {
if #[cfg(feature = "simd-accel")] { if #[cfg(feature = "simd-accel")] {
#[allow(unused_imports)] #[allow(unused_imports)]
use ::std::intrinsics::unlikely; use ::core::intrinsics::unlikely;
#[allow(unused_imports)] #[allow(unused_imports)]
use ::std::intrinsics::likely; use ::core::intrinsics::likely;
} else { } else {
#[allow(dead_code)] #[allow(dead_code)]
#[inline(always)] #[inline(always)]
@ -103,7 +103,7 @@ macro_rules! ascii_alu {
let mut until_alignment = { let mut until_alignment = {
// Check if the other unit aligns if we move the narrower unit // Check if the other unit aligns if we move the narrower unit
// to alignment. // to alignment.
// if ::std::mem::size_of::<$src_unit>() == ::std::mem::size_of::<$dst_unit>() { // if ::core::mem::size_of::<$src_unit>() == ::core::mem::size_of::<$dst_unit>() {
// ascii_to_ascii // ascii_to_ascii
let src_alignment = (src as usize) & ALU_ALIGNMENT_MASK; let src_alignment = (src as usize) & ALU_ALIGNMENT_MASK;
let dst_alignment = (dst as usize) & ALU_ALIGNMENT_MASK; let dst_alignment = (dst as usize) & ALU_ALIGNMENT_MASK;
@ -111,7 +111,7 @@ macro_rules! ascii_alu {
break; break;
} }
(ALU_ALIGNMENT - src_alignment) & ALU_ALIGNMENT_MASK (ALU_ALIGNMENT - src_alignment) & ALU_ALIGNMENT_MASK
// } else if ::std::mem::size_of::<$src_unit>() < ::std::mem::size_of::<$dst_unit>() { // } else if ::core::mem::size_of::<$src_unit>() < ::core::mem::size_of::<$dst_unit>() {
// ascii_to_basic_latin // ascii_to_basic_latin
// let src_until_alignment = (ALIGNMENT - ((src as usize) & ALIGNMENT_MASK)) & ALIGNMENT_MASK; // let src_until_alignment = (ALIGNMENT - ((src as usize) & ALIGNMENT_MASK)) & ALIGNMENT_MASK;
// if (dst.add(src_until_alignment) as usize) & ALIGNMENT_MASK != 0 { // if (dst.add(src_until_alignment) as usize) & ALIGNMENT_MASK != 0 {
@ -197,7 +197,7 @@ macro_rules! basic_latin_alu {
let mut until_alignment = { let mut until_alignment = {
// Check if the other unit aligns if we move the narrower unit // Check if the other unit aligns if we move the narrower unit
// to alignment. // to alignment.
// if ::std::mem::size_of::<$src_unit>() == ::std::mem::size_of::<$dst_unit>() { // if ::core::mem::size_of::<$src_unit>() == ::core::mem::size_of::<$dst_unit>() {
// ascii_to_ascii // ascii_to_ascii
// let src_alignment = (src as usize) & ALIGNMENT_MASK; // let src_alignment = (src as usize) & ALIGNMENT_MASK;
// let dst_alignment = (dst as usize) & ALIGNMENT_MASK; // let dst_alignment = (dst as usize) & ALIGNMENT_MASK;
@ -206,12 +206,14 @@ macro_rules! basic_latin_alu {
// } // }
// (ALIGNMENT - src_alignment) & ALIGNMENT_MASK // (ALIGNMENT - src_alignment) & ALIGNMENT_MASK
// } else // } else
if ::std::mem::size_of::<$src_unit>() < ::std::mem::size_of::<$dst_unit>() { if ::core::mem::size_of::<$src_unit>() < ::core::mem::size_of::<$dst_unit>() {
// ascii_to_basic_latin // ascii_to_basic_latin
let src_until_alignment = (ALU_ALIGNMENT let src_until_alignment = (ALU_ALIGNMENT
- ((src as usize) & ALU_ALIGNMENT_MASK)) - ((src as usize) & ALU_ALIGNMENT_MASK))
& ALU_ALIGNMENT_MASK; & ALU_ALIGNMENT_MASK;
if (dst.add(src_until_alignment) as usize) & ALU_ALIGNMENT_MASK != 0 { if (dst.wrapping_add(src_until_alignment) as usize) & ALU_ALIGNMENT_MASK
!= 0
{
break; break;
} }
src_until_alignment src_until_alignment
@ -220,7 +222,9 @@ macro_rules! basic_latin_alu {
let dst_until_alignment = (ALU_ALIGNMENT let dst_until_alignment = (ALU_ALIGNMENT
- ((dst as usize) & ALU_ALIGNMENT_MASK)) - ((dst as usize) & ALU_ALIGNMENT_MASK))
& ALU_ALIGNMENT_MASK; & ALU_ALIGNMENT_MASK;
if (src.add(dst_until_alignment) as usize) & ALU_ALIGNMENT_MASK != 0 { if (src.wrapping_add(dst_until_alignment) as usize) & ALU_ALIGNMENT_MASK
!= 0
{
break; break;
} }
dst_until_alignment dst_until_alignment
@ -286,12 +290,14 @@ macro_rules! latin1_alu {
// This loop is only broken out of as a `goto` forward // This loop is only broken out of as a `goto` forward
loop { loop {
let mut until_alignment = { let mut until_alignment = {
if ::std::mem::size_of::<$src_unit>() < ::std::mem::size_of::<$dst_unit>() { if ::core::mem::size_of::<$src_unit>() < ::core::mem::size_of::<$dst_unit>() {
// unpack // unpack
let src_until_alignment = (ALU_ALIGNMENT let src_until_alignment = (ALU_ALIGNMENT
- ((src as usize) & ALU_ALIGNMENT_MASK)) - ((src as usize) & ALU_ALIGNMENT_MASK))
& ALU_ALIGNMENT_MASK; & ALU_ALIGNMENT_MASK;
if (dst.add(src_until_alignment) as usize) & ALU_ALIGNMENT_MASK != 0 { if (dst.wrapping_add(src_until_alignment) as usize) & ALU_ALIGNMENT_MASK
!= 0
{
break; break;
} }
src_until_alignment src_until_alignment
@ -300,7 +306,9 @@ macro_rules! latin1_alu {
let dst_until_alignment = (ALU_ALIGNMENT let dst_until_alignment = (ALU_ALIGNMENT
- ((dst as usize) & ALU_ALIGNMENT_MASK)) - ((dst as usize) & ALU_ALIGNMENT_MASK))
& ALU_ALIGNMENT_MASK; & ALU_ALIGNMENT_MASK;
if (src.add(dst_until_alignment) as usize) & ALU_ALIGNMENT_MASK != 0 { if (src.wrapping_add(dst_until_alignment) as usize) & ALU_ALIGNMENT_MASK
!= 0
{
break; break;
} }
dst_until_alignment dst_until_alignment
@ -439,7 +447,7 @@ macro_rules! ascii_simd_check_align_unrolled {
dst: *mut $dst_unit, dst: *mut $dst_unit,
len: usize, len: usize,
) -> Option<($src_unit, usize)> { ) -> Option<($src_unit, usize)> {
let unit_size = ::std::mem::size_of::<$src_unit>(); let unit_size = ::core::mem::size_of::<$src_unit>();
let mut offset = 0usize; let mut offset = 0usize;
// This loop is only broken out of as a goto forward without // This loop is only broken out of as a goto forward without
// actually looping // actually looping
@ -621,7 +629,7 @@ macro_rules! latin1_simd_check_align_unrolled {
) => { ) => {
#[inline(always)] #[inline(always)]
pub unsafe fn $name(src: *const $src_unit, dst: *mut $dst_unit, len: usize) { pub unsafe fn $name(src: *const $src_unit, dst: *mut $dst_unit, len: usize) {
let unit_size = ::std::mem::size_of::<$src_unit>(); let unit_size = ::core::mem::size_of::<$src_unit>();
let mut offset = 0usize; let mut offset = 0usize;
if SIMD_STRIDE_SIZE <= len { if SIMD_STRIDE_SIZE <= len {
let mut until_alignment = ((SIMD_STRIDE_SIZE let mut until_alignment = ((SIMD_STRIDE_SIZE
@ -1500,9 +1508,10 @@ pub fn iso_2022_jp_ascii_valid_up_to(bytes: &[u8]) -> usize {
// Any copyright to the test code below this comment is dedicated to the // Any copyright to the test code below this comment is dedicated to the
// Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ // Public Domain. http://creativecommons.org/publicdomain/zero/1.0/
#[cfg(test)] #[cfg(all(test, feature = "alloc"))]
mod tests { mod tests {
use super::*; use super::*;
use alloc::vec::Vec;
macro_rules! test_ascii { macro_rules! test_ascii {
($test_name:ident, $fn_tested:ident, $src_unit:ty, $dst_unit:ty) => { ($test_name:ident, $fn_tested:ident, $src_unit:ty, $dst_unit:ty) => {

View file

@ -1,4 +1,4 @@
// Copyright 2015-2016 Mozilla Foundation. See the COPYRIGHT // Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -8,9 +8,9 @@
// except according to those terms. // except according to those terms.
use super::*; use super::*;
use data::*; use crate::data::*;
use handles::*; use crate::handles::*;
use variant::*; use crate::variant::*;
// Rust 1.14.0 requires the following despite the asterisk above. // Rust 1.14.0 requires the following despite the asterisk above.
use super::in_inclusive_range32; use super::in_inclusive_range32;
@ -263,7 +263,7 @@ impl Big5Encoder {
// Any copyright to the test code below this comment is dedicated to the // Any copyright to the test code below this comment is dedicated to the
// Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ // Public Domain. http://creativecommons.org/publicdomain/zero/1.0/
#[cfg(test)] #[cfg(all(test, feature = "alloc"))]
mod tests { mod tests {
use super::super::testing::*; use super::super::testing::*;
use super::super::*; use super::super::*;
@ -365,18 +365,21 @@ mod tests {
// ASCII // ASCII
encode_big5("\u{0061}\u{0062}", b"\x61\x62"); encode_big5("\u{0061}\u{0062}", b"\x61\x62");
// Edge cases if !cfg!(miri) {
encode_big5("\u{9EA6}\u{0061}", b"&#40614;\x61"); // Miri is too slow
encode_big5("\u{2626B}\u{0061}", b"&#156267;\x61"); // Edge cases
encode_big5("\u{3000}", b"\xA1\x40"); encode_big5("\u{9EA6}\u{0061}", b"&#40614;\x61");
encode_big5("\u{20AC}", b"\xA3\xE1"); encode_big5("\u{2626B}\u{0061}", b"&#156267;\x61");
encode_big5("\u{4E00}", b"\xA4\x40"); encode_big5("\u{3000}", b"\xA1\x40");
encode_big5("\u{27607}", b"\xC8\xA4"); encode_big5("\u{20AC}", b"\xA3\xE1");
encode_big5("\u{FFE2}", b"\xC8\xCD"); encode_big5("\u{4E00}", b"\xA4\x40");
encode_big5("\u{79D4}", b"\xFE\xFE"); encode_big5("\u{27607}", b"\xC8\xA4");
encode_big5("\u{FFE2}", b"\xC8\xCD");
encode_big5("\u{79D4}", b"\xFE\xFE");
// Not in index // Not in index
encode_big5("\u{2603}\u{0061}", b"&#9731;\x61"); encode_big5("\u{2603}\u{0061}", b"&#9731;\x61");
}
// duplicate low bits // duplicate low bits
encode_big5("\u{203B5}", b"\xFD\x6A"); encode_big5("\u{203B5}", b"\xFD\x6A");
@ -387,6 +390,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_big5_decode_all() { fn test_big5_decode_all() {
let input = include_bytes!("test_data/big5_in.txt"); let input = include_bytes!("test_data/big5_in.txt");
let expectation = include_str!("test_data/big5_in_ref.txt"); let expectation = include_str!("test_data/big5_in_ref.txt");
@ -396,6 +400,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_big5_encode_all() { fn test_big5_encode_all() {
let input = include_str!("test_data/big5_out.txt"); let input = include_str!("test_data/big5_out.txt");
let expectation = include_bytes!("test_data/big5_out_ref.txt"); let expectation = include_bytes!("test_data/big5_out_ref.txt");
@ -406,6 +411,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_big5_encode_from_two_low_surrogates() { fn test_big5_encode_from_two_low_surrogates() {
let expectation = b"&#65533;&#65533;"; let expectation = b"&#65533;&#65533;";
let mut output = [0u8; 40]; let mut output = [0u8; 40];

View file

@ -1,4 +1,4 @@
// Copyright 2015-2016 Mozilla Foundation. See the COPYRIGHT // Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or

View file

@ -1,4 +1,4 @@
// Copyright 2015-2016 Mozilla Foundation. See the COPYRIGHT // Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -8,9 +8,9 @@
// except according to those terms. // except according to those terms.
use super::*; use super::*;
use data::*; use crate::data::*;
use handles::*; use crate::handles::*;
use variant::*; use crate::variant::*;
// Rust 1.14.0 requires the following despite the asterisk above. // Rust 1.14.0 requires the following despite the asterisk above.
use super::in_inclusive_range16; use super::in_inclusive_range16;
@ -346,7 +346,7 @@ impl EucJpEncoder {
// Any copyright to the test code below this comment is dedicated to the // Any copyright to the test code below this comment is dedicated to the
// Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ // Public Domain. http://creativecommons.org/publicdomain/zero/1.0/
#[cfg(test)] #[cfg(all(test, feature = "alloc"))]
mod tests { mod tests {
use super::super::testing::*; use super::super::testing::*;
use super::super::*; use super::super::*;
@ -437,6 +437,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_jis0208_decode_all() { fn test_jis0208_decode_all() {
let input = include_bytes!("test_data/jis0208_in.txt"); let input = include_bytes!("test_data/jis0208_in.txt");
let expectation = include_str!("test_data/jis0208_in_ref.txt"); let expectation = include_str!("test_data/jis0208_in_ref.txt");
@ -446,6 +447,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_jis0208_encode_all() { fn test_jis0208_encode_all() {
let input = include_str!("test_data/jis0208_out.txt"); let input = include_str!("test_data/jis0208_out.txt");
let expectation = include_bytes!("test_data/jis0208_out_ref.txt"); let expectation = include_bytes!("test_data/jis0208_out_ref.txt");
@ -456,6 +458,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_jis0212_decode_all() { fn test_jis0212_decode_all() {
let input = include_bytes!("test_data/jis0212_in.txt"); let input = include_bytes!("test_data/jis0212_in.txt");
let expectation = include_str!("test_data/jis0212_in_ref.txt"); let expectation = include_str!("test_data/jis0212_in_ref.txt");

View file

@ -1,4 +1,4 @@
// Copyright 2015-2016 Mozilla Foundation. See the COPYRIGHT // Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -8,9 +8,9 @@
// except according to those terms. // except according to those terms.
use super::*; use super::*;
use data::*; use crate::data::*;
use handles::*; use crate::handles::*;
use variant::*; use crate::variant::*;
// Rust 1.14.0 requires the following despite the asterisk above. // Rust 1.14.0 requires the following despite the asterisk above.
use super::in_inclusive_range16; use super::in_inclusive_range16;
use super::in_range16; use super::in_range16;
@ -362,7 +362,7 @@ impl EucKrEncoder {
// Any copyright to the test code below this comment is dedicated to the // Any copyright to the test code below this comment is dedicated to the
// Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ // Public Domain. http://creativecommons.org/publicdomain/zero/1.0/
#[cfg(test)] #[cfg(all(test, feature = "alloc"))]
mod tests { mod tests {
use super::super::testing::*; use super::super::testing::*;
use super::super::*; use super::super::*;
@ -406,6 +406,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_euc_kr_decode_all() { fn test_euc_kr_decode_all() {
let input = include_bytes!("test_data/euc_kr_in.txt"); let input = include_bytes!("test_data/euc_kr_in.txt");
let expectation = include_str!("test_data/euc_kr_in_ref.txt"); let expectation = include_str!("test_data/euc_kr_in_ref.txt");
@ -415,6 +416,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_euc_kr_encode_all() { fn test_euc_kr_encode_all() {
let input = include_str!("test_data/euc_kr_out.txt"); let input = include_str!("test_data/euc_kr_out.txt");
let expectation = include_bytes!("test_data/euc_kr_out_ref.txt"); let expectation = include_bytes!("test_data/euc_kr_out_ref.txt");

View file

@ -1,4 +1,4 @@
// Copyright 2015-2016 Mozilla Foundation. See the COPYRIGHT // Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -8,9 +8,9 @@
// except according to those terms. // except according to those terms.
use super::*; use super::*;
use data::*; use crate::data::*;
use handles::*; use crate::handles::*;
use variant::*; use crate::variant::*;
// Rust 1.14.0 requires the following despite the asterisk above. // Rust 1.14.0 requires the following despite the asterisk above.
use super::in_inclusive_range16; use super::in_inclusive_range16;
use super::in_range16; use super::in_range16;
@ -571,7 +571,7 @@ impl Gb18030Encoder {
// Any copyright to the test code below this comment is dedicated to the // Any copyright to the test code below this comment is dedicated to the
// Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ // Public Domain. http://creativecommons.org/publicdomain/zero/1.0/
#[cfg(test)] #[cfg(all(test, feature = "alloc"))]
mod tests { mod tests {
use super::super::testing::*; use super::super::testing::*;
use super::super::*; use super::super::*;
@ -653,12 +653,15 @@ mod tests {
// two bytes // two bytes
encode_gb18030("\u{4E02}", b"\x81\x40"); encode_gb18030("\u{4E02}", b"\x81\x40");
encode_gb18030("\u{4E8A}", b"\x81\x7E"); encode_gb18030("\u{4E8A}", b"\x81\x7E");
encode_gb18030("\u{4E90}", b"\x81\x80"); if !cfg!(miri) {
encode_gb18030("\u{4FA2}", b"\x81\xFE"); // Miri is too slow
encode_gb18030("\u{FA0C}", b"\xFE\x40"); encode_gb18030("\u{4E90}", b"\x81\x80");
encode_gb18030("\u{E843}", b"\xFE\x7E"); encode_gb18030("\u{4FA2}", b"\x81\xFE");
encode_gb18030("\u{4723}", b"\xFE\x80"); encode_gb18030("\u{FA0C}", b"\xFE\x40");
encode_gb18030("\u{E4C5}", b"\xFE\xFE"); encode_gb18030("\u{E843}", b"\xFE\x7E");
encode_gb18030("\u{4723}", b"\xFE\x80");
encode_gb18030("\u{E4C5}", b"\xFE\xFE");
}
// The difference from the original GB18030 // The difference from the original GB18030
encode_gb18030("\u{E5E5}", b"&#58853;"); encode_gb18030("\u{E5E5}", b"&#58853;");
@ -667,9 +670,12 @@ mod tests {
// Four bytes // Four bytes
encode_gb18030("\u{0080}", b"\x81\x30\x81\x30"); encode_gb18030("\u{0080}", b"\x81\x30\x81\x30");
encode_gb18030("\u{E7C7}", b"\x81\x35\xF4\x37"); encode_gb18030("\u{E7C7}", b"\x81\x35\xF4\x37");
encode_gb18030("\u{2603}", b"\x81\x37\xA3\x30"); if !cfg!(miri) {
encode_gb18030("\u{1F4A9}", b"\x94\x39\xDA\x33"); // Miri is too slow
encode_gb18030("\u{10FFFF}", b"\xE3\x32\x9A\x35"); encode_gb18030("\u{2603}", b"\x81\x37\xA3\x30");
encode_gb18030("\u{1F4A9}", b"\x94\x39\xDA\x33");
encode_gb18030("\u{10FFFF}", b"\xE3\x32\x9A\x35");
}
// Edge cases // Edge cases
encode_gb18030("\u{00F7}", b"\xA1\xC2"); encode_gb18030("\u{00F7}", b"\xA1\xC2");
@ -689,12 +695,15 @@ mod tests {
// two bytes // two bytes
encode_gbk("\u{4E02}", b"\x81\x40"); encode_gbk("\u{4E02}", b"\x81\x40");
encode_gbk("\u{4E8A}", b"\x81\x7E"); encode_gbk("\u{4E8A}", b"\x81\x7E");
encode_gbk("\u{4E90}", b"\x81\x80"); if !cfg!(miri) {
encode_gbk("\u{4FA2}", b"\x81\xFE"); // Miri is too slow
encode_gbk("\u{FA0C}", b"\xFE\x40"); encode_gbk("\u{4E90}", b"\x81\x80");
encode_gbk("\u{E843}", b"\xFE\x7E"); encode_gbk("\u{4FA2}", b"\x81\xFE");
encode_gbk("\u{4723}", b"\xFE\x80"); encode_gbk("\u{FA0C}", b"\xFE\x40");
encode_gbk("\u{E4C5}", b"\xFE\xFE"); encode_gbk("\u{E843}", b"\xFE\x7E");
encode_gbk("\u{4723}", b"\xFE\x80");
encode_gbk("\u{E4C5}", b"\xFE\xFE");
}
// The difference from the original gb18030 // The difference from the original gb18030
encode_gbk("\u{E5E5}", b"&#58853;"); encode_gbk("\u{E5E5}", b"&#58853;");
@ -703,15 +712,19 @@ mod tests {
// Four bytes // Four bytes
encode_gbk("\u{0080}", b"&#128;"); encode_gbk("\u{0080}", b"&#128;");
encode_gbk("\u{E7C7}", b"&#59335;"); encode_gbk("\u{E7C7}", b"&#59335;");
encode_gbk("\u{2603}", b"&#9731;"); if !cfg!(miri) {
encode_gbk("\u{1F4A9}", b"&#128169;"); // Miri is too slow
encode_gbk("\u{10FFFF}", b"&#1114111;"); encode_gbk("\u{2603}", b"&#9731;");
encode_gbk("\u{1F4A9}", b"&#128169;");
encode_gbk("\u{10FFFF}", b"&#1114111;");
}
// Edge cases // Edge cases
encode_gbk("\u{00F7}", b"\xA1\xC2"); encode_gbk("\u{00F7}", b"\xA1\xC2");
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_gb18030_decode_all() { fn test_gb18030_decode_all() {
let input = include_bytes!("test_data/gb18030_in.txt"); let input = include_bytes!("test_data/gb18030_in.txt");
let expectation = include_str!("test_data/gb18030_in_ref.txt"); let expectation = include_str!("test_data/gb18030_in_ref.txt");
@ -721,6 +734,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_gb18030_encode_all() { fn test_gb18030_encode_all() {
let input = include_str!("test_data/gb18030_out.txt"); let input = include_str!("test_data/gb18030_out.txt");
let expectation = include_bytes!("test_data/gb18030_out_ref.txt"); let expectation = include_bytes!("test_data/gb18030_out_ref.txt");

View file

@ -1,4 +1,4 @@
// Copyright 2015-2016 Mozilla Foundation. See the COPYRIGHT // Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -24,7 +24,7 @@
all(target_endian = "little", target_feature = "neon") all(target_endian = "little", target_feature = "neon")
) )
))] ))]
use simd_funcs::*; use crate::simd_funcs::*;
#[cfg(all( #[cfg(all(
feature = "simd-accel", feature = "simd-accel",
@ -38,9 +38,9 @@ use packed_simd::u16x8;
use super::DecoderResult; use super::DecoderResult;
use super::EncoderResult; use super::EncoderResult;
use ascii::*; use crate::ascii::*;
use utf_8::convert_utf8_to_utf16_up_to_invalid; use crate::utf_8::convert_utf8_to_utf16_up_to_invalid;
use utf_8::utf8_valid_up_to; use crate::utf_8::utf8_valid_up_to;
pub enum Space<T> { pub enum Space<T> {
Available(T), Available(T),
@ -108,11 +108,13 @@ impl UnalignedU16Slice {
#[inline(always)] #[inline(always)]
pub fn at(&self, i: usize) -> u16 { pub fn at(&self, i: usize) -> u16 {
use core::mem::MaybeUninit;
assert!(i < self.len); assert!(i < self.len);
unsafe { unsafe {
let mut u: u16 = ::std::mem::uninitialized(); let mut u: MaybeUninit<u16> = MaybeUninit::uninit();
::std::ptr::copy_nonoverlapping(self.ptr.add(i * 2), &mut u as *mut u16 as *mut u8, 2); ::core::ptr::copy_nonoverlapping(self.ptr.add(i * 2), u.as_mut_ptr() as *mut u8, 2);
u u.assume_init()
} }
} }
@ -193,7 +195,7 @@ fn copy_unaligned_basic_latin_to_ascii_alu<E: Endian>(
dst: &mut [u8], dst: &mut [u8],
offset: usize, offset: usize,
) -> CopyAsciiResult<usize, (u16, usize)> { ) -> CopyAsciiResult<usize, (u16, usize)> {
let len = ::std::cmp::min(src.len(), dst.len()); let len = ::core::cmp::min(src.len(), dst.len());
let mut i = 0usize; let mut i = 0usize;
loop { loop {
if i == len { if i == len {
@ -232,7 +234,7 @@ fn copy_unaligned_basic_latin_to_ascii<E: Endian>(
src: UnalignedU16Slice, src: UnalignedU16Slice,
dst: &mut [u8], dst: &mut [u8],
) -> CopyAsciiResult<usize, (u16, usize)> { ) -> CopyAsciiResult<usize, (u16, usize)> {
let len = ::std::cmp::min(src.len(), dst.len()); let len = ::core::cmp::min(src.len(), dst.len());
let mut offset = 0; let mut offset = 0;
if SIMD_STRIDE_SIZE <= len { if SIMD_STRIDE_SIZE <= len {
let len_minus_stride = len - SIMD_STRIDE_SIZE; let len_minus_stride = len - SIMD_STRIDE_SIZE;
@ -734,7 +736,7 @@ impl<'a> Utf16Destination<'a> {
let mut src_unaligned = unsafe { let mut src_unaligned = unsafe {
UnalignedU16Slice::new( UnalignedU16Slice::new(
src_remaining.as_ptr(), src_remaining.as_ptr(),
::std::cmp::min(src_remaining.len() / 2, dst_remaining.len()), ::core::cmp::min(src_remaining.len() / 2, dst_remaining.len()),
) )
}; };
if src_unaligned.len() == 0 { if src_unaligned.len() == 0 {
@ -1078,7 +1080,7 @@ impl<'a> Utf8Destination<'a> {
pub fn copy_utf8_up_to_invalid_from(&mut self, source: &mut ByteSource) { pub fn copy_utf8_up_to_invalid_from(&mut self, source: &mut ByteSource) {
let src_remaining = &source.slice[source.pos..]; let src_remaining = &source.slice[source.pos..];
let dst_remaining = &mut self.slice[self.pos..]; let dst_remaining = &mut self.slice[self.pos..];
let min_len = ::std::cmp::min(src_remaining.len(), dst_remaining.len()); let min_len = ::core::cmp::min(src_remaining.len(), dst_remaining.len());
// Validate first, then memcpy to let memcpy do its thing even for // Validate first, then memcpy to let memcpy do its thing even for
// non-ASCII. (And potentially do something better than SSE2 for ASCII.) // non-ASCII. (And potentially do something better than SSE2 for ASCII.)
let valid_len = utf8_valid_up_to(&src_remaining[..min_len]); let valid_len = utf8_valid_up_to(&src_remaining[..min_len]);
@ -1154,7 +1156,7 @@ impl<'a> Utf16Source<'a> {
self.pos += 1; self.pos += 1;
let unit_minus_surrogate_start = unit.wrapping_sub(0xD800); let unit_minus_surrogate_start = unit.wrapping_sub(0xD800);
if unit_minus_surrogate_start > (0xDFFF - 0xD800) { if unit_minus_surrogate_start > (0xDFFF - 0xD800) {
return unsafe { ::std::char::from_u32_unchecked(u32::from(unit)) }; return unsafe { ::core::char::from_u32_unchecked(u32::from(unit)) };
} }
if unit_minus_surrogate_start <= (0xDBFF - 0xD800) { if unit_minus_surrogate_start <= (0xDBFF - 0xD800) {
// high surrogate // high surrogate
@ -1165,7 +1167,7 @@ impl<'a> Utf16Source<'a> {
// The next code unit is a low surrogate. Advance position. // The next code unit is a low surrogate. Advance position.
self.pos += 1; self.pos += 1;
return unsafe { return unsafe {
::std::char::from_u32_unchecked( ::core::char::from_u32_unchecked(
(u32::from(unit) << 10) + u32::from(second) (u32::from(unit) << 10) + u32::from(second)
- (((0xD800u32 << 10) - 0x10000u32) + 0xDC00u32), - (((0xD800u32 << 10) - 0x10000u32) + 0xDC00u32),
) )
@ -1202,7 +1204,7 @@ impl<'a> Utf16Source<'a> {
// The next code unit is a low surrogate. Advance position. // The next code unit is a low surrogate. Advance position.
self.pos += 1; self.pos += 1;
return Unicode::NonAscii(NonAscii::Astral(unsafe { return Unicode::NonAscii(NonAscii::Astral(unsafe {
::std::char::from_u32_unchecked( ::core::char::from_u32_unchecked(
(u32::from(unit) << 10) + u32::from(second) (u32::from(unit) << 10) + u32::from(second)
- (((0xD800u32 << 10) - 0x10000u32) + 0xDC00u32), - (((0xD800u32 << 10) - 0x10000u32) + 0xDC00u32),
) )
@ -1266,7 +1268,7 @@ impl<'a> Utf16Source<'a> {
// The next code unit is a low surrogate. Advance position. // The next code unit is a low surrogate. Advance position.
self.pos += 1; self.pos += 1;
NonAscii::Astral(unsafe { NonAscii::Astral(unsafe {
::std::char::from_u32_unchecked( ::core::char::from_u32_unchecked(
(u32::from(unit) << 10) + u32::from(second) (u32::from(unit) << 10) + u32::from(second)
- (((0xD800u32 << 10) - 0x10000u32) + 0xDC00u32), - (((0xD800u32 << 10) - 0x10000u32) + 0xDC00u32),
) )
@ -1339,7 +1341,7 @@ impl<'a> Utf16Source<'a> {
// The next code unit is a low surrogate. Advance position. // The next code unit is a low surrogate. Advance position.
self.pos += 1; self.pos += 1;
NonAscii::Astral(unsafe { NonAscii::Astral(unsafe {
::std::char::from_u32_unchecked( ::core::char::from_u32_unchecked(
(u32::from(unit) << 10) + u32::from(second) (u32::from(unit) << 10) + u32::from(second)
- (((0xD800u32 << 10) - 0x1_0000u32) + 0xDC00u32), - (((0xD800u32 << 10) - 0x1_0000u32) + 0xDC00u32),
) )
@ -1467,21 +1469,21 @@ impl<'a> Utf8Source<'a> {
let point = let point =
((u32::from(unit) & 0x1F) << 6) | (u32::from(self.slice[self.pos + 1]) & 0x3F); ((u32::from(unit) & 0x1F) << 6) | (u32::from(self.slice[self.pos + 1]) & 0x3F);
self.pos += 2; self.pos += 2;
return unsafe { ::std::char::from_u32_unchecked(point) }; return unsafe { ::core::char::from_u32_unchecked(point) };
} }
if unit < 0xF0 { if unit < 0xF0 {
let point = ((u32::from(unit) & 0xF) << 12) let point = ((u32::from(unit) & 0xF) << 12)
| ((u32::from(self.slice[self.pos + 1]) & 0x3F) << 6) | ((u32::from(self.slice[self.pos + 1]) & 0x3F) << 6)
| (u32::from(self.slice[self.pos + 2]) & 0x3F); | (u32::from(self.slice[self.pos + 2]) & 0x3F);
self.pos += 3; self.pos += 3;
return unsafe { ::std::char::from_u32_unchecked(point) }; return unsafe { ::core::char::from_u32_unchecked(point) };
} }
let point = ((u32::from(unit) & 0x7) << 18) let point = ((u32::from(unit) & 0x7) << 18)
| ((u32::from(self.slice[self.pos + 1]) & 0x3F) << 12) | ((u32::from(self.slice[self.pos + 1]) & 0x3F) << 12)
| ((u32::from(self.slice[self.pos + 2]) & 0x3F) << 6) | ((u32::from(self.slice[self.pos + 2]) & 0x3F) << 6)
| (u32::from(self.slice[self.pos + 3]) & 0x3F); | (u32::from(self.slice[self.pos + 3]) & 0x3F);
self.pos += 4; self.pos += 4;
unsafe { ::std::char::from_u32_unchecked(point) } unsafe { ::core::char::from_u32_unchecked(point) }
} }
#[inline(always)] #[inline(always)]
fn read_enum(&mut self) -> Unicode { fn read_enum(&mut self) -> Unicode {
@ -1510,7 +1512,7 @@ impl<'a> Utf8Source<'a> {
| (u32::from(self.slice[self.pos + 3]) & 0x3F); | (u32::from(self.slice[self.pos + 3]) & 0x3F);
self.pos += 4; self.pos += 4;
Unicode::NonAscii(NonAscii::Astral(unsafe { Unicode::NonAscii(NonAscii::Astral(unsafe {
::std::char::from_u32_unchecked(point) ::core::char::from_u32_unchecked(point)
})) }))
} }
#[inline(always)] #[inline(always)]
@ -1565,7 +1567,7 @@ impl<'a> Utf8Source<'a> {
| ((u32::from(self.slice[self.pos + 2]) & 0x3F) << 6) | ((u32::from(self.slice[self.pos + 2]) & 0x3F) << 6)
| (u32::from(self.slice[self.pos + 3]) & 0x3F); | (u32::from(self.slice[self.pos + 3]) & 0x3F);
self.pos += 4; self.pos += 4;
NonAscii::Astral(unsafe { ::std::char::from_u32_unchecked(point) }) NonAscii::Astral(unsafe { ::core::char::from_u32_unchecked(point) })
} }
} }
} }
@ -1615,7 +1617,7 @@ impl<'a> Utf8Source<'a> {
| ((u32::from(self.slice[self.pos + 2]) & 0x3F) << 6) | ((u32::from(self.slice[self.pos + 2]) & 0x3F) << 6)
| (u32::from(self.slice[self.pos + 3]) & 0x3F); | (u32::from(self.slice[self.pos + 3]) & 0x3F);
self.pos += 4; self.pos += 4;
NonAscii::Astral(unsafe { ::std::char::from_u32_unchecked(point) }) NonAscii::Astral(unsafe { ::core::char::from_u32_unchecked(point) })
} }
} else { } else {
return CopyAsciiResult::Stop(( return CopyAsciiResult::Stop((
@ -1672,7 +1674,7 @@ impl<'a> Utf8Source<'a> {
| ((u32::from(self.slice[self.pos + 2]) & 0x3F) << 6) | ((u32::from(self.slice[self.pos + 2]) & 0x3F) << 6)
| (u32::from(self.slice[self.pos + 3]) & 0x3F); | (u32::from(self.slice[self.pos + 3]) & 0x3F);
self.pos += 4; self.pos += 4;
NonAscii::Astral(unsafe { ::std::char::from_u32_unchecked(point) }) NonAscii::Astral(unsafe { ::core::char::from_u32_unchecked(point) })
} }
} else { } else {
return CopyAsciiResult::Stop(( return CopyAsciiResult::Stop((

View file

@ -1,4 +1,4 @@
// Copyright 2015-2016 Mozilla Foundation. See the COPYRIGHT // Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -8,9 +8,9 @@
// except according to those terms. // except according to those terms.
use super::*; use super::*;
use data::*; use crate::data::*;
use handles::*; use crate::handles::*;
use variant::*; use crate::variant::*;
// Rust 1.14.0 requires the following despite the asterisk above. // Rust 1.14.0 requires the following despite the asterisk above.
use super::in_inclusive_range16; use super::in_inclusive_range16;
@ -754,7 +754,7 @@ impl Iso2022JpEncoder {
// Any copyright to the test code below this comment is dedicated to the // Any copyright to the test code below this comment is dedicated to the
// Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ // Public Domain. http://creativecommons.org/publicdomain/zero/1.0/
#[cfg(test)] #[cfg(all(test, feature = "alloc"))]
mod tests { mod tests {
use super::super::testing::*; use super::super::testing::*;
use super::super::*; use super::super::*;
@ -863,6 +863,11 @@ mod tests {
decode_iso_2022_jp(b"\x1B$@\x80\x54\x64", "\u{FFFD}\u{58FA}"); decode_iso_2022_jp(b"\x1B$@\x80\x54\x64", "\u{FFFD}\u{58FA}");
decode_iso_2022_jp(b"\x1B$B\x28\x80", "\u{FFFD}"); decode_iso_2022_jp(b"\x1B$B\x28\x80", "\u{FFFD}");
if cfg!(miri) {
// Miri is too slow
return;
}
// Transitions // Transitions
decode_iso_2022_jp(b"\x1B(B\x5C\x1B(J\x5C", "\u{005C}\u{00A5}"); decode_iso_2022_jp(b"\x1B(B\x5C\x1B(J\x5C", "\u{005C}\u{00A5}");
decode_iso_2022_jp(b"\x1B(B\x5C\x1B(I\x21", "\u{005C}\u{FF61}"); decode_iso_2022_jp(b"\x1B(B\x5C\x1B(I\x21", "\u{005C}\u{FF61}");
@ -938,35 +943,45 @@ mod tests {
// Roman // Roman
encode_iso_2022_jp("a\u{00A5}b", b"a\x1B(J\x5Cb\x1B(B"); encode_iso_2022_jp("a\u{00A5}b", b"a\x1B(J\x5Cb\x1B(B");
encode_iso_2022_jp("a\u{203E}b", b"a\x1B(J\x7Eb\x1B(B"); encode_iso_2022_jp("a\u{203E}b", b"a\x1B(J\x7Eb\x1B(B");
encode_iso_2022_jp("a\u{00A5}b\x5C", b"a\x1B(J\x5Cb\x1B(B\x5C"); if !cfg!(miri) {
encode_iso_2022_jp("a\u{203E}b\x7E", b"a\x1B(J\x7Eb\x1B(B\x7E"); // Miri is too slow
encode_iso_2022_jp("\u{00A5}\u{1F4A9}", b"\x1B(J\x5C&#128169;\x1B(B"); encode_iso_2022_jp("a\u{00A5}b\x5C", b"a\x1B(J\x5Cb\x1B(B\x5C");
encode_iso_2022_jp("\u{00A5}\x1B", b"\x1B(J\x5C&#65533;\x1B(B"); encode_iso_2022_jp("a\u{203E}b\x7E", b"a\x1B(J\x7Eb\x1B(B\x7E");
encode_iso_2022_jp("\u{00A5}\x0E", b"\x1B(J\x5C&#65533;\x1B(B"); encode_iso_2022_jp("\u{00A5}\u{1F4A9}", b"\x1B(J\x5C&#128169;\x1B(B");
encode_iso_2022_jp("\u{00A5}\x0F", b"\x1B(J\x5C&#65533;\x1B(B"); encode_iso_2022_jp("\u{00A5}\x1B", b"\x1B(J\x5C&#65533;\x1B(B");
encode_iso_2022_jp("\u{00A5}\u{58FA}", b"\x1B(J\x5C\x1B$B\x54\x64\x1B(B"); encode_iso_2022_jp("\u{00A5}\x0E", b"\x1B(J\x5C&#65533;\x1B(B");
encode_iso_2022_jp("\u{00A5}\x0F", b"\x1B(J\x5C&#65533;\x1B(B");
encode_iso_2022_jp("\u{00A5}\u{58FA}", b"\x1B(J\x5C\x1B$B\x54\x64\x1B(B");
}
// Half-width Katakana // Half-width Katakana
encode_iso_2022_jp("\u{FF61}", b"\x1B$B\x21\x23\x1B(B"); encode_iso_2022_jp("\u{FF61}", b"\x1B$B\x21\x23\x1B(B");
encode_iso_2022_jp("\u{FF65}", b"\x1B$B\x21\x26\x1B(B"); encode_iso_2022_jp("\u{FF65}", b"\x1B$B\x21\x26\x1B(B");
encode_iso_2022_jp("\u{FF66}", b"\x1B$B\x25\x72\x1B(B"); if !cfg!(miri) {
encode_iso_2022_jp("\u{FF70}", b"\x1B$B\x21\x3C\x1B(B"); // Miri is too slow
encode_iso_2022_jp("\u{FF9D}", b"\x1B$B\x25\x73\x1B(B"); encode_iso_2022_jp("\u{FF66}", b"\x1B$B\x25\x72\x1B(B");
encode_iso_2022_jp("\u{FF9E}", b"\x1B$B\x21\x2B\x1B(B"); encode_iso_2022_jp("\u{FF70}", b"\x1B$B\x21\x3C\x1B(B");
encode_iso_2022_jp("\u{FF9F}", b"\x1B$B\x21\x2C\x1B(B"); encode_iso_2022_jp("\u{FF9D}", b"\x1B$B\x25\x73\x1B(B");
encode_iso_2022_jp("\u{FF9E}", b"\x1B$B\x21\x2B\x1B(B");
encode_iso_2022_jp("\u{FF9F}", b"\x1B$B\x21\x2C\x1B(B");
}
// 0208 // 0208
encode_iso_2022_jp("\u{58FA}", b"\x1B$B\x54\x64\x1B(B"); encode_iso_2022_jp("\u{58FA}", b"\x1B$B\x54\x64\x1B(B");
encode_iso_2022_jp("\u{58FA}\u{250F}", b"\x1B$B\x54\x64\x28\x2E\x1B(B"); encode_iso_2022_jp("\u{58FA}\u{250F}", b"\x1B$B\x54\x64\x28\x2E\x1B(B");
encode_iso_2022_jp("\u{58FA}\u{1F4A9}", b"\x1B$B\x54\x64\x1B(B&#128169;"); if !cfg!(miri) {
encode_iso_2022_jp("\u{58FA}\x1B", b"\x1B$B\x54\x64\x1B(B&#65533;"); // Miri is too slow
encode_iso_2022_jp("\u{58FA}\x0E", b"\x1B$B\x54\x64\x1B(B&#65533;"); encode_iso_2022_jp("\u{58FA}\u{1F4A9}", b"\x1B$B\x54\x64\x1B(B&#128169;");
encode_iso_2022_jp("\u{58FA}\x0F", b"\x1B$B\x54\x64\x1B(B&#65533;"); encode_iso_2022_jp("\u{58FA}\x1B", b"\x1B$B\x54\x64\x1B(B&#65533;");
encode_iso_2022_jp("\u{58FA}\u{00A5}", b"\x1B$B\x54\x64\x1B(J\x5C\x1B(B"); encode_iso_2022_jp("\u{58FA}\x0E", b"\x1B$B\x54\x64\x1B(B&#65533;");
encode_iso_2022_jp("\u{58FA}a", b"\x1B$B\x54\x64\x1B(Ba"); encode_iso_2022_jp("\u{58FA}\x0F", b"\x1B$B\x54\x64\x1B(B&#65533;");
encode_iso_2022_jp("\u{58FA}\u{00A5}", b"\x1B$B\x54\x64\x1B(J\x5C\x1B(B");
encode_iso_2022_jp("\u{58FA}a", b"\x1B$B\x54\x64\x1B(Ba");
}
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_iso_2022_jp_decode_all() { fn test_iso_2022_jp_decode_all() {
let input = include_bytes!("test_data/iso_2022_jp_in.txt"); let input = include_bytes!("test_data/iso_2022_jp_in.txt");
let expectation = include_str!("test_data/iso_2022_jp_in_ref.txt"); let expectation = include_str!("test_data/iso_2022_jp_in_ref.txt");
@ -976,6 +991,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_iso_2022_jp_encode_all() { fn test_iso_2022_jp_encode_all() {
let input = include_str!("test_data/iso_2022_jp_out.txt"); let input = include_str!("test_data/iso_2022_jp_out.txt");
let expectation = include_bytes!("test_data/iso_2022_jp_out_ref.txt"); let expectation = include_bytes!("test_data/iso_2022_jp_out_ref.txt");

View file

@ -1,4 +1,4 @@
// Copyright 2015-2016 Mozilla Foundation. See the COPYRIGHT // Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -11,7 +11,6 @@
feature = "cargo-clippy", feature = "cargo-clippy",
allow(doc_markdown, inline_always, new_ret_no_self) allow(doc_markdown, inline_always, new_ret_no_self)
)] )]
#![doc(html_root_url = "https://docs.rs/encoding_rs/0.8.22")]
//! encoding_rs is a Gecko-oriented Free Software / Open Source implementation //! encoding_rs is a Gecko-oriented Free Software / Open Source implementation
//! of the [Encoding Standard](https://encoding.spec.whatwg.org/) in Rust. //! of the [Encoding Standard](https://encoding.spec.whatwg.org/) in Rust.
@ -60,6 +59,7 @@
//! Decode using the non-streaming API: //! Decode using the non-streaming API:
//! //!
//! ``` //! ```
//! #[cfg(feature = "alloc")] {
//! use encoding_rs::*; //! use encoding_rs::*;
//! //!
//! let expectation = "\u{30CF}\u{30ED}\u{30FC}\u{30FB}\u{30EF}\u{30FC}\u{30EB}\u{30C9}"; //! let expectation = "\u{30CF}\u{30ED}\u{30FC}\u{30FB}\u{30EF}\u{30FC}\u{30EB}\u{30C9}";
@ -69,6 +69,7 @@
//! assert_eq!(&cow[..], expectation); //! assert_eq!(&cow[..], expectation);
//! assert_eq!(encoding_used, SHIFT_JIS); //! assert_eq!(encoding_used, SHIFT_JIS);
//! assert!(!had_errors); //! assert!(!had_errors);
//! }
//! ``` //! ```
//! //!
//! Decode using the streaming API with minimal `unsafe`: //! Decode using the streaming API with minimal `unsafe`:
@ -248,6 +249,9 @@
//! [charset](https://crates.io/crates/charset) wraps encoding_rs and adds //! [charset](https://crates.io/crates/charset) wraps encoding_rs and adds
//! UTF-7 decoding for email purposes. //! UTF-7 decoding for email purposes.
//! //!
//! For single-byte DOS encodings beyond the ones supported by the Encoding
//! Standard, there is the [`oem_cp`](https://crates.io/crates/oem_cp) crate.
//!
//! # Preparing Text for the Encoders //! # Preparing Text for the Encoders
//! //!
//! Normalizing text into Unicode Normalization Form C prior to encoding text //! Normalizing text into Unicode Normalization Form C prior to encoding text
@ -677,8 +681,14 @@
//! See the section [_UTF-16LE, UTF-16BE and Unicode Encoding Schemes_](#utf-16le-utf-16be-and-unicode-encoding-schemes) //! See the section [_UTF-16LE, UTF-16BE and Unicode Encoding Schemes_](#utf-16le-utf-16be-and-unicode-encoding-schemes)
//! for discussion about the UTF-16 family. //! for discussion about the UTF-16 family.
#![no_std]
#![cfg_attr(feature = "simd-accel", feature(stdsimd, core_intrinsics))] #![cfg_attr(feature = "simd-accel", feature(stdsimd, core_intrinsics))]
#[cfg(feature = "alloc")]
#[cfg_attr(test, macro_use)]
extern crate alloc;
extern crate core;
#[macro_use] #[macro_use]
extern crate cfg_if; extern crate cfg_if;
@ -717,7 +727,7 @@ mod macros;
))] ))]
mod simd_funcs; mod simd_funcs;
#[cfg(test)] #[cfg(all(test, feature = "alloc"))]
mod testing; mod testing;
mod big5; mod big5;
@ -739,15 +749,20 @@ mod variant;
pub mod mem; pub mod mem;
use ascii::ascii_valid_up_to; use crate::ascii::ascii_valid_up_to;
use ascii::iso_2022_jp_ascii_valid_up_to; use crate::ascii::iso_2022_jp_ascii_valid_up_to;
use utf_8::utf8_valid_up_to; use crate::utf_8::utf8_valid_up_to;
use variant::*; use crate::variant::*;
use std::borrow::Cow; #[cfg(feature = "alloc")]
use std::cmp::Ordering; use alloc::borrow::Cow;
use std::hash::Hash; #[cfg(feature = "alloc")]
use std::hash::Hasher; use alloc::string::String;
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
use core::cmp::Ordering;
use core::hash::Hash;
use core::hash::Hasher;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::de::Visitor; use serde::de::Visitor;
@ -2129,7 +2144,7 @@ pub static X_USER_DEFINED_INIT: Encoding = Encoding {
/// `static`. /// `static`.
pub static X_USER_DEFINED: &'static Encoding = &X_USER_DEFINED_INIT; pub static X_USER_DEFINED: &'static Encoding = &X_USER_DEFINED_INIT;
static LABELS_SORTED: [&'static str; 219] = [ static LABELS_SORTED: [&'static str; 228] = [
"l1", "l1",
"l2", "l2",
"l3", "l3",
@ -2145,6 +2160,7 @@ static LABELS_SORTED: [&'static str; 219] = [
"utf8", "utf8",
"koi8", "koi8",
"sjis", "sjis",
"ucs-2",
"ms932", "ms932",
"cp866", "cp866",
"utf-8", "utf-8",
@ -2189,6 +2205,7 @@ static LABELS_SORTED: [&'static str; 219] = [
"gb_2312", "gb_2312",
"dos-874", "dos-874",
"cn-big5", "cn-big5",
"unicode",
"chinese", "chinese",
"logical", "logical",
"cskoi8r", "cskoi8r",
@ -2241,6 +2258,7 @@ static LABELS_SORTED: [&'static str; 219] = [
"iso8859-8", "iso8859-8",
"iso-ir-58", "iso-ir-58",
"iso8859-9", "iso8859-9",
"csunicode",
"macintosh", "macintosh",
"shift-jis", "shift-jis",
"shift_jis", "shift_jis",
@ -2300,6 +2318,8 @@ static LABELS_SORTED: [&'static str; 219] = [
"csisolatin9", "csisolatin9",
"csiso88596e", "csiso88596e",
"csiso88598e", "csiso88598e",
"unicodefffe",
"unicodefeff",
"csmacintosh", "csmacintosh",
"csiso88596i", "csiso88596i",
"csiso88598i", "csiso88598i",
@ -2326,12 +2346,15 @@ static LABELS_SORTED: [&'static str; 219] = [
"iso-8859-8-i", "iso-8859-8-i",
"sun_eu_greek", "sun_eu_greek",
"csksc56011987", "csksc56011987",
"unicode20utf8",
"unicode11utf8",
"ks_c_5601-1987", "ks_c_5601-1987",
"ansi_x3.4-1968", "ansi_x3.4-1968",
"ks_c_5601-1989", "ks_c_5601-1989",
"x-mac-cyrillic", "x-mac-cyrillic",
"x-user-defined", "x-user-defined",
"csiso58gb231280", "csiso58gb231280",
"iso-10646-ucs-2",
"iso_8859-1:1987", "iso_8859-1:1987",
"iso_8859-2:1987", "iso_8859-2:1987",
"iso_8859-6:1987", "iso_8859-6:1987",
@ -2340,6 +2363,7 @@ static LABELS_SORTED: [&'static str; 219] = [
"iso_8859-4:1988", "iso_8859-4:1988",
"iso_8859-5:1988", "iso_8859-5:1988",
"iso_8859-8:1988", "iso_8859-8:1988",
"x-unicode20utf8",
"iso_8859-9:1989", "iso_8859-9:1989",
"csisolatingreek", "csisolatingreek",
"x-mac-ukrainian", "x-mac-ukrainian",
@ -2351,7 +2375,7 @@ static LABELS_SORTED: [&'static str; 219] = [
"cseucpkdfmtjapanese", "cseucpkdfmtjapanese",
]; ];
static ENCODINGS_IN_LABEL_SORT: [&'static Encoding; 219] = [ static ENCODINGS_IN_LABEL_SORT: [&'static Encoding; 228] = [
&WINDOWS_1252_INIT, &WINDOWS_1252_INIT,
&ISO_8859_2_INIT, &ISO_8859_2_INIT,
&ISO_8859_3_INIT, &ISO_8859_3_INIT,
@ -2367,6 +2391,7 @@ static ENCODINGS_IN_LABEL_SORT: [&'static Encoding; 219] = [
&UTF_8_INIT, &UTF_8_INIT,
&KOI8_R_INIT, &KOI8_R_INIT,
&SHIFT_JIS_INIT, &SHIFT_JIS_INIT,
&UTF_16LE_INIT,
&SHIFT_JIS_INIT, &SHIFT_JIS_INIT,
&IBM866_INIT, &IBM866_INIT,
&UTF_8_INIT, &UTF_8_INIT,
@ -2411,6 +2436,7 @@ static ENCODINGS_IN_LABEL_SORT: [&'static Encoding; 219] = [
&GBK_INIT, &GBK_INIT,
&WINDOWS_874_INIT, &WINDOWS_874_INIT,
&BIG5_INIT, &BIG5_INIT,
&UTF_16LE_INIT,
&GBK_INIT, &GBK_INIT,
&ISO_8859_8_I_INIT, &ISO_8859_8_I_INIT,
&KOI8_R_INIT, &KOI8_R_INIT,
@ -2463,6 +2489,7 @@ static ENCODINGS_IN_LABEL_SORT: [&'static Encoding; 219] = [
&ISO_8859_8_INIT, &ISO_8859_8_INIT,
&GBK_INIT, &GBK_INIT,
&WINDOWS_1254_INIT, &WINDOWS_1254_INIT,
&UTF_16LE_INIT,
&MACINTOSH_INIT, &MACINTOSH_INIT,
&SHIFT_JIS_INIT, &SHIFT_JIS_INIT,
&SHIFT_JIS_INIT, &SHIFT_JIS_INIT,
@ -2522,6 +2549,8 @@ static ENCODINGS_IN_LABEL_SORT: [&'static Encoding; 219] = [
&ISO_8859_15_INIT, &ISO_8859_15_INIT,
&ISO_8859_6_INIT, &ISO_8859_6_INIT,
&ISO_8859_8_INIT, &ISO_8859_8_INIT,
&UTF_16BE_INIT,
&UTF_16LE_INIT,
&MACINTOSH_INIT, &MACINTOSH_INIT,
&ISO_8859_6_INIT, &ISO_8859_6_INIT,
&ISO_8859_8_I_INIT, &ISO_8859_8_I_INIT,
@ -2548,12 +2577,15 @@ static ENCODINGS_IN_LABEL_SORT: [&'static Encoding; 219] = [
&ISO_8859_8_I_INIT, &ISO_8859_8_I_INIT,
&ISO_8859_7_INIT, &ISO_8859_7_INIT,
&EUC_KR_INIT, &EUC_KR_INIT,
&UTF_8_INIT,
&UTF_8_INIT,
&EUC_KR_INIT, &EUC_KR_INIT,
&WINDOWS_1252_INIT, &WINDOWS_1252_INIT,
&EUC_KR_INIT, &EUC_KR_INIT,
&X_MAC_CYRILLIC_INIT, &X_MAC_CYRILLIC_INIT,
&X_USER_DEFINED_INIT, &X_USER_DEFINED_INIT,
&GBK_INIT, &GBK_INIT,
&UTF_16LE_INIT,
&WINDOWS_1252_INIT, &WINDOWS_1252_INIT,
&ISO_8859_2_INIT, &ISO_8859_2_INIT,
&ISO_8859_6_INIT, &ISO_8859_6_INIT,
@ -2562,6 +2594,7 @@ static ENCODINGS_IN_LABEL_SORT: [&'static Encoding; 219] = [
&ISO_8859_4_INIT, &ISO_8859_4_INIT,
&ISO_8859_5_INIT, &ISO_8859_5_INIT,
&ISO_8859_8_INIT, &ISO_8859_8_INIT,
&UTF_8_INIT,
&WINDOWS_1254_INIT, &WINDOWS_1254_INIT,
&ISO_8859_7_INIT, &ISO_8859_7_INIT,
&X_MAC_CYRILLIC_INIT, &X_MAC_CYRILLIC_INIT,
@ -2664,6 +2697,20 @@ impl Encoding {
/// on it.) /// on it.)
/// ///
/// Available via the C wrapper. /// Available via the C wrapper.
///
/// # Example
/// ```
/// use encoding_rs::Encoding;
///
/// assert_eq!(Some(encoding_rs::UTF_8), Encoding::for_label(b"utf-8"));
/// assert_eq!(Some(encoding_rs::UTF_8), Encoding::for_label(b"unicode11utf8"));
///
/// assert_eq!(Some(encoding_rs::ISO_8859_2), Encoding::for_label(b"latin2"));
///
/// assert_eq!(Some(encoding_rs::UTF_16BE), Encoding::for_label(b"utf-16be"));
///
/// assert_eq!(None, Encoding::for_label(b"unrecognized label"));
/// ```
pub fn for_label(label: &[u8]) -> Option<&'static Encoding> { pub fn for_label(label: &[u8]) -> Option<&'static Encoding> {
let mut trimmed = [0u8; LONGEST_LABEL_LENGTH]; let mut trimmed = [0u8; LONGEST_LABEL_LENGTH];
let mut trimmed_pos = 0usize; let mut trimmed_pos = 0usize;
@ -2683,12 +2730,12 @@ impl Encoding {
0x09u8 | 0x0Au8 | 0x0Cu8 | 0x0Du8 | 0x20u8 => { 0x09u8 | 0x0Au8 | 0x0Cu8 | 0x0Du8 | 0x20u8 => {
continue; continue;
} }
b'A'...b'Z' => { b'A'..=b'Z' => {
trimmed[trimmed_pos] = *byte + 0x20u8; trimmed[trimmed_pos] = *byte + 0x20u8;
trimmed_pos = 1usize; trimmed_pos = 1usize;
break; break;
} }
b'a'...b'z' | b'0'...b'9' | b'-' | b'_' | b':' | b'.' => { b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b':' | b'.' => {
trimmed[trimmed_pos] = *byte; trimmed[trimmed_pos] = *byte;
trimmed_pos = 1usize; trimmed_pos = 1usize;
break; break;
@ -2711,7 +2758,7 @@ impl Encoding {
0x09u8 | 0x0Au8 | 0x0Cu8 | 0x0Du8 | 0x20u8 => { 0x09u8 | 0x0Au8 | 0x0Cu8 | 0x0Du8 | 0x20u8 => {
break; break;
} }
b'A'...b'Z' => { b'A'..=b'Z' => {
if trimmed_pos == LONGEST_LABEL_LENGTH { if trimmed_pos == LONGEST_LABEL_LENGTH {
// There's no encoding with a label this long // There's no encoding with a label this long
return None; return None;
@ -2720,7 +2767,7 @@ impl Encoding {
trimmed_pos += 1usize; trimmed_pos += 1usize;
continue; continue;
} }
b'a'...b'z' | b'0'...b'9' | b'-' | b'_' | b':' | b'.' => { b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b':' | b'.' => {
if trimmed_pos == LONGEST_LABEL_LENGTH { if trimmed_pos == LONGEST_LABEL_LENGTH {
// There's no encoding with a label this long // There's no encoding with a label this long
return None; return None;
@ -2868,6 +2915,7 @@ impl Encoding {
/// Checks whether the bytes 0x00...0x7F map mostly to the characters /// Checks whether the bytes 0x00...0x7F map mostly to the characters
/// U+0000...U+007F and vice versa. /// U+0000...U+007F and vice versa.
#[cfg(feature = "alloc")]
#[inline] #[inline]
fn is_potentially_borrowable(&'static self) -> bool { fn is_potentially_borrowable(&'static self) -> bool {
!(self == REPLACEMENT || self == UTF_16BE || self == UTF_16LE) !(self == REPLACEMENT || self == UTF_16BE || self == UTF_16LE)
@ -2919,7 +2967,9 @@ impl Encoding {
/// If the size calculation for a heap-allocated backing buffer overflows /// If the size calculation for a heap-allocated backing buffer overflows
/// `usize`. /// `usize`.
/// ///
/// Available to Rust only. /// Available to Rust only and only with the `alloc` feature enabled (enabled
/// by default).
#[cfg(feature = "alloc")]
#[inline] #[inline]
pub fn decode<'a>(&'static self, bytes: &'a [u8]) -> (Cow<'a, str>, &'static Encoding, bool) { pub fn decode<'a>(&'static self, bytes: &'a [u8]) -> (Cow<'a, str>, &'static Encoding, bool) {
let (encoding, without_bom) = match Encoding::for_bom(bytes) { let (encoding, without_bom) = match Encoding::for_bom(bytes) {
@ -2962,7 +3012,9 @@ impl Encoding {
/// If the size calculation for a heap-allocated backing buffer overflows /// If the size calculation for a heap-allocated backing buffer overflows
/// `usize`. /// `usize`.
/// ///
/// Available to Rust only. /// Available to Rust only and only with the `alloc` feature enabled (enabled
/// by default).
#[cfg(feature = "alloc")]
#[inline] #[inline]
pub fn decode_with_bom_removal<'a>(&'static self, bytes: &'a [u8]) -> (Cow<'a, str>, bool) { pub fn decode_with_bom_removal<'a>(&'static self, bytes: &'a [u8]) -> (Cow<'a, str>, bool) {
let without_bom = if self == UTF_8 && bytes.starts_with(b"\xEF\xBB\xBF") { let without_bom = if self == UTF_8 && bytes.starts_with(b"\xEF\xBB\xBF") {
@ -3009,7 +3061,9 @@ impl Encoding {
/// If the size calculation for a heap-allocated backing buffer overflows /// If the size calculation for a heap-allocated backing buffer overflows
/// `usize`. /// `usize`.
/// ///
/// Available to Rust only. /// Available to Rust only and only with the `alloc` feature enabled (enabled
/// by default).
#[cfg(feature = "alloc")]
pub fn decode_without_bom_handling<'a>(&'static self, bytes: &'a [u8]) -> (Cow<'a, str>, bool) { pub fn decode_without_bom_handling<'a>(&'static self, bytes: &'a [u8]) -> (Cow<'a, str>, bool) {
let (mut decoder, mut string, mut total_read) = if self.is_potentially_borrowable() { let (mut decoder, mut string, mut total_read) = if self.is_potentially_borrowable() {
let valid_up_to = if self == UTF_8 { let valid_up_to = if self == UTF_8 {
@ -3020,7 +3074,7 @@ impl Encoding {
ascii_valid_up_to(bytes) ascii_valid_up_to(bytes)
}; };
if valid_up_to == bytes.len() { if valid_up_to == bytes.len() {
let str: &str = unsafe { std::str::from_utf8_unchecked(bytes) }; let str: &str = unsafe { core::str::from_utf8_unchecked(bytes) };
return (Cow::Borrowed(str), false); return (Cow::Borrowed(str), false);
} }
let decoder = self.new_decoder_without_bom_handling(); let decoder = self.new_decoder_without_bom_handling();
@ -3039,7 +3093,7 @@ impl Encoding {
unsafe { unsafe {
let vec = string.as_mut_vec(); let vec = string.as_mut_vec();
vec.set_len(valid_up_to); vec.set_len(valid_up_to);
std::ptr::copy_nonoverlapping(bytes.as_ptr(), vec.as_mut_ptr(), valid_up_to); core::ptr::copy_nonoverlapping(bytes.as_ptr(), vec.as_mut_ptr(), valid_up_to);
} }
(decoder, string, valid_up_to) (decoder, string, valid_up_to)
} else { } else {
@ -3104,7 +3158,9 @@ impl Encoding {
/// If the size calculation for a heap-allocated backing buffer overflows /// If the size calculation for a heap-allocated backing buffer overflows
/// `usize`. /// `usize`.
/// ///
/// Available to Rust only. /// Available to Rust only and only with the `alloc` feature enabled (enabled
/// by default).
#[cfg(feature = "alloc")]
pub fn decode_without_bom_handling_and_without_replacement<'a>( pub fn decode_without_bom_handling_and_without_replacement<'a>(
&'static self, &'static self,
bytes: &'a [u8], bytes: &'a [u8],
@ -3112,7 +3168,7 @@ impl Encoding {
if self == UTF_8 { if self == UTF_8 {
let valid_up_to = utf8_valid_up_to(bytes); let valid_up_to = utf8_valid_up_to(bytes);
if valid_up_to == bytes.len() { if valid_up_to == bytes.len() {
let str: &str = unsafe { std::str::from_utf8_unchecked(bytes) }; let str: &str = unsafe { core::str::from_utf8_unchecked(bytes) };
return Some(Cow::Borrowed(str)); return Some(Cow::Borrowed(str));
} }
return None; return None;
@ -3124,7 +3180,7 @@ impl Encoding {
ascii_valid_up_to(bytes) ascii_valid_up_to(bytes)
}; };
if valid_up_to == bytes.len() { if valid_up_to == bytes.len() {
let str: &str = unsafe { std::str::from_utf8_unchecked(bytes) }; let str: &str = unsafe { core::str::from_utf8_unchecked(bytes) };
return Some(Cow::Borrowed(str)); return Some(Cow::Borrowed(str));
} }
let decoder = self.new_decoder_without_bom_handling(); let decoder = self.new_decoder_without_bom_handling();
@ -3138,7 +3194,7 @@ impl Encoding {
unsafe { unsafe {
let vec = string.as_mut_vec(); let vec = string.as_mut_vec();
vec.set_len(valid_up_to); vec.set_len(valid_up_to);
std::ptr::copy_nonoverlapping(bytes.as_ptr(), vec.as_mut_ptr(), valid_up_to); core::ptr::copy_nonoverlapping(bytes.as_ptr(), vec.as_mut_ptr(), valid_up_to);
} }
(decoder, string, &bytes[valid_up_to..]) (decoder, string, &bytes[valid_up_to..])
} else { } else {
@ -3199,7 +3255,9 @@ impl Encoding {
/// If the size calculation for a heap-allocated backing buffer overflows /// If the size calculation for a heap-allocated backing buffer overflows
/// `usize`. /// `usize`.
/// ///
/// Available to Rust only. /// Available to Rust only and only with the `alloc` feature enabled (enabled
/// by default).
#[cfg(feature = "alloc")]
pub fn encode<'a>(&'static self, string: &'a str) -> (Cow<'a, [u8]>, &'static Encoding, bool) { pub fn encode<'a>(&'static self, string: &'a str) -> (Cow<'a, [u8]>, &'static Encoding, bool) {
let output_encoding = self.output_encoding(); let output_encoding = self.output_encoding();
if output_encoding == UTF_8 { if output_encoding == UTF_8 {
@ -3226,7 +3284,7 @@ impl Encoding {
); );
unsafe { unsafe {
vec.set_len(valid_up_to); vec.set_len(valid_up_to);
std::ptr::copy_nonoverlapping(bytes.as_ptr(), vec.as_mut_ptr(), valid_up_to); core::ptr::copy_nonoverlapping(bytes.as_ptr(), vec.as_mut_ptr(), valid_up_to);
} }
let mut total_read = valid_up_to; let mut total_read = valid_up_to;
let mut total_had_errors = false; let mut total_had_errors = false;
@ -3355,6 +3413,20 @@ impl PartialEq for Encoding {
impl Eq for Encoding {} impl Eq for Encoding {}
#[cfg(test)]
impl PartialOrd for Encoding {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
(self as *const Encoding as usize).partial_cmp(&(other as *const Encoding as usize))
}
}
#[cfg(test)]
impl Ord for Encoding {
fn cmp(&self, other: &Self) -> Ordering {
(self as *const Encoding as usize).cmp(&(other as *const Encoding as usize))
}
}
impl Hash for Encoding { impl Hash for Encoding {
#[inline] #[inline]
fn hash<H: Hasher>(&self, state: &mut H) { fn hash<H: Hasher>(&self, state: &mut H) {
@ -3362,9 +3434,9 @@ impl Hash for Encoding {
} }
} }
impl std::fmt::Debug for Encoding { impl core::fmt::Debug for Encoding {
#[inline] #[inline]
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "Encoding {{ {} }}", self.name) write!(f, "Encoding {{ {} }}", self.name)
} }
} }
@ -3387,7 +3459,7 @@ struct EncodingVisitor;
impl<'de> Visitor<'de> for EncodingVisitor { impl<'de> Visitor<'de> for EncodingVisitor {
type Value = &'static Encoding; type Value = &'static Encoding;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { fn expecting(&self, formatter: &mut core::fmt::Formatter) -> core::fmt::Result {
formatter.write_str("a valid encoding label") formatter.write_str("a valid encoding label")
} }
@ -3398,7 +3470,10 @@ impl<'de> Visitor<'de> for EncodingVisitor {
if let Some(enc) = Encoding::for_label(value.as_bytes()) { if let Some(enc) = Encoding::for_label(value.as_bytes()) {
Ok(enc) Ok(enc)
} else { } else {
Err(E::custom(format!("invalid encoding label: {}", value))) Err(E::custom(alloc::format!(
"invalid encoding label: {}",
value
)))
} }
} }
} }
@ -3672,7 +3747,7 @@ impl Decoder {
1, 1,
checked_mul(3, checked_div(byte_length.checked_add(1), 2)), checked_mul(3, checked_div(byte_length.checked_add(1), 2)),
) { ) {
let utf_bom = std::cmp::max(utf8_bom, utf16_bom); let utf_bom = core::cmp::max(utf8_bom, utf16_bom);
let encoding = self.encoding(); let encoding = self.encoding();
if encoding == UTF_8 || encoding == UTF_16LE || encoding == UTF_16BE { if encoding == UTF_8 || encoding == UTF_16LE || encoding == UTF_16BE {
// No need to consider the internal state of the underlying decoder, // No need to consider the internal state of the underlying decoder,
@ -3681,7 +3756,7 @@ impl Decoder {
} else if let Some(non_bom) = } else if let Some(non_bom) =
self.variant.max_utf8_buffer_length(byte_length) self.variant.max_utf8_buffer_length(byte_length)
{ {
return Some(std::cmp::max(utf_bom, non_bom)); return Some(core::cmp::max(utf_bom, non_bom));
} }
} }
} }
@ -3699,7 +3774,7 @@ impl Decoder {
// because it is at start, because no data has reached it yet. // because it is at start, because no data has reached it yet.
return Some(utf8_bom); return Some(utf8_bom);
} else if let Some(non_bom) = self.variant.max_utf8_buffer_length(sum) { } else if let Some(non_bom) = self.variant.max_utf8_buffer_length(sum) {
return Some(std::cmp::max(utf8_bom, non_bom)); return Some(core::cmp::max(utf8_bom, non_bom));
} }
} }
} }
@ -3725,7 +3800,7 @@ impl Decoder {
// because it is at start, because no data has reached it yet. // because it is at start, because no data has reached it yet.
return Some(utf16_bom); return Some(utf16_bom);
} else if let Some(non_bom) = self.variant.max_utf8_buffer_length(sum) { } else if let Some(non_bom) = self.variant.max_utf8_buffer_length(sum) {
return Some(std::cmp::max(utf16_bom, non_bom)); return Some(core::cmp::max(utf16_bom, non_bom));
} }
} }
} }
@ -3764,7 +3839,7 @@ impl Decoder {
1, 1,
checked_mul(3, checked_div(byte_length.checked_add(1), 2)), checked_mul(3, checked_div(byte_length.checked_add(1), 2)),
) { ) {
let utf_bom = std::cmp::max(utf8_bom, utf16_bom); let utf_bom = core::cmp::max(utf8_bom, utf16_bom);
let encoding = self.encoding(); let encoding = self.encoding();
if encoding == UTF_8 || encoding == UTF_16LE || encoding == UTF_16BE { if encoding == UTF_8 || encoding == UTF_16LE || encoding == UTF_16BE {
// No need to consider the internal state of the underlying decoder, // No need to consider the internal state of the underlying decoder,
@ -3774,7 +3849,7 @@ impl Decoder {
.variant .variant
.max_utf8_buffer_length_without_replacement(byte_length) .max_utf8_buffer_length_without_replacement(byte_length)
{ {
return Some(std::cmp::max(utf_bom, non_bom)); return Some(core::cmp::max(utf_bom, non_bom));
} }
} }
} }
@ -3794,7 +3869,7 @@ impl Decoder {
} else if let Some(non_bom) = } else if let Some(non_bom) =
self.variant.max_utf8_buffer_length_without_replacement(sum) self.variant.max_utf8_buffer_length_without_replacement(sum)
{ {
return Some(std::cmp::max(utf8_bom, non_bom)); return Some(core::cmp::max(utf8_bom, non_bom));
} }
} }
} }
@ -3822,7 +3897,7 @@ impl Decoder {
} else if let Some(non_bom) = } else if let Some(non_bom) =
self.variant.max_utf8_buffer_length_without_replacement(sum) self.variant.max_utf8_buffer_length_without_replacement(sum)
{ {
return Some(std::cmp::max(utf16_bom, non_bom)); return Some(core::cmp::max(utf16_bom, non_bom));
} }
} }
} }
@ -3916,7 +3991,7 @@ impl Decoder {
// bytes of trailing garbage. No need to optimize non-ASCII-compatible // bytes of trailing garbage. No need to optimize non-ASCII-compatible
// encodings to avoid overwriting here. // encodings to avoid overwriting here.
if self.encoding != UTF_8 { if self.encoding != UTF_8 {
let max = std::cmp::min(len, trail + ascii::MAX_STRIDE_SIZE); let max = core::cmp::min(len, trail + ascii::MAX_STRIDE_SIZE);
while trail < max { while trail < max {
bytes[trail] = 0; bytes[trail] = 0;
trail += 1; trail += 1;
@ -3945,7 +4020,9 @@ impl Decoder {
/// See the documentation of the struct for documentation for `decode_*` /// See the documentation of the struct for documentation for `decode_*`
/// methods collectively. /// methods collectively.
/// ///
/// Available to Rust only. /// Available to Rust only and only with the `alloc` feature enabled (enabled
/// by default).
#[cfg(feature = "alloc")]
pub fn decode_to_string( pub fn decode_to_string(
&mut self, &mut self,
src: &[u8], src: &[u8],
@ -4006,7 +4083,7 @@ impl Decoder {
// bytes of trailing garbage. No need to optimize non-ASCII-compatible // bytes of trailing garbage. No need to optimize non-ASCII-compatible
// encodings to avoid overwriting here. // encodings to avoid overwriting here.
if self.encoding != UTF_8 { if self.encoding != UTF_8 {
let max = std::cmp::min(len, trail + ascii::MAX_STRIDE_SIZE); let max = core::cmp::min(len, trail + ascii::MAX_STRIDE_SIZE);
while trail < max { while trail < max {
bytes[trail] = 0; bytes[trail] = 0;
trail += 1; trail += 1;
@ -4033,7 +4110,9 @@ impl Decoder {
/// See the documentation of the struct for documentation for `decode_*` /// See the documentation of the struct for documentation for `decode_*`
/// methods collectively. /// methods collectively.
/// ///
/// Available to Rust only. /// Available to Rust only and only with the `alloc` feature enabled (enabled
/// by default).
#[cfg(feature = "alloc")]
pub fn decode_to_string_without_replacement( pub fn decode_to_string_without_replacement(
&mut self, &mut self,
src: &[u8], src: &[u8],
@ -4079,7 +4158,7 @@ impl Decoder {
if let Some(utf16_bom) = if let Some(utf16_bom) =
checked_add(1, checked_div(byte_length.checked_add(1), 2)) checked_add(1, checked_div(byte_length.checked_add(1), 2))
{ {
let utf_bom = std::cmp::max(utf8_bom, utf16_bom); let utf_bom = core::cmp::max(utf8_bom, utf16_bom);
let encoding = self.encoding(); let encoding = self.encoding();
if encoding == UTF_8 || encoding == UTF_16LE || encoding == UTF_16BE { if encoding == UTF_8 || encoding == UTF_16LE || encoding == UTF_16BE {
// No need to consider the internal state of the underlying decoder, // No need to consider the internal state of the underlying decoder,
@ -4088,7 +4167,7 @@ impl Decoder {
} else if let Some(non_bom) = } else if let Some(non_bom) =
self.variant.max_utf16_buffer_length(byte_length) self.variant.max_utf16_buffer_length(byte_length)
{ {
return Some(std::cmp::max(utf_bom, non_bom)); return Some(core::cmp::max(utf_bom, non_bom));
} }
} }
} }
@ -4106,7 +4185,7 @@ impl Decoder {
// because it is at start, because no data has reached it yet. // because it is at start, because no data has reached it yet.
return Some(utf8_bom); return Some(utf8_bom);
} else if let Some(non_bom) = self.variant.max_utf16_buffer_length(sum) { } else if let Some(non_bom) = self.variant.max_utf16_buffer_length(sum) {
return Some(std::cmp::max(utf8_bom, non_bom)); return Some(core::cmp::max(utf8_bom, non_bom));
} }
} }
} }
@ -4130,7 +4209,7 @@ impl Decoder {
// because it is at start, because no data has reached it yet. // because it is at start, because no data has reached it yet.
return Some(utf16_bom); return Some(utf16_bom);
} else if let Some(non_bom) = self.variant.max_utf16_buffer_length(sum) { } else if let Some(non_bom) = self.variant.max_utf16_buffer_length(sum) {
return Some(std::cmp::max(utf16_bom, non_bom)); return Some(core::cmp::max(utf16_bom, non_bom));
} }
} }
} }
@ -4265,7 +4344,7 @@ pub enum EncoderResult {
impl EncoderResult { impl EncoderResult {
fn unmappable_from_bmp(bmp: u16) -> EncoderResult { fn unmappable_from_bmp(bmp: u16) -> EncoderResult {
EncoderResult::Unmappable(::std::char::from_u32(u32::from(bmp)).unwrap()) EncoderResult::Unmappable(::core::char::from_u32(u32::from(bmp)).unwrap())
} }
} }
@ -4532,7 +4611,9 @@ impl Encoder {
/// See the documentation of the struct for documentation for `encode_*` /// See the documentation of the struct for documentation for `encode_*`
/// methods collectively. /// methods collectively.
/// ///
/// Available to Rust only. /// Available to Rust only and only with the `alloc` feature enabled (enabled
/// by default).
#[cfg(feature = "alloc")]
pub fn encode_from_utf8_to_vec( pub fn encode_from_utf8_to_vec(
&mut self, &mut self,
src: &str, src: &str,
@ -4570,7 +4651,9 @@ impl Encoder {
/// See the documentation of the struct for documentation for `encode_*` /// See the documentation of the struct for documentation for `encode_*`
/// methods collectively. /// methods collectively.
/// ///
/// Available to Rust only. /// Available to Rust only and only with the `alloc` feature enabled (enabled
/// by default).
#[cfg(feature = "alloc")]
pub fn encode_from_utf8_to_vec_without_replacement( pub fn encode_from_utf8_to_vec_without_replacement(
&mut self, &mut self,
src: &str, src: &str,
@ -4836,16 +4919,18 @@ fn checked_div(opt: Option<usize>, num: usize) -> Option<usize> {
} }
} }
#[cfg(feature = "alloc")]
#[inline(always)] #[inline(always)]
fn checked_next_power_of_two(opt: Option<usize>) -> Option<usize> { fn checked_next_power_of_two(opt: Option<usize>) -> Option<usize> {
opt.map(|n| n.next_power_of_two()) opt.map(|n| n.next_power_of_two())
} }
#[cfg(feature = "alloc")]
#[inline(always)] #[inline(always)]
fn checked_min(one: Option<usize>, other: Option<usize>) -> Option<usize> { fn checked_min(one: Option<usize>, other: Option<usize>) -> Option<usize> {
if let Some(a) = one { if let Some(a) = one {
if let Some(b) = other { if let Some(b) = other {
Some(::std::cmp::min(a, b)) Some(::core::cmp::min(a, b))
} else { } else {
Some(a) Some(a)
} }
@ -4867,10 +4952,10 @@ struct Demo {
#[cfg(test)] #[cfg(test)]
mod test_labels_names; mod test_labels_names;
#[cfg(test)] #[cfg(all(test, feature = "alloc"))]
mod tests { mod tests {
use super::*; use super::*;
use std::borrow::Cow; use alloc::borrow::Cow;
fn sniff_to_utf16( fn sniff_to_utf16(
initial_encoding: &'static Encoding, initial_encoding: &'static Encoding,
@ -5623,7 +5708,7 @@ mod tests {
#[test] #[test]
fn test_hash() { fn test_hash() {
let mut encodings = ::std::collections::HashSet::new(); let mut encodings = ::alloc::collections::btree_set::BTreeSet::new();
encodings.insert(UTF_8); encodings.insert(UTF_8);
encodings.insert(ISO_2022_JP); encodings.insert(ISO_2022_JP);
assert!(encodings.contains(UTF_8)); assert!(encodings.contains(UTF_8));

View file

@ -1,4 +1,4 @@
// Copyright 2015-2016 Mozilla Foundation. See the COPYRIGHT // Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -571,7 +571,7 @@ macro_rules! gb18030_decoder_function {
} }
Space::Available(destination_handle) => { Space::Available(destination_handle) => {
let (b, _) = source_handle.read(); let (b, _) = source_handle.read();
'innermost: loop { loop {
if b > 127 { if b > 127 {
$non_ascii = b; $non_ascii = b;
$handle = destination_handle; $handle = destination_handle;
@ -875,7 +875,7 @@ macro_rules! euc_jp_decoder_function {
} }
Space::Available(destination_handle) => { Space::Available(destination_handle) => {
let (b, _) = source_handle.read(); let (b, _) = source_handle.read();
'innermost: loop { loop {
if b > 127 { if b > 127 {
$non_ascii = b; $non_ascii = b;
$handle = destination_handle; $handle = destination_handle;

View file

@ -1,4 +1,4 @@
// Copyright 2015-2016 Mozilla Foundation. See the COPYRIGHT // Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -24,7 +24,12 @@
//! The FFI binding for this module are in the //! The FFI binding for this module are in the
//! [encoding_c_mem crate](https://github.com/hsivonen/encoding_c_mem). //! [encoding_c_mem crate](https://github.com/hsivonen/encoding_c_mem).
use std::borrow::Cow; #[cfg(feature = "alloc")]
use alloc::borrow::Cow;
#[cfg(feature = "alloc")]
use alloc::string::String;
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
use super::in_inclusive_range16; use super::in_inclusive_range16;
use super::in_inclusive_range32; use super::in_inclusive_range32;
@ -32,8 +37,8 @@ use super::in_inclusive_range8;
use super::in_range16; use super::in_range16;
use super::in_range32; use super::in_range32;
use super::DecoderResult; use super::DecoderResult;
use ascii::*; use crate::ascii::*;
use utf_8::*; use crate::utf_8::*;
macro_rules! non_fuzz_debug_assert { macro_rules! non_fuzz_debug_assert {
($($arg:tt)*) => (if !cfg!(fuzzing) { debug_assert!($($arg)*); }) ($($arg:tt)*) => (if !cfg!(fuzzing) { debug_assert!($($arg)*); })
@ -41,8 +46,8 @@ macro_rules! non_fuzz_debug_assert {
cfg_if! { cfg_if! {
if #[cfg(feature = "simd-accel")] { if #[cfg(feature = "simd-accel")] {
use ::std::intrinsics::likely; use ::core::intrinsics::likely;
use ::std::intrinsics::unlikely; use ::core::intrinsics::unlikely;
} else { } else {
#[inline(always)] #[inline(always)]
// Unsafe to match the intrinsic, which is needlessly unsafe. // Unsafe to match the intrinsic, which is needlessly unsafe.
@ -85,7 +90,7 @@ macro_rules! by_unit_check_alu {
fn $name(buffer: &[$unit]) -> bool { fn $name(buffer: &[$unit]) -> bool {
let mut offset = 0usize; let mut offset = 0usize;
let mut accu = 0usize; let mut accu = 0usize;
let unit_size = ::std::mem::size_of::<$unit>(); let unit_size = ::core::mem::size_of::<$unit>();
let len = buffer.len(); let len = buffer.len();
if len >= ALU_ALIGNMENT / unit_size { if len >= ALU_ALIGNMENT / unit_size {
// The most common reason to return `false` is for the first code // The most common reason to return `false` is for the first code
@ -157,7 +162,7 @@ macro_rules! by_unit_check_simd {
fn $name(buffer: &[$unit]) -> bool { fn $name(buffer: &[$unit]) -> bool {
let mut offset = 0usize; let mut offset = 0usize;
let mut accu = 0usize; let mut accu = 0usize;
let unit_size = ::std::mem::size_of::<$unit>(); let unit_size = ::core::mem::size_of::<$unit>();
let len = buffer.len(); let len = buffer.len();
if len >= SIMD_STRIDE_SIZE / unit_size { if len >= SIMD_STRIDE_SIZE / unit_size {
// The most common reason to return `false` is for the first code // The most common reason to return `false` is for the first code
@ -230,7 +235,7 @@ macro_rules! by_unit_check_simd {
cfg_if! { cfg_if! {
if #[cfg(all(feature = "simd-accel", any(target_feature = "sse2", all(target_endian = "little", target_arch = "aarch64"), all(target_endian = "little", target_feature = "neon"))))] { if #[cfg(all(feature = "simd-accel", any(target_feature = "sse2", all(target_endian = "little", target_arch = "aarch64"), all(target_endian = "little", target_feature = "neon"))))] {
use simd_funcs::*; use crate::simd_funcs::*;
use packed_simd::u8x16; use packed_simd::u8x16;
use packed_simd::u16x8; use packed_simd::u16x8;
@ -248,7 +253,7 @@ cfg_if! {
// only aligned SIMD (perhaps misguidedly) and needs to deal with // only aligned SIMD (perhaps misguidedly) and needs to deal with
// the last code unit in a SIMD stride being part of a valid // the last code unit in a SIMD stride being part of a valid
// surrogate pair. // surrogate pair.
let unit_size = ::std::mem::size_of::<u16>(); let unit_size = ::core::mem::size_of::<u16>();
let src = buffer.as_ptr(); let src = buffer.as_ptr();
let len = buffer.len(); let len = buffer.len();
let mut offset = 0usize; let mut offset = 0usize;
@ -276,7 +281,7 @@ cfg_if! {
offset = offset_plus_until_alignment; offset = offset_plus_until_alignment;
} }
let len_minus_stride = len - SIMD_STRIDE_SIZE / unit_size; let len_minus_stride = len - SIMD_STRIDE_SIZE / unit_size;
'inner: loop { loop {
let offset_plus_stride = offset + SIMD_STRIDE_SIZE / unit_size; let offset_plus_stride = offset + SIMD_STRIDE_SIZE / unit_size;
if contains_surrogates(unsafe { *(src.add(offset) as *const u16x8) }) { if contains_surrogates(unsafe { *(src.add(offset) as *const u16x8) }) {
if offset_plus_stride == len { if offset_plus_stride == len {
@ -740,13 +745,13 @@ pub fn is_utf8_bidi(buffer: &[u8]) -> bool {
'inner: loop { 'inner: loop {
// At this point, `byte` is not included in `read`. // At this point, `byte` is not included in `read`.
match byte { match byte {
0...0x7F => { 0..=0x7F => {
// ASCII: go back to SIMD. // ASCII: go back to SIMD.
read += 1; read += 1;
src = &src[read..]; src = &src[read..];
continue 'outer; continue 'outer;
} }
0xC2...0xD5 => { 0xC2..=0xD5 => {
// Two-byte // Two-byte
let second = unsafe { *(src.get_unchecked(read + 1)) }; let second = unsafe { *(src.get_unchecked(read + 1)) };
if !in_inclusive_range8(second, 0x80, 0xBF) { if !in_inclusive_range8(second, 0x80, 0xBF) {
@ -767,7 +772,7 @@ pub fn is_utf8_bidi(buffer: &[u8]) -> bool {
read += 2; read += 2;
} }
// two-byte starting with 0xD7 and above is bidi // two-byte starting with 0xD7 and above is bidi
0xE1 | 0xE3...0xEC | 0xEE => { 0xE1 | 0xE3..=0xEC | 0xEE => {
// Three-byte normal // Three-byte normal
let second = unsafe { *(src.get_unchecked(read + 1)) }; let second = unsafe { *(src.get_unchecked(read + 1)) };
let third = unsafe { *(src.get_unchecked(read + 2)) }; let third = unsafe { *(src.get_unchecked(read + 2)) };
@ -876,7 +881,7 @@ pub fn is_utf8_bidi(buffer: &[u8]) -> bool {
} }
read += 3; read += 3;
} }
0xF1...0xF4 => { 0xF1..=0xF4 => {
// Four-byte normal // Four-byte normal
let second = unsafe { *(src.get_unchecked(read + 1)) }; let second = unsafe { *(src.get_unchecked(read + 1)) };
let third = unsafe { *(src.get_unchecked(read + 2)) }; let third = unsafe { *(src.get_unchecked(read + 2)) };
@ -939,13 +944,13 @@ pub fn is_utf8_bidi(buffer: &[u8]) -> bool {
// At this point, `byte` is not included in `read`. // At this point, `byte` is not included in `read`.
match byte { match byte {
0...0x7F => { 0..=0x7F => {
// ASCII: go back to SIMD. // ASCII: go back to SIMD.
read += 1; read += 1;
src = &src[read..]; src = &src[read..];
continue 'outer; continue 'outer;
} }
0xC2...0xD5 => { 0xC2..=0xD5 => {
// Two-byte // Two-byte
let new_read = read + 2; let new_read = read + 2;
if new_read > src.len() { if new_read > src.len() {
@ -982,7 +987,7 @@ pub fn is_utf8_bidi(buffer: &[u8]) -> bool {
continue 'outer; continue 'outer;
} }
// two-byte starting with 0xD7 and above is bidi // two-byte starting with 0xD7 and above is bidi
0xE1 | 0xE3...0xEC | 0xEE => { 0xE1 | 0xE3..=0xEC | 0xEE => {
// Three-byte normal // Three-byte normal
let new_read = read + 3; let new_read = read + 3;
if new_read > src.len() { if new_read > src.len() {
@ -1781,7 +1786,7 @@ pub fn convert_latin1_to_utf8_partial(src: &[u8], dst: &mut [u8]) -> (usize, usi
// src can't advance more than dst // src can't advance more than dst
let src_left = src_len - total_read; let src_left = src_len - total_read;
let dst_left = dst_len - total_written; let dst_left = dst_len - total_written;
let min_left = ::std::cmp::min(src_left, dst_left); let min_left = ::core::cmp::min(src_left, dst_left);
if let Some((non_ascii, consumed)) = unsafe { if let Some((non_ascii, consumed)) = unsafe {
ascii_to_ascii( ascii_to_ascii(
src_ptr.add(total_read), src_ptr.add(total_read),
@ -1850,7 +1855,7 @@ pub fn convert_latin1_to_str_partial(src: &[u8], dst: &mut str) -> (usize, usize
let (read, written) = convert_latin1_to_utf8_partial(src, bytes); let (read, written) = convert_latin1_to_utf8_partial(src, bytes);
let len = bytes.len(); let len = bytes.len();
let mut trail = written; let mut trail = written;
let max = ::std::cmp::min(len, trail + MAX_STRIDE_SIZE); let max = ::core::cmp::min(len, trail + MAX_STRIDE_SIZE);
while trail < max { while trail < max {
bytes[trail] = 0; bytes[trail] = 0;
trail += 1; trail += 1;
@ -1986,12 +1991,15 @@ pub fn convert_utf16_to_latin1_lossy(src: &[u16], dst: &mut [u8]) {
/// ///
/// Borrows if input is ASCII-only. Performs a single heap allocation /// Borrows if input is ASCII-only. Performs a single heap allocation
/// otherwise. /// otherwise.
///
/// Only available if the `alloc` feature is enabled (enabled by default).
#[cfg(feature = "alloc")]
pub fn decode_latin1<'a>(bytes: &'a [u8]) -> Cow<'a, str> { pub fn decode_latin1<'a>(bytes: &'a [u8]) -> Cow<'a, str> {
let up_to = ascii_valid_up_to(bytes); let up_to = ascii_valid_up_to(bytes);
// >= makes later things optimize better than == // >= makes later things optimize better than ==
if up_to >= bytes.len() { if up_to >= bytes.len() {
debug_assert_eq!(up_to, bytes.len()); debug_assert_eq!(up_to, bytes.len());
let s: &str = unsafe { ::std::str::from_utf8_unchecked(bytes) }; let s: &str = unsafe { ::core::str::from_utf8_unchecked(bytes) };
return Cow::Borrowed(s); return Cow::Borrowed(s);
} }
let (head, tail) = bytes.split_at(up_to); let (head, tail) = bytes.split_at(up_to);
@ -2020,6 +2028,9 @@ pub fn decode_latin1<'a>(bytes: &'a [u8]) -> Cow<'a, str> {
/// ///
/// Borrows if input is ASCII-only. Performs a single heap allocation /// Borrows if input is ASCII-only. Performs a single heap allocation
/// otherwise. /// otherwise.
///
/// Only available if the `alloc` feature is enabled (enabled by default).
#[cfg(feature = "alloc")]
pub fn encode_latin1_lossy<'a>(string: &'a str) -> Cow<'a, [u8]> { pub fn encode_latin1_lossy<'a>(string: &'a str) -> Cow<'a, [u8]> {
let bytes = string.as_bytes(); let bytes = string.as_bytes();
let up_to = ascii_valid_up_to(bytes); let up_to = ascii_valid_up_to(bytes);
@ -2056,7 +2067,7 @@ pub fn utf8_latin1_up_to(buffer: &[u8]) -> usize {
/// Returns the index of first byte that starts a non-Latin1 byte /// Returns the index of first byte that starts a non-Latin1 byte
/// sequence, or the length of the string if there are none. /// sequence, or the length of the string if there are none.
pub fn str_latin1_up_to(buffer: &str) -> usize { pub fn str_latin1_up_to(buffer: &str) -> usize {
is_str_latin1_impl(buffer).unwrap_or(buffer.len()) is_str_latin1_impl(buffer).unwrap_or_else(|| buffer.len())
} }
/// Replaces unpaired surrogates in the input with the REPLACEMENT CHARACTER. /// Replaces unpaired surrogates in the input with the REPLACEMENT CHARACTER.
@ -2153,7 +2164,7 @@ pub fn copy_basic_latin_to_ascii(src: &[u16], dst: &mut [u8]) -> usize {
// Any copyright to the test code below this comment is dedicated to the // Any copyright to the test code below this comment is dedicated to the
// Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ // Public Domain. http://creativecommons.org/publicdomain/zero/1.0/
#[cfg(test)] #[cfg(all(test, feature = "alloc"))]
mod tests { mod tests {
use super::*; use super::*;
@ -2231,8 +2242,9 @@ mod tests {
#[test] #[test]
fn test_is_utf16_latin1_fail() { fn test_is_utf16_latin1_fail() {
let mut src: Vec<u16> = Vec::with_capacity(256); let len = if cfg!(miri) { 64 } else { 256 }; // Miri is too slow
src.resize(256, 0); let mut src: Vec<u16> = Vec::with_capacity(len);
src.resize(len, 0);
for i in 0..src.len() { for i in 0..src.len() {
src[i] = i as u16; src[i] = i as u16;
} }
@ -2248,8 +2260,9 @@ mod tests {
#[test] #[test]
fn test_is_str_latin1_success() { fn test_is_str_latin1_success() {
let mut src: Vec<u16> = Vec::with_capacity(256); let len = if cfg!(miri) { 64 } else { 256 }; // Miri is too slow
src.resize(256, 0); let mut src: Vec<u16> = Vec::with_capacity(len);
src.resize(len, 0);
for i in 0..src.len() { for i in 0..src.len() {
src[i] = i as u16; src[i] = i as u16;
} }
@ -2262,8 +2275,9 @@ mod tests {
#[test] #[test]
fn test_is_str_latin1_fail() { fn test_is_str_latin1_fail() {
let mut src: Vec<u16> = Vec::with_capacity(256); let len = if cfg!(miri) { 32 } else { 256 }; // Miri is too slow
src.resize(256, 0); let mut src: Vec<u16> = Vec::with_capacity(len);
src.resize(len, 0);
for i in 0..src.len() { for i in 0..src.len() {
src[i] = i as u16; src[i] = i as u16;
} }
@ -2280,8 +2294,9 @@ mod tests {
#[test] #[test]
fn test_is_utf8_latin1_success() { fn test_is_utf8_latin1_success() {
let mut src: Vec<u16> = Vec::with_capacity(256); let len = if cfg!(miri) { 64 } else { 256 }; // Miri is too slow
src.resize(256, 0); let mut src: Vec<u16> = Vec::with_capacity(len);
src.resize(len, 0);
for i in 0..src.len() { for i in 0..src.len() {
src[i] = i as u16; src[i] = i as u16;
} }
@ -2297,8 +2312,9 @@ mod tests {
#[test] #[test]
fn test_is_utf8_latin1_fail() { fn test_is_utf8_latin1_fail() {
let mut src: Vec<u16> = Vec::with_capacity(256); let len = if cfg!(miri) { 32 } else { 256 }; // Miri is too slow
src.resize(256, 0); let mut src: Vec<u16> = Vec::with_capacity(len);
src.resize(len, 0);
for i in 0..src.len() { for i in 0..src.len() {
src[i] = i as u16; src[i] = i as u16;
} }
@ -3112,11 +3128,11 @@ mod tests {
#[inline(always)] #[inline(always)]
pub fn reference_is_char_bidi(c: char) -> bool { pub fn reference_is_char_bidi(c: char) -> bool {
match c { match c {
'\u{0590}'...'\u{08FF}' '\u{0590}'..='\u{08FF}'
| '\u{FB1D}'...'\u{FDFF}' | '\u{FB1D}'..='\u{FDFF}'
| '\u{FE70}'...'\u{FEFE}' | '\u{FE70}'..='\u{FEFE}'
| '\u{10800}'...'\u{10FFF}' | '\u{10800}'..='\u{10FFF}'
| '\u{1E800}'...'\u{1EFFF}' | '\u{1E800}'..='\u{1EFFF}'
| '\u{200F}' | '\u{200F}'
| '\u{202B}' | '\u{202B}'
| '\u{202E}' | '\u{202E}'
@ -3128,9 +3144,9 @@ mod tests {
#[inline(always)] #[inline(always)]
pub fn reference_is_utf16_code_unit_bidi(u: u16) -> bool { pub fn reference_is_utf16_code_unit_bidi(u: u16) -> bool {
match u { match u {
0x0590...0x08FF 0x0590..=0x08FF
| 0xFB1D...0xFDFF | 0xFB1D..=0xFDFF
| 0xFE70...0xFEFE | 0xFE70..=0xFEFE
| 0xD802 | 0xD802
| 0xD803 | 0xD803
| 0xD83A | 0xD83A
@ -3144,18 +3160,20 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_is_char_bidi_thoroughly() { fn test_is_char_bidi_thoroughly() {
for i in 0..0xD800u32 { for i in 0..0xD800u32 {
let c: char = ::std::char::from_u32(i).unwrap(); let c: char = ::core::char::from_u32(i).unwrap();
assert_eq!(is_char_bidi(c), reference_is_char_bidi(c)); assert_eq!(is_char_bidi(c), reference_is_char_bidi(c));
} }
for i in 0xE000..0x110000u32 { for i in 0xE000..0x110000u32 {
let c: char = ::std::char::from_u32(i).unwrap(); let c: char = ::core::char::from_u32(i).unwrap();
assert_eq!(is_char_bidi(c), reference_is_char_bidi(c)); assert_eq!(is_char_bidi(c), reference_is_char_bidi(c));
} }
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_is_utf16_code_unit_bidi_thoroughly() { fn test_is_utf16_code_unit_bidi_thoroughly() {
for i in 0..0x10000u32 { for i in 0..0x10000u32 {
let u = i as u16; let u = i as u16;
@ -3167,17 +3185,18 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_is_str_bidi_thoroughly() { fn test_is_str_bidi_thoroughly() {
let mut buf = [0; 4]; let mut buf = [0; 4];
for i in 0..0xD800u32 { for i in 0..0xD800u32 {
let c: char = ::std::char::from_u32(i).unwrap(); let c: char = ::core::char::from_u32(i).unwrap();
assert_eq!( assert_eq!(
is_str_bidi(c.encode_utf8(&mut buf[..])), is_str_bidi(c.encode_utf8(&mut buf[..])),
reference_is_char_bidi(c) reference_is_char_bidi(c)
); );
} }
for i in 0xE000..0x110000u32 { for i in 0xE000..0x110000u32 {
let c: char = ::std::char::from_u32(i).unwrap(); let c: char = ::core::char::from_u32(i).unwrap();
assert_eq!( assert_eq!(
is_str_bidi(c.encode_utf8(&mut buf[..])), is_str_bidi(c.encode_utf8(&mut buf[..])),
reference_is_char_bidi(c) reference_is_char_bidi(c)
@ -3186,10 +3205,11 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_is_utf8_bidi_thoroughly() { fn test_is_utf8_bidi_thoroughly() {
let mut buf = [0; 8]; let mut buf = [0; 8];
for i in 0..0xD800u32 { for i in 0..0xD800u32 {
let c: char = ::std::char::from_u32(i).unwrap(); let c: char = ::core::char::from_u32(i).unwrap();
let expect = reference_is_char_bidi(c); let expect = reference_is_char_bidi(c);
{ {
let len = { let len = {
@ -3207,7 +3227,7 @@ mod tests {
assert_eq!(is_utf8_bidi(&buf[..]), expect); assert_eq!(is_utf8_bidi(&buf[..]), expect);
} }
for i in 0xE000..0x110000u32 { for i in 0xE000..0x110000u32 {
let c: char = ::std::char::from_u32(i).unwrap(); let c: char = ::core::char::from_u32(i).unwrap();
let expect = reference_is_char_bidi(c); let expect = reference_is_char_bidi(c);
{ {
let len = { let len = {
@ -3227,6 +3247,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_is_utf16_bidi_thoroughly() { fn test_is_utf16_bidi_thoroughly() {
let mut buf = [0; 32]; let mut buf = [0; 32];
for i in 0..0x10000u32 { for i in 0..0x10000u32 {

View file

@ -1,4 +1,4 @@
// Copyright 2015-2016 Mozilla Foundation. See the COPYRIGHT // Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -8,7 +8,7 @@
// except according to those terms. // except according to those terms.
use super::*; use super::*;
use variant::*; use crate::variant::*;
pub struct ReplacementDecoder { pub struct ReplacementDecoder {
emitted: bool, emitted: bool,
@ -73,7 +73,7 @@ impl ReplacementDecoder {
// Any copyright to the test code below this comment is dedicated to the // Any copyright to the test code below this comment is dedicated to the
// Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ // Public Domain. http://creativecommons.org/publicdomain/zero/1.0/
#[cfg(test)] #[cfg(all(test, feature = "alloc"))]
mod tests { mod tests {
use super::super::testing::*; use super::super::testing::*;
use super::super::*; use super::super::*;

View file

@ -1,4 +1,4 @@
// Copyright 2015-2016 Mozilla Foundation. See the COPYRIGHT // Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -8,9 +8,9 @@
// except according to those terms. // except according to those terms.
use super::*; use super::*;
use data::*; use crate::data::*;
use handles::*; use crate::handles::*;
use variant::*; use crate::variant::*;
// Rust 1.14.0 requires the following despite the asterisk above. // Rust 1.14.0 requires the following despite the asterisk above.
use super::in_inclusive_range; use super::in_inclusive_range;
use super::in_inclusive_range16; use super::in_inclusive_range16;
@ -305,7 +305,7 @@ impl ShiftJisEncoder {
// Any copyright to the test code below this comment is dedicated to the // Any copyright to the test code below this comment is dedicated to the
// Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ // Public Domain. http://creativecommons.org/publicdomain/zero/1.0/
#[cfg(test)] #[cfg(all(test, feature = "alloc"))]
mod tests { mod tests {
use super::super::testing::*; use super::super::testing::*;
use super::super::*; use super::super::*;
@ -385,6 +385,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_shift_jis_decode_all() { fn test_shift_jis_decode_all() {
let input = include_bytes!("test_data/shift_jis_in.txt"); let input = include_bytes!("test_data/shift_jis_in.txt");
let expectation = include_str!("test_data/shift_jis_in_ref.txt"); let expectation = include_str!("test_data/shift_jis_in_ref.txt");
@ -394,6 +395,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_shift_jis_encode_all() { fn test_shift_jis_encode_all() {
let input = include_str!("test_data/shift_jis_out.txt"); let input = include_str!("test_data/shift_jis_out.txt");
let expectation = include_bytes!("test_data/shift_jis_out_ref.txt"); let expectation = include_bytes!("test_data/shift_jis_out_ref.txt");

View file

@ -1,4 +1,4 @@
// Copyright 2016 Mozilla Foundation. See the COPYRIGHT // Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -16,8 +16,8 @@ use packed_simd::FromBits;
#[inline(always)] #[inline(always)]
pub unsafe fn load16_unaligned(ptr: *const u8) -> u8x16 { pub unsafe fn load16_unaligned(ptr: *const u8) -> u8x16 {
let mut simd = ::std::mem::uninitialized(); let mut simd = ::core::mem::uninitialized();
::std::ptr::copy_nonoverlapping(ptr, &mut simd as *mut u8x16 as *mut u8, 16); ::core::ptr::copy_nonoverlapping(ptr, &mut simd as *mut u8x16 as *mut u8, 16);
simd simd
} }
@ -29,7 +29,7 @@ pub unsafe fn load16_aligned(ptr: *const u8) -> u8x16 {
#[inline(always)] #[inline(always)]
pub unsafe fn store16_unaligned(ptr: *mut u8, s: u8x16) { pub unsafe fn store16_unaligned(ptr: *mut u8, s: u8x16) {
::std::ptr::copy_nonoverlapping(&s as *const u8x16 as *const u8, ptr, 16); ::core::ptr::copy_nonoverlapping(&s as *const u8x16 as *const u8, ptr, 16);
} }
#[allow(dead_code)] #[allow(dead_code)]
@ -40,8 +40,8 @@ pub unsafe fn store16_aligned(ptr: *mut u8, s: u8x16) {
#[inline(always)] #[inline(always)]
pub unsafe fn load8_unaligned(ptr: *const u16) -> u16x8 { pub unsafe fn load8_unaligned(ptr: *const u16) -> u16x8 {
let mut simd = ::std::mem::uninitialized(); let mut simd = ::core::mem::uninitialized();
::std::ptr::copy_nonoverlapping(ptr as *const u8, &mut simd as *mut u16x8 as *mut u8, 16); ::core::ptr::copy_nonoverlapping(ptr as *const u8, &mut simd as *mut u16x8 as *mut u8, 16);
simd simd
} }
@ -53,7 +53,7 @@ pub unsafe fn load8_aligned(ptr: *const u16) -> u16x8 {
#[inline(always)] #[inline(always)]
pub unsafe fn store8_unaligned(ptr: *mut u16, s: u16x8) { pub unsafe fn store8_unaligned(ptr: *mut u16, s: u16x8) {
::std::ptr::copy_nonoverlapping(&s as *const u16x8 as *const u8, ptr as *mut u8, 16); ::core::ptr::copy_nonoverlapping(&s as *const u16x8 as *const u8, ptr as *mut u8, 16);
} }
#[allow(dead_code)] #[allow(dead_code)]
@ -64,18 +64,18 @@ pub unsafe fn store8_aligned(ptr: *mut u16, s: u16x8) {
cfg_if! { cfg_if! {
if #[cfg(all(target_feature = "sse2", target_arch = "x86_64"))] { if #[cfg(all(target_feature = "sse2", target_arch = "x86_64"))] {
use std::arch::x86_64::__m128i; use core::arch::x86_64::__m128i;
use std::arch::x86_64::_mm_movemask_epi8; use core::arch::x86_64::_mm_movemask_epi8;
use std::arch::x86_64::_mm_packus_epi16; use core::arch::x86_64::_mm_packus_epi16;
} else if #[cfg(all(target_feature = "sse2", target_arch = "x86"))] { } else if #[cfg(all(target_feature = "sse2", target_arch = "x86"))] {
use std::arch::x86::__m128i; use core::arch::x86::__m128i;
use std::arch::x86::_mm_movemask_epi8; use core::arch::x86::_mm_movemask_epi8;
use std::arch::x86::_mm_packus_epi16; use core::arch::x86::_mm_packus_epi16;
} else if #[cfg(target_arch = "aarch64")]{ } else if #[cfg(target_arch = "aarch64")]{
use std::arch::aarch64::uint8x16_t; use core::arch::aarch64::uint8x16_t;
use std::arch::aarch64::uint16x8_t; use core::arch::aarch64::uint16x8_t;
use std::arch::aarch64::vmaxvq_u8; use core::arch::aarch64::vmaxvq_u8;
use std::arch::aarch64::vmaxvq_u16; use core::arch::aarch64::vmaxvq_u16;
} else { } else {
} }
@ -327,6 +327,7 @@ cfg_if! {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use alloc::vec::Vec;
#[test] #[test]
fn test_unpack() { fn test_unpack() {
@ -446,7 +447,7 @@ mod tests {
]; ];
let mut alu = 0u64; let mut alu = 0u64;
unsafe { unsafe {
::std::ptr::copy_nonoverlapping(input.as_ptr(), &mut alu as *mut u64 as *mut u8, 8); ::core::ptr::copy_nonoverlapping(input.as_ptr(), &mut alu as *mut u64 as *mut u8, 8);
} }
let masked = alu & 0x8080808080808080; let masked = alu & 0x8080808080808080;
assert_eq!(masked.trailing_zeros(), 39); assert_eq!(masked.trailing_zeros(), 39);

View file

@ -1,4 +1,4 @@
// Copyright 2015-2016 Mozilla Foundation. See the COPYRIGHT // Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -8,10 +8,10 @@
// except according to those terms. // except according to those terms.
use super::*; use super::*;
use ascii::*; use crate::ascii::*;
use data::position; use crate::data::position;
use handles::*; use crate::handles::*;
use variant::*; use crate::variant::*;
pub struct SingleByteDecoder { pub struct SingleByteDecoder {
table: &'static [u16; 128], table: &'static [u16; 128],
@ -432,7 +432,7 @@ impl SingleByteEncoder {
} }
// The next code unit is a low surrogate. // The next code unit is a low surrogate.
let astral: char = unsafe { let astral: char = unsafe {
::std::char::from_u32_unchecked( ::core::char::from_u32_unchecked(
(u32::from(non_ascii) << 10) + second (u32::from(non_ascii) << 10) + second
- (((0xD800u32 << 10) - 0x1_0000u32) + 0xDC00u32), - (((0xD800u32 << 10) - 0x1_0000u32) + 0xDC00u32),
) )
@ -503,7 +503,7 @@ impl SingleByteEncoder {
// Any copyright to the test code below this comment is dedicated to the // Any copyright to the test code below this comment is dedicated to the
// Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ // Public Domain. http://creativecommons.org/publicdomain/zero/1.0/
#[cfg(test)] #[cfg(all(test, feature = "alloc"))]
mod tests { mod tests {
use super::super::testing::*; use super::super::testing::*;
use super::super::*; use super::super::*;
@ -645,6 +645,10 @@ mod tests {
fn test_single_byte_decode() { fn test_single_byte_decode() {
decode_single_byte(IBM866, &data::SINGLE_BYTE_DATA.ibm866); decode_single_byte(IBM866, &data::SINGLE_BYTE_DATA.ibm866);
decode_single_byte(ISO_8859_10, &data::SINGLE_BYTE_DATA.iso_8859_10); decode_single_byte(ISO_8859_10, &data::SINGLE_BYTE_DATA.iso_8859_10);
if cfg!(miri) {
// Miri is too slow
return;
}
decode_single_byte(ISO_8859_13, &data::SINGLE_BYTE_DATA.iso_8859_13); decode_single_byte(ISO_8859_13, &data::SINGLE_BYTE_DATA.iso_8859_13);
decode_single_byte(ISO_8859_14, &data::SINGLE_BYTE_DATA.iso_8859_14); decode_single_byte(ISO_8859_14, &data::SINGLE_BYTE_DATA.iso_8859_14);
decode_single_byte(ISO_8859_15, &data::SINGLE_BYTE_DATA.iso_8859_15); decode_single_byte(ISO_8859_15, &data::SINGLE_BYTE_DATA.iso_8859_15);
@ -676,6 +680,10 @@ mod tests {
fn test_single_byte_encode() { fn test_single_byte_encode() {
encode_single_byte(IBM866, &data::SINGLE_BYTE_DATA.ibm866); encode_single_byte(IBM866, &data::SINGLE_BYTE_DATA.ibm866);
encode_single_byte(ISO_8859_10, &data::SINGLE_BYTE_DATA.iso_8859_10); encode_single_byte(ISO_8859_10, &data::SINGLE_BYTE_DATA.iso_8859_10);
if cfg!(miri) {
// Miri is too slow
return;
}
encode_single_byte(ISO_8859_13, &data::SINGLE_BYTE_DATA.iso_8859_13); encode_single_byte(ISO_8859_13, &data::SINGLE_BYTE_DATA.iso_8859_13);
encode_single_byte(ISO_8859_14, &data::SINGLE_BYTE_DATA.iso_8859_14); encode_single_byte(ISO_8859_14, &data::SINGLE_BYTE_DATA.iso_8859_14);
encode_single_byte(ISO_8859_15, &data::SINGLE_BYTE_DATA.iso_8859_15); encode_single_byte(ISO_8859_15, &data::SINGLE_BYTE_DATA.iso_8859_15);

View file

@ -23,6 +23,7 @@ fn test_all_labels() {
assert_eq!(Encoding::for_label(b"utf8"), Some(UTF_8)); assert_eq!(Encoding::for_label(b"utf8"), Some(UTF_8));
assert_eq!(Encoding::for_label(b"koi8"), Some(KOI8_R)); assert_eq!(Encoding::for_label(b"koi8"), Some(KOI8_R));
assert_eq!(Encoding::for_label(b"sjis"), Some(SHIFT_JIS)); assert_eq!(Encoding::for_label(b"sjis"), Some(SHIFT_JIS));
assert_eq!(Encoding::for_label(b"ucs-2"), Some(UTF_16LE));
assert_eq!(Encoding::for_label(b"ms932"), Some(SHIFT_JIS)); assert_eq!(Encoding::for_label(b"ms932"), Some(SHIFT_JIS));
assert_eq!(Encoding::for_label(b"cp866"), Some(IBM866)); assert_eq!(Encoding::for_label(b"cp866"), Some(IBM866));
assert_eq!(Encoding::for_label(b"utf-8"), Some(UTF_8)); assert_eq!(Encoding::for_label(b"utf-8"), Some(UTF_8));
@ -67,6 +68,7 @@ fn test_all_labels() {
assert_eq!(Encoding::for_label(b"gb_2312"), Some(GBK)); assert_eq!(Encoding::for_label(b"gb_2312"), Some(GBK));
assert_eq!(Encoding::for_label(b"dos-874"), Some(WINDOWS_874)); assert_eq!(Encoding::for_label(b"dos-874"), Some(WINDOWS_874));
assert_eq!(Encoding::for_label(b"cn-big5"), Some(BIG5)); assert_eq!(Encoding::for_label(b"cn-big5"), Some(BIG5));
assert_eq!(Encoding::for_label(b"unicode"), Some(UTF_16LE));
assert_eq!(Encoding::for_label(b"chinese"), Some(GBK)); assert_eq!(Encoding::for_label(b"chinese"), Some(GBK));
assert_eq!(Encoding::for_label(b"logical"), Some(ISO_8859_8_I)); assert_eq!(Encoding::for_label(b"logical"), Some(ISO_8859_8_I));
assert_eq!(Encoding::for_label(b"cskoi8r"), Some(KOI8_R)); assert_eq!(Encoding::for_label(b"cskoi8r"), Some(KOI8_R));
@ -119,6 +121,7 @@ fn test_all_labels() {
assert_eq!(Encoding::for_label(b"iso8859-8"), Some(ISO_8859_8)); assert_eq!(Encoding::for_label(b"iso8859-8"), Some(ISO_8859_8));
assert_eq!(Encoding::for_label(b"iso-ir-58"), Some(GBK)); assert_eq!(Encoding::for_label(b"iso-ir-58"), Some(GBK));
assert_eq!(Encoding::for_label(b"iso8859-9"), Some(WINDOWS_1254)); assert_eq!(Encoding::for_label(b"iso8859-9"), Some(WINDOWS_1254));
assert_eq!(Encoding::for_label(b"csunicode"), Some(UTF_16LE));
assert_eq!(Encoding::for_label(b"macintosh"), Some(MACINTOSH)); assert_eq!(Encoding::for_label(b"macintosh"), Some(MACINTOSH));
assert_eq!(Encoding::for_label(b"shift-jis"), Some(SHIFT_JIS)); assert_eq!(Encoding::for_label(b"shift-jis"), Some(SHIFT_JIS));
assert_eq!(Encoding::for_label(b"shift_jis"), Some(SHIFT_JIS)); assert_eq!(Encoding::for_label(b"shift_jis"), Some(SHIFT_JIS));
@ -178,6 +181,8 @@ fn test_all_labels() {
assert_eq!(Encoding::for_label(b"csisolatin9"), Some(ISO_8859_15)); assert_eq!(Encoding::for_label(b"csisolatin9"), Some(ISO_8859_15));
assert_eq!(Encoding::for_label(b"csiso88596e"), Some(ISO_8859_6)); assert_eq!(Encoding::for_label(b"csiso88596e"), Some(ISO_8859_6));
assert_eq!(Encoding::for_label(b"csiso88598e"), Some(ISO_8859_8)); assert_eq!(Encoding::for_label(b"csiso88598e"), Some(ISO_8859_8));
assert_eq!(Encoding::for_label(b"unicodefffe"), Some(UTF_16BE));
assert_eq!(Encoding::for_label(b"unicodefeff"), Some(UTF_16LE));
assert_eq!(Encoding::for_label(b"csmacintosh"), Some(MACINTOSH)); assert_eq!(Encoding::for_label(b"csmacintosh"), Some(MACINTOSH));
assert_eq!(Encoding::for_label(b"csiso88596i"), Some(ISO_8859_6)); assert_eq!(Encoding::for_label(b"csiso88596i"), Some(ISO_8859_6));
assert_eq!(Encoding::for_label(b"csiso88598i"), Some(ISO_8859_8_I)); assert_eq!(Encoding::for_label(b"csiso88598i"), Some(ISO_8859_8_I));
@ -204,12 +209,15 @@ fn test_all_labels() {
assert_eq!(Encoding::for_label(b"iso-8859-8-i"), Some(ISO_8859_8_I)); assert_eq!(Encoding::for_label(b"iso-8859-8-i"), Some(ISO_8859_8_I));
assert_eq!(Encoding::for_label(b"sun_eu_greek"), Some(ISO_8859_7)); assert_eq!(Encoding::for_label(b"sun_eu_greek"), Some(ISO_8859_7));
assert_eq!(Encoding::for_label(b"csksc56011987"), Some(EUC_KR)); assert_eq!(Encoding::for_label(b"csksc56011987"), Some(EUC_KR));
assert_eq!(Encoding::for_label(b"unicode20utf8"), Some(UTF_8));
assert_eq!(Encoding::for_label(b"unicode11utf8"), Some(UTF_8));
assert_eq!(Encoding::for_label(b"ks_c_5601-1987"), Some(EUC_KR)); assert_eq!(Encoding::for_label(b"ks_c_5601-1987"), Some(EUC_KR));
assert_eq!(Encoding::for_label(b"ansi_x3.4-1968"), Some(WINDOWS_1252)); assert_eq!(Encoding::for_label(b"ansi_x3.4-1968"), Some(WINDOWS_1252));
assert_eq!(Encoding::for_label(b"ks_c_5601-1989"), Some(EUC_KR)); assert_eq!(Encoding::for_label(b"ks_c_5601-1989"), Some(EUC_KR));
assert_eq!(Encoding::for_label(b"x-mac-cyrillic"), Some(X_MAC_CYRILLIC)); assert_eq!(Encoding::for_label(b"x-mac-cyrillic"), Some(X_MAC_CYRILLIC));
assert_eq!(Encoding::for_label(b"x-user-defined"), Some(X_USER_DEFINED)); assert_eq!(Encoding::for_label(b"x-user-defined"), Some(X_USER_DEFINED));
assert_eq!(Encoding::for_label(b"csiso58gb231280"), Some(GBK)); assert_eq!(Encoding::for_label(b"csiso58gb231280"), Some(GBK));
assert_eq!(Encoding::for_label(b"iso-10646-ucs-2"), Some(UTF_16LE));
assert_eq!(Encoding::for_label(b"iso_8859-1:1987"), Some(WINDOWS_1252)); assert_eq!(Encoding::for_label(b"iso_8859-1:1987"), Some(WINDOWS_1252));
assert_eq!(Encoding::for_label(b"iso_8859-2:1987"), Some(ISO_8859_2)); assert_eq!(Encoding::for_label(b"iso_8859-2:1987"), Some(ISO_8859_2));
assert_eq!(Encoding::for_label(b"iso_8859-6:1987"), Some(ISO_8859_6)); assert_eq!(Encoding::for_label(b"iso_8859-6:1987"), Some(ISO_8859_6));
@ -218,6 +226,7 @@ fn test_all_labels() {
assert_eq!(Encoding::for_label(b"iso_8859-4:1988"), Some(ISO_8859_4)); assert_eq!(Encoding::for_label(b"iso_8859-4:1988"), Some(ISO_8859_4));
assert_eq!(Encoding::for_label(b"iso_8859-5:1988"), Some(ISO_8859_5)); assert_eq!(Encoding::for_label(b"iso_8859-5:1988"), Some(ISO_8859_5));
assert_eq!(Encoding::for_label(b"iso_8859-8:1988"), Some(ISO_8859_8)); assert_eq!(Encoding::for_label(b"iso_8859-8:1988"), Some(ISO_8859_8));
assert_eq!(Encoding::for_label(b"x-unicode20utf8"), Some(UTF_8));
assert_eq!(Encoding::for_label(b"iso_8859-9:1989"), Some(WINDOWS_1254)); assert_eq!(Encoding::for_label(b"iso_8859-9:1989"), Some(WINDOWS_1254));
assert_eq!(Encoding::for_label(b"csisolatingreek"), Some(ISO_8859_7)); assert_eq!(Encoding::for_label(b"csisolatingreek"), Some(ISO_8859_7));
assert_eq!( assert_eq!(

View file

@ -1,4 +1,4 @@
// Copyright 2016 Mozilla Foundation. See the COPYRIGHT // Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -12,7 +12,12 @@ use super::*;
pub fn decode(encoding: &'static Encoding, bytes: &[u8], expect: &str) { pub fn decode(encoding: &'static Encoding, bytes: &[u8], expect: &str) {
let mut vec = Vec::with_capacity(bytes.len() + 32); let mut vec = Vec::with_capacity(bytes.len() + 32);
let mut string = String::with_capacity(expect.len() + 32); let mut string = String::with_capacity(expect.len() + 32);
for i in 0usize..32usize { let range = if cfg!(miri) {
0usize..4usize
} else {
0usize..32usize
};
for i in range {
vec.clear(); vec.clear();
string.clear(); string.clear();
for j in 0usize..i { for j in 0usize..i {
@ -44,7 +49,12 @@ fn decode_without_padding_impl(
pub fn encode(encoding: &'static Encoding, str: &str, expect: &[u8]) { pub fn encode(encoding: &'static Encoding, str: &str, expect: &[u8]) {
let mut vec = Vec::with_capacity(expect.len() + 32); let mut vec = Vec::with_capacity(expect.len() + 32);
let mut string = String::with_capacity(str.len() + 32); let mut string = String::with_capacity(str.len() + 32);
for i in 0usize..32usize { let range = if cfg!(miri) {
0usize..4usize
} else {
0usize..32usize
};
for i in range {
vec.clear(); vec.clear();
string.clear(); string.clear();
for j in 0usize..i { for j in 0usize..i {

View file

@ -1,4 +1,4 @@
// Copyright 2015-2016 Mozilla Foundation. See the COPYRIGHT // Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -8,8 +8,8 @@
// except according to those terms. // except according to those terms.
use super::*; use super::*;
use handles::*; use crate::handles::*;
use variant::*; use crate::variant::*;
pub struct Utf16Decoder { pub struct Utf16Decoder {
lead_surrogate: u16, // If non-zero and pending_bmp == false, a pending lead surrogate lead_surrogate: u16, // If non-zero and pending_bmp == false, a pending lead surrogate
@ -200,7 +200,7 @@ impl Utf16Decoder {
// Any copyright to the test code below this comment is dedicated to the // Any copyright to the test code below this comment is dedicated to the
// Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ // Public Domain. http://creativecommons.org/publicdomain/zero/1.0/
#[cfg(test)] #[cfg(all(test, feature = "alloc"))]
mod tests { mod tests {
use super::super::testing::*; use super::super::testing::*;
use super::super::*; use super::super::*;

View file

@ -1,4 +1,4 @@
// Copyright 2015-2016 Mozilla Foundation. See the COPYRIGHT // Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -8,17 +8,17 @@
// except according to those terms. // except according to those terms.
use super::*; use super::*;
use ascii::ascii_to_basic_latin; use crate::ascii::ascii_to_basic_latin;
use ascii::basic_latin_to_ascii; use crate::ascii::basic_latin_to_ascii;
use ascii::validate_ascii; use crate::ascii::validate_ascii;
use handles::*; use crate::handles::*;
use mem::convert_utf16_to_utf8_partial; use crate::mem::convert_utf16_to_utf8_partial;
use variant::*; use crate::variant::*;
cfg_if! { cfg_if! {
if #[cfg(feature = "simd-accel")] { if #[cfg(feature = "simd-accel")] {
use ::std::intrinsics::unlikely; use ::core::intrinsics::unlikely;
use ::std::intrinsics::likely; use ::core::intrinsics::likely;
} else { } else {
#[inline(always)] #[inline(always)]
// Unsafe to match the intrinsic, which is needlessly unsafe. // Unsafe to match the intrinsic, which is needlessly unsafe.
@ -236,7 +236,7 @@ pub fn convert_utf8_to_utf16_up_to_invalid(src: &[u8], dst: &mut [u16]) -> (usiz
let mut byte = { let mut byte = {
let src_remaining = &src[read..]; let src_remaining = &src[read..];
let dst_remaining = &mut dst[written..]; let dst_remaining = &mut dst[written..];
let length = ::std::cmp::min(src_remaining.len(), dst_remaining.len()); let length = ::core::cmp::min(src_remaining.len(), dst_remaining.len());
match unsafe { match unsafe {
ascii_to_basic_latin(src_remaining.as_ptr(), dst_remaining.as_mut_ptr(), length) ascii_to_basic_latin(src_remaining.as_ptr(), dst_remaining.as_mut_ptr(), length)
} { } {
@ -886,7 +886,7 @@ impl Utf8Encoder {
// Any copyright to the test code below this comment is dedicated to the // Any copyright to the test code below this comment is dedicated to the
// Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ // Public Domain. http://creativecommons.org/publicdomain/zero/1.0/
#[cfg(test)] #[cfg(all(test, feature = "alloc"))]
mod tests { mod tests {
use super::super::testing::*; use super::super::testing::*;
use super::super::*; use super::super::*;

View file

@ -1,4 +1,4 @@
// Copyright 2015-2016 Mozilla Foundation. See the COPYRIGHT // Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or

View file

@ -1,4 +1,4 @@
// Copyright 2015-2016 Mozilla Foundation. See the COPYRIGHT // Copyright Mozilla Foundation. See the COPYRIGHT
// file at the top-level directory of this distribution. // file at the top-level directory of this distribution.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -8,8 +8,8 @@
// except according to those terms. // except according to those terms.
use super::*; use super::*;
use handles::*; use crate::handles::*;
use variant::*; use crate::variant::*;
cfg_if! { cfg_if! {
if #[cfg(feature = "simd-accel")] { if #[cfg(feature = "simd-accel")] {
@ -196,7 +196,7 @@ impl UserDefinedEncoder {
// Any copyright to the test code below this comment is dedicated to the // Any copyright to the test code below this comment is dedicated to the
// Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ // Public Domain. http://creativecommons.org/publicdomain/zero/1.0/
#[cfg(test)] #[cfg(all(test, feature = "alloc"))]
mod tests { mod tests {
use super::super::testing::*; use super::super::testing::*;
use super::super::*; use super::super::*;

View file

@ -1,45 +0,0 @@
[package]
name = "packed_simd"
version = "0.3.4"
authors = ["Gonzalo Brito Gadeschi <gonzalobg88@gmail.com>"]
description = "Portable Packed SIMD vectors"
documentation = "https://docs.rs/crate/packed_simd/"
homepage = "https://github.com/rust-lang-nursery/packed_simd"
repository = "https://github.com/rust-lang-nursery/packed_simd"
keywords = ["simd", "vector", "portability"]
categories = ["hardware-support", "concurrency", "no-std", "data-structures"]
license = "MIT/Apache-2.0"
build = "build.rs"
edition = "2018"
[badges]
appveyor = { repository = "rust-lang-nursery/packed_simd" }
travis-ci = { repository = "rust-lang-nursery/packed_simd" }
codecov = { repository = "rust-lang-nursery/packed_simd" }
is-it-maintained-issue-resolution = { repository = "rust-lang-nursery/packed_simd" }
is-it-maintained-open-issues = { repository = "rust-lang-nursery/packed_simd" }
maintenance = { status = "experimental" }
[dependencies]
cfg-if = "0.1.10"
core_arch = { version = "0.1.5", optional = true }
[features]
default = []
into_bits = []
libcore_neon = []
[build-dependencies]
rustc_version = "0.2"
[dev-dependencies]
paste = "^0.1.3"
arrayvec = { version = "^0.5", default-features = false }
[target.'cfg(target_arch = "x86_64")'.dependencies.sleef-sys]
version = "0.1.2"
optional = true
[target.wasm32-unknown-unknown.dev-dependencies]
wasm-bindgen = "=0.2.52"
wasm-bindgen-test = "=0.3.2"

View file

@ -1,34 +0,0 @@
use rustc_version::{version_meta, Channel, Version};
fn main() {
println!("cargo:rustc-env=RUSTC_BOOTSTRAP=1");
let target = std::env::var("TARGET")
.expect("TARGET environment variable not defined");
if target.contains("neon") {
println!("cargo:rustc-cfg=libcore_neon");
}
let ver_meta = version_meta().unwrap();
let old_const_generics =
if ver_meta.semver < Version::parse("1.56.0-alpha").unwrap() {
true
} else if ver_meta.semver >= Version::parse("1.57.0-alpha").unwrap() {
false
} else {
match ver_meta.channel {
Channel::Stable | Channel::Beta => false,
Channel::Nightly | Channel::Dev
if ver_meta
.commit_date
.as_deref()
.map(|d| d < "2021-08-31")
.unwrap_or(false) =>
{
true
}
_ => false,
}
};
if old_const_generics {
println!("cargo:rustc-cfg=const_generics");
}
}

View file

@ -1,79 +0,0 @@
//! `FromCast` and `IntoCast` implementations for portable 128-bit wide vectors
#[rustfmt::skip]
use crate::*;
impl_from_cast!(
i8x16[test_v128]: u8x16, m8x16, i16x16, u16x16, m16x16, i32x16, u32x16, f32x16, m32x16
);
impl_from_cast!(
u8x16[test_v128]: i8x16, m8x16, i16x16, u16x16, m16x16, i32x16, u32x16, f32x16, m32x16
);
impl_from_cast_mask!(
m8x16[test_v128]: i8x16, u8x16, i16x16, u16x16, m16x16, i32x16, u32x16, f32x16, m32x16
);
impl_from_cast!(
i16x8[test_v128]: i8x8, u8x8, m8x8, u16x8, m16x8, i32x8, u32x8, f32x8, m32x8,
i64x8, u64x8, f64x8, m64x8, isizex8, usizex8, msizex8
);
impl_from_cast!(
u16x8[test_v128]: i8x8, u8x8, m8x8, i16x8, m16x8, i32x8, u32x8, f32x8, m32x8,
i64x8, u64x8, f64x8, m64x8, isizex8, usizex8, msizex8
);
impl_from_cast_mask!(
m16x8[test_v128]: i8x8, u8x8, m8x8, i16x8, u16x8, i32x8, u32x8, f32x8, m32x8,
i64x8, u64x8, f64x8, m64x8, isizex8, usizex8, msizex8
);
impl_from_cast!(
i32x4[test_v128]: i8x4, u8x4, m8x4, i16x4, u16x4, m16x4, u32x4, f32x4, m32x4,
i64x4, u64x4, f64x4, m64x4, i128x4, u128x4, m128x4, isizex4, usizex4, msizex4
);
impl_from_cast!(
u32x4[test_v128]: i8x4, u8x4, m8x4, i16x4, u16x4, m16x4, i32x4, f32x4, m32x4,
i64x4, u64x4, f64x4, m64x4, i128x4, u128x4, m128x4, isizex4, usizex4, msizex4
);
impl_from_cast!(
f32x4[test_v128]: i8x4, u8x4, m8x4, i16x4, u16x4, m16x4, i32x4, u32x4, m32x4,
i64x4, u64x4, f64x4, m64x4, i128x4, u128x4, m128x4, isizex4, usizex4, msizex4
);
impl_from_cast_mask!(
m32x4[test_v128]: i8x4, u8x4, m8x4, i16x4, u16x4, m16x4, i32x4, u32x4, f32x4,
i64x4, u64x4, f64x4, m64x4, i128x4, u128x4, m128x4, isizex4, usizex4, msizex4
);
impl_from_cast!(
i64x2[test_v128]: i8x2, u8x2, m8x2, i16x2, u16x2, m16x2, i32x2, u32x2, f32x2, m32x2,
u64x2, f64x2, m64x2, i128x2, u128x2, m128x2, isizex2, usizex2, msizex2
);
impl_from_cast!(
u64x2[test_v128]: i8x2, u8x2, m8x2, i16x2, u16x2, m16x2, i32x2, u32x2, f32x2, m32x2,
i64x2, f64x2, m64x2, i128x2, u128x2, m128x2, isizex2, usizex2, msizex2
);
impl_from_cast!(
f64x2[test_v128]: i8x2, u8x2, m8x2, i16x2, u16x2, m16x2, i32x2, u32x2, f32x2, m32x2,
i64x2, u64x2, m64x2, i128x2, u128x2, m128x2, isizex2, usizex2, msizex2
);
impl_from_cast_mask!(
m64x2[test_v128]: i8x2, u8x2, m8x2, i16x2, u16x2, m16x2, i32x2, u32x2, f32x2, m32x2,
i64x2, u64x2, f64x2, i128x2, u128x2, m128x2, isizex2, usizex2, msizex2
);
impl_from_cast!(
isizex2[test_v128]: i8x2, u8x2, m8x2, i16x2, u16x2, m16x2, i32x2, u32x2, f32x2, m32x2,
i64x2, u64x2, f64x2, m64x2, i128x2, u128x2, m128x2, usizex2, msizex2
);
impl_from_cast!(
usizex2[test_v128]: i8x2, u8x2, m8x2, i16x2, u16x2, m16x2, i32x2, u32x2, f32x2, m32x2,
i64x2, u64x2, f64x2, m64x2, i128x2, u128x2, m128x2, isizex2, msizex2
);
impl_from_cast_mask!(
msizex2[test_v128]: i8x2, u8x2, m8x2, i16x2, u16x2, m16x2, i32x2, u32x2, f32x2, m32x2,
i64x2, u64x2, f64x2, m64x2, i128x2, u128x2, m128x2, isizex2, usizex2
);
// FIXME[test_v128]: 64-bit single element vectors into_cast impls
impl_from_cast!(i128x1[test_v128]: u128x1, m128x1);
impl_from_cast!(u128x1[test_v128]: i128x1, m128x1);
impl_from_cast!(m128x1[test_v128]: i128x1, u128x1);

View file

@ -1,17 +0,0 @@
//! `FromCast` and `IntoCast` implementations for portable 16-bit wide vectors
#[rustfmt::skip]
use crate::*;
impl_from_cast!(
i8x2[test_v16]: u8x2, m8x2, i16x2, u16x2, m16x2, i32x2, u32x2, f32x2, m32x2,
i64x2, u64x2, f64x2, m64x2, i128x2, u128x2, m128x2, isizex2, usizex2, msizex2
);
impl_from_cast!(
u8x2[test_v16]: i8x2, m8x2, i16x2, u16x2, m16x2, i32x2, u32x2, f32x2, m32x2,
i64x2, u64x2, f64x2, m64x2, i128x2, u128x2, m128x2, isizex2, usizex2, msizex2
);
impl_from_cast_mask!(
m8x2[test_v16]: i8x2, u8x2, i16x2, u16x2, m16x2, i32x2, u32x2, f32x2, m32x2,
i64x2, u64x2, f64x2, m64x2, i128x2, u128x2, m128x2, isizex2, usizex2, msizex2
);

View file

@ -1,81 +0,0 @@
//! `FromCast` and `IntoCast` implementations for portable 256-bit wide vectors
#[rustfmt::skip]
use crate::*;
impl_from_cast!(i8x32[test_v256]: u8x32, m8x32, i16x32, u16x32, m16x32);
impl_from_cast!(u8x32[test_v256]: i8x32, m8x32, i16x32, u16x32, m16x32);
impl_from_cast_mask!(m8x32[test_v256]: i8x32, u8x32, i16x32, u16x32, m16x32);
impl_from_cast!(
i16x16[test_v256]: i8x16, u8x16, m8x16, u16x16, m16x16,
i32x16, u32x16, f32x16, m32x16
);
impl_from_cast!(
u16x16[test_v256]: i8x16, u8x16, m8x16, i16x16, m16x16,
i32x16, u32x16, f32x16, m32x16
);
impl_from_cast_mask!(
m16x16[test_v256]: i8x16, u8x16, m8x16, i16x16, u16x16,
i32x16, u32x16, f32x16, m32x16
);
impl_from_cast!(
i32x8[test_v256]: i8x8, u8x8, m8x8, i16x8, u16x8, m16x8, u32x8, f32x8, m32x8,
i64x8, u64x8, f64x8, m64x8, isizex8, usizex8, msizex8
);
impl_from_cast!(
u32x8[test_v256]: i8x8, u8x8, m8x8, i16x8, u16x8, m16x8, i32x8, f32x8, m32x8,
i64x8, u64x8, f64x8, m64x8, isizex8, usizex8, msizex8
);
impl_from_cast!(
f32x8[test_v256]: i8x8, u8x8, m8x8, i16x8, u16x8, m16x8, i32x8, u32x8, m32x8,
i64x8, u64x8, f64x8, m64x8, isizex8, usizex8, msizex8
);
impl_from_cast_mask!(
m32x8[test_v256]: i8x8, u8x8, m8x8, i16x8, u16x8, m16x8, i32x8, u32x8, f32x8,
i64x8, u64x8, f64x8, m64x8, isizex8, usizex8, msizex8
);
impl_from_cast!(
i64x4[test_v256]: i8x4, u8x4, m8x4, i16x4, u16x4, m16x4, i32x4, u32x4, f32x4, m32x4,
u64x4, f64x4, m64x4, i128x4, u128x4, m128x4, isizex4, usizex4, msizex4
);
impl_from_cast!(
u64x4[test_v256]: i8x4, u8x4, m8x4, i16x4, u16x4, m16x4, i32x4, u32x4, f32x4, m32x4,
i64x4, f64x4, m64x4, i128x4, u128x4, m128x4, isizex4, usizex4, msizex4
);
impl_from_cast!(
f64x4[test_v256]: i8x4, u8x4, m8x4, i16x4, u16x4, m16x4, i32x4, u32x4, f32x4, m32x4,
i64x4, u64x4, m64x4, i128x4, u128x4, m128x4, isizex4, usizex4, msizex4
);
impl_from_cast_mask!(
m64x4[test_v256]: i8x4, u8x4, m8x4, i16x4, u16x4, m16x4, i32x4, u32x4, f32x4, m32x4,
i64x4, u64x4, f64x4, i128x4, u128x4, m128x4, isizex4, usizex4, msizex4
);
impl_from_cast!(
i128x2[test_v256]: i8x2, u8x2, m8x2, i16x2, u16x2, m16x2, i32x2, u32x2, f32x2, m32x2,
i64x2, u64x2, f64x2, m64x2, u128x2, m128x2, isizex2, usizex2, msizex2
);
impl_from_cast!(
u128x2[test_v256]: i8x2, u8x2, m8x2, i16x2, u16x2, m16x2, i32x2, u32x2, f32x2, m32x2,
i64x2, u64x2, f64x2, m64x2, i128x2, m128x2, isizex2, usizex2, msizex2
);
impl_from_cast_mask!(
m128x2[test_v256]: i8x2, u8x2, m8x2, i16x2, u16x2, m16x2, i32x2, u32x2, f32x2, m32x2,
i64x2, u64x2, m64x2, f64x2, i128x2, u128x2, isizex2, usizex2, msizex2
);
impl_from_cast!(
isizex4[test_v256]: i8x4, u8x4, m8x4, i16x4, u16x4, m16x4, i32x4, u32x4, f32x4, m32x4,
i64x4, u64x4, f64x4, m64x4, i128x4, u128x4, m128x4, usizex4, msizex4
);
impl_from_cast!(
usizex4[test_v256]: i8x4, u8x4, m8x4, i16x4, u16x4, m16x4, i32x4, u32x4, f32x4, m32x4,
i64x4, u64x4, f64x4, m64x4, i128x4, u128x4, m128x4, isizex4, msizex4
);
impl_from_cast_mask!(
msizex4[test_v256]: i8x4, u8x4, m8x4, i16x4, u16x4, m16x4, i32x4, u32x4, f32x4, m32x4,
i64x4, u64x4, f64x4, m64x4, i128x4, u128x4, m128x4, isizex4, usizex4
);

View file

@ -1,30 +0,0 @@
//! `FromCast` and `IntoCast` implementations for portable 32-bit wide vectors
#[rustfmt::skip]
use crate::*;
impl_from_cast!(
i8x4[test_v32]: u8x4, m8x4, i16x4, u16x4, m16x4, i32x4, u32x4, f32x4, m32x4,
i64x4, u64x4, f64x4, m64x4, i128x4, u128x4, m128x4, isizex4, usizex4, msizex4
);
impl_from_cast!(
u8x4[test_v32]: i8x4, m8x4, i16x4, u16x4, m16x4, i32x4, u32x4, f32x4, m32x4,
i64x4, u64x4, f64x4, m64x4, i128x4, u128x4, m128x4, isizex4, usizex4, msizex4
);
impl_from_cast_mask!(
m8x4[test_v32]: i8x4, u8x4, i16x4, u16x4, m16x4, i32x4, u32x4, f32x4, m32x4,
i64x4, u64x4, f64x4, m64x4, i128x4, u128x4, m128x4, isizex4, usizex4, msizex4
);
impl_from_cast!(
i16x2[test_v32]: i8x2, u8x2, m8x2, u16x2, m16x2, i32x2, u32x2, f32x2, m32x2,
i64x2, u64x2, f64x2, m64x2, i128x2, u128x2, m128x2, isizex2, usizex2, msizex2
);
impl_from_cast!(
u16x2[test_v32]: i8x2, u8x2, m8x2, i16x2, m16x2, i32x2, u32x2, f32x2, m32x2,
i64x2, u64x2, f64x2, m64x2, i128x2, u128x2, m128x2, isizex2, usizex2, msizex2
);
impl_from_cast_mask!(
m16x2[test_v32]: i8x2, u8x2, m8x2, i16x2, u16x2, i32x2, u32x2, f32x2, m32x2,
i64x2, u64x2, f64x2, m64x2, i128x2, u128x2, m128x2, isizex2, usizex2, msizex2
);

View file

@ -1,68 +0,0 @@
//! `FromCast` and `IntoCast` implementations for portable 512-bit wide vectors
#[rustfmt::skip]
use crate::*;
impl_from_cast!(i8x64[test_v512]: u8x64, m8x64);
impl_from_cast!(u8x64[test_v512]: i8x64, m8x64);
impl_from_cast_mask!(m8x64[test_v512]: i8x64, u8x64);
impl_from_cast!(i16x32[test_v512]: i8x32, u8x32, m8x32, u16x32, m16x32);
impl_from_cast!(u16x32[test_v512]: i8x32, u8x32, m8x32, i16x32, m16x32);
impl_from_cast_mask!(m16x32[test_v512]: i8x32, u8x32, m8x32, i16x32, u16x32);
impl_from_cast!(
i32x16[test_v512]: i8x16, u8x16, m8x16, i16x16, u16x16, m16x16, u32x16, f32x16, m32x16
);
impl_from_cast!(
u32x16[test_v512]: i8x16, u8x16, m8x16, i16x16, u16x16, m16x16, i32x16, f32x16, m32x16
);
impl_from_cast!(
f32x16[test_v512]: i8x16, u8x16, m8x16, i16x16, u16x16, m16x16, i32x16, u32x16, m32x16
);
impl_from_cast_mask!(
m32x16[test_v512]: i8x16, u8x16, m8x16, i16x16, u16x16, m16x16, i32x16, u32x16, f32x16
);
impl_from_cast!(
i64x8[test_v512]: i8x8, u8x8, m8x8, i16x8, u16x8, m16x8, i32x8, u32x8, f32x8, m32x8,
u64x8, f64x8, m64x8, isizex8, usizex8, msizex8
);
impl_from_cast!(
u64x8[test_v512]: i8x8, u8x8, m8x8, i16x8, u16x8, m16x8, i32x8, u32x8, f32x8, m32x8,
i64x8, f64x8, m64x8, isizex8, usizex8, msizex8
);
impl_from_cast!(
f64x8[test_v512]: i8x8, u8x8, m8x8, i16x8, u16x8, m16x8, i32x8, u32x8, f32x8, m32x8,
i64x8, u64x8, m64x8, isizex8, usizex8, msizex8
);
impl_from_cast_mask!(
m64x8[test_v512]: i8x8, u8x8, m8x8, i16x8, u16x8, m16x8, i32x8, u32x8, f32x8, m32x8,
i64x8, u64x8, f64x8, isizex8, usizex8, msizex8
);
impl_from_cast!(
i128x4[test_v512]: i8x4, u8x4, m8x4, i16x4, u16x4, m16x4, i32x4, u32x4, f32x4, m32x4,
i64x4, u64x4, f64x4, m64x4, u128x4, m128x4, isizex4, usizex4, msizex4
);
impl_from_cast!(
u128x4[test_v512]: i8x4, u8x4, m8x4, i16x4, u16x4, m16x4, i32x4, u32x4, f32x4, m32x4,
i64x4, u64x4, f64x4, m64x4, i128x4, m128x4, isizex4, usizex4, msizex4
);
impl_from_cast_mask!(
m128x4[test_v512]: i8x4, u8x4, m8x4, i16x4, u16x4, m16x4, i32x4, u32x4, f32x4, m32x4,
i64x4, u64x4, m64x4, f64x4, i128x4, u128x4, isizex4, usizex4, msizex4
);
impl_from_cast!(
isizex8[test_v512]: i8x8, u8x8, m8x8, i16x8, u16x8, m16x8, i32x8, u32x8, f32x8, m32x8,
i64x8, u64x8, f64x8, m64x8, usizex8, msizex8
);
impl_from_cast!(
usizex8[test_v512]: i8x8, u8x8, m8x8, i16x8, u16x8, m16x8, i32x8, u32x8, f32x8, m32x8,
i64x8, u64x8, f64x8, m64x8, isizex8, msizex8
);
impl_from_cast_mask!(
msizex8[test_v512]: i8x8, u8x8, m8x8, i16x8, u16x8, m16x8, i32x8, u32x8, f32x8, m32x8,
i64x8, u64x8, f64x8, m64x8, isizex8, usizex8
);

View file

@ -1,47 +0,0 @@
//! `FromCast` and `IntoCast` implementations for portable 64-bit wide vectors
#[rustfmt::skip]
use crate::*;
impl_from_cast!(
i8x8[test_v64]: u8x8, m8x8, i16x8, u16x8, m16x8, i32x8, u32x8, f32x8, m32x8,
i64x8, u64x8, f64x8, m64x8, isizex8, usizex8, msizex8
);
impl_from_cast!(
u8x8[test_v64]: i8x8, m8x8, i16x8, u16x8, m16x8, i32x8, u32x8, f32x8, m32x8,
i64x8, u64x8, f64x8, m64x8, isizex8, usizex8, msizex8
);
impl_from_cast_mask!(
m8x8[test_v64]: i8x8, u8x8, i16x8, u16x8, m16x8, i32x8, u32x8, f32x8, m32x8,
i64x8, u64x8, f64x8, m64x8, isizex8, usizex8, msizex8
);
impl_from_cast!(
i16x4[test_v64]: i8x4, u8x4, m8x4, u16x4, m16x4, i32x4, u32x4, f32x4, m32x4,
i64x4, u64x4, f64x4, m64x4, i128x4, u128x4, m128x4, isizex4, usizex4, msizex4
);
impl_from_cast!(
u16x4[test_v64]: i8x4, u8x4, m8x4, i16x4, m16x4, i32x4, u32x4, f32x4, m32x4,
i64x4, u64x4, f64x4, m64x4, i128x4, u128x4, m128x4, isizex4, usizex4, msizex4
);
impl_from_cast_mask!(
m16x4[test_v64]: i8x4, u8x4, m8x4, i16x4, u16x4, i32x4, u32x4, f32x4, m32x4,
i64x4, u64x4, f64x4, m64x4, i128x4, u128x4, m128x4, isizex4, usizex4, msizex4
);
impl_from_cast!(
i32x2[test_v64]: i8x2, u8x2, m8x2, i16x2, u16x2, m16x2, u32x2, f32x2, m32x2,
i64x2, u64x2, f64x2, m64x2, i128x2, u128x2, m128x2, isizex2, usizex2, msizex2
);
impl_from_cast!(
u32x2[test_v64]: i8x2, u8x2, m8x2, i16x2, u16x2, m16x2, i32x2, f32x2, m32x2,
i64x2, u64x2, f64x2, m64x2, i128x2, u128x2, m128x2, isizex2, usizex2, msizex2
);
impl_from_cast!(
f32x2[test_v64]: i8x2, u8x2, m8x2, i16x2, u16x2, m16x2, i32x2, u32x2, m32x2,
i64x2, u64x2, f64x2, m64x2, i128x2, u128x2, m128x2, isizex2, usizex2, msizex2
);
impl_from_cast_mask!(
m32x2[test_v64]: i8x2, u8x2, m8x2, i16x2, u16x2, m16x2, i32x2, u32x2, f32x2,
i64x2, u64x2, f64x2, m64x2, i128x2, u128x2, m128x2, isizex2, usizex2, msizex2
);

View file

@ -1,28 +0,0 @@
//! `FromBits` and `IntoBits` implementations for portable 128-bit wide vectors
#[rustfmt::skip]
#[allow(unused)] // wasm_bindgen_test
use crate::*;
impl_from_bits!(i8x16[test_v128]: u8x16, m8x16, i16x8, u16x8, m16x8, i32x4, u32x4, f32x4, m32x4, i64x2, u64x2, f64x2, m64x2, i128x1, u128x1, m128x1);
impl_from_bits!(u8x16[test_v128]: i8x16, m8x16, i16x8, u16x8, m16x8, i32x4, u32x4, f32x4, m32x4, i64x2, u64x2, f64x2, m64x2, i128x1, u128x1, m128x1);
impl_from_bits!(m8x16[test_v128]: m16x8, m32x4, m64x2, m128x1);
impl_from_bits!(i16x8[test_v128]: i8x16, u8x16, m8x16, u16x8, m16x8, i32x4, u32x4, f32x4, m32x4, i64x2, u64x2, f64x2, m64x2, i128x1, u128x1, m128x1);
impl_from_bits!(u16x8[test_v128]: i8x16, u8x16, m8x16, i16x8, m16x8, i32x4, u32x4, f32x4, m32x4, i64x2, u64x2, f64x2, m64x2, i128x1, u128x1, m128x1);
impl_from_bits!(m16x8[test_v128]: m32x4, m64x2, m128x1);
impl_from_bits!(i32x4[test_v128]: i8x16, u8x16, m8x16, i16x8, u16x8, m16x8, u32x4, f32x4, m32x4, i64x2, u64x2, f64x2, m64x2, i128x1, u128x1, m128x1);
impl_from_bits!(u32x4[test_v128]: i8x16, u8x16, m8x16, i16x8, u16x8, m16x8, i32x4, f32x4, m32x4, i64x2, u64x2, f64x2, m64x2, i128x1, u128x1, m128x1);
impl_from_bits!(f32x4[test_v128]: i8x16, u8x16, m8x16, i16x8, u16x8, m16x8, i32x4, u32x4, m32x4, i64x2, u64x2, f64x2, m64x2, i128x1, u128x1, m128x1);
impl_from_bits!(m32x4[test_v128]: m64x2, m128x1);
impl_from_bits!(i64x2[test_v128]: i8x16, u8x16, m8x16, i16x8, u16x8, m16x8, i32x4, u32x4, f32x4, m32x4, u64x2, f64x2, m64x2, i128x1, u128x1, m128x1);
impl_from_bits!(u64x2[test_v128]: i8x16, u8x16, m8x16, i16x8, u16x8, m16x8, i32x4, u32x4, f32x4, m32x4, i64x2, f64x2, m64x2, i128x1, u128x1, m128x1);
impl_from_bits!(f64x2[test_v128]: i8x16, u8x16, m8x16, i16x8, u16x8, m16x8, i32x4, u32x4, f32x4, m32x4, i64x2, u64x2, m64x2, i128x1, u128x1, m128x1);
impl_from_bits!(m64x2[test_v128]: m128x1);
impl_from_bits!(i128x1[test_v128]: i8x16, u8x16, m8x16, i16x8, u16x8, m16x8, i32x4, u32x4, f32x4, m32x4, i64x2, u64x2, f64x2, m64x2, u128x1, m128x1);
impl_from_bits!(u128x1[test_v128]: i8x16, u8x16, m8x16, i16x8, u16x8, m16x8, i32x4, u32x4, f32x4, m32x4, i64x2, u64x2, f64x2, m64x2, i128x1, m128x1);
// note: m128x1 cannot be constructed from all the other masks bit patterns in here

View file

@ -1,27 +0,0 @@
//! `FromBits` and `IntoBits` implementations for portable 256-bit wide vectors
#[rustfmt::skip]
#[allow(unused)] // wasm_bindgen_test
use crate::*;
impl_from_bits!(i8x32[test_v256]: u8x32, m8x32, i16x16, u16x16, m16x16, i32x8, u32x8, f32x8, m32x8, i64x4, u64x4, f64x4, m64x4, i128x2, u128x2, m128x2);
impl_from_bits!(u8x32[test_v256]: i8x32, m8x32, i16x16, u16x16, m16x16, i32x8, u32x8, f32x8, m32x8, i64x4, u64x4, f64x4, m64x4, i128x2, u128x2, m128x2);
impl_from_bits!(m8x32[test_v256]: m16x16, m32x8, m64x4, m128x2);
impl_from_bits!(i16x16[test_v256]: i8x32, u8x32, m8x32, u16x16, m16x16, i32x8, u32x8, f32x8, m32x8, i64x4, u64x4, f64x4, m64x4, i128x2, u128x2, m128x2);
impl_from_bits!(u16x16[test_v256]: i8x32, u8x32, m8x32, i16x16, m16x16, i32x8, u32x8, f32x8, m32x8, i64x4, u64x4, f64x4, m64x4, i128x2, u128x2, m128x2);
impl_from_bits!(m16x16[test_v256]: m32x8, m64x4, m128x2);
impl_from_bits!(i32x8[test_v256]: i8x32, u8x32, m8x32, i16x16, u16x16, m16x16, u32x8, f32x8, m32x8, i64x4, u64x4, f64x4, m64x4, i128x2, u128x2, m128x2);
impl_from_bits!(u32x8[test_v256]: i8x32, u8x32, m8x32, i16x16, u16x16, m16x16, i32x8, f32x8, m32x8, i64x4, u64x4, f64x4, m64x4, i128x2, u128x2, m128x2);
impl_from_bits!(f32x8[test_v256]: i8x32, u8x32, m8x32, i16x16, u16x16, m16x16, i32x8, u32x8, m32x8, i64x4, u64x4, f64x4, m64x4, i128x2, u128x2, m128x2);
impl_from_bits!(m32x8[test_v256]: m64x4, m128x2);
impl_from_bits!(i64x4[test_v256]: i8x32, u8x32, m8x32, i16x16, u16x16, m16x16, i32x8, u32x8, f32x8, m32x8, u64x4, f64x4, m64x4, i128x2, u128x2, m128x2);
impl_from_bits!(u64x4[test_v256]: i8x32, u8x32, m8x32, i16x16, u16x16, m16x16, i32x8, u32x8, f32x8, m32x8, i64x4, f64x4, m64x4, i128x2, u128x2, m128x2);
impl_from_bits!(f64x4[test_v256]: i8x32, u8x32, m8x32, i16x16, u16x16, m16x16, i32x8, u32x8, f32x8, m32x8, i64x4, u64x4, m64x4, i128x2, u128x2, m128x2);
impl_from_bits!(m64x4[test_v256]: m128x2);
impl_from_bits!(i128x2[test_v256]: i8x32, u8x32, m8x32, i16x16, u16x16, m16x16, i32x8, u32x8, f32x8, m32x8, i64x4, u64x4, f64x4, m64x4, u128x2, m128x2);
impl_from_bits!(u128x2[test_v256]: i8x32, u8x32, m8x32, i16x16, u16x16, m16x16, i32x8, u32x8, f32x8, m32x8, i64x4, u64x4, f64x4, m64x4, i128x2, m128x2);
// note: m128x2 cannot be constructed from all the other masks bit patterns in here

View file

@ -1,27 +0,0 @@
//! `FromBits` and `IntoBits` implementations for portable 512-bit wide vectors
#[rustfmt::skip]
#[allow(unused)] // wasm_bindgen_test
use crate::*;
impl_from_bits!(i8x64[test_v512]: u8x64, m8x64, i16x32, u16x32, m16x32, i32x16, u32x16, f32x16, m32x16, i64x8, u64x8, f64x8, m64x8, i128x4, u128x4, m128x4);
impl_from_bits!(u8x64[test_v512]: i8x64, m8x64, i16x32, u16x32, m16x32, i32x16, u32x16, f32x16, m32x16, i64x8, u64x8, f64x8, m64x8, i128x4, u128x4, m128x4);
impl_from_bits!(m8x64[test_v512]: m16x32, m32x16, m64x8, m128x4);
impl_from_bits!(i16x32[test_v512]: i8x64, u8x64, m8x64, u16x32, m16x32, i32x16, u32x16, f32x16, m32x16, i64x8, u64x8, f64x8, m64x8, i128x4, u128x4, m128x4);
impl_from_bits!(u16x32[test_v512]: i8x64, u8x64, m8x64, i16x32, m16x32, i32x16, u32x16, f32x16, m32x16, i64x8, u64x8, f64x8, m64x8, i128x4, u128x4, m128x4);
impl_from_bits!(m16x32[test_v512]: m32x16, m64x8, m128x4);
impl_from_bits!(i32x16[test_v512]: i8x64, u8x64, m8x64, i16x32, u16x32, m16x32, u32x16, f32x16, m32x16, i64x8, u64x8, f64x8, m64x8, i128x4, u128x4, m128x4);
impl_from_bits!(u32x16[test_v512]: i8x64, u8x64, m8x64, i16x32, u16x32, m16x32, i32x16, f32x16, m32x16, i64x8, u64x8, f64x8, m64x8, i128x4, u128x4, m128x4);
impl_from_bits!(f32x16[test_v512]: i8x64, u8x64, m8x64, i16x32, u16x32, m16x32, i32x16, u32x16, m32x16, i64x8, u64x8, f64x8, m64x8, i128x4, u128x4, m128x4);
impl_from_bits!(m32x16[test_v512]: m64x8, m128x4);
impl_from_bits!(i64x8[test_v512]: i8x64, u8x64, m8x64, i16x32, u16x32, m16x32, i32x16, u32x16, f32x16, m32x16, u64x8, f64x8, m64x8, i128x4, u128x4, m128x4);
impl_from_bits!(u64x8[test_v512]: i8x64, u8x64, m8x64, i16x32, u16x32, m16x32, i32x16, u32x16, f32x16, m32x16, i64x8, f64x8, m64x8, i128x4, u128x4, m128x4);
impl_from_bits!(f64x8[test_v512]: i8x64, u8x64, m8x64, i16x32, u16x32, m16x32, i32x16, u32x16, f32x16, m32x16, i64x8, u64x8, m64x8, i128x4, u128x4, m128x4);
impl_from_bits!(m64x8[test_v512]: m128x4);
impl_from_bits!(i128x4[test_v512]: i8x64, u8x64, m8x64, i16x32, u16x32, m16x32, i32x16, u32x16, f32x16, m32x16, i64x8, u64x8, f64x8, m64x8, u128x4, m128x4);
impl_from_bits!(u128x4[test_v512]: i8x64, u8x64, m8x64, i16x32, u16x32, m16x32, i32x16, u32x16, f32x16, m32x16, i64x8, u64x8, f64x8, m64x8, i128x4, m128x4);
// note: m128x4 cannot be constructed from all the other masks bit patterns in here

View file

@ -1,44 +0,0 @@
//! Testing macros
macro_rules! test_if {
($cfg_tt:tt: $it:item) => {
#[cfg(any(
// Test everything if:
//
// * tests are enabled,
// * no features about exclusively testing
// specific vector classes are enabled
all(test, not(any(
test_v16,
test_v32,
test_v64,
test_v128,
test_v256,
test_v512,
test_none, // disables all tests
))),
// Test if:
//
// * tests are enabled
// * a particular cfg token tree returns true
all(test, $cfg_tt),
))]
$it
};
}
#[cfg(test)]
#[allow(unused)]
macro_rules! ref_ {
($anything:tt) => {
&$anything
};
}
#[cfg(test)]
#[allow(unused)]
macro_rules! ref_mut_ {
($anything:tt) => {
&mut $anything
};
}

View file

@ -20,9 +20,6 @@ jobs:
- env: TARGET=arm-linux-androideabi - env: TARGET=arm-linux-androideabi
name: "arm-linux-androideabi" name: "arm-linux-androideabi"
stage: build-test-verify stage: build-test-verify
- env: TARGET=arm-linux-androideabi RUSTFLAGS="-C target-feature=+v7,+neon"
name: "arm-linux-androideabi + NEON"
stage: build-test-verify
- name: "aarch64-unknown-linux-android + NEON" - name: "aarch64-unknown-linux-android + NEON"
env: TARGET=aarch64-linux-android RUSTFLAGS="-C target-feature=+neon" env: TARGET=aarch64-linux-android RUSTFLAGS="-C target-feature=+neon"
stage: build-test-verify stage: build-test-verify
@ -50,21 +47,13 @@ jobs:
stage: 32bit-tier1 stage: 32bit-tier1
- env: TARGET=x86_64-unknown-linux-gnu RUSTFLAGS="-C target-feature=+sse4.2" - env: TARGET=x86_64-unknown-linux-gnu RUSTFLAGS="-C target-feature=+sse4.2"
name: "x86_64-unknown-linux-gnu + SSE4.2" name: "x86_64-unknown-linux-gnu + SSE4.2"
install: rustup component add rustfmt-preview
stage: build-test-verify stage: build-test-verify
- env: TARGET=x86_64-unknown-linux-gnu RUSTFLAGS="-C target-feature=+avx2" - env: TARGET=x86_64-unknown-linux-gnu RUSTFLAGS="-C target-feature=+avx2"
name: "x86_64-unknown-linux-gnu + AVX2" name: "x86_64-unknown-linux-gnu + AVX2"
install: rustup component add rustfmt-preview
stage: build-test-verify
- env: TARGET=arm-unknown-linux-gnueabi RUSTFLAGS="-C target-feature=+v7,+neon"
name: "arm-unknown-linux-gnueabi + NEON"
stage: build-test-verify stage: build-test-verify
- env: TARGET=arm-unknown-linux-gnueabihf - env: TARGET=arm-unknown-linux-gnueabihf
name: "arm-unknown-linux-gnueabihf" name: "arm-unknown-linux-gnueabihf"
stage: build-test-verify stage: build-test-verify
- env: TARGET=arm-unknown-linux-gnueabihf RUSTFLAGS="-C target-feature=+v7,+neon"
name: "arm-unknown-linux-gnueabihf + NEON"
stage: build-test-verify
- env: TARGET=armv7-unknown-linux-gnueabihf - env: TARGET=armv7-unknown-linux-gnueabihf
name: "armv7-unknown-linux-gnueabihf" name: "armv7-unknown-linux-gnueabihf"
stage: build-test-verify stage: build-test-verify
@ -181,16 +170,8 @@ jobs:
- name: "rustfmt" - name: "rustfmt"
install: true install: true
script: | script: |
if rustup component add rustfmt-preview ; then rustup toolchain install nightly -c rustfmt --allow-downgrade
ci/all.sh check_fmt || true ci/all.sh check_fmt || true
fi
stage: tools
- name: "clippy"
install: true
script: |
if rustup component add clippy-preview ; then
ci/all.sh clippy
fi
stage: tools stage: tools
allow_failures: allow_failures:
@ -213,14 +194,6 @@ jobs:
# Is this related to the above? Mysterious test failure # Is this related to the above? Mysterious test failure
- name: "aarch64-apple-ios + NEON" - name: "aarch64-apple-ios + NEON"
# FIXME: https://github.com/rust-lang-nursery/packed_simd/issues/182
- env: TARGET=arm-unknown-linux-gnueabi RUSTFLAGS="-C target-feature=+v7,+neon"
- env: TARGET=arm-unknown-linux-gnueabihf RUSTFLAGS="-C target-feature=+v7,+neon"
- env: TARGET=armv7-unknown-linux-gnueabihf RUSTFLAGS="-C target-feature=+neon"
# FIXME: https://github.com/rust-lang-nursery/packed_simd/issues/183
- env: TARGET=wasm32-unknown-unknown
install: travis_retry rustup target add $TARGET install: travis_retry rustup target add $TARGET
before_script: cargo generate-lockfile before_script: cargo generate-lockfile
script: travis_wait 50 ci/run-docker.sh script: travis_wait 50 ci/run-docker.sh

View file

@ -0,0 +1,42 @@
[package]
name = "packed_simd_2"
version = "0.3.7"
description = "Portable Packed SIMD vectors"
documentation = "https://docs.rs/crate/packed_simd/"
homepage = "https://github.com/rust-lang/packed_simd"
repository = "https://github.com/rust-lang/packed_simd"
keywords = ["simd", "vector", "portability"]
categories = ["hardware-support", "concurrency", "no-std", "data-structures"]
license = "MIT OR Apache-2.0"
build = "build.rs"
edition = "2018"
[badges]
appveyor = { repository = "rust-lang/packed_simd" }
travis-ci = { repository = "rust-lang/packed_simd" }
codecov = { repository = "rust-lang/packed_simd" }
is-it-maintained-issue-resolution = { repository = "rust-lang/packed_simd" }
is-it-maintained-open-issues = { repository = "rust-lang/packed_simd" }
maintenance = { status = "experimental" }
[dependencies]
cfg-if = "1.0.0"
core_arch = { version = "0.1.5", optional = true }
[features]
default = []
into_bits = []
libcore_neon = []
[dev-dependencies]
paste = "^0.1.3"
arrayvec = { version = "^0.5", default-features = false }
[target.'cfg(target_arch = "x86_64")'.dependencies.sleef-sys]
version = "0.1.2"
optional = true
[target.wasm32-unknown-unknown.dev-dependencies]
# Keep in sync with the version on Dockerfile.
wasm-bindgen = "=0.2.73"
wasm-bindgen-test = "=0.3.23"

View file

@ -1,11 +1,24 @@
# The Crates.io Version Can No Longer Be Updated!
The original maintainer is out of contact, and the new maintainers (the Portable SIMD Project Group) do not have the appropriate crates.io permissions to issue updates.
We are aware that the version available on crates.io is currently broken, and will not build.
If you need to continue to use the crate, we have published a "next version" under an alternative name.
Adjust your `[dependencies]` section of `Cargo.toml` to be the following:
```toml
packed_simd = { version = "0.3.6", package = "packed_simd_2" }
```
# `Simd<[T; N]>` # `Simd<[T; N]>`
## Implementation of [Rust RFC #2366: `std::simd`][rfc2366] ## Implementation of [Rust RFC #2366: `std::simd`][rfc2366]
[![Travis-CI Status]][travis] [![Appveyor Status]][appveyor] [![Latest Version]][crates.io] [![docs]][master_docs] [![Travis-CI Status]][travis] <!-- [![Appveyor Status]][appveyor] --> [![Latest Version]][crates.io] [![docs]][master_docs]
**WARNING**: this crate only supports the most recent nightly Rust toolchain **WARNING**: this crate only supports the most recent nightly Rust toolchain
and will be superceded by [stdsimd](https://github.com/rust-lang/stdsimd). and will be superseded by [stdsimd](https://github.com/rust-lang/stdsimd).
## Documentation ## Documentation
@ -129,15 +142,15 @@ Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in `packed_simd` by you, as defined in the Apache-2.0 license, shall be for inclusion in `packed_simd` by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions. dual licensed as above, without any additional terms or conditions.
[travis]: https://travis-ci.com/rust-lang-nursery/packed_simd [travis]: https://travis-ci.com/rust-lang/packed_simd
[Travis-CI Status]: https://travis-ci.com/rust-lang-nursery/packed_simd.svg?branch=master [Travis-CI Status]: https://travis-ci.com/rust-lang/packed_simd.svg?branch=master
[appveyor]: https://ci.appveyor.com/project/gnzlbg/packed-simd [appveyor]: https://ci.appveyor.com/project/gnzlbg/packed-simd
[Appveyor Status]: https://ci.appveyor.com/api/projects/status/hd7v9dvr442hgdix?svg=true [Appveyor Status]: https://ci.appveyor.com/api/projects/status/hd7v9dvr442hgdix?svg=true
[Latest Version]: https://img.shields.io/crates/v/packed_simd.svg [Latest Version]: https://img.shields.io/crates/v/packed_simd_2.svg
[crates.io]: https://crates.io/crates/packed_simd [crates.io]: https://crates.io/crates/packed_simd_2
[docs]: https://docs.rs/packed_simd/badge.svg [docs]: https://docs.rs/packed_simd_2/badge.svg
[docs.rs]: https://docs.rs/packed_simd/ [docs.rs]: https://docs.rs/packed_simd_2
[master_docs]: https://rust-lang-nursery.github.io/packed_simd/packed_simd/ [master_docs]: https://rust-lang-nursery.github.io/packed_simd/packed_simd_2/
[perf_guide]: https://rust-lang-nursery.github.io/packed_simd/perf-guide/ [perf_guide]: https://rust-lang-nursery.github.io/packed_simd/perf-guide/
[rfc2366]: https://github.com/rust-lang/rfcs/pull/2366 [rfc2366]: https://github.com/rust-lang/rfcs/pull/2366
[ISPC]: https://ispc.github.io/ [ISPC]: https://ispc.github.io/

View file

@ -0,0 +1,6 @@
fn main() {
let target = std::env::var("TARGET").expect("TARGET environment variable not defined");
if target.contains("neon") {
println!("cargo:rustc-cfg=libcore_neon");
}
}

View file

@ -17,14 +17,15 @@ RUN make -C wabt -j$(nproc)
ENV PATH=$PATH:/wabt/bin ENV PATH=$PATH:/wabt/bin
# Install `wasm-bindgen-test-runner` # Install `wasm-bindgen-test-runner`
RUN curl -L https://github.com/rustwasm/wasm-bindgen/releases/download/0.2.19/wasm-bindgen-0.2.19-x86_64-unknown-linux-musl.tar.gz \ RUN curl -L https://github.com/rustwasm/wasm-bindgen/releases/download/0.2.73/wasm-bindgen-0.2.73-x86_64-unknown-linux-musl.tar.gz \
| tar xzf - | tar xzf -
ENV PATH=$PATH:/wasm-bindgen-0.2.19-x86_64-unknown-linux-musl # Keep in sync with the version on Cargo.toml.
ENV PATH=$PATH:/wasm-bindgen-0.2.73-x86_64-unknown-linux-musl
ENV CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER=wasm-bindgen-test-runner ENV CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER=wasm-bindgen-test-runner
# Install `node` # Install `node`
RUN curl https://nodejs.org/dist/v10.8.0/node-v10.8.0-linux-x64.tar.xz | tar xJf - RUN curl https://nodejs.org/dist/v14.16.0/node-v14.16.0-linux-x64.tar.xz | tar xJf -
ENV PATH=$PATH:/node-v10.8.0-linux-x64/bin ENV PATH=$PATH:/node-v14.16.0-linux-x64/bin
# We use a shim linker that removes `--strip-debug` when passed to LLD. While # We use a shim linker that removes `--strip-debug` when passed to LLD. While
# this typically results in invalid debug information in release mode it doesn't # this typically results in invalid debug information in release mode it doesn't

View file

@ -35,7 +35,7 @@ If LLVM is indeed the cause, the issue will be reported upstream to the
## Submitting Pull Requests ## Submitting Pull Requests
New code is submitted to the crate using GitHub's [pull request] mechanism. New code is submitted to the crate using GitHub's [pull request] mechanism.
You should first fork this repository, make your changes (preferrably in a new You should first fork this repository, make your changes (preferably in a new
branch), then use GitHub's web UI to create a new PR. branch), then use GitHub's web UI to create a new PR.
[pull request]: https://help.github.com/articles/about-pull-requests/ [pull request]: https://help.github.com/articles/about-pull-requests/

Some files were not shown because too many files have changed in this diff Show more