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;
}
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) {
Ok(func) => {
info!("Take {}::{}.", crate_name, &item.ident);
@@ -582,6 +582,12 @@ impl Parse {
}
}
} 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() {
warn!(
"Skip {}::{} - (`extern` but not `no_mangle`).",
@@ -649,14 +655,29 @@ impl Parse {
let static_name = item.ident.to_string();
match Static::load(static_name.clone(), ty, mutability, &item.attrs, mod_cfg) {
Ok(constant) => {
info!("Take {}::{}.", crate_name, &item.ident);
if item.vis == syn::Visibility::Public && item.is_no_mangle() {
match Static::load(static_name.clone(), ty, mutability, &item.attrs, mod_cfg) {
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) => {
warn!("Skip {}::{} - ({})", crate_name, &item.ident, msg);
} else {
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;
#[no_mangle]
extern "C" fn root(x: IntFoo,
y: DoubleFoo,
z: Unit,
w: SpecialStatus)
{ }
pub extern "C" fn root(
x: IntFoo,
y: DoubleFoo,
z: Unit,
w: SpecialStatus
) { }
+5 -4
View File
@@ -16,7 +16,8 @@ enum C {
}
#[no_mangle]
extern "C" fn root(x: A,
y: B,
z: C)
{ }
pub extern "C" fn root(
x: A,
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];
#[no_mangle]
extern "C" fn O() -> fn ()
pub extern "C" fn O() -> fn ()
{ }
#[no_mangle]
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)
{ }
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
) { }
+1 -1
View File
@@ -22,5 +22,5 @@ struct Root {
}
#[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))]
#[no_mangle]
extern "C" fn root(a: FooHandle)
pub extern "C" fn root(a: FooHandle)
{ }
#[cfg(any(windows, target_pointer_width="32"))]
#[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]
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]
extern "C" fn root(o: *mut Opaque,
a: A,
b: B,
c: C,
d: D,
e: E)
{ }
pub extern "C" fn root(
o: *mut Opaque,
a: A,
b: B,
c: C,
d: D,
e: E
) { }
+24 -23
View File
@@ -55,26 +55,27 @@ type LayoutPoint2D = TypedPoint2D<f32, LayoutUnit>;
type LayoutRect = TypedRect<f32, LayoutUnit>;
#[no_mangle]
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>) {
}
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>
) { }
+3 -3
View File
@@ -1,11 +1,11 @@
#[no_mangle]
extern "C" fn first()
pub extern "C" fn first()
{ }
#[no_mangle]
extern fn second()
pub extern fn second()
{ }
#[no_mangle]
fn third()
pub fn third()
{ }
+4 -3
View File
@@ -6,6 +6,7 @@ struct Foo<'a> {
const BAR: &'static str = "";
#[no_mangle]
extern "C" fn root(a: Foo<'static>,
b: &'static str)
{ }
pub extern "C" fn root(
a: Foo<'static>,
b: &'static str
) { }
+1 -1
View File
@@ -6,5 +6,5 @@ mod foo {
}
#[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>;
#[no_mangle]
extern "C" fn root(a: Foo<i32>,
b: Foo<f32>,
c: Bar<f32>,
d: Foo<Bar<f32>>,
e: Bar<Foo<f32>>,
f: Bar<Bar<f32>>,
g: Tuple<Foo<f32>, f32>,
h: Indirection<f32>) {
}
pub extern "C" fn root(
a: Foo<i32>,
b: Foo<f32>,
c: Bar<f32>,
d: Foo<Bar<f32>>,
e: Bar<Foo<f32>>,
f: Bar<Bar<f32>>,
g: Tuple<Foo<f32>, f32>,
h: Indirection<f32>
) { }
+2 -2
View File
@@ -9,7 +9,7 @@ struct A;
struct B;
#[no_mangle]
extern "C" fn foo(a: List<A>) { }
pub extern "C" fn foo(a: List<A>) { }
#[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>;
#[no_mangle]
extern "C" fn root(a: Foo<i32>,
b: Foo<f32>,
c: Bar<f32>,
d: Foo<Bar<f32>>,
e: Bar<Foo<f32>>,
f: Bar<Bar<f32>>,
g: Tuple<Foo<f32>, f32>,
h: Indirection<f32>) {
}
pub extern "C" fn root(
a: Foo<i32>,
b: Foo<f32>,
c: Bar<f32>,
d: Foo<Bar<f32>>,
e: Bar<Foo<f32>>,
f: Bar<Bar<f32>>,
g: Tuple<Foo<f32>, f32>,
h: Indirection<f32>
) { }
+6 -5
View File
@@ -16,8 +16,9 @@ union Bar {
}
#[no_mangle]
extern "C" fn root(a: Option<&Opaque>,
b: Option<&mut Opaque>,
c: Foo,
d: Bar)
{ }
pub extern "C" fn root(
a: Option<&Opaque>,
b: Option<&mut Opaque>,
c: Foo,
d: Bar
) { }
+9 -5
View File
@@ -1,5 +1,7 @@
static NUMBER: i32 = 10;
static STRING: &'static libc::c_char = "hello world";
#[no_mangle]
pub static NUMBER: i32 = 10;
#[no_mangle]
pub static STRING: &'static libc::c_char = "hello world";
#[repr(C)]
struct Foo {
@@ -8,8 +10,10 @@ struct Foo {
struct Bar {
}
static mut FOO: Foo = Foo { };
static BAR: Bar = Bar { };
#[no_mangle]
pub static mut FOO: Foo = Foo { };
#[no_mangle]
pub static BAR: Bar = Bar { };
#[no_mangle]
extern "C" fn root() { }
pub extern "C" fn root() { }
+5 -4
View File
@@ -1,5 +1,6 @@
#[no_mangle]
extern "C" fn root(a: &Vec<String>,
b: &Option<i32>,
c: &Result<i32, String>)
{ }
pub extern "C" fn root(
a: &Vec<String>,
b: &Option<i32>,
c: &Result<i32, String>
) { }
+7 -6
View File
@@ -28,9 +28,10 @@ struct TupleRenamed(i32, f32);
struct TupleNamed(i32, f32);
#[no_mangle]
extern "C" fn root(a: *mut Opaque,
b: Normal,
c: NormalWithZST,
d: TupleRenamed,
e: TupleNamed)
{ }
pub extern "C" fn root(
a: *mut Opaque,
b: Normal,
c: NormalWithZST,
d: TupleRenamed,
e: TupleNamed
) { }
+1 -1
View File
@@ -7,5 +7,5 @@ struct Foo<T, U> {
type IntFoo<T> = Foo<i32, T>;
#[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]
extern "C" fn root(a: *mut Opaque,
b: Normal,
c: NormalWithZST)
{ }
pub extern "C" fn root(
a: *mut Opaque,
b: Normal,
c: NormalWithZST
) { }