Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-c-api) Fix several warnings #232

Merged

Conversation

Hywan
Copy link
Contributor

@Hywan Hywan commented Mar 4, 2019

This patch fixes several warnings: Some generated by rustc, some other generated by Clippy.

I tried to generate 3 “clean” commits:

  1. To remove unsafe blocks inside unsafe functions,
  2. To remove unmutated mutable bindings,
  3. To resolve Clippy warnings.

I hope those changes are OK for you. I will comment the patch a little bit to provide further help.

@Hywan Hywan added the 🎉 enhancement New feature! label Mar 4, 2019
@Hywan Hywan requested a review from bjfish March 4, 2019 14:41
@@ -17,23 +17,23 @@ use wasmer_runtime_core::module::{ExportIndex, ImportName};
use wasmer_runtime_core::types::{ElementType, FuncSig, MemoryDescriptor, TableDescriptor, Type};
use wasmer_runtime_core::units::{Bytes, Pages};

#[allow(non_camel_case_types)]
pub struct wasmer_module_t();
#[repr(C)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repr(C) implies no_mangle and allow(non_camel_case_types) as my tests shown. Not sure, but it has removed several warnings.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍, also when changes are made that may affect the header files you can run make capi from the root project. That and running tests is described in this projects README. Please run make capi for this PR if you haven’t already.

Copy link
Contributor Author

@Hywan Hywan Mar 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I think we have an issue 😄.

#[allow(non_camel_case_types)]
pub struct wasmer_module_t();
#[repr(C)]
pub struct wasmer_module_t;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed () at the end of the structure declaration. I don't think they are required.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

lib/runtime-c-api/src/lib.rs Show resolved Hide resolved
@@ -180,7 +181,7 @@ pub unsafe extern "C" fn wasmer_validate(
/// and `wasmer_last_error_message` to get an error message.
#[no_mangle]
pub unsafe extern "C" fn wasmer_memory_new(
mut memory: *mut *mut wasmer_memory_t,
memory: *mut *mut wasmer_memory_t,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memory contains a mutable pointer, but the binding itself is not mutable. rustc generates a warning for that.

@@ -301,8 +302,7 @@ pub extern "C" fn wasmer_table_grow(
#[no_mangle]
pub extern "C" fn wasmer_table_length(table: *mut wasmer_table_t) -> uint32_t {
let table = unsafe { &*(table as *mut Table) };
let len = table.size();
len
table.size()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clippy suggests to return the value directly instead of the binding.

lib/runtime-c-api/src/lib.rs Outdated Show resolved Hide resolved
}
for (module_name, namespace) in namespaces.into_iter() {
import_object.register(module_name, namespace);
}

let module = unsafe { &*(module as *mut Module) };
let module = &*(module as *const Module);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's not necessary to get a mutable module here. Correct me if I misunderstood the code!

lib/runtime-c-api/src/lib.rs Show resolved Hide resolved
wasmer_value_tag::WASM_I64 => Type::I64,
wasmer_value_tag::WASM_F32 => Type::F32,
wasmer_value_tag::WASM_F64 => Type::F64,
_ => panic!("not implemented"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I get it correctly, the _ arm is unreachable, but we don't trust the v input, is that right? In other words, we don't assume that v is correctly built.

Copy link
Contributor

@bjfish bjfish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@Hywan Hywan force-pushed the fix-runtime-c-api-remove-warnings branch from 7675396 to f0a467c Compare March 4, 2019 15:25
@Hywan
Copy link
Contributor Author

Hywan commented Mar 4, 2019

Rebased on top of master.

Copy link
Contributor Author

@Hywan Hywan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to double check what happens with cbindgen. It seems that 2 structures are not exported correctly.

@syrusakbary
Copy link
Member

Once the conflicts are resolved (I think they were caused by merging #227), and we check cbindgen we should be good to merge.

Hywan added 5 commits March 5, 2019 10:07
This patch removes `unsafe { … }` blocks inside `unsafe` functions.

This patch also removes some warnings about camel case. All structures
with a C representation are automatically not mangle, and allow non
camel case.
This patch cleans several warnings where mutable bindings are declared
but used only as immutable bindings.

It's a little bit opinionated patch. I think it's interesting to use
`const` pointers as much as possible.
This patch fixes warnings raised by Clippy.
@Hywan Hywan force-pushed the fix-runtime-c-api-remove-warnings branch from 8e17079 to 25feef7 Compare March 5, 2019 09:15
@Hywan
Copy link
Contributor Author

Hywan commented Mar 5, 2019

Everything is alright for me 👍.

@Hywan
Copy link
Contributor Author

Hywan commented Mar 5, 2019

I think we need to update the C source file, because some types have changed (like const * for instance). It only generates warnings, but we need to fix them.

@syrusakbary syrusakbary merged commit 28bb264 into wasmerio:master Mar 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎉 enhancement New feature!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants