mirror of
https://github.com/fluencelabs/wasmer
synced 2025-03-16 16:20:49 +00:00
Merge pull request #241 from Hywan/feat-runtime-c-api-strict-c-cpp
test(runtime-c-api) Deny all warnings
This commit is contained in:
commit
d3c4733f78
@ -232,8 +232,8 @@ pub extern "C" fn wasmer_memory_grow(
|
||||
/// Returns the current length in pages of the given memory
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasmer_memory_length(memory: *mut wasmer_memory_t) -> uint32_t {
|
||||
let memory = unsafe { &*(memory as *mut Memory) };
|
||||
pub extern "C" fn wasmer_memory_length(memory: *const wasmer_memory_t) -> uint32_t {
|
||||
let memory = unsafe { &*(memory as *const Memory) };
|
||||
let Pages(len) = memory.size();
|
||||
len
|
||||
}
|
||||
@ -1142,7 +1142,7 @@ pub unsafe extern "C" fn wasmer_import_func_new(
|
||||
params_len: c_int,
|
||||
returns: *const wasmer_value_tag,
|
||||
returns_len: c_int,
|
||||
) -> *const wasmer_import_func_t {
|
||||
) -> *mut wasmer_import_func_t {
|
||||
let params: &[wasmer_value_tag] = slice::from_raw_parts(params, params_len as usize);
|
||||
let params: Vec<Type> = params.iter().cloned().map(|x| x.into()).collect();
|
||||
let returns: &[wasmer_value_tag] = slice::from_raw_parts(returns, returns_len as usize);
|
||||
@ -1342,7 +1342,7 @@ pub unsafe extern "C" fn wasmer_export_func_call(
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasmer_instance_context_memory(
|
||||
ctx: *mut wasmer_instance_context_t,
|
||||
ctx: *const wasmer_instance_context_t,
|
||||
_memory_idx: uint32_t,
|
||||
) -> *const wasmer_memory_t {
|
||||
let ctx = unsafe { &*(ctx as *const Ctx) };
|
||||
@ -1353,8 +1353,8 @@ pub extern "C" fn wasmer_instance_context_memory(
|
||||
/// Gets the start pointer to the bytes within a Memory
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasmer_memory_data(mem: *mut wasmer_memory_t) -> *mut uint8_t {
|
||||
let memory = mem as *mut Memory;
|
||||
pub extern "C" fn wasmer_memory_data(mem: *const wasmer_memory_t) -> *mut uint8_t {
|
||||
let memory = mem as *const Memory;
|
||||
use std::cell::Cell;
|
||||
unsafe { ((*memory).view::<u8>()[..]).as_ptr() as *mut Cell<u8> as *mut u8 }
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
cmake_minimum_required (VERSION 2.6)
|
||||
project (WasmerCApiTests)
|
||||
project (WasmerRuntimeCApiTests)
|
||||
|
||||
add_executable(test-imports test-imports.c)
|
||||
add_executable(test-exports test-exports.c)
|
||||
@ -22,39 +22,58 @@ if(NOT WASMER_LIB)
|
||||
message(FATAL_ERROR "wasmer library not found")
|
||||
endif()
|
||||
|
||||
target_link_libraries(test-imports
|
||||
general ${WASMER_LIB})
|
||||
target_link_libraries(test-exports
|
||||
general ${WASMER_LIB})
|
||||
target_link_libraries(test-globals
|
||||
general ${WASMER_LIB})
|
||||
target_link_libraries(test-instantiate
|
||||
general ${WASMER_LIB})
|
||||
target_link_libraries(test-import-function
|
||||
general ${WASMER_LIB})
|
||||
target_link_libraries(test-memory
|
||||
general ${WASMER_LIB})
|
||||
target_link_libraries(test-module-imports
|
||||
general ${WASMER_LIB})
|
||||
target_link_libraries(test-module
|
||||
general ${WASMER_LIB})
|
||||
target_link_libraries(test-module-exports
|
||||
general ${WASMER_LIB})
|
||||
target_link_libraries(test-validate
|
||||
general ${WASMER_LIB})
|
||||
target_link_libraries(test-tables
|
||||
general ${WASMER_LIB})
|
||||
|
||||
enable_testing()
|
||||
add_test(test-imports test-imports)
|
||||
add_test(test-exports test-exports)
|
||||
add_test(test-globals test-globals)
|
||||
add_test(test-instantiate test-instantiate)
|
||||
add_test(test-import-function test-import-function)
|
||||
add_test(test-memory test-memory)
|
||||
add_test(test-module-imports test-module-imports)
|
||||
add_test(test-module test-module)
|
||||
add_test(test-module-exports test-module-exports)
|
||||
add_test(test-validate test-validate)
|
||||
add_test(test-tables test-tables)
|
||||
|
||||
set(
|
||||
COMPILER_OPTIONS
|
||||
# Clang or gcc
|
||||
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>:
|
||||
"-Werror" >
|
||||
# MSVC
|
||||
$<$<CXX_COMPILER_ID:MSVC>:
|
||||
"/WX" >
|
||||
)
|
||||
|
||||
target_link_libraries(test-imports general ${WASMER_LIB})
|
||||
target_compile_options(test-imports PRIVATE ${COMPILER_OPTIONS})
|
||||
add_test(test-imports test-imports)
|
||||
|
||||
target_link_libraries(test-exports general ${WASMER_LIB})
|
||||
target_compile_options(test-exports PRIVATE ${COMPILER_OPTIONS})
|
||||
add_test(test-exports test-exports)
|
||||
|
||||
target_link_libraries(test-globals general ${WASMER_LIB})
|
||||
target_compile_options(test-globals PRIVATE ${COMPILER_OPTIONS})
|
||||
add_test(test-globals test-globals)
|
||||
|
||||
target_link_libraries(test-instantiate general ${WASMER_LIB})
|
||||
target_compile_options(test-instantiate PRIVATE ${COMPILER_OPTIONS})
|
||||
add_test(test-instantiate test-instantiate)
|
||||
|
||||
target_link_libraries(test-import-function general ${WASMER_LIB})
|
||||
target_compile_options(test-import-function PRIVATE ${COMPILER_OPTIONS})
|
||||
add_test(test-import-function test-import-function)
|
||||
|
||||
target_link_libraries(test-memory general ${WASMER_LIB})
|
||||
target_compile_options(test-memory PRIVATE ${COMPILER_OPTIONS})
|
||||
add_test(test-memory test-memory)
|
||||
|
||||
target_link_libraries(test-module-imports general ${WASMER_LIB})
|
||||
target_compile_options(test-module-imports PRIVATE ${COMPILER_OPTIONS})
|
||||
add_test(test-module-imports test-module-imports)
|
||||
|
||||
target_link_libraries(test-module general ${WASMER_LIB})
|
||||
target_compile_options(test-module PRIVATE ${COMPILER_OPTIONS})
|
||||
add_test(test-module test-module)
|
||||
|
||||
target_link_libraries(test-module-exports general ${WASMER_LIB})
|
||||
target_compile_options(test-module-exports PRIVATE ${COMPILER_OPTIONS})
|
||||
add_test(test-module-exports test-module-exports)
|
||||
|
||||
target_link_libraries(test-validate general ${WASMER_LIB})
|
||||
target_compile_options(test-validate PRIVATE ${COMPILER_OPTIONS})
|
||||
add_test(test-validate test-validate)
|
||||
|
||||
target_link_libraries(test-tables general ${WASMER_LIB})
|
||||
target_compile_options(test-tables PRIVATE ${COMPILER_OPTIONS})
|
||||
add_test(test-tables test-tables)
|
||||
|
@ -3,37 +3,47 @@ use std::process::Command;
|
||||
#[test]
|
||||
fn test_c_api() {
|
||||
let project_tests_dir = concat!(env!("CARGO_MANIFEST_DIR"), "/tests");
|
||||
|
||||
run_command("cmake", project_tests_dir, Some("."));
|
||||
run_command("make", project_tests_dir, None);
|
||||
run_command("make", project_tests_dir, Some("-Wdev -Werror=dev"));
|
||||
run_command("make", project_tests_dir, Some("test"));
|
||||
}
|
||||
|
||||
fn run_command(command_str: &str, dir: &str, arg: Option<&str>) {
|
||||
println!("Running command: `{}` arg: {:?}", command_str, arg);
|
||||
|
||||
let mut command = Command::new(command_str);
|
||||
|
||||
if let Some(a) = arg {
|
||||
command.arg(a);
|
||||
}
|
||||
|
||||
command.current_dir(dir);
|
||||
|
||||
let result = command.output();
|
||||
|
||||
match result {
|
||||
Ok(r) => {
|
||||
println!("output:");
|
||||
|
||||
if let Some(code) = r.status.code() {
|
||||
println!("status: {}", code);
|
||||
} else {
|
||||
println!("status: None");
|
||||
}
|
||||
|
||||
println!("stdout:");
|
||||
println!("{}", String::from_utf8_lossy(&r.stdout[..]));
|
||||
println!("stderr:");
|
||||
println!("{}", String::from_utf8_lossy(&r.stderr[..]));
|
||||
|
||||
if r.status.success() {
|
||||
assert!(true)
|
||||
} else {
|
||||
panic!("Command failed with exit status: {:?}", r.status);
|
||||
}
|
||||
}
|
||||
|
||||
Err(e) => panic!("Command failed: {}", e),
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ int main()
|
||||
|
||||
wasmer_import_export_kind kind = wasmer_export_kind(export);
|
||||
assert(kind == WASM_FUNCTION);
|
||||
wasmer_export_func_t *func = wasmer_export_to_func(export);
|
||||
const wasmer_export_func_t *func = wasmer_export_to_func(export);
|
||||
|
||||
wasmer_byte_array name_bytes = wasmer_export_name(export);
|
||||
assert(name_bytes.bytes_len == 3);
|
||||
@ -83,4 +83,4 @@ int main()
|
||||
printf("Destroy exports\n");
|
||||
wasmer_exports_destroy(exports);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -4,14 +4,14 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
static print_str_called = false;
|
||||
static memory_len = 0;
|
||||
static ptr_len = 0;
|
||||
static bool print_str_called = false;
|
||||
static int memory_len = 0;
|
||||
static int ptr_len = 0;
|
||||
static char actual_str[14] = {};
|
||||
|
||||
void print_str(wasmer_instance_context_t *ctx, int32_t ptr, int32_t len)
|
||||
{
|
||||
wasmer_memory_t *memory = wasmer_instance_context_memory(ctx, 0);
|
||||
const wasmer_memory_t *memory = wasmer_instance_context_memory(ctx, 0);
|
||||
uint32_t mem_len = wasmer_memory_length(memory);
|
||||
uint8_t *mem_bytes = wasmer_memory_data(memory);
|
||||
for (int32_t idx = 0; idx < len; idx++)
|
||||
@ -31,16 +31,16 @@ int main()
|
||||
wasmer_value_tag returns_sig[] = {};
|
||||
|
||||
printf("Creating new func\n");
|
||||
wasmer_import_func_t *func = wasmer_import_func_new(print_str, params_sig, 2, returns_sig, 0);
|
||||
wasmer_import_func_t *func = wasmer_import_func_new((void (*)(void *)) print_str, params_sig, 2, returns_sig, 0);
|
||||
wasmer_import_t import;
|
||||
|
||||
char *module_name = "env";
|
||||
wasmer_byte_array module_name_bytes;
|
||||
module_name_bytes.bytes = module_name;
|
||||
module_name_bytes.bytes = (const uint8_t *) module_name;
|
||||
module_name_bytes.bytes_len = strlen(module_name);
|
||||
char *import_name = "print_str";
|
||||
wasmer_byte_array import_name_bytes;
|
||||
import_name_bytes.bytes = import_name;
|
||||
import_name_bytes.bytes = (const uint8_t *) import_name;
|
||||
import_name_bytes.bytes_len = strlen(import_name);
|
||||
|
||||
import.module_name = module_name_bytes;
|
||||
@ -88,4 +88,4 @@ int main()
|
||||
printf("Destroy instance\n");
|
||||
wasmer_instance_destroy(instance);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,15 @@
|
||||
#include "../wasmer.h"
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
static print_str_called = false;
|
||||
bool static print_str_called = false;
|
||||
|
||||
// Host function that will be imported into the Web Assembly Instance
|
||||
void print_str(wasmer_instance_context_t *ctx, int32_t ptr, int32_t len)
|
||||
void print_str(const wasmer_instance_context_t *ctx, int32_t ptr, int32_t len)
|
||||
{
|
||||
print_str_called = true;
|
||||
wasmer_memory_t *memory = wasmer_instance_context_memory(ctx, 0);
|
||||
const wasmer_memory_t *memory = wasmer_instance_context_memory(ctx, 0);
|
||||
uint32_t mem_len = wasmer_memory_length(memory);
|
||||
uint8_t *mem_bytes = wasmer_memory_data(memory);
|
||||
printf("%.*s", len, mem_bytes + ptr);
|
||||
@ -31,19 +32,19 @@ int main()
|
||||
// of our `print_str` host function
|
||||
wasmer_value_tag params_sig[] = {WASM_I32, WASM_I32};
|
||||
wasmer_value_tag returns_sig[] = {};
|
||||
wasmer_import_func_t *func = wasmer_import_func_new(print_str, params_sig, 2, returns_sig, 0);
|
||||
wasmer_import_func_t *func = wasmer_import_func_new((void (*)(void *)) print_str, params_sig, 2, returns_sig, 0);
|
||||
|
||||
// Create module name for our imports
|
||||
// represented in bytes for UTF-8 compatability
|
||||
char *module_name = "env";
|
||||
const char *module_name = "env";
|
||||
wasmer_byte_array module_name_bytes;
|
||||
module_name_bytes.bytes = module_name;
|
||||
module_name_bytes.bytes = (const uint8_t *) module_name;
|
||||
module_name_bytes.bytes_len = strlen(module_name);
|
||||
|
||||
// Define a function import
|
||||
char *import_name = "_print_str";
|
||||
const char *import_name = "_print_str";
|
||||
wasmer_byte_array import_name_bytes;
|
||||
import_name_bytes.bytes = import_name;
|
||||
import_name_bytes.bytes = (const uint8_t *) import_name;
|
||||
import_name_bytes.bytes_len = strlen(import_name);
|
||||
wasmer_import_t func_import;
|
||||
func_import.module_name = module_name_bytes;
|
||||
@ -52,9 +53,9 @@ int main()
|
||||
func_import.value.func = func;
|
||||
|
||||
// Define a memory import
|
||||
char *import_memory_name = "memory";
|
||||
const char *import_memory_name = "memory";
|
||||
wasmer_byte_array import_memory_name_bytes;
|
||||
import_memory_name_bytes.bytes = import_memory_name;
|
||||
import_memory_name_bytes.bytes = (const uint8_t *) import_memory_name;
|
||||
import_memory_name_bytes.bytes_len = strlen(import_memory_name);
|
||||
wasmer_import_t memory_import;
|
||||
memory_import.module_name = module_name_bytes;
|
||||
@ -75,9 +76,9 @@ int main()
|
||||
memory_import.value.memory = memory;
|
||||
|
||||
// Define a global import
|
||||
char *import_global_name = "__memory_base";
|
||||
const char *import_global_name = "__memory_base";
|
||||
wasmer_byte_array import_global_name_bytes;
|
||||
import_global_name_bytes.bytes = import_global_name;
|
||||
import_global_name_bytes.bytes = (const uint8_t *) import_global_name;
|
||||
import_global_name_bytes.bytes_len = strlen(import_global_name);
|
||||
wasmer_import_t global_import;
|
||||
global_import.module_name = module_name_bytes;
|
||||
@ -90,9 +91,9 @@ int main()
|
||||
global_import.value.global = global;
|
||||
|
||||
// Define a table import
|
||||
char *import_table_name = "table";
|
||||
const char *import_table_name = "table";
|
||||
wasmer_byte_array import_table_name_bytes;
|
||||
import_table_name_bytes.bytes = import_table_name;
|
||||
import_table_name_bytes.bytes = (const uint8_t *) import_table_name;
|
||||
import_table_name_bytes.bytes_len = strlen(import_table_name);
|
||||
wasmer_import_t table_import;
|
||||
table_import.module_name = module_name_bytes;
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "../wasmer.h"
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
@ -53,4 +54,4 @@ int main()
|
||||
printf("Destroy instance\n");
|
||||
wasmer_instance_destroy(instance);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "../wasmer.h"
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -325,11 +325,11 @@ void wasmer_import_func_destroy(wasmer_import_func_t *func);
|
||||
* Creates new func
|
||||
* The caller owns the object and should call `wasmer_import_func_destroy` to free it.
|
||||
*/
|
||||
const wasmer_import_func_t *wasmer_import_func_new(void (*func)(void *data),
|
||||
const wasmer_value_tag *params,
|
||||
int params_len,
|
||||
const wasmer_value_tag *returns,
|
||||
int returns_len);
|
||||
wasmer_import_func_t *wasmer_import_func_new(void (*func)(void *data),
|
||||
const wasmer_value_tag *params,
|
||||
int params_len,
|
||||
const wasmer_value_tag *returns,
|
||||
int returns_len);
|
||||
|
||||
/**
|
||||
* Sets the params buffer to the parameter types of the given wasmer_import_func_t
|
||||
@ -386,7 +386,7 @@ wasmer_result_t wasmer_instance_call(wasmer_instance_t *instance,
|
||||
* Gets the memory within the context at the index `memory_idx`.
|
||||
* The index is always 0 until multiple memories are supported.
|
||||
*/
|
||||
const wasmer_memory_t *wasmer_instance_context_memory(wasmer_instance_context_t *ctx,
|
||||
const wasmer_memory_t *wasmer_instance_context_memory(const wasmer_instance_context_t *ctx,
|
||||
uint32_t _memory_idx);
|
||||
|
||||
/**
|
||||
@ -442,7 +442,7 @@ int wasmer_last_error_message(char *buffer, int length);
|
||||
/**
|
||||
* Gets the start pointer to the bytes within a Memory
|
||||
*/
|
||||
uint8_t *wasmer_memory_data(wasmer_memory_t *mem);
|
||||
uint8_t *wasmer_memory_data(const wasmer_memory_t *mem);
|
||||
|
||||
/**
|
||||
* Gets the size in bytes of a Memory
|
||||
@ -465,7 +465,7 @@ wasmer_result_t wasmer_memory_grow(wasmer_memory_t *memory, uint32_t delta);
|
||||
/**
|
||||
* Returns the current length in pages of the given memory
|
||||
*/
|
||||
uint32_t wasmer_memory_length(wasmer_memory_t *memory);
|
||||
uint32_t wasmer_memory_length(const wasmer_memory_t *memory);
|
||||
|
||||
/**
|
||||
* Creates a new Memory for the given descriptor and initializes the given
|
||||
|
@ -260,11 +260,11 @@ void wasmer_import_func_destroy(wasmer_import_func_t *func);
|
||||
|
||||
/// Creates new func
|
||||
/// The caller owns the object and should call `wasmer_import_func_destroy` to free it.
|
||||
const wasmer_import_func_t *wasmer_import_func_new(void (*func)(void *data),
|
||||
const wasmer_value_tag *params,
|
||||
int params_len,
|
||||
const wasmer_value_tag *returns,
|
||||
int returns_len);
|
||||
wasmer_import_func_t *wasmer_import_func_new(void (*func)(void *data),
|
||||
const wasmer_value_tag *params,
|
||||
int params_len,
|
||||
const wasmer_value_tag *returns,
|
||||
int returns_len);
|
||||
|
||||
/// Sets the params buffer to the parameter types of the given wasmer_import_func_t
|
||||
/// Returns `wasmer_result_t::WASMER_OK` upon success.
|
||||
@ -309,7 +309,7 @@ wasmer_result_t wasmer_instance_call(wasmer_instance_t *instance,
|
||||
|
||||
/// Gets the memory within the context at the index `memory_idx`.
|
||||
/// The index is always 0 until multiple memories are supported.
|
||||
const wasmer_memory_t *wasmer_instance_context_memory(wasmer_instance_context_t *ctx,
|
||||
const wasmer_memory_t *wasmer_instance_context_memory(const wasmer_instance_context_t *ctx,
|
||||
uint32_t _memory_idx);
|
||||
|
||||
/// Frees memory for the given Instance
|
||||
@ -353,7 +353,7 @@ int wasmer_last_error_length();
|
||||
int wasmer_last_error_message(char *buffer, int length);
|
||||
|
||||
/// Gets the start pointer to the bytes within a Memory
|
||||
uint8_t *wasmer_memory_data(wasmer_memory_t *mem);
|
||||
uint8_t *wasmer_memory_data(const wasmer_memory_t *mem);
|
||||
|
||||
/// Gets the size in bytes of a Memory
|
||||
uint32_t wasmer_memory_data_length(wasmer_memory_t *mem);
|
||||
@ -368,7 +368,7 @@ void wasmer_memory_destroy(wasmer_memory_t *memory);
|
||||
wasmer_result_t wasmer_memory_grow(wasmer_memory_t *memory, uint32_t delta);
|
||||
|
||||
/// Returns the current length in pages of the given memory
|
||||
uint32_t wasmer_memory_length(wasmer_memory_t *memory);
|
||||
uint32_t wasmer_memory_length(const wasmer_memory_t *memory);
|
||||
|
||||
/// Creates a new Memory for the given descriptor and initializes the given
|
||||
/// pointer to pointer to a pointer to the new memory.
|
||||
|
Loading…
x
Reference in New Issue
Block a user