Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 19 Jun 2021 15:15:14 GMT
From:      Tobias Kortkamp <tobik@FreeBSD.org>
To:        ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org
Subject:   git: d9f5e35feca9 - main - security/suricata: Unbreak build with Rust 1.53.0
Message-ID:  <202106191515.15JFFEm1067060@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by tobik:

URL: https://cgit.FreeBSD.org/ports/commit/?id=d9f5e35feca9ae3e28edfe511e3ffa58810e7f2c

commit d9f5e35feca9ae3e28edfe511e3ffa58810e7f2c
Author:     Tobias Kortkamp <tobik@FreeBSD.org>
AuthorDate: 2021-06-19 12:29:36 +0000
Commit:     Tobias Kortkamp <tobik@FreeBSD.org>
CommitDate: 2021-06-19 15:13:19 +0000

    security/suricata: Unbreak build with Rust 1.53.0
    
    error[E0308]: mismatched types
      --> rust/vendor/lexical-core/src/atof/algorithm/bhcomp.rs:62:24
       |
    62 |     let bytes = bits / Limb::BITS;
       |                        ^^^^^^^^^^ expected `usize`, found `u32`
    
    error[E0277]: cannot divide `usize` by `u32`
    
    http://package23.nyi.freebsd.org/data/114i386-default-foo/2021-06-18_08h49m22s/logs/errors/suricata-6.0.2_2.log
    
    PR:             256653
---
 security/suricata/Makefile                         |   5 +
 ...endor_lexical-core_src_atof_algorithm_bhcomp.rs |  11 ++
 ...ndor_lexical-core_src_atof_algorithm_bigcomp.rs |  39 ++++
 ..._vendor_lexical-core_src_atof_algorithm_math.rs | 211 +++++++++++++++++++++
 4 files changed, 266 insertions(+)

diff --git a/security/suricata/Makefile b/security/suricata/Makefile
index e5dcf9c2aeca..e047f1fb6838 100644
--- a/security/suricata/Makefile
+++ b/security/suricata/Makefile
@@ -108,6 +108,11 @@ TESTS_CONFIGURE_ENABLE=		unittests
 pre-patch:
 	@${CP} ${FILESDIR}/ax_check_compile_flag.m4 ${WRKSRC}/m4
 
+post-patch:
+# Disable vendor checksums
+	@${REINPLACE_CMD} 's,"files":{[^}]*},"files":{},' \
+		${WRKSRC}/rust/vendor/*/.cargo-checksum.json
+
 post-patch-PYTHON-on:
 	@${REINPLACE_CMD} -e "/AC_PATH_PROGS.*HAVE_PYTHON/ s/python[^,]*,/${PYTHON_VERSION},/g" \
 		${WRKSRC}/configure.ac
diff --git a/security/suricata/files/patch-rust_vendor_lexical-core_src_atof_algorithm_bhcomp.rs b/security/suricata/files/patch-rust_vendor_lexical-core_src_atof_algorithm_bhcomp.rs
new file mode 100644
index 000000000000..5ab5c0f66d7b
--- /dev/null
+++ b/security/suricata/files/patch-rust_vendor_lexical-core_src_atof_algorithm_bhcomp.rs
@@ -0,0 +1,11 @@
+--- rust/vendor/lexical-core/src/atof/algorithm/bhcomp.rs.orig	2021-06-19 12:41:29 UTC
++++ rust/vendor/lexical-core/src/atof/algorithm/bhcomp.rs
+@@ -59,7 +59,7 @@ pub(super) fn parse_mantissa<'a, Data>(data: Data, rad
+     let small_powers = Bigint::small_powers(radix);
+     let count = data.mantissa_digits();
+     let bits = count / integral_binary_factor(radix).as_usize();
+-    let bytes = bits / Limb::BITS;
++    let bytes = bits / <Limb as Integer>::BITS;
+ 
+     // Main loop
+     let step = small_powers.len() - 2;
diff --git a/security/suricata/files/patch-rust_vendor_lexical-core_src_atof_algorithm_bigcomp.rs b/security/suricata/files/patch-rust_vendor_lexical-core_src_atof_algorithm_bigcomp.rs
new file mode 100644
index 000000000000..585f9630bbaa
--- /dev/null
+++ b/security/suricata/files/patch-rust_vendor_lexical-core_src_atof_algorithm_bigcomp.rs
@@ -0,0 +1,39 @@
+error[E0308]: mismatched types
+   --> src/atof/algorithm/bigcomp.rs:242:55
+    |
+242 |     let nlz = den.leading_zeros().wrapping_sub(wlz) & (u32::BITS - 1);
+    |                                                       ^^^^^^^^^^^^^^^ expected `usize`, found `u32`
+
+error[E0277]: no implementation for `usize & u32`
+
+https://github.com/Alexhuszagh/rust-lexical/commit/05f2cf96b080a81e2bee1f30ae389dc4f9cb6d00
+
+--- rust/vendor/lexical-core/src/atof/algorithm/bigcomp.rs.orig	2021-03-01 16:15:39 UTC
++++ rust/vendor/lexical-core/src/atof/algorithm/bigcomp.rs
+@@ -154,7 +154,7 @@ pub(super) fn make_ratio<F: Float>(radix: u32, sci_exp
+     // Scale the denominator so it has the number of bits
+     // in the radix as the number of leading zeros.
+     let wlz = integral_binary_factor(radix).as_usize();
+-    let nlz = den.leading_zeros().wrapping_sub(wlz) & (u32::BITS - 1);
++    let nlz = den.leading_zeros().wrapping_sub(wlz) & (<u32 as Integer>::BITS - 1);
+     small::ishl_bits(den.data_mut(), nlz);
+     den.exp -= nlz.as_i32();
+ 
+@@ -172,7 +172,7 @@ pub(super) fn make_ratio<F: Float>(radix: u32, sci_exp
+         // denominator will be normalized.
+         // We need to add one to the quotient,since we're calculating the
+         // ceiling of the divmod.
+-        let (q, r) = shift.ceil_divmod(Limb::BITS);
++        let (q, r) = shift.ceil_divmod(<Limb as Integer>::BITS);
+         // Since we're using a power from the denominator to the
+         // numerator, we to invert r, not add u32::BITS.
+         let r = -r;
+@@ -180,7 +180,7 @@ pub(super) fn make_ratio<F: Float>(radix: u32, sci_exp
+         num.exp -= r;
+         if !q.is_zero() {
+             den.pad_zero_digits(q);
+-            den.exp -= Limb::BITS.as_i32() * q.as_i32();
++            den.exp -= <Limb as Integer>::BITS.as_i32() * q.as_i32();
+         }
+     }
+ 
diff --git a/security/suricata/files/patch-rust_vendor_lexical-core_src_atof_algorithm_math.rs b/security/suricata/files/patch-rust_vendor_lexical-core_src_atof_algorithm_math.rs
new file mode 100644
index 000000000000..d402b44e44a5
--- /dev/null
+++ b/security/suricata/files/patch-rust_vendor_lexical-core_src_atof_algorithm_math.rs
@@ -0,0 +1,211 @@
+--- rust/vendor/lexical-core/src/atof/algorithm/math.rs.orig	2021-03-01 16:15:39 UTC
++++ rust/vendor/lexical-core/src/atof/algorithm/math.rs
+@@ -956,7 +956,7 @@ pub fn mul(x: Limb, y: Limb, carry: Limb)
+     // the following is always true:
+     // `Wide::max_value() - (Narrow::max_value() * Narrow::max_value()) >= Narrow::max_value()`
+     let z: Wide = as_wide(x) * as_wide(y) + as_wide(carry);
+-    (as_limb(z), as_limb(z >> Limb::BITS))
++    (as_limb(z), as_limb(z >> <Limb as Integer>::BITS))
+ }}
+ 
+ /// Multiply two small integers (with carry) (and return if overflow happens).
+@@ -979,7 +979,7 @@ pub fn div(x: Limb, y: Limb, rem: Limb)
+     -> (Limb, Limb)
+ {
+     // Cannot overflow, as long as wide is 2x as wide.
+-    let x = as_wide(x) | (as_wide(rem) << Limb::BITS);
++    let x = as_wide(x) | (as_wide(rem) << <Limb as Integer>::BITS);
+     let y = as_wide(y);
+     (as_limb(x / y), as_limb(x % y))
+ }}
+@@ -1046,7 +1046,7 @@ perftools_inline!{
+ pub fn trailing_zeros(x: &[Limb]) -> usize {
+     // Get the index of the last non-zero value
+     let index = trailing_zero_limbs(x);
+-    let mut count = index.saturating_mul(Limb::BITS);
++    let mut count = index.saturating_mul(<Limb as Integer>::BITS);
+     if let Some(value) = x.get(index) {
+         count = count.saturating_add(value.trailing_zeros().as_usize());
+     }
+@@ -1061,7 +1061,7 @@ pub fn bit_length(x: &[Limb]) -> usize {
+     // Avoid overflowing, calculate via total number of bits
+     // minus leading zero bits.
+     let nlz = leading_zeros(x);
+-    Limb::BITS.checked_mul(x.len())
++    <Limb as Integer>::BITS.checked_mul(x.len())
+         .map(|v| v - nlz)
+         .unwrap_or(usize::max_value())
+ }}
+@@ -1080,14 +1080,14 @@ pub fn limb_length(x: &[Limb]) -> usize {
+ ///
+ /// Returns the truncated bits.
+ ///
+-/// Assumes `n < Limb::BITS`, IE, internally shifting bits.
++/// Assumes `n < <Limb as Integer>::BITS`, IE, internally shifting bits.
+ perftools_inline!{
+ pub fn ishr_bits<T>(x: &mut T, n: usize)
+     -> Limb
+     where T: CloneableVecLike<Limb>
+ {
+-    // Need to shift by the number of `bits % Limb::BITS`.
+-    let bits = Limb::BITS;
++    // Need to shift by the number of `bits % <Limb as Integer>::BITS`.
++    let bits = <Limb as Integer>::BITS;
+     debug_assert!(n < bits && n != 0);
+ 
+     // Internally, for each item, we shift left by n, and add the previous
+@@ -1134,9 +1134,9 @@ pub fn ishr<T>(x: &mut T, n: usize)
+     -> bool
+     where T: CloneableVecLike<Limb>
+ {
+-    let bits = Limb::BITS;
+-    // Need to pad with zeros for the number of `bits / Limb::BITS`,
+-    // and shift-left with carry for `bits % Limb::BITS`.
++    let bits = <Limb as Integer>::BITS;
++    // Need to pad with zeros for the number of `bits / <Limb as Integer>::BITS`,
++    // and shift-left with carry for `bits % <Limb as Integer>::BITS`.
+     let rem = n % bits;
+     let div = n / bits;
+     let is_zero = match div.is_zero() {
+@@ -1187,13 +1187,13 @@ pub fn shr<T>(x: &[Limb], n: usize)
+ 
+ /// Shift-left bits inside a buffer.
+ ///
+-/// Assumes `n < Limb::BITS`, IE, internally shifting bits.
++/// Assumes `n < <Limb as Integer>::BITS`, IE, internally shifting bits.
+ perftools_inline!{
+ pub fn ishl_bits<T>(x: &mut T, n: usize)
+     where T: CloneableVecLike<Limb>
+ {
+-    // Need to shift by the number of `bits % Limb::BITS)`.
+-    let bits = Limb::BITS;
++    // Need to shift by the number of `bits % <Limb as Integer>::BITS)`.
++    let bits = <Limb as Integer>::BITS;
+     debug_assert!(n < bits);
+     if n.is_zero() {
+         return;
+@@ -1223,7 +1223,7 @@ pub fn ishl_bits<T>(x: &mut T, n: usize)
+ 
+ /// Shift-left bits inside a buffer.
+ ///
+-/// Assumes `n < Limb::BITS`, IE, internally shifting bits.
++/// Assumes `n < <Limb as Integer>::BITS`, IE, internally shifting bits.
+ perftools_inline!{
+ pub fn shl_bits<T>(x: &[Limb], n: usize)
+     -> T
+@@ -1253,9 +1253,9 @@ perftools_inline!{
+ pub fn ishl<T>(x: &mut T, n: usize)
+     where T: CloneableVecLike<Limb>
+ {
+-    let bits = Limb::BITS;
+-    // Need to pad with zeros for the number of `bits / Limb::BITS`,
+-    // and shift-left with carry for `bits % Limb::BITS`.
++    let bits = <Limb as Integer>::BITS;
++    // Need to pad with zeros for the number of `bits / <Limb as Integer>::BITS`,
++    // and shift-left with carry for `bits % <Limb as Integer>::BITS`.
+     let rem = n % bits;
+     let div = n / bits;
+     ishl_bits(x, rem);
+@@ -1912,7 +1912,7 @@ pub fn mul<T>(x: &[Limb], y: &[Limb])
+ // DIVISION
+ 
+ /// Constants for algorithm D.
+-const ALGORITHM_D_B: Wide = 1 << Limb::BITS;
++const ALGORITHM_D_B: Wide = 1 << <Limb as Integer>::BITS;
+ const ALGORITHM_D_M: Wide = ALGORITHM_D_B - 1;
+ 
+ /// Calculate qhat (an estimate for the quotient).
+@@ -1932,7 +1932,7 @@ fn calculate_qhat(x: &[Limb], y: &[Limb], j: usize)
+     //  rhat = (x[j+n]*B + x[j+n-1]) - qhat*y[n-1];
+     let x_jn = as_wide(x[j+n]);
+     let x_jn1 = as_wide(x[j+n-1]);
+-    let num = (x_jn << Limb::BITS) + x_jn1;
++    let num = (x_jn << <Limb as Integer>::BITS) + x_jn1;
+     let den = as_wide(y[n-1]);
+     let mut qhat = num / den;
+     let mut rhat = num - qhat * den;
+@@ -1949,7 +1949,7 @@ fn calculate_qhat(x: &[Limb], y: &[Limb], j: usize)
+     let y_n2 = as_wide(y[n-2]);
+     let y_n1 = as_wide(y[n-1]);
+     // This only happens when the leading bit of qhat is set.
+-    while qhat >= ALGORITHM_D_B || qhat * y_n2 > (rhat << Limb::BITS) + x_jn2 {
++    while qhat >= ALGORITHM_D_B || qhat * y_n2 > (rhat << <Limb as Integer>::BITS) + x_jn2 {
+         qhat -= 1;
+         rhat += y_n1;
+         if rhat >= ALGORITHM_D_B {
+@@ -1989,7 +1989,7 @@ fn multiply_and_subtract<T>(x: &mut T, y: &T, qhat: Wi
+         let p = qhat * y_i;
+         t = x_ij.wrapping_sub(k).wrapping_sub(as_signed_wide(p & ALGORITHM_D_M));
+         x[i+j] = as_limb(t);
+-        k = as_signed_wide(p >> Limb::BITS) - (t >> Limb::BITS);
++        k = as_signed_wide(p >> <Limb as Integer>::BITS) - (t >> <Limb as Integer>::BITS);
+     }
+     t = as_signed_wide(x[j+n]) - k;
+     x[j+n] = as_limb(t);
+@@ -2045,7 +2045,7 @@ fn add_back<T>(x: &mut T, y: &T, mut t: SignedWide, j:
+         for i in 0..n {
+             t = as_signed_wide(as_wide(x[i+j]) + as_wide(y[i])) + k;
+             x[i+j] = as_limb(t);
+-            k = t >> Limb::BITS;
++            k = t >> <Limb as Integer>::BITS;
+         }
+         let x_jn = as_signed_wide(x[j+n]) + k;
+         x[j+n] = as_limb(x_jn);
+@@ -2068,7 +2068,7 @@ fn calculate_remainder<T>(x: &[Limb], y: &[Limb], s: u
+     let n = y.len();
+     let mut r = T::default();
+     r.reserve_exact(n);
+-    let rs = Limb::BITS - s;
++    let rs = <Limb as Integer>::BITS - s;
+     for i in 0..n-1 {
+         let xi = as_wide(x[i]) >> s;
+         let xi1 = as_wide(x[i+1]) << rs;
+@@ -2205,9 +2205,9 @@ pub fn quorem<T>(x: &mut T, y: &T)
+         let mut carry: Wide = 0;
+         for j in 0..m {
+             let p = as_wide(y[j]) * as_wide(q) + carry;
+-            carry = p >> Limb::BITS;
++            carry = p >> <Limb as Integer>::BITS;
+             let t = as_wide(x[j]).wrapping_sub(p & mask).wrapping_sub(borrow);
+-            borrow = (t >> Limb::BITS) & 1;
++            borrow = (t >> <Limb as Integer>::BITS) & 1;
+             x[j] = as_limb(t);
+         }
+         small::normalize(x);
+@@ -2220,9 +2220,9 @@ pub fn quorem<T>(x: &mut T, y: &T)
+         let mut carry: Wide = 0;
+         for j in 0..m {
+             let p = as_wide(y[j]) + carry;
+-            carry = p >> Limb::BITS;
++            carry = p >> <Limb as Integer>::BITS;
+             let t = as_wide(x[j]).wrapping_sub(p & mask).wrapping_sub(borrow);
+-            borrow = (t >> Limb::BITS) & 1;
++            borrow = (t >> <Limb as Integer>::BITS) & 1;
+             x[j] = as_limb(t);
+         }
+         small::normalize(x);
+@@ -3137,18 +3137,18 @@ mod tests {
+     fn leading_zeros_test() {
+         assert_eq!(Bigint::new().leading_zeros(), 0);
+ 
+-        assert_eq!(Bigint::from_u16(0xFF).leading_zeros(), Limb::BITS-8);
+-        assert_eq!(Bigint::from_u32(0xFF).leading_zeros(), Limb::BITS-8);
++        assert_eq!(Bigint::from_u16(0xFF).leading_zeros(), <Limb as Integer>::BITS-8);
++        assert_eq!(Bigint::from_u32(0xFF).leading_zeros(), <Limb as Integer>::BITS-8);
+         assert_eq!(Bigint::from_u64(0xFF00000000).leading_zeros(), 24);
+         assert_eq!(Bigint::from_u128(0xFF000000000000000000000000).leading_zeros(), 24);
+ 
+-        assert_eq!(Bigint::from_u16(0xF).leading_zeros(), Limb::BITS-4);
+-        assert_eq!(Bigint::from_u32(0xF).leading_zeros(), Limb::BITS-4);
++        assert_eq!(Bigint::from_u16(0xF).leading_zeros(), <Limb as Integer>::BITS-4);
++        assert_eq!(Bigint::from_u32(0xF).leading_zeros(), <Limb as Integer>::BITS-4);
+         assert_eq!(Bigint::from_u64(0xF00000000).leading_zeros(), 28);
+         assert_eq!(Bigint::from_u128(0xF000000000000000000000000).leading_zeros(), 28);
+ 
+-        assert_eq!(Bigint::from_u16(0xF0).leading_zeros(), Limb::BITS-8);
+-        assert_eq!(Bigint::from_u32(0xF0).leading_zeros(), Limb::BITS-8);
++        assert_eq!(Bigint::from_u16(0xF0).leading_zeros(), <Limb as Integer>::BITS-8);
++        assert_eq!(Bigint::from_u32(0xF0).leading_zeros(), <Limb as Integer>::BITS-8);
+         assert_eq!(Bigint::from_u64(0xF000000000).leading_zeros(), 24);
+         assert_eq!(Bigint::from_u128(0xF0000000000000000000000000).leading_zeros(), 24);
+     }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202106191515.15JFFEm1067060>