Skip to content

Commit

Permalink
check in bindgen.py
Browse files Browse the repository at this point in the history
As part of doing this, we blacklist the max_align_t type. This was
causing a generated test failure. See:
rust-lang/rust-bindgen#550
  • Loading branch information
oconnor663 committed Nov 5, 2017
1 parent a22ce17 commit 59a97b6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 57 deletions.
23 changes: 23 additions & 0 deletions src/bindgen.py
Original file line number Diff line number Diff line change
@@ -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)
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
63 changes: 16 additions & 47 deletions src/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<max_align_t>(),
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;
Expand Down Expand Up @@ -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__ {
Expand Down

0 comments on commit 59a97b6

Please sign in to comment.