From 59a97b616320b57f2ea097da0c5b0068895b3c8e Mon Sep 17 00:00:00 2001 From: Jack O'Connor Date: Sun, 5 Nov 2017 17:05:10 -0500 Subject: [PATCH] check in bindgen.py As part of doing this, we blacklist the max_align_t type. This was causing a generated test failure. See: https://github.com/rust-lang-nursery/rust-bindgen/issues/550 --- src/bindgen.py | 23 ++++++++++++++++++ src/lib.rs | 20 ++++++++-------- src/sys.rs | 63 +++++++++++++------------------------------------- 3 files changed, 49 insertions(+), 57 deletions(-) create mode 100755 src/bindgen.py diff --git a/src/bindgen.py b/src/bindgen.py new file mode 100755 index 0000000..0d6403e --- /dev/null +++ b/src/bindgen.py @@ -0,0 +1,23 @@ +#! /usr/bin/env python3 + +# This script generates sys.rs, which is checked in. + +from pathlib import Path +from subprocess import run + +root = Path(__file__).parent / ".." +ref_header = root / "BLAKE2/ref/blake2.h" +sse_header = root / "BLAKE2/sse/blake2.h" + +# Make sure that the two headers are identical, since we're using the same +# generated file in both modes. +assert ref_header.open().read() == sse_header.open().read() + +command = ["bindgen", str(ref_header)] +command += ["--constified-enum-module", "blake2b_constant"] +command += ["--constified-enum-module", "blake2s_constant"] +# If we don't blacklist this symbol we get a test failure: +# https://github.com/rust-lang-nursery/rust-bindgen/issues/550. +command += ["--blacklist-type", "max_align_t"] +with (root / "src/sys.rs").open("w") as output: + run(command, stdout=output, check=True) diff --git a/src/lib.rs b/src/lib.rs index bebfeab..f1b575a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,11 +27,11 @@ pub fn blake2s_256(input: &[u8]) -> blake2s::Digest { pub mod blake2b { use super::*; - pub const BLOCKBYTES: usize = sys::blake2b_constant_BLAKE2B_BLOCKBYTES as usize; - pub const OUTBYTES: usize = sys::blake2b_constant_BLAKE2B_OUTBYTES as usize; - pub const KEYBYTES: usize = sys::blake2b_constant_BLAKE2B_KEYBYTES as usize; - pub const SALTBYTES: usize = sys::blake2b_constant_BLAKE2B_SALTBYTES as usize; - pub const PERSONALBYTES: usize = sys::blake2b_constant_BLAKE2B_PERSONALBYTES as usize; + pub const BLOCKBYTES: usize = sys::blake2b_constant::BLAKE2B_BLOCKBYTES as usize; + pub const OUTBYTES: usize = sys::blake2b_constant::BLAKE2B_OUTBYTES as usize; + pub const KEYBYTES: usize = sys::blake2b_constant::BLAKE2B_KEYBYTES as usize; + pub const SALTBYTES: usize = sys::blake2b_constant::BLAKE2B_SALTBYTES as usize; + pub const PERSONALBYTES: usize = sys::blake2b_constant::BLAKE2B_PERSONALBYTES as usize; // TODO: Clone, Debug pub struct Builder { @@ -251,11 +251,11 @@ pub mod blake2b { pub mod blake2s { use super::*; - pub const BLOCKBYTES: usize = sys::blake2s_constant_BLAKE2S_BLOCKBYTES as usize; - pub const OUTBYTES: usize = sys::blake2s_constant_BLAKE2S_OUTBYTES as usize; - pub const KEYBYTES: usize = sys::blake2s_constant_BLAKE2S_KEYBYTES as usize; - pub const SALTBYTES: usize = sys::blake2s_constant_BLAKE2S_SALTBYTES as usize; - pub const PERSONALBYTES: usize = sys::blake2s_constant_BLAKE2S_PERSONALBYTES as usize; + pub const BLOCKBYTES: usize = sys::blake2s_constant::BLAKE2S_BLOCKBYTES as usize; + pub const OUTBYTES: usize = sys::blake2s_constant::BLAKE2S_OUTBYTES as usize; + pub const KEYBYTES: usize = sys::blake2s_constant::BLAKE2S_KEYBYTES as usize; + pub const SALTBYTES: usize = sys::blake2s_constant::BLAKE2S_SALTBYTES as usize; + pub const PERSONALBYTES: usize = sys::blake2s_constant::BLAKE2S_PERSONALBYTES as usize; // TODO: Clone, Debug pub struct Builder { diff --git a/src/sys.rs b/src/sys.rs index fa3ca82..6555a2c 100644 --- a/src/sys.rs +++ b/src/sys.rs @@ -85,41 +85,6 @@ pub const SIZE_MAX: ::std::os::raw::c_int = -1; pub const WINT_MIN: ::std::os::raw::c_uint = 0; pub const WINT_MAX: ::std::os::raw::c_uint = 4294967295; pub type wchar_t = ::std::os::raw::c_int; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct max_align_t { - pub __clang_max_align_nonce1: ::std::os::raw::c_longlong, - pub __bindgen_padding_0: u64, - pub __clang_max_align_nonce2: f64, -} -#[test] -fn bindgen_test_layout_max_align_t() { - assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(max_align_t)) - ); - assert_eq!( - unsafe { &(*(0 as *const max_align_t)).__clang_max_align_nonce1 as *const _ as usize }, - 0usize, - concat!( - "Alignment of field: ", - stringify!(max_align_t), - "::", - stringify!(__clang_max_align_nonce1) - ) - ); - assert_eq!( - unsafe { &(*(0 as *const max_align_t)).__clang_max_align_nonce2 as *const _ as usize }, - 16usize, - concat!( - "Alignment of field: ", - stringify!(max_align_t), - "::", - stringify!(__clang_max_align_nonce2) - ) - ); -} pub type __u_char = ::std::os::raw::c_uchar; pub type __u_short = ::std::os::raw::c_ushort; pub type __u_int = ::std::os::raw::c_uint; @@ -220,18 +185,22 @@ pub type uint_fast32_t = ::std::os::raw::c_ulong; pub type uint_fast64_t = ::std::os::raw::c_ulong; pub type intmax_t = __intmax_t; pub type uintmax_t = __uintmax_t; -pub const blake2s_constant_BLAKE2S_BLOCKBYTES: blake2s_constant = 64; -pub const blake2s_constant_BLAKE2S_OUTBYTES: blake2s_constant = 32; -pub const blake2s_constant_BLAKE2S_KEYBYTES: blake2s_constant = 32; -pub const blake2s_constant_BLAKE2S_SALTBYTES: blake2s_constant = 8; -pub const blake2s_constant_BLAKE2S_PERSONALBYTES: blake2s_constant = 8; -pub type blake2s_constant = ::std::os::raw::c_uint; -pub const blake2b_constant_BLAKE2B_BLOCKBYTES: blake2b_constant = 128; -pub const blake2b_constant_BLAKE2B_OUTBYTES: blake2b_constant = 64; -pub const blake2b_constant_BLAKE2B_KEYBYTES: blake2b_constant = 64; -pub const blake2b_constant_BLAKE2B_SALTBYTES: blake2b_constant = 16; -pub const blake2b_constant_BLAKE2B_PERSONALBYTES: blake2b_constant = 16; -pub type blake2b_constant = ::std::os::raw::c_uint; +pub mod blake2s_constant { + pub type Type = ::std::os::raw::c_uint; + pub const BLAKE2S_BLOCKBYTES: Type = 64; + pub const BLAKE2S_OUTBYTES: Type = 32; + pub const BLAKE2S_KEYBYTES: Type = 32; + pub const BLAKE2S_SALTBYTES: Type = 8; + pub const BLAKE2S_PERSONALBYTES: Type = 8; +} +pub mod blake2b_constant { + pub type Type = ::std::os::raw::c_uint; + pub const BLAKE2B_BLOCKBYTES: Type = 128; + pub const BLAKE2B_OUTBYTES: Type = 64; + pub const BLAKE2B_KEYBYTES: Type = 64; + pub const BLAKE2B_SALTBYTES: Type = 16; + pub const BLAKE2B_PERSONALBYTES: Type = 16; +} #[repr(C)] #[derive(Copy, Clone)] pub struct blake2s_state__ {