更新libclamav库1.0.0版本

This commit is contained in:
2023-01-14 18:28:39 +08:00
parent b879ee0b2e
commit 45fe15f472
8531 changed files with 1222046 additions and 177272 deletions

View File

@@ -0,0 +1,32 @@
#[repr(C)]
struct Dep {
a: i32,
b: f32,
}
#[repr(C)]
struct Foo<X> {
a: X,
b: X,
c: Dep,
}
#[repr(u32)]
enum Status {
Ok,
Err,
}
type IntFoo = Foo<i32>;
type DoubleFoo = Foo<f64>;
type Unit = i32;
type SpecialStatus = Status;
#[no_mangle]
pub extern "C" fn root(
x: IntFoo,
y: DoubleFoo,
z: Unit,
w: SpecialStatus
) { }

View File

@@ -0,0 +1,43 @@
/// cbindgen:derive-lt=true
/// cbindgen:derive-lte=true
/// cbindgen:derive-constructor=true
/// cbindgen:rename-all=GeckoCase
#[repr(C)]
struct A(i32);
/// cbindgen:field-names=[x, y]
#[repr(C)]
struct B(i32, f32);
/// cbindgen:trailing-values=[Z, W]
#[repr(u32)]
enum C {
X = 2,
Y,
}
/// cbindgen:derive-helper-methods=true
#[repr(u8)]
enum F {
Foo(i16),
Bar { x: u8, y: i16 },
Baz
}
/// cbindgen:derive-helper-methods
#[repr(C, u8)]
enum H {
Hello(i16),
There { x: u8, y: i16 },
Everyone
}
#[no_mangle]
pub extern "C" fn root(
x: A,
y: B,
z: C,
f: F,
h: H,
) { }

View File

@@ -0,0 +1,7 @@
#[repr(C)]
enum Foo {
A([f32; 20])
}
#[no_mangle]
pub extern "C" fn root(a: Foo) {}

View File

@@ -0,0 +1,2 @@
[enum]
derive_helper_methods = true

View File

@@ -0,0 +1,44 @@
/// cbindgen:prefix-with-name
#[repr(C, u8)]
pub enum H {
/// cbindgen:variant-mut-cast-attributes=MY_ATTRS
Foo(i16),
/// cbindgen:variant-const-cast-attributes=MY_ATTRS
Bar { x: u8, y: i16 },
/// cbindgen:variant-is-attributes=MY_ATTRS
Baz
}
/// cbindgen:prefix-with-name
#[repr(C, u8, u16)]
pub enum I {
/// cbindgen:variant-constructor-attributes=MY_ATTRS
Foo(i16),
/// cbindgen:eq-attributes=MY_ATTRS
Bar { x: u8, y: i16 },
Baz
}
/// cbindgen:prefix-with-name
#[repr(C, u8)]
pub enum J {
Foo(i16),
Bar { x: u8, y: i16 },
Baz
}
/// cbindgen:prefix-with-name
#[repr(u8)]
pub enum K {
Foo(i16),
Bar { x: u8, y: i16 },
Baz
}
#[no_mangle]
pub extern "C" fn foo(
h: H,
i: I,
j: J,
k: K,
) {}

View File

@@ -0,0 +1,10 @@
header = """
#define MY_ASSERT(...) do { } while (0)
#define MY_ATTRS __attribute((noinline))
"""
[enum]
derive_helper_methods = true
derive_const_casts = true
derive_mut_casts = true
cast_assert_name = "MY_ASSERT"

View File

@@ -0,0 +1,9 @@
#[repr(C)]
struct Foo {}
pub const Foo_FOO: u32 = 42;
impl Foo {
const FOO: i32 = 0;
}

View File

@@ -0,0 +1,14 @@
#[repr(C)]
struct Foo {}
impl Foo {
pub const GA: i32 = 10;
pub const BU: &'static str = "hello world";
pub const ZO: f32 = 3.14;
pub(crate) const DONT_EXPORT_CRATE: i32 = 20;
const DONT_EXPORT_PRIV: i32 = 30;
}
#[no_mangle]
pub extern "C" fn root(x: Foo) { }

View File

@@ -0,0 +1,7 @@
pub trait F {
const B: u8;
}
impl F for u16 {
const B: u8 = 3;
}

View File

@@ -0,0 +1,22 @@
bitflags! {
/// Constants shared by multiple CSS Box Alignment properties
///
/// These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
#[derive(MallocSizeOf, ToComputedValue)]
#[repr(C)]
pub struct AlignFlags: u8 {
/// 'auto'
const AUTO = 0;
/// 'normal'
const NORMAL = 1;
/// 'start'
const START = 1 << 1;
/// 'end'
const END = 1 << 2;
/// 'flex-start'
const FLEX_START = 1 << 3;
}
}
#[no_mangle]
pub extern "C" fn root(flags: AlignFlags) {}

View File

@@ -0,0 +1,8 @@
[struct]
associated_constants_in_body = true
[macro_expansion]
bitflags = true
[export]
prefix = "Style" # Just ensuring they play well together :)

View File

@@ -0,0 +1,30 @@
bitflags! {
/// Constants shared by multiple CSS Box Alignment properties
///
/// These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
#[derive(MallocSizeOf, ToComputedValue)]
#[repr(C)]
pub struct AlignFlags: u8 {
/// 'auto'
const AUTO = 0;
/// 'normal'
const NORMAL = 1;
/// 'start'
const START = 1 << 1;
/// 'end'
const END = 1 << 2;
/// 'flex-start'
const FLEX_START = 1 << 3;
}
}
bitflags! {
#[repr(C)]
pub struct DebugFlags: u32 {
/// Flag with the topmost bit set of the u32
const BIGGEST_ALLOWED = 1 << 31;
}
}
#[no_mangle]
pub extern "C" fn root(flags: AlignFlags, bigger_flags: DebugFlags) {}

View File

@@ -0,0 +1,2 @@
[macro_expansion]
bitflags = true

View File

@@ -0,0 +1,55 @@
#[repr(C)]
pub struct MyFancyStruct {
i: i32,
}
#[repr(C)]
pub enum MyFancyEnum {
Foo,
Bar(i32),
Baz(i32),
}
#[repr(C)]
pub enum MyCLikeEnum {
Foo1,
Bar1,
Baz1,
}
#[repr(C)]
pub union MyUnion {
pub f: f32,
pub u: u32,
}
#[repr(C)]
pub struct MyFancyStruct_Prepended {
i: i32,
}
#[repr(C)]
pub enum MyFancyEnum_Prepended {
Foo_Prepended,
Bar_Prepended(i32),
Baz_Prepended(i32),
}
#[repr(C)]
pub enum MyCLikeEnum_Prepended {
Foo1_Prepended,
Bar1_Prepended,
Baz1_Prepended,
}
#[repr(C)]
pub union MyUnion_Prepended {
pub f: f32,
pub u: u32,
}
#[no_mangle]
pub extern "C" fn root(s: MyFancyStruct, e: MyFancyEnum, c: MyCLikeEnum, u: MyUnion, sp: MyFancyStruct_Prepended, ep: MyFancyEnum_Prepended, cp: MyCLikeEnum_Prepended, up: MyUnion_Prepended) {}

View File

@@ -0,0 +1,41 @@
[export.body]
"MyFancyStruct" = """
#ifdef __cplusplus
inline void foo();
#endif
"""
"MyFancyEnum" = """
#ifdef __cplusplus
inline void wohoo();
#endif
"""
"MyCLikeEnum" = """
BogusVariantForSerializationForExample,
"""
"MyUnion" = """
int32_t extra_member;
"""
[export.pre_body]
"MyFancyStruct_Prepended" = """
#ifdef __cplusplus
inline void prepended_wohoo();
#endif
"""
"MyFancyEnum_Prepended" = """
#ifdef __cplusplus
inline void wohoo();
#endif
"""
"MyCLikeEnum_Prepended" = """
BogusVariantForSerializationForExample,
"""
"MyUnion_Prepended" = """
int32_t extra_member;
"""

View File

@@ -0,0 +1,19 @@
#[repr(C)]
pub struct MyStruct {
number: Box<i32>,
}
pub struct NotReprC<T> {
inner: T,
}
pub type Foo = NotReprC<Box<i32>>;
#[no_mangle]
pub extern "C" fn root(a: &Foo, with_box: &MyStruct) {}
#[no_mangle]
pub extern "C" fn drop_box(x: Box<i32>) {}
#[no_mangle]
pub extern "C" fn drop_box_opt(x: Option<Box<i32>>) {}

View File

@@ -0,0 +1,18 @@
header = """
#if 0
''' '
#endif
#ifdef __cplusplus
template <typename T>
using Box = T*;
#endif
#if 0
' '''
#endif
"""
[export]
exclude = [
"Box",
]

View File

@@ -0,0 +1,41 @@
type A = fn ();
type B = fn () -> ();
type C = fn (i32, i32) -> bool;
type D = fn (i32) -> fn (f32) -> bool;
type E = fn () -> *const [i32; 16];
type F = *const i32;
type G = *const *const i32;
type H = *const *mut i32;
type I = *const [i32; 16];
type J = *const fn (f32) -> f64;
type K = [i32; 16];
type L = [*const i32; 16];
type M = [fn (i32, i32) -> bool; 16];
type N = [fn (i32, i32) -> (); 16];
#[no_mangle]
pub extern "C" fn O() -> fn ()
{ }
type P = fn (named1st: i32, bool, named3rd: bool, _: i32);
#[no_mangle]
pub extern "C" fn root(
a: A,
b: B,
c: C,
d: D,
e: E,
f: F,
g: G,
h: H,
i: I,
j: J,
k: K,
l: L,
m: M,
n: N,
p: P
) { }

View File

@@ -0,0 +1,11 @@
#[repr(C)]
pub struct MyStruct {
number: std::cell::Cell<i32>,
}
pub struct NotReprC<T> { inner: T }
pub type Foo = NotReprC<std::cell::RefCell<i32>>;
#[no_mangle]
pub extern "C" fn root(a: &Foo, with_cell: &MyStruct) {}

View File

@@ -0,0 +1,64 @@
#[cfg(all(unix, x11))]
#[repr(u32)]
enum FooType {
A,
B,
C,
}
#[cfg(all(unix, x11))]
#[repr(C)]
struct FooHandle {
ty: FooType,
x: i32,
y: f32,
}
#[cfg(any(windows, target_pointer_width="32"))]
#[repr(u32)]
enum BarType {
A,
B,
C,
}
#[repr(u8)]
pub enum C {
C1,
C2,
#[cfg(windows)]
C3,
#[cfg(unix)]
C5 { int: i32 },
}
#[cfg(any(windows, target_pointer_width="32"))]
#[repr(C)]
struct BarHandle {
ty: BarType,
x: i32,
y: f32,
}
// FIXME(#634): Support deriving methods for structs with conditional fields.
/// cbindgen:derive-eq=false
/// cbindgen:derive-neq=false
#[repr(C)]
struct ConditionalField {
#[cfg(x11)]
field: i32,
}
#[cfg(all(unix, x11))]
#[no_mangle]
pub extern "C" fn root(a: FooHandle, c: C)
{ }
#[cfg(any(windows, target_pointer_width="32"))]
#[no_mangle]
pub extern "C" fn root(a: BarHandle, c: C)
{ }
#[no_mangle]
pub extern "C" fn cond(a: ConditionalField)
{ }

View File

@@ -0,0 +1,25 @@
header = """
#if 0
DEF PLATFORM_UNIX = 0
DEF PLATFORM_WIN = 0
DEF X11 = 0
DEF M_32 = 0
#endif
"""
[defines]
"unix" = "PLATFORM_UNIX"
"windows" = "PLATFORM_WIN"
"x11" = "X11"
"target_pointer_width = 32" = "M_32"
[enum]
derive_tagged_enum_destructor = true
derive_tagged_enum_copy_constructor = true
derive_tagged_enum_copy_assignment = true
derive_helper_methods = true
private_default_tagged_enum_constructor = true
[struct]
derive_eq = true
derive_neq = true

View File

@@ -0,0 +1,32 @@
#[cfg(any(windows, unix))]
#[repr(C)]
struct Foo {
x: i32,
}
#[cfg(windows)]
#[repr(C)]
struct Bar {
y: Foo,
}
#[cfg(unix)]
#[repr(C)]
struct Bar {
z: Foo,
}
#[repr(C)]
struct Root {
w: Bar,
}
#[cfg(windows)]
pub const DEFAULT_X: i32 = 0x08;
#[cfg(unix)]
pub const DEFAULT_X: i32 = 0x2a;
#[no_mangle]
pub extern "C" fn root(a: Root)
{ }

View File

@@ -0,0 +1,11 @@
header = """
#if 0
DEF DEFINED = 1
DEF NOT_DEFINED = 0
#endif
"""
[defines]
"unix" = "DEFINED"
"macos" = "NOT_DEFINED"
"windows" = "NOT_DEFINED"

View File

@@ -0,0 +1,11 @@
struct Foo {
#[cfg(windows)]
x: i32,
}
pub fn foo() {
Foo {
#[cfg(windows)]
x: 0,
};
}

View File

@@ -0,0 +1,7 @@
#[repr(C)]
struct Foo {
a: char,
}
#[no_mangle]
pub extern "C" fn root(a: Foo) {}

View File

@@ -0,0 +1,9 @@
#[repr(C)]
struct Foo {}
impl Foo {
const FOO: i32 = 0;
}
pub const Foo_FOO: u32 = 42;

View File

@@ -0,0 +1,4 @@
#[repr(transparent)]
struct Transparent { field: u8 }
pub const FOO: Transparent = Transparent { field: 0 };

View File

@@ -0,0 +1,38 @@
pub const FOO: i32 = 10;
pub const BAR: &'static str = "hello world";
pub const DELIMITER: char = ':';
pub const LEFTCURLY: char = '{';
pub const QUOTE: char = '\'';
pub const TAB: char = '\t';
pub const NEWLINE: char = '\n';
pub const HEART: char = '❤';
pub const EQUID: char = '𐂃';
pub const ZOM: f32 = 3.14;
pub(crate) const DONT_EXPORT_CRATE: i32 = 20;
const DONT_EXPORT_PRIV: i32 = 30;
/// A single-line doc comment.
pub const POS_ONE: i8 = 1;
/// A
/// multi-line
/// doc
/// comment.
pub const NEG_ONE: i8 = -1;
// Some doc for shifting //
pub const SHIFT: i64 = 3;
pub const XBOOL: i64 = 1;
pub const XFALSE: i64 = (0 << SHIFT) | XBOOL;
pub const XTRUE: i64 = 1 << (SHIFT | XBOOL);
pub const CAST: u8 = 'A' as u8;
pub const DOUBLE_CAST: u32 = 1 as f32 as u32;
#[repr(C)]
struct Foo {
x: [i32; FOO],
}
#[no_mangle]
pub extern "C" fn root(x: Foo) {}

View File

@@ -0,0 +1,8 @@
pub const UNSIGNED_NEEDS_ULL_SUFFIX: u64 = 0x8000_0000_0000_0000;
pub const UNSIGNED_DOESNT_NEED_ULL_SUFFIX: u64 = 0x7000_0000_0000_0000;
// i64::min_value()
pub const SIGNED_NEEDS_ULL_SUFFIX: i64 = -9223372036854775808;
// i64::min_value() + 1
pub const SIGNED_DOESNT_NEED_ULL_SUFFIX: i64 = -9223372036854775807;

View File

@@ -0,0 +1,14 @@
pub const CONSTANT_I64: i64 = 216;
pub const CONSTANT_FLOAT32: f32 = 312.292;
pub const DELIMITER: char = ':';
pub const LEFTCURLY: char = '{';
#[repr(C)]
struct Foo {
x: i32,
}
pub const SomeFoo: Foo = Foo { x: 99, };
impl Foo {
pub const CONSTANT_I64_BODY: i64 = 216;
}

View File

@@ -0,0 +1,5 @@
[const]
allow_constexpr = true
[struct]
associated_constants_in_body = true

View File

@@ -0,0 +1,7 @@
pub const B: u8 = 0;
pub const A: u8 = 0;
#[no_mangle]
pub static D: u8 = 0;
#[no_mangle]
pub static C: u8 = 0;

View File

@@ -0,0 +1,2 @@
[const]
sort_by = "Name"

View File

@@ -0,0 +1,7 @@
pub const B: u8 = 0;
pub const A: u8 = 0;
#[no_mangle]
pub static D: u8 = 0;
#[no_mangle]
pub static C: u8 = 0;

View File

@@ -0,0 +1,17 @@
#[repr(C)]
pub struct S {
field: u8,
}
/// cbindgen:enum-class=false
#[repr(C)]
pub enum E {
V,
}
use E::*;
pub type A = u8;
pub const C1: S = S { field: 0 };
pub const C2: E = V;
pub const C3: A = 0;

View File

@@ -0,0 +1,3 @@
#[no_mangle]
pub extern "C" fn root() {
}

View File

@@ -0,0 +1,11 @@
no_includes = true
header = """
#if 0
# This file is generated by cbindgen. DO NOT EDIT
#endif
"""
trailer = """
#if 0
# This is a simple test to ensure that trailers do not cause extra newlines in files
#endif
"""

View File

@@ -0,0 +1,6 @@
[cython]
header = '"my_header.h"'
[cython.cimports]
"libc.stdint" = ["int8_t", "int16_t"]
"libc.stddef" = ["*"]

View File

@@ -0,0 +1,14 @@
mod uhoh {
enum BindingType { Buffer, NotBuffer }
}
#[repr(u32)]
pub enum BindingType { Buffer = 0, NotBuffer = 1 }
#[repr(C)]
pub struct BindGroupLayoutEntry {
pub ty: BindingType, // This is the repr(u32) enum
}
#[no_mangle]
pub extern "C" fn root(entry: BindGroupLayoutEntry) {}

View File

@@ -0,0 +1,59 @@
/// cbindgen:derive-ostream
#[repr(C)]
pub struct A(i32);
/// cbindgen:field-names=[x, y]
/// cbindgen:derive-ostream
#[repr(C)]
pub struct B(i32, f32);
/// cbindgen:derive-ostream
#[repr(u32)]
pub enum C {
X = 2,
Y,
}
/// cbindgen:derive-ostream
#[repr(C)]
pub struct D {
List: u8,
Of: usize,
Things: B,
}
/// cbindgen:derive-ostream
#[repr(u8)]
pub enum F {
Foo(i16),
Bar { x: u8, y: i16 },
Baz
}
/// cbindgen:derive-ostream
#[repr(C, u8)]
pub enum H {
Hello(i16),
There { x: u8, y: i16 },
Everyone
}
/// cbindgen:derive-ostream=false
#[repr(C, u8)]
pub enum I {
/// cbindgen:derive-ostream=true
ThereAgain { x: u8, y: i16 },
SomethingElse
}
#[no_mangle]
pub extern "C" fn root(
a: A,
b: B,
c: C,
d: D,
f: F,
h: H,
i: I,
) { }

View File

@@ -0,0 +1,97 @@
use std::ptr::NonNull;
/// This will have a destructor manually implemented via variant_body, and
/// similarly a Drop impl in Rust.
#[repr(C)]
pub struct OwnedSlice<T> {
len: usize,
ptr: NonNull<T>,
}
#[repr(u8)]
pub enum FillRule { A, B }
#[repr(C)]
pub struct Polygon<LengthPercentage> {
pub fill: FillRule,
pub coordinates: OwnedSlice<LengthPercentage>,
}
#[repr(C, u8)]
pub enum Foo<T> {
Bar,
Polygon1(Polygon<T>),
Slice1(OwnedSlice<T>),
Slice2(OwnedSlice<i32>),
Slice3 {
fill: FillRule,
coords: OwnedSlice<T>,
},
Slice4 {
fill: FillRule,
coords: OwnedSlice<i32>,
},
}
#[repr(u8)]
pub enum Baz<T> {
Bar2,
Polygon21(Polygon<T>),
Slice21(OwnedSlice<T>),
Slice22(OwnedSlice<i32>),
Slice23 {
fill: FillRule,
coords: OwnedSlice<T>,
},
Slice24 {
fill: FillRule,
coords: OwnedSlice<i32>,
},
}
#[repr(u8)]
pub enum Taz {
Bar3,
Taz1(i32),
Taz3(OwnedSlice<i32>),
}
/// cbindgen:derive-tagged-enum-destructor=false
/// cbindgen:derive-tagged-enum-copy-constructor=false
#[repr(u8)]
pub enum Tazz {
Bar4,
Taz2(i32),
}
/// cbindgen:derive-tagged-enum-copy-assignment=false
#[repr(u8)]
pub enum Tazzz {
Bar5,
Taz5(i32),
}
#[repr(u8)]
pub enum Tazzzz {
Taz6(i32),
Taz7(u32),
}
/// cbindgen:derive-eq=true
/// cbindgen:derive-neq=true
/// cbindgen:neq-attributes=NODISCARD
/// cbindgen:eq-attributes=NODISCARD
/// cbindgen:destructor-attributes=NOINLINE
/// cbindgen:copy-constructor-attributes=NOINLINE
/// cbindgen:copy-assignment-attributes=NOINLINE
#[repr(u8)]
pub enum Qux {
/// cbindgen:derive-eq=true
Qux1(i32),
/// cbindgen:derive-eq=true
Qux2(u32),
}
#[no_mangle]
pub extern "C" fn root(a: &Foo<u32>, b: &Baz<i32>, c: &Taz, d: Tazz, e: &Tazzz, f: &Tazzzz, g: &Qux) {}

View File

@@ -0,0 +1,16 @@
header = """
#define NOINLINE __attribute__((noinline))
#define NODISCARD [[nodiscard]]
"""
[enum]
derive_tagged_enum_destructor = true
derive_tagged_enum_copy_constructor = true
derive_tagged_enum_copy_assignment = true
derive_helper_methods = true
private_default_tagged_enum_constructor = true
[export.body]
"OwnedSlice" = """
~OwnedSlice() {}
"""

View File

@@ -0,0 +1,18 @@
#[repr(u8)]
pub enum DisplayItem {
Fill(Rect, Color),
Image { id: u32, bounds: Rect },
ClearScreen,
}
#[repr(C)]
pub struct Rect { x: f32, y: f32, w: f32, h: f32 }
#[repr(C)]
pub struct Color { r: u8, g: u8, b: u8, a: u8 }
#[no_mangle]
pub extern "C" fn push_item(item: DisplayItem) -> bool {
::std::mem::drop(item);
true
}

View File

@@ -0,0 +1,4 @@
/// The root of all evil.
#[no_mangle]
pub extern "C" fn root() {
}

View File

@@ -0,0 +1 @@
documentation_style = "auto"

View File

@@ -0,0 +1,4 @@
/// The root of all evil.
#[no_mangle]
pub extern "C" fn root() {
}

View File

@@ -0,0 +1 @@
documentation_style = "c99"

View File

@@ -0,0 +1,4 @@
/// The root of all evil.
#[no_mangle]
pub extern "C" fn root() {
}

View File

@@ -0,0 +1 @@
documentation_style = "doxy"

View File

@@ -0,0 +1,21 @@
/// The root of all evil.
///
/// But at least it contains some more documentation as someone would expect
/// from a simple test case like this.
///
/// # Hint
///
/// Always ensure that everything is properly documented, even if you feel lazy.
/// **Sometimes** it is also helpful to include some markdown formatting.
///
/// ////////////////////////////////////////////////////////////////////////////
///
/// Attention:
///
/// Rust is going to trim all leading `/` symbols. If you want to use them as a
/// marker you need to add at least a single whitespace inbetween the tripple
/// slash doc-comment marker and the rest.
///
#[no_mangle]
pub extern "C" fn root() {
}

View File

@@ -0,0 +1,12 @@
#[doc="With doc attr, each attr contribute to one line of document"]
#[doc="like this one with a new line character at its end"]
#[doc="and this one as well. So they are in the same paragraph"]
#[doc=""]
#[doc="Line ends with one new line\nshould not break"]
#[doc=""]
#[doc="Line ends with two spaces and a new line \nshould break to next line"]
#[doc=""]
#[doc="Line ends with two new lines\n\nShould break to next paragraph"]
#[no_mangle]
pub extern "C" fn root() {
}

View File

@@ -0,0 +1,150 @@
enum Opaque {
Foo(i32),
Bar,
}
#[repr(u64)]
enum A {
a1 = 0,
a2 = 2,
a3,
a4 = 5,
}
#[repr(u32)]
enum B {
b1 = 0,
b2 = 2,
b3,
b4 = 5,
}
#[repr(u16)]
enum C {
c1 = 0,
c2 = 2,
c3,
c4 = 5,
}
#[repr(u8)]
enum D {
d1 = 0,
d2 = 2,
d3,
d4 = 5,
}
#[repr(usize)]
enum E {
e1 = 0,
e2 = 2,
e3,
e4 = 5,
}
#[repr(isize)]
enum F {
f1 = 0,
f2 = 2,
f3,
f4 = 5,
}
#[repr(u8)]
enum G {
Foo(i16),
Bar { x: u8, y: i16 },
Baz,
}
/// cbindgen:prefix-with-name
#[repr(C)]
enum H {
Foo(i16),
Bar { x: u8, y: i16 },
Baz,
}
/// cbindgen:prefix-with-name
#[repr(C, u8)]
enum I {
Foo(i16),
Bar { x: u8, y: i16 },
Baz,
}
#[repr(C, u8, u16)]
enum J {
Foo(i16),
Bar { x: u8, y: i16 },
Baz,
}
#[repr(C, u8, unknown_hint)]
enum K {
Foo(i16),
Bar { x: u8, y: i16 },
Baz,
}
#[repr(C)]
enum L {
l1,
l2,
l3,
l4,
}
#[repr(i8)]
enum M {
m1 = -1,
m2 = 0,
m3 = 1,
}
/// cbindgen:enum-class=false
#[repr(C)]
enum N {
n1,
n2,
n3,
n4,
}
/// cbindgen:enum-class=false
#[repr(i8)]
enum O {
o1,
o2,
o3,
o4,
}
#[repr(C, u8)]
enum P {
P0(u8),
P1(u8, u8, u8),
}
#[no_mangle]
pub extern "C" fn root(
opaque: *mut Opaque,
a: A,
b: B,
c: C,
d: D,
e: E,
f: F,
g: G,
h: H,
i: I,
j: J,
k: K,
l: L,
m: M,
n: N,
o: O,
p: P,
) {
}

View File

@@ -0,0 +1,19 @@
trailer = """
#if 0
''' '
#endif
#include <stddef.h>
#include "testing-helpers.h"
static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag");
static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0");
static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1");
static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P");
#if 0
' '''
#endif
"""
[export.rename]
"I" = "ExI"

View File

@@ -0,0 +1,15 @@
pub const FOUR: i8 = 4;
#[repr(i8)]
enum E {
A = 1,
B = -1,
C = 1 + 2,
D = FOUR,
F = (5),
G = b'6' as i8,
H = false as i8,
}
#[no_mangle]
pub extern "C" fn root(_: &E) {}

View File

@@ -0,0 +1,2 @@
[export.rename]
"FOUR" = "FOURTY_FOUR"

View File

@@ -0,0 +1,15 @@
#[repr(C)]
pub struct Foo<T> {
something: *const i32,
phantom: std::marker::PhantomData<T>,
}
#[repr(u8)]
pub enum Bar {
Min(Foo<Self>),
Max(Foo<Self>),
Other,
}
#[no_mangle]
pub extern "C" fn root(b: Bar) {}

View File

@@ -0,0 +1,81 @@
struct UnknownUnit;
struct LayoutUnit;
#[repr(C)]
struct TypedLength<T, Unit>(T, PhantomData<Unit>);
#[repr(C)]
struct TypedSideOffsets2D<T, U> {
top: T,
right: T,
bottom: T,
left: T,
_phantom: PhantomData<U>,
}
#[repr(C)]
struct TypedSize2D<T, U> {
width: T,
height: T,
_phantom: PhantomData<U>,
}
#[repr(C)]
struct TypedPoint2D<T, U> {
x: T,
y: T,
_phantom: PhantomData<U>,
}
#[repr(C)]
struct TypedRect<T, U> {
origin: TypedPoint2D<T, U>,
size: TypedSize2D<T, U>,
_phantom: PhantomData<U>,
}
#[repr(C)]
struct TypedTransform2D<T, Src, Dst> {
m11: T, m12: T,
m21: T, m22: T,
m31: T, m32: T,
_phantom: PhantomData<U>,
}
type Length<T> = TypedLength<T, UnknownUnit>;
type SideOffsets2D<T> = TypedSideOffsets2D<T, UnknownUnit>;
type Size2D<T> = TypedSize2D<T, UnknownUnit>;
type Point2D<T> = TypedPoint2D<T, UnknownUnit>;
type Rect<T> = TypedRect<T, UnknownUnit>;
type LayoutLength = TypedLength<f32, LayoutUnit>;
type LayoutSideOffsets2D = TypedSideOffsets2D<f32, LayoutUnit>;
type LayoutSize2D = TypedSize2D<f32, LayoutUnit>;
type LayoutPoint2D = TypedPoint2D<f32, LayoutUnit>;
type LayoutRect = TypedRect<f32, LayoutUnit>;
#[no_mangle]
pub extern "C" fn root(
length_a: TypedLength<f32, UnknownUnit>,
length_b: TypedLength<f32, LayoutUnit>,
length_c: Length<f32>,
length_d: LayoutLength,
side_offsets_a: TypedSideOffsets2D<f32, UnknownUnit>,
side_offsets_b: TypedSideOffsets2D<f32, LayoutUnit>,
side_offsets_c: SideOffsets2D<f32>,
side_offsets_d: LayoutSideOffsets2D,
size_a: TypedSize2D<f32, UnknownUnit>,
size_b: TypedSize2D<f32, LayoutUnit>,
size_c: Size2D<f32>,
size_d: LayoutSize2D,
point_a: TypedPoint2D<f32, UnknownUnit>,
point_b: TypedPoint2D<f32, LayoutUnit>,
point_c: Point2D<f32>,
point_d: LayoutPoint2D,
rect_a: TypedRect<f32, UnknownUnit>,
rect_b: TypedRect<f32, LayoutUnit>,
rect_c: Rect<f32>,
rect_d: LayoutRect,
transform_a: TypedTransform2D<f32, UnknownUnit, LayoutUnit>,
transform_b: TypedTransform2D<f32, LayoutUnit, UnknownUnit>
) { }

View File

@@ -0,0 +1,10 @@
#[repr(transparent)]
pub struct Foo(NonZeroU64);
#[repr(C)]
pub struct Bar {
foo: Option<Foo>,
}
#[no_mangle]
pub extern "C" fn root(f: Bar) {}

View File

@@ -0,0 +1,24 @@
language = "C"
header = """
#include <stdint.h>
#if 0
''' '
#endif
typedef uint64_t Option_Foo;
#if 0
' '''
#endif
#if 0
from libc.stdint cimport uint64_t
ctypedef uint64_t Option_Foo
#endif
"""
[export]
exclude = [
"Option_Foo",
]

View File

@@ -0,0 +1,4 @@
#[export_name = "do_the_thing_with_export_name"]
pub extern "C" fn do_the_thing() {
println!("doing the thing!");
}

View File

@@ -0,0 +1,11 @@
#[repr(C)]
struct Normal {
x: i32,
y: f32,
}
extern "C" {
fn foo() -> i32;
fn bar(a: Normal);
}

View File

@@ -0,0 +1,11 @@
#[no_mangle]
pub extern "C" fn first()
{ }
#[no_mangle]
pub extern fn second()
{ }
#[no_mangle]
pub fn third()
{ }

View File

@@ -0,0 +1,16 @@
#[repr(C)]
pub struct Fns {
noArgs: fn(),
anonymousArg: fn(i32),
returnsNumber: fn() -> i32,
namedArgs: fn(first: i32, snd: i16) -> i8,
namedArgsWildcards: fn(_: i32, named: i16, _: i64) -> i8,
}
#[no_mangle]
pub extern "C" fn root(_fns: Fns) {}
#[no_mangle]
pub extern "C" fn no_return() -> ! {
loop {}
}

View File

@@ -0,0 +1,21 @@
#[repr(C)]
struct TypeInfo {
data: TypeData,
}
#[repr(C)]
enum TypeData {
Primitive,
Struct(StructInfo),
}
#[repr(C)]
struct StructInfo {
fields: *const *const TypeInfo, // requires forward declaration
num_fields: usize,
}
#[no_mangle]
pub extern "C" fn root(
x: TypeInfo,
) {}

View File

@@ -0,0 +1,23 @@
header = """
#if 0
''' '
#endif
#if defined(CBINDGEN_STYLE_TYPE)
/* ANONYMOUS STRUCTS DO NOT SUPPORT FORWARD DECLARATIONS!
#endif
#if 0
' '''
#endif
"""
trailer = """
#if 0
''' '
#endif
#if defined(CBINDGEN_STYLE_TYPE)
*/
#endif
#if 0
' '''
#endif
"""

View File

@@ -0,0 +1,25 @@
#[no_mangle]
pub unsafe extern fn array_print(a: &[u64]) {
eprintln!("{:?}", a);
}
#[no_mangle]
pub unsafe extern fn array_test(a: [u64; 3]) {
array_print(&a);
}
#[no_mangle]
pub unsafe extern fn unnamed(_: *const u64) {
}
#[no_mangle]
pub unsafe extern fn pointer_test(a: *const u64) {
let a = std::slice::from_raw_parts(a, 3);
array_print(a);
}
#[no_mangle]
pub unsafe extern fn print_from_rust() {
let a = [0, 1, 2];
array_print(&a);
}

View File

@@ -0,0 +1,9 @@
#[no_mangle]
pub extern fn loop_forever() -> ! {
loop {}
}
#[no_mangle]
pub extern fn normal_return() -> u8 {
0
}

View File

@@ -0,0 +1,12 @@
after_includes = """
#ifndef NO_RETURN_ATTR
#ifdef __GNUC__
#define NO_RETURN_ATTR __attribute__ ((noreturn))
#else // __GNUC__
#define NO_RETURN_ATTR
#endif // __GNUC__
#endif // NO_RETURN_ATTR
"""
[fn]
no_return = "NO_RETURN_ATTR"

View File

@@ -0,0 +1,15 @@
#[no_mangle]
pub extern "C" fn C()
{ }
#[no_mangle]
pub extern "C" fn B()
{ }
#[no_mangle]
pub extern "C" fn D()
{ }
#[no_mangle]
pub extern "C" fn A()
{ }

View File

@@ -0,0 +1,2 @@
[fn]
sort_by = "Name"

View File

@@ -0,0 +1,15 @@
#[no_mangle]
pub extern "C" fn C()
{ }
#[no_mangle]
pub extern "C" fn B()
{ }
#[no_mangle]
pub extern "C" fn D()
{ }
#[no_mangle]
pub extern "C" fn A()
{ }

View File

@@ -0,0 +1,11 @@
#[repr(C)]
pub struct Foo<T> {
a: T,
}
pub type Boo = Foo<*mut u8>;
#[no_mangle]
pub extern "C" fn root(
x: Boo,
) { }

View File

@@ -0,0 +1 @@
#![allow(unused_variables)]

View File

@@ -0,0 +1,5 @@
#[no_mangle]
pub static mut MUT_GLOBAL_ARRAY: [c_char; 128] = [0; 128];
#[no_mangle]
pub static CONST_GLOBAL_ARRAY: [c_char; 128] = [0; 128];

View File

@@ -0,0 +1,12 @@
/// cbindgen:ignore
#[no_mangle]
pub extern "C" fn root() {}
/// cbindgen:ignore
///
/// Something else.
#[no_mangle]
pub extern "C" fn another_root() {}
#[no_mangle]
pub extern "C" fn no_ignore_root() {}

View File

@@ -0,0 +1 @@
sys_includes = ["math.h"]

View File

@@ -0,0 +1,3 @@
#[no_mangle]
pub extern "C" fn root() {
}

View File

@@ -0,0 +1,2 @@
include_guard = "INCLUDE_GUARD_H"
no_includes = true

View File

@@ -0,0 +1,10 @@
#[repr(C)]
struct A {
x: i32,
y: f32,
}
#[repr(C)]
struct B {
data: A,
}

View File

@@ -0,0 +1,2 @@
[export]
include = ["B"]

View File

@@ -0,0 +1,2 @@
sys_includes = ["math.h"]
no_includes = true

View File

@@ -0,0 +1,2 @@
pub type TryVec<T> = fallible_collections::TryVec<T>;
pub type TryString = fallible_collections::TryVec<u8>;

View File

@@ -0,0 +1,10 @@
mod foo {
#[repr(C)]
struct Foo {
x: f32,
}
}
#[no_mangle]
pub extern "C" fn root(a: foo::Foo)
{ }

View File

@@ -0,0 +1,12 @@
pub const MY_CONST: u8 = 4;
#[no_mangle]
pub extern "C" fn ExternFunction() {
}
#[repr(u8)]
pub enum OnlyThisShouldBeGenerated {
Foo,
Bar,
}

View File

@@ -0,0 +1,3 @@
[export]
item_types = ["enums"]
include = ["OnlyThisShouldBeGenerated"]

View File

@@ -0,0 +1,12 @@
pub const MY_CONST: u8 = 4;
#[no_mangle]
pub extern "C" fn ExternFunction() {
}
#[repr(u8)]
pub enum OnlyThisShouldBeGenerated {
Foo,
Bar,
}

View File

@@ -0,0 +1,4 @@
[export]
item_types = ["enums"]
include = ["OnlyThisShouldBeGenerated"]
prefix = "Style"

View File

@@ -0,0 +1,108 @@
#[repr(align(1), C)]
pub struct Align1Struct {
pub arg1: usize,
pub arg2: *mut u8,
}
#[repr(align(2), C)]
pub struct Align2Struct {
pub arg1: usize,
pub arg2: *mut u8,
}
#[repr(align(4), C)]
pub struct Align4Struct {
pub arg1: usize,
pub arg2: *mut u8,
}
#[repr(align(8), C)]
pub struct Align8Struct {
pub arg1: usize,
pub arg2: *mut u8,
}
#[repr(align(32), C)]
pub struct Align32Struct {
pub arg1: usize,
pub arg2: *mut u8,
}
#[repr(packed, C)]
pub struct PackedStruct {
pub arg1: usize,
pub arg2: *mut u8,
}
#[repr(align(1), C)]
pub union Align1Union {
pub variant1: usize,
pub variant2: *mut u8,
}
#[repr(align(4), C)]
pub union Align4Union {
pub variant1: usize,
pub variant2: *mut u8,
}
#[repr(align(16), C)]
pub union Align16Union {
pub variant1: usize,
pub variant2: *mut u8,
}
#[repr(packed, C)]
pub union PackedUnion {
pub variant1: usize,
pub variant2: *mut u8,
}
// #[repr(packed(n), C)] structs are currently unsupported.
#[repr(packed(4), C)]
pub struct UnsupportedPacked4Struct {
pub arg1: usize,
pub arg2: *mut u8,
}
// #[repr(packed(n), C)] unions are currently unsupported.
#[repr(packed(4), C)]
pub union UnsupportedPacked4Union {
pub variant1: usize,
pub variant2: *mut u8,
}
// #[repr(align(n), C)] enums are currently unsupported.
#[repr(align(4), C)]
pub enum UnsupportedAlign4Enum {
Variant1,
Variant2,
}
// Non-repr(C) structs aren't translated.
#[repr(align(4))]
pub struct RustAlign4Struct {
pub arg1: usize,
pub arg2: *mut u8,
}
// Non-repr(C) structs aren't translated.
#[repr(packed)]
pub struct RustPackedStruct {
pub arg1: usize,
pub arg2: *mut u8,
}
// Non-repr(C) unions aren't translated.
#[repr(align(4))]
pub struct RustAlign4Union {
pub arg1: usize,
pub arg2: *mut u8,
}
// Non-repr(C) unions aren't translated.
#[repr(packed)]
pub struct RustPackedUnion {
pub arg1: usize,
pub arg2: *mut u8,
}

View File

@@ -0,0 +1,29 @@
header = """
#define CBINDGEN_PACKED __attribute__ ((packed))
#define CBINDGEN_ALIGNED(n) __attribute__ ((aligned(n)))
"""
[layout]
packed = "CBINDGEN_PACKED"
aligned_n = "CBINDGEN_ALIGNED"
[export]
include = [
"Align1Struct",
"Align2Struct",
"Align4Struct",
"Align8Struct",
"Align32Struct",
"PackedStruct",
"Align1Union",
"Align4Union",
"Align16Union",
"PackedUnion",
"UnsupportedPacked4Struct",
"UnsupportedPacked4Union",
"UnsupportedAlign4Enum",
"RustAlign4Struct",
"RustPackedStruct",
"RustAlign4Union",
"RustPackedUnion",
]

View File

@@ -0,0 +1,67 @@
#[repr(packed, C)]
pub struct PackedStruct {
pub arg1: usize,
pub arg2: *mut u8,
}
#[repr(packed, C)]
pub union PackedUnion {
pub variant1: usize,
pub variant2: *mut u8,
}
// Opaque because aligned_n is not defined.
#[repr(align(1), C)]
pub union OpaqueAlign1Union {
pub variant1: usize,
pub variant2: *mut u8,
}
// Opaque because aligned_n is not defined.
#[repr(align(4), C)]
pub union OpaqueAlign4Union {
pub variant1: usize,
pub variant2: *mut u8,
}
// Opaque because aligned_n is not defined.
#[repr(align(16), C)]
pub union OpaqueAlign16Union {
pub variant1: usize,
pub variant2: *mut u8,
}
// Opaque because aligned_n is not defined.
#[repr(align(1), C)]
pub struct OpaqueAlign1Struct {
pub arg1: usize,
pub arg2: *mut u8,
}
// Opaque because aligned_n is not defined.
#[repr(align(2), C)]
pub struct OpaqueAlign2Struct {
pub arg1: usize,
pub arg2: *mut u8,
}
// Opaque because aligned_n is not defined.
#[repr(align(4), C)]
pub struct OpaqueAlign4Struct {
pub arg1: usize,
pub arg2: *mut u8,
}
// Opaque because aligned_n is not defined.
#[repr(align(8), C)]
pub struct OpaqueAlign8Struct {
pub arg1: usize,
pub arg2: *mut u8,
}
// Opaque because aligned_n is not defined.
#[repr(align(32), C)]
pub struct OpaqueAlign32Struct {
pub arg1: usize,
pub arg2: *mut u8,
}

View File

@@ -0,0 +1,22 @@
header = """
#define CBINDGEN_PACKED __attribute__ ((packed))
#define CBINDGEN_ALIGNED(n) __attribute__ ((aligned(n)))
"""
[layout]
# We do not define aligned_n.
packed = "CBINDGEN_PACKED"
[export]
include = [
"PackedStruct",
"PackedUnion",
"OpaqueAlign1Union",
"OpaqueAlign4Union",
"OpaqueAlign16Union",
"OpaqueAlign1Struct",
"OpaqueAlign2Struct",
"OpaqueAlign4Struct",
"OpaqueAlign8Struct",
"OpaqueAlign32Struct",
]

View File

@@ -0,0 +1,61 @@
#[repr(align(1), C)]
pub union Align1Union {
pub variant1: usize,
pub variant2: *mut u8,
}
#[repr(align(4), C)]
pub union Align4Union {
pub variant1: usize,
pub variant2: *mut u8,
}
#[repr(align(16), C)]
pub union Align16Union {
pub variant1: usize,
pub variant2: *mut u8,
}
#[repr(align(1), C)]
pub struct Align1Struct {
pub arg1: usize,
pub arg2: *mut u8,
}
#[repr(align(2), C)]
pub struct Align2Struct {
pub arg1: usize,
pub arg2: *mut u8,
}
#[repr(align(4), C)]
pub struct Align4Struct {
pub arg1: usize,
pub arg2: *mut u8,
}
#[repr(align(8), C)]
pub struct Align8Struct {
pub arg1: usize,
pub arg2: *mut u8,
}
#[repr(align(32), C)]
pub struct Align32Struct {
pub arg1: usize,
pub arg2: *mut u8,
}
// Opaque because packed is not defined.
#[repr(packed, C)]
pub struct OpaquePackedStruct {
pub arg1: usize,
pub arg2: *mut u8,
}
// Opaque because packed is not defined.
#[repr(packed, C)]
pub union OpaquePackedUnion {
pub variant1: usize,
pub variant2: *mut u8,
}

View File

@@ -0,0 +1,22 @@
header = """
#define CBINDGEN_PACKED __attribute__ ((packed))
#define CBINDGEN_ALIGNED(n) __attribute__ ((aligned(n)))
"""
[layout]
# We do not define packed.
aligned_n = "CBINDGEN_ALIGNED"
[export]
include = [
"Align1Union",
"Align4Union",
"Align16Union",
"Align1Struct",
"Align2Struct",
"Align4Struct",
"Align8Struct",
"Align32Struct",
"OpaquePackedStruct",
"OpaquePackedUnion",
]

View File

@@ -0,0 +1,14 @@
#[repr(C)]
struct A<'a> {
data: &'a i32
}
#[repr(C)]
enum E<'a> {
V,
U(&'a u8),
}
#[no_mangle]
pub extern "C" fn root<'a>(_a: A<'a>, _e: E<'a>)
{ }

View File

@@ -0,0 +1,8 @@
#[repr(C)]
struct Dummy {
x: i32,
y: f32,
}
#[no_mangle]
pub extern "C" fn root(d: Dummy) {}

View File

@@ -0,0 +1 @@
line_endings = "CR"

View File

@@ -0,0 +1,8 @@
#[repr(C)]
struct Dummy {
x: i32,
y: f32,
}
#[no_mangle]
pub extern "C" fn root(d: Dummy) {}

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