Skip to content

Commit bb07b7c

Browse files
authored
Fix a compilation error because of c_char (#15)
The error was: ``` = note: expected raw pointer `*mut *mut u8` found raw pointer `*mut *mut i8` ```
1 parent 9d6f2bb commit bb07b7c

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/helper.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44
*/
55

6-
use std::ffi::CStr;
7-
use std::os::raw::c_char;
6+
use std::ffi::{c_char, CStr};
87
use std::string::String;
98

109
pub const DEFAULT_ERROR_BUF_SIZE: usize = 128;

src/module.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
helper::error_buf_to_string, helper::DEFAULT_ERROR_BUF_SIZE, runtime::Runtime,
1111
wasi_context::WasiCtx, RuntimeError,
1212
};
13-
use std::{fs::File, io::Read, path::Path, ptr, string::String, vec::Vec};
13+
use std::{ffi::c_char, fs::File, io::Read, path::Path, ptr, string::String, vec::Vec};
1414
use wamr_sys::{
1515
wasm_module_t, wasm_runtime_load, wasm_runtime_set_wasi_addr_pool, wasm_runtime_set_wasi_args,
1616
wasm_runtime_set_wasi_ns_lookup_pool, wasm_runtime_unload,
@@ -49,7 +49,7 @@ impl Module {
4949
/// If the wasm file is not a valid wasm file, an `RuntimeError::CompilationError` will be returned.
5050
pub fn from_buf(_runtime: &Runtime, buf: &[u8]) -> Result<Self, RuntimeError> {
5151
let mut content = buf.to_vec();
52-
let mut error_buf = [0i8; DEFAULT_ERROR_BUF_SIZE];
52+
let mut error_buf: [c_char; DEFAULT_ERROR_BUF_SIZE] = [0; DEFAULT_ERROR_BUF_SIZE];
5353
let module = unsafe {
5454
wasm_runtime_load(
5555
content.as_mut_ptr(),
@@ -90,25 +90,25 @@ impl Module {
9090
let real_paths = if self.wasi_ctx.get_preopen_real_paths().is_empty() {
9191
ptr::null_mut()
9292
} else {
93-
self.wasi_ctx.get_preopen_real_paths().as_ptr() as *mut *const i8
93+
self.wasi_ctx.get_preopen_real_paths().as_ptr() as *mut *const c_char
9494
};
9595

9696
let mapped_paths = if self.wasi_ctx.get_preopen_mapped_paths().is_empty() {
9797
ptr::null_mut()
9898
} else {
99-
self.wasi_ctx.get_preopen_mapped_paths().as_ptr() as *mut *const i8
99+
self.wasi_ctx.get_preopen_mapped_paths().as_ptr() as *mut *const c_char
100100
};
101101

102102
let env = if self.wasi_ctx.get_env_vars().is_empty() {
103103
ptr::null_mut()
104104
} else {
105-
self.wasi_ctx.get_env_vars().as_ptr() as *mut *const i8
105+
self.wasi_ctx.get_env_vars().as_ptr() as *mut *const c_char
106106
};
107107

108108
let args = if self.wasi_ctx.get_arguments().is_empty() {
109109
ptr::null_mut()
110110
} else {
111-
self.wasi_ctx.get_arguments().as_ptr() as *mut *mut i8
111+
self.wasi_ctx.get_arguments().as_ptr() as *mut *mut c_char
112112
};
113113

114114
unsafe {
@@ -127,7 +127,7 @@ impl Module {
127127
let ns_lookup_pool = if self.wasi_ctx.get_allowed_dns().is_empty() {
128128
ptr::null_mut()
129129
} else {
130-
self.wasi_ctx.get_allowed_dns().as_ptr() as *mut *const i8
130+
self.wasi_ctx.get_allowed_dns().as_ptr() as *mut *const c_char
131131
};
132132

133133
wasm_runtime_set_wasi_ns_lookup_pool(
@@ -139,7 +139,7 @@ impl Module {
139139
let addr_pool = if self.wasi_ctx.get_allowed_address().is_empty() {
140140
ptr::null_mut()
141141
} else {
142-
self.wasi_ctx.get_allowed_address().as_ptr() as *mut *const i8
142+
self.wasi_ctx.get_allowed_address().as_ptr() as *mut *const c_char
143143
};
144144
wasm_runtime_set_wasi_addr_pool(
145145
self.get_inner_module(),

0 commit comments

Comments
 (0)