Check for no_mangle and pub on functions and static items

This commit is contained in:
Ryan Hunt
2018-01-04 14:42:02 -06:00
parent bcd532f674
commit 21d917b723
21 changed files with 155 additions and 118 deletions
+28 -7
View File
@@ -570,7 +570,7 @@ impl Parse {
return; return;
} }
if item.is_no_mangle() && (abi.is_omitted() || abi.is_c()) { if item.vis == syn::Visibility::Public && item.is_no_mangle() && (abi.is_omitted() || abi.is_c()) {
match Function::load(item.ident.to_string(), decl, false, &item.attrs, mod_cfg) { match Function::load(item.ident.to_string(), decl, false, &item.attrs, mod_cfg) {
Ok(func) => { Ok(func) => {
info!("Take {}::{}.", crate_name, &item.ident); info!("Take {}::{}.", crate_name, &item.ident);
@@ -582,6 +582,12 @@ impl Parse {
} }
} }
} else { } else {
if item.vis != syn::Visibility::Public {
warn!(
"Skip {}::{} - (not `pub`).",
crate_name, &item.ident
);
}
if (abi.is_omitted() || abi.is_c()) && !item.is_no_mangle() { if (abi.is_omitted() || abi.is_c()) && !item.is_no_mangle() {
warn!( warn!(
"Skip {}::{} - (`extern` but not `no_mangle`).", "Skip {}::{} - (`extern` but not `no_mangle`).",
@@ -649,14 +655,29 @@ impl Parse {
let static_name = item.ident.to_string(); let static_name = item.ident.to_string();
match Static::load(static_name.clone(), ty, mutability, &item.attrs, mod_cfg) { if item.vis == syn::Visibility::Public && item.is_no_mangle() {
Ok(constant) => { match Static::load(static_name.clone(), ty, mutability, &item.attrs, mod_cfg) {
info!("Take {}::{}.", crate_name, &item.ident); Ok(constant) => {
info!("Take {}::{}.", crate_name, &item.ident);
self.globals.try_insert(constant); self.globals.try_insert(constant);
}
Err(msg) => {
warn!("Skip {}::{} - ({})", crate_name, &item.ident, msg);
}
} }
Err(msg) => { } else {
warn!("Skip {}::{} - ({})", crate_name, &item.ident, msg); if item.vis != syn::Visibility::Public {
warn!(
"Skip {}::{} - (not `pub`).",
crate_name, &item.ident
);
}
if !item.is_no_mangle() {
warn!(
"Skip {}::{} - (not `no_mangle`).",
crate_name, &item.ident
);
} }
} }
} }
+6 -5
View File
@@ -24,8 +24,9 @@ type Unit = i32;
type SpecialStatus = Status; type SpecialStatus = Status;
#[no_mangle] #[no_mangle]
extern "C" fn root(x: IntFoo, pub extern "C" fn root(
y: DoubleFoo, x: IntFoo,
z: Unit, y: DoubleFoo,
w: SpecialStatus) z: Unit,
{ } w: SpecialStatus
) { }
+5 -4
View File
@@ -16,7 +16,8 @@ enum C {
} }
#[no_mangle] #[no_mangle]
extern "C" fn root(x: A, pub extern "C" fn root(
y: B, x: A,
z: C) y: B,
{ } z: C
) { }
+17 -16
View File
@@ -16,22 +16,23 @@ type M = [fn (i32, i32) -> bool; 16];
type N = [fn (i32, i32) -> (); 16]; type N = [fn (i32, i32) -> (); 16];
#[no_mangle] #[no_mangle]
extern "C" fn O() -> fn () pub extern "C" fn O() -> fn ()
{ } { }
#[no_mangle] #[no_mangle]
extern "C" fn root(a: A, pub extern "C" fn root(
b: B, a: A,
c: C, b: B,
d: D, c: C,
e: E, d: D,
f: F, e: E,
g: G, f: F,
h: H, g: G,
i: I, h: H,
j: J, i: I,
k: K, j: J,
l: L, k: K,
m: M, l: L,
n: N) m: M,
{ } n: N
) { }
+1 -1
View File
@@ -22,5 +22,5 @@ struct Root {
} }
#[no_mangle] #[no_mangle]
extern "C" fn root(a: Root) pub extern "C" fn root(a: Root)
{ } { }
+2 -2
View File
@@ -32,10 +32,10 @@ struct BarHandle {
#[cfg(all(unix, x11))] #[cfg(all(unix, x11))]
#[no_mangle] #[no_mangle]
extern "C" fn root(a: FooHandle) pub extern "C" fn root(a: FooHandle)
{ } { }
#[cfg(any(windows, target_pointer_width="32"))] #[cfg(any(windows, target_pointer_width="32"))]
#[no_mangle] #[no_mangle]
extern "C" fn root(a: BarHandle) pub extern "C" fn root(a: BarHandle)
{ } { }
+1 -1
View File
@@ -8,4 +8,4 @@ struct Foo {
} }
#[no_mangle] #[no_mangle]
extern "C" fn root(x: Foo) { } pub extern "C" fn root(x: Foo) { }
+8 -7
View File
@@ -44,10 +44,11 @@ enum E {
} }
#[no_mangle] #[no_mangle]
extern "C" fn root(o: *mut Opaque, pub extern "C" fn root(
a: A, o: *mut Opaque,
b: B, a: A,
c: C, b: B,
d: D, c: C,
e: E) d: D,
{ } e: E
) { }
+24 -23
View File
@@ -55,26 +55,27 @@ type LayoutPoint2D = TypedPoint2D<f32, LayoutUnit>;
type LayoutRect = TypedRect<f32, LayoutUnit>; type LayoutRect = TypedRect<f32, LayoutUnit>;
#[no_mangle] #[no_mangle]
extern "C" fn root(length_a: TypedLength<f32, UnknownUnit>, pub extern "C" fn root(
length_b: TypedLength<f32, LayoutUnit>, length_a: TypedLength<f32, UnknownUnit>,
length_c: Length<f32>, length_b: TypedLength<f32, LayoutUnit>,
length_d: LayoutLength, length_c: Length<f32>,
side_offsets_a: TypedSideOffsets2D<f32, UnknownUnit>, length_d: LayoutLength,
side_offsets_b: TypedSideOffsets2D<f32, LayoutUnit>, side_offsets_a: TypedSideOffsets2D<f32, UnknownUnit>,
side_offsets_c: SideOffsets2D<f32>, side_offsets_b: TypedSideOffsets2D<f32, LayoutUnit>,
side_offsets_d: LayoutSideOffsets2D, side_offsets_c: SideOffsets2D<f32>,
size_a: TypedSize2D<f32, UnknownUnit>, side_offsets_d: LayoutSideOffsets2D,
size_b: TypedSize2D<f32, LayoutUnit>, size_a: TypedSize2D<f32, UnknownUnit>,
size_c: Size2D<f32>, size_b: TypedSize2D<f32, LayoutUnit>,
size_d: LayoutSize2D, size_c: Size2D<f32>,
point_a: TypedPoint2D<f32, UnknownUnit>, size_d: LayoutSize2D,
point_b: TypedPoint2D<f32, LayoutUnit>, point_a: TypedPoint2D<f32, UnknownUnit>,
point_c: Point2D<f32>, point_b: TypedPoint2D<f32, LayoutUnit>,
point_d: LayoutPoint2D, point_c: Point2D<f32>,
rect_a: TypedRect<f32, UnknownUnit>, point_d: LayoutPoint2D,
rect_b: TypedRect<f32, LayoutUnit>, rect_a: TypedRect<f32, UnknownUnit>,
rect_c: Rect<f32>, rect_b: TypedRect<f32, LayoutUnit>,
rect_d: LayoutRect, rect_c: Rect<f32>,
transform_a: TypedTransform2D<f32, UnknownUnit, LayoutUnit>, rect_d: LayoutRect,
transform_b: TypedTransform2D<f32, LayoutUnit, UnknownUnit>) { transform_a: TypedTransform2D<f32, UnknownUnit, LayoutUnit>,
} transform_b: TypedTransform2D<f32, LayoutUnit, UnknownUnit>
) { }
+3 -3
View File
@@ -1,11 +1,11 @@
#[no_mangle] #[no_mangle]
extern "C" fn first() pub extern "C" fn first()
{ } { }
#[no_mangle] #[no_mangle]
extern fn second() pub extern fn second()
{ } { }
#[no_mangle] #[no_mangle]
fn third() pub fn third()
{ } { }
+4 -3
View File
@@ -6,6 +6,7 @@ struct Foo<'a> {
const BAR: &'static str = ""; const BAR: &'static str = "";
#[no_mangle] #[no_mangle]
extern "C" fn root(a: Foo<'static>, pub extern "C" fn root(
b: &'static str) a: Foo<'static>,
{ } b: &'static str
) { }
+1 -1
View File
@@ -6,5 +6,5 @@ mod foo {
} }
#[no_mangle] #[no_mangle]
extern "C" fn root(a: foo::Foo) pub extern "C" fn root(a: foo::Foo)
{ } { }
+10 -9
View File
@@ -16,12 +16,13 @@ struct Tuple<T, E> {
type Indirection<T> = Tuple<T, f32>; type Indirection<T> = Tuple<T, f32>;
#[no_mangle] #[no_mangle]
extern "C" fn root(a: Foo<i32>, pub extern "C" fn root(
b: Foo<f32>, a: Foo<i32>,
c: Bar<f32>, b: Foo<f32>,
d: Foo<Bar<f32>>, c: Bar<f32>,
e: Bar<Foo<f32>>, d: Foo<Bar<f32>>,
f: Bar<Bar<f32>>, e: Bar<Foo<f32>>,
g: Tuple<Foo<f32>, f32>, f: Bar<Bar<f32>>,
h: Indirection<f32>) { g: Tuple<Foo<f32>, f32>,
} h: Indirection<f32>
) { }
+2 -2
View File
@@ -9,7 +9,7 @@ struct A;
struct B; struct B;
#[no_mangle] #[no_mangle]
extern "C" fn foo(a: List<A>) { } pub extern "C" fn foo(a: List<A>) { }
#[no_mangle] #[no_mangle]
extern "C" fn bar(b: List<B>) { } pub extern "C" fn bar(b: List<B>) { }
+10 -9
View File
@@ -16,12 +16,13 @@ union Tuple<T, E> {
type Indirection<T> = Tuple<T, f32>; type Indirection<T> = Tuple<T, f32>;
#[no_mangle] #[no_mangle]
extern "C" fn root(a: Foo<i32>, pub extern "C" fn root(
b: Foo<f32>, a: Foo<i32>,
c: Bar<f32>, b: Foo<f32>,
d: Foo<Bar<f32>>, c: Bar<f32>,
e: Bar<Foo<f32>>, d: Foo<Bar<f32>>,
f: Bar<Bar<f32>>, e: Bar<Foo<f32>>,
g: Tuple<Foo<f32>, f32>, f: Bar<Bar<f32>>,
h: Indirection<f32>) { g: Tuple<Foo<f32>, f32>,
} h: Indirection<f32>
) { }
+6 -5
View File
@@ -16,8 +16,9 @@ union Bar {
} }
#[no_mangle] #[no_mangle]
extern "C" fn root(a: Option<&Opaque>, pub extern "C" fn root(
b: Option<&mut Opaque>, a: Option<&Opaque>,
c: Foo, b: Option<&mut Opaque>,
d: Bar) c: Foo,
{ } d: Bar
) { }
+9 -5
View File
@@ -1,5 +1,7 @@
static NUMBER: i32 = 10; #[no_mangle]
static STRING: &'static libc::c_char = "hello world"; pub static NUMBER: i32 = 10;
#[no_mangle]
pub static STRING: &'static libc::c_char = "hello world";
#[repr(C)] #[repr(C)]
struct Foo { struct Foo {
@@ -8,8 +10,10 @@ struct Foo {
struct Bar { struct Bar {
} }
static mut FOO: Foo = Foo { }; #[no_mangle]
static BAR: Bar = Bar { }; pub static mut FOO: Foo = Foo { };
#[no_mangle]
pub static BAR: Bar = Bar { };
#[no_mangle] #[no_mangle]
extern "C" fn root() { } pub extern "C" fn root() { }
+5 -4
View File
@@ -1,5 +1,6 @@
#[no_mangle] #[no_mangle]
extern "C" fn root(a: &Vec<String>, pub extern "C" fn root(
b: &Option<i32>, a: &Vec<String>,
c: &Result<i32, String>) b: &Option<i32>,
{ } c: &Result<i32, String>
) { }
+7 -6
View File
@@ -28,9 +28,10 @@ struct TupleRenamed(i32, f32);
struct TupleNamed(i32, f32); struct TupleNamed(i32, f32);
#[no_mangle] #[no_mangle]
extern "C" fn root(a: *mut Opaque, pub extern "C" fn root(
b: Normal, a: *mut Opaque,
c: NormalWithZST, b: Normal,
d: TupleRenamed, c: NormalWithZST,
e: TupleNamed) d: TupleRenamed,
{ } e: TupleNamed
) { }
+1 -1
View File
@@ -7,5 +7,5 @@ struct Foo<T, U> {
type IntFoo<T> = Foo<i32, T>; type IntFoo<T> = Foo<i32, T>;
#[no_mangle] #[no_mangle]
extern "C" fn root(a: IntFoo<i32>) pub extern "C" fn root(a: IntFoo<i32>)
{ } { }
+5 -4
View File
@@ -20,7 +20,8 @@ union NormalWithZST {
} }
#[no_mangle] #[no_mangle]
extern "C" fn root(a: *mut Opaque, pub extern "C" fn root(
b: Normal, a: *mut Opaque,
c: NormalWithZST) b: Normal,
{ } c: NormalWithZST
) { }