Skip to content

Commit 59a97b6

Browse files
committed
check in bindgen.py
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
1 parent a22ce17 commit 59a97b6

File tree

3 files changed

+49
-57
lines changed

3 files changed

+49
-57
lines changed

src/bindgen.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#! /usr/bin/env python3
2+
3+
# This script generates sys.rs, which is checked in.
4+
5+
from pathlib import Path
6+
from subprocess import run
7+
8+
root = Path(__file__).parent / ".."
9+
ref_header = root / "BLAKE2/ref/blake2.h"
10+
sse_header = root / "BLAKE2/sse/blake2.h"
11+
12+
# Make sure that the two headers are identical, since we're using the same
13+
# generated file in both modes.
14+
assert ref_header.open().read() == sse_header.open().read()
15+
16+
command = ["bindgen", str(ref_header)]
17+
command += ["--constified-enum-module", "blake2b_constant"]
18+
command += ["--constified-enum-module", "blake2s_constant"]
19+
# If we don't blacklist this symbol we get a test failure:
20+
# https://github.com/rust-lang-nursery/rust-bindgen/issues/550.
21+
command += ["--blacklist-type", "max_align_t"]
22+
with (root / "src/sys.rs").open("w") as output:
23+
run(command, stdout=output, check=True)

src/lib.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ pub fn blake2s_256(input: &[u8]) -> blake2s::Digest {
2727
pub mod blake2b {
2828
use super::*;
2929

30-
pub const BLOCKBYTES: usize = sys::blake2b_constant_BLAKE2B_BLOCKBYTES as usize;
31-
pub const OUTBYTES: usize = sys::blake2b_constant_BLAKE2B_OUTBYTES as usize;
32-
pub const KEYBYTES: usize = sys::blake2b_constant_BLAKE2B_KEYBYTES as usize;
33-
pub const SALTBYTES: usize = sys::blake2b_constant_BLAKE2B_SALTBYTES as usize;
34-
pub const PERSONALBYTES: usize = sys::blake2b_constant_BLAKE2B_PERSONALBYTES as usize;
30+
pub const BLOCKBYTES: usize = sys::blake2b_constant::BLAKE2B_BLOCKBYTES as usize;
31+
pub const OUTBYTES: usize = sys::blake2b_constant::BLAKE2B_OUTBYTES as usize;
32+
pub const KEYBYTES: usize = sys::blake2b_constant::BLAKE2B_KEYBYTES as usize;
33+
pub const SALTBYTES: usize = sys::blake2b_constant::BLAKE2B_SALTBYTES as usize;
34+
pub const PERSONALBYTES: usize = sys::blake2b_constant::BLAKE2B_PERSONALBYTES as usize;
3535

3636
// TODO: Clone, Debug
3737
pub struct Builder {
@@ -251,11 +251,11 @@ pub mod blake2b {
251251
pub mod blake2s {
252252
use super::*;
253253

254-
pub const BLOCKBYTES: usize = sys::blake2s_constant_BLAKE2S_BLOCKBYTES as usize;
255-
pub const OUTBYTES: usize = sys::blake2s_constant_BLAKE2S_OUTBYTES as usize;
256-
pub const KEYBYTES: usize = sys::blake2s_constant_BLAKE2S_KEYBYTES as usize;
257-
pub const SALTBYTES: usize = sys::blake2s_constant_BLAKE2S_SALTBYTES as usize;
258-
pub const PERSONALBYTES: usize = sys::blake2s_constant_BLAKE2S_PERSONALBYTES as usize;
254+
pub const BLOCKBYTES: usize = sys::blake2s_constant::BLAKE2S_BLOCKBYTES as usize;
255+
pub const OUTBYTES: usize = sys::blake2s_constant::BLAKE2S_OUTBYTES as usize;
256+
pub const KEYBYTES: usize = sys::blake2s_constant::BLAKE2S_KEYBYTES as usize;
257+
pub const SALTBYTES: usize = sys::blake2s_constant::BLAKE2S_SALTBYTES as usize;
258+
pub const PERSONALBYTES: usize = sys::blake2s_constant::BLAKE2S_PERSONALBYTES as usize;
259259

260260
// TODO: Clone, Debug
261261
pub struct Builder {

src/sys.rs

+16-47
Original file line numberDiff line numberDiff line change
@@ -85,41 +85,6 @@ pub const SIZE_MAX: ::std::os::raw::c_int = -1;
8585
pub const WINT_MIN: ::std::os::raw::c_uint = 0;
8686
pub const WINT_MAX: ::std::os::raw::c_uint = 4294967295;
8787
pub type wchar_t = ::std::os::raw::c_int;
88-
#[repr(C)]
89-
#[derive(Debug, Copy, Clone)]
90-
pub struct max_align_t {
91-
pub __clang_max_align_nonce1: ::std::os::raw::c_longlong,
92-
pub __bindgen_padding_0: u64,
93-
pub __clang_max_align_nonce2: f64,
94-
}
95-
#[test]
96-
fn bindgen_test_layout_max_align_t() {
97-
assert_eq!(
98-
::std::mem::size_of::<max_align_t>(),
99-
32usize,
100-
concat!("Size of: ", stringify!(max_align_t))
101-
);
102-
assert_eq!(
103-
unsafe { &(*(0 as *const max_align_t)).__clang_max_align_nonce1 as *const _ as usize },
104-
0usize,
105-
concat!(
106-
"Alignment of field: ",
107-
stringify!(max_align_t),
108-
"::",
109-
stringify!(__clang_max_align_nonce1)
110-
)
111-
);
112-
assert_eq!(
113-
unsafe { &(*(0 as *const max_align_t)).__clang_max_align_nonce2 as *const _ as usize },
114-
16usize,
115-
concat!(
116-
"Alignment of field: ",
117-
stringify!(max_align_t),
118-
"::",
119-
stringify!(__clang_max_align_nonce2)
120-
)
121-
);
122-
}
12388
pub type __u_char = ::std::os::raw::c_uchar;
12489
pub type __u_short = ::std::os::raw::c_ushort;
12590
pub type __u_int = ::std::os::raw::c_uint;
@@ -220,18 +185,22 @@ pub type uint_fast32_t = ::std::os::raw::c_ulong;
220185
pub type uint_fast64_t = ::std::os::raw::c_ulong;
221186
pub type intmax_t = __intmax_t;
222187
pub type uintmax_t = __uintmax_t;
223-
pub const blake2s_constant_BLAKE2S_BLOCKBYTES: blake2s_constant = 64;
224-
pub const blake2s_constant_BLAKE2S_OUTBYTES: blake2s_constant = 32;
225-
pub const blake2s_constant_BLAKE2S_KEYBYTES: blake2s_constant = 32;
226-
pub const blake2s_constant_BLAKE2S_SALTBYTES: blake2s_constant = 8;
227-
pub const blake2s_constant_BLAKE2S_PERSONALBYTES: blake2s_constant = 8;
228-
pub type blake2s_constant = ::std::os::raw::c_uint;
229-
pub const blake2b_constant_BLAKE2B_BLOCKBYTES: blake2b_constant = 128;
230-
pub const blake2b_constant_BLAKE2B_OUTBYTES: blake2b_constant = 64;
231-
pub const blake2b_constant_BLAKE2B_KEYBYTES: blake2b_constant = 64;
232-
pub const blake2b_constant_BLAKE2B_SALTBYTES: blake2b_constant = 16;
233-
pub const blake2b_constant_BLAKE2B_PERSONALBYTES: blake2b_constant = 16;
234-
pub type blake2b_constant = ::std::os::raw::c_uint;
188+
pub mod blake2s_constant {
189+
pub type Type = ::std::os::raw::c_uint;
190+
pub const BLAKE2S_BLOCKBYTES: Type = 64;
191+
pub const BLAKE2S_OUTBYTES: Type = 32;
192+
pub const BLAKE2S_KEYBYTES: Type = 32;
193+
pub const BLAKE2S_SALTBYTES: Type = 8;
194+
pub const BLAKE2S_PERSONALBYTES: Type = 8;
195+
}
196+
pub mod blake2b_constant {
197+
pub type Type = ::std::os::raw::c_uint;
198+
pub const BLAKE2B_BLOCKBYTES: Type = 128;
199+
pub const BLAKE2B_OUTBYTES: Type = 64;
200+
pub const BLAKE2B_KEYBYTES: Type = 64;
201+
pub const BLAKE2B_SALTBYTES: Type = 16;
202+
pub const BLAKE2B_PERSONALBYTES: Type = 16;
203+
}
235204
#[repr(C)]
236205
#[derive(Copy, Clone)]
237206
pub struct blake2s_state__ {

0 commit comments

Comments
 (0)