Skip to content

Commit

Permalink
[rust] fix build on Linux due to difference type of c_char
Browse files Browse the repository at this point in the history
  • Loading branch information
hkrn committed Sep 18, 2023
1 parent 1d0b7dc commit 02dda7d
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 84 deletions.
20 changes: 10 additions & 10 deletions rust/plugin_wasm/src/model/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOCreate(
/// This function should be called from nanoem via plugin loader
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginModelIOCreateWithLocation(
path: *const i8,
path: *const c_char,
) -> *mut nanoem_application_plugin_model_io_t {
let path = CStr::from_ptr(path as *const c_char);
if let Ok(mut instance) = nanoem_application_plugin_model_io_t::new(path) {
Expand Down Expand Up @@ -76,7 +76,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOSetLanguage(
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetName(
plugin: *const nanoem_application_plugin_model_io_t,
) -> *const i8 {
) -> *const c_char {
match nanoem_application_plugin_model_io_t::get(plugin) {
Some(instance) => instance.name(),
None => null(),
Expand All @@ -89,7 +89,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetName(
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetDescription(
plugin: *const nanoem_application_plugin_model_io_t,
) -> *const i8 {
) -> *const c_char {
match nanoem_application_plugin_model_io_t::get(plugin) {
Some(instance) => instance.description(),
None => null(),
Expand All @@ -102,7 +102,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetDescription(
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetVersion(
plugin: *const nanoem_application_plugin_model_io_t,
) -> *const i8 {
) -> *const c_char {
match nanoem_application_plugin_model_io_t::get(plugin) {
Some(instance) => instance.version(),
None => null(),
Expand All @@ -129,7 +129,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOCountAllFunctions(
pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetFunctionName(
plugin: *const nanoem_application_plugin_model_io_t,
index: i32,
) -> *const i8 {
) -> *const c_char {
match nanoem_application_plugin_model_io_t::get(plugin) {
Some(instance) => instance.function_name(index),
None => null(),
Expand Down Expand Up @@ -663,7 +663,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetUIWindowLayoutData(
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginModelIOSetUIComponentLayoutData(
plugin: *mut nanoem_application_plugin_model_io_t,
id: *const i8,
id: *const c_char,
data: *const u8,
length: u32,
reload_layout: *mut i32,
Expand Down Expand Up @@ -695,10 +695,10 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOSetUIComponentLayoutData(
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetFailureReason(
plugin: *const nanoem_application_plugin_model_io_t,
) -> *const i8 {
) -> *const c_char {
match nanoem_application_plugin_model_io_t::get(plugin) {
Some(instance) => match instance.failure_reason() {
Some(reason) => reason.as_ptr() as *const i8,
Some(reason) => reason.as_ptr() as *const c_char,
None => null(),
},
None => null(),
Expand All @@ -711,10 +711,10 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetFailureReason(
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetRecoverySuggestion(
plugin: *const nanoem_application_plugin_model_io_t,
) -> *const i8 {
) -> *const c_char {
match nanoem_application_plugin_model_io_t::get(plugin) {
Some(instance) => match instance.recovery_suggestion() {
Some(reason) => reason.as_ptr() as *const i8,
Some(reason) => reason.as_ptr() as *const c_char,
None => null(),
},
None => null(),
Expand Down
16 changes: 8 additions & 8 deletions rust/plugin_wasm/src/model/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::nanoem_application_plugin_status_t;

use super::plugin::ModelIOPluginController;

use std::ffi::CStr;
use std::ffi::{c_char, CStr};
use std::path::Path;
use std::ptr::null;

Expand Down Expand Up @@ -52,19 +52,19 @@ impl nanoem_application_plugin_model_io_t {
pub fn create(&mut self) -> Result<()> {
self.controller.create()
}
pub fn name(&self) -> *const i8 {
crate::PLUGIN_NAME.as_ptr() as *const i8
pub fn name(&self) -> *const c_char {
crate::PLUGIN_NAME.as_ptr() as *const c_char
}
pub fn description(&self) -> *const i8 {
crate::PLUGIN_DESCRIPTION.as_ptr() as *const i8
pub fn description(&self) -> *const c_char {
crate::PLUGIN_DESCRIPTION.as_ptr() as *const c_char
}
pub fn version(&self) -> *const i8 {
crate::PLUGIN_VERSION.as_ptr() as *const i8
pub fn version(&self) -> *const c_char {
crate::PLUGIN_VERSION.as_ptr() as *const c_char
}
pub fn count_all_functions(&self) -> i32 {
self.controller.count_all_functions()
}
pub fn function_name(&self, value: i32) -> *const i8 {
pub fn function_name(&self, value: i32) -> *const c_char {
if let Ok(name) = self.controller.function_name(value) {
name.as_ptr()
} else {
Expand Down
24 changes: 12 additions & 12 deletions rust/plugin_wasm/src/motion/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIOCreate(
/// This function should be called from nanoem via plugin loader
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginMotionIOCreateWithLocation(
path: *const i8,
path: *const c_char,
) -> *mut nanoem_application_plugin_motion_io_t {
let path = CStr::from_ptr(path as *const c_char);
if let Ok(mut instance) = nanoem_application_plugin_motion_io_t::new(path) {
Expand Down Expand Up @@ -76,7 +76,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIOSetLanguage(
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginMotionIOGetName(
plugin: *const nanoem_application_plugin_motion_io_t,
) -> *const i8 {
) -> *const c_char {
match nanoem_application_plugin_motion_io_t::get(plugin) {
Some(instance) => instance.name(),
None => null(),
Expand All @@ -89,7 +89,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIOGetName(
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginMotionIOGetDescription(
plugin: *const nanoem_application_plugin_motion_io_t,
) -> *const i8 {
) -> *const c_char {
match nanoem_application_plugin_motion_io_t::get(plugin) {
Some(instance) => instance.description(),
None => null(),
Expand All @@ -102,7 +102,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIOGetDescription(
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginMotionIOGetVersion(
plugin: *const nanoem_application_plugin_motion_io_t,
) -> *const i8 {
) -> *const c_char {
match nanoem_application_plugin_motion_io_t::get(plugin) {
Some(instance) => instance.version(),
None => null(),
Expand All @@ -129,7 +129,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIOCountAllFunctions(
pub unsafe extern "C" fn nanoemApplicationPluginMotionIOGetFunctionName(
plugin: *const nanoem_application_plugin_motion_io_t,
index: i32,
) -> *const i8 {
) -> *const c_char {
match nanoem_application_plugin_motion_io_t::get(plugin) {
Some(instance) => instance.function_name(index),
None => null(),
Expand Down Expand Up @@ -161,7 +161,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIOSetFunction(
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginMotionIOSetAllNamedSelectedBoneKeyframes(
plugin: *mut nanoem_application_plugin_motion_io_t,
name: *const i8,
name: *const c_char,
frame_indices: *const u32,
length: u32,
status_ptr: *mut nanoem_application_plugin_status_t,
Expand Down Expand Up @@ -191,7 +191,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIOSetAllNamedSelectedBoneK
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginMotionIOSetAllNamedSelectedMorphKeyframes(
plugin: *mut nanoem_application_plugin_motion_io_t,
name: *const i8,
name: *const c_char,
frame_indices: *const u32,
length: u32,
status_ptr: *mut nanoem_application_plugin_status_t,
Expand Down Expand Up @@ -643,7 +643,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIOGetUIWindowLayoutData(
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginMotionIOSetUIComponentLayoutData(
plugin: *mut nanoem_application_plugin_motion_io_t,
id: *const i8,
id: *const c_char,
data: *const u8,
length: u32,
reload_layout: *mut i32,
Expand Down Expand Up @@ -675,10 +675,10 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIOSetUIComponentLayoutData
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginMotionIOGetFailureReason(
plugin: *const nanoem_application_plugin_motion_io_t,
) -> *const i8 {
) -> *const c_char {
match nanoem_application_plugin_motion_io_t::get(plugin) {
Some(instance) => match instance.failure_reason() {
Some(reason) => reason.as_ptr() as *const i8,
Some(reason) => reason.as_ptr() as *const c_char,
None => null(),
},
None => null(),
Expand All @@ -691,10 +691,10 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIOGetFailureReason(
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginMotionIOGetRecoverySuggestion(
plugin: *const nanoem_application_plugin_motion_io_t,
) -> *const i8 {
) -> *const c_char {
match nanoem_application_plugin_motion_io_t::get(plugin) {
Some(instance) => match instance.recovery_suggestion() {
Some(reason) => reason.as_ptr() as *const i8,
Some(reason) => reason.as_ptr() as *const c_char,
None => null(),
},
None => null(),
Expand Down
16 changes: 8 additions & 8 deletions rust/plugin_wasm/src/motion/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::nanoem_application_plugin_status_t;

use super::plugin::MotionIOPluginController;

use std::ffi::CStr;
use std::ffi::{c_char, CStr};
use std::path::Path;
use std::ptr::null;

Expand Down Expand Up @@ -52,19 +52,19 @@ impl nanoem_application_plugin_motion_io_t {
pub fn create(&mut self) -> Result<()> {
self.controller.create()
}
pub fn name(&self) -> *const i8 {
crate::PLUGIN_NAME.as_ptr() as *const i8
pub fn name(&self) -> *const c_char {
crate::PLUGIN_NAME.as_ptr() as *const c_char
}
pub fn description(&self) -> *const i8 {
crate::PLUGIN_DESCRIPTION.as_ptr() as *const i8
pub fn description(&self) -> *const c_char {
crate::PLUGIN_DESCRIPTION.as_ptr() as *const c_char
}
pub fn version(&self) -> *const i8 {
crate::PLUGIN_VERSION.as_ptr() as *const i8
pub fn version(&self) -> *const c_char {
crate::PLUGIN_VERSION.as_ptr() as *const c_char
}
pub fn count_all_functions(&self) -> i32 {
self.controller.count_all_functions()
}
pub fn function_name(&self, value: i32) -> *const i8 {
pub fn function_name(&self, value: i32) -> *const c_char {
if let Ok(name) = self.controller.function_name(value) {
name.as_ptr()
} else {
Expand Down
26 changes: 13 additions & 13 deletions rust/plugin_wasm_test_model_full/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOSetLanguage(
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetName(
_plugin: *const nanoem_application_plugin_model_io_t,
) -> *const i8 {
) -> *const c_char {
println!(
"{}",
serde_json::to_string(&Output {
Expand All @@ -135,7 +135,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetName(
})
.unwrap()
);
b"plugin_wasm_test_model_full\0" as *const u8 as *const i8
b"plugin_wasm_test_model_full\0" as *const u8 as *const c_char
}

/// # Safety
Expand All @@ -144,7 +144,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetName(
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetDescription(
_plugin: *const nanoem_application_plugin_model_io_t,
) -> *const i8 {
) -> *const c_char {
println!(
"{}",
serde_json::to_string(&Output {
Expand All @@ -153,7 +153,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetDescription(
})
.unwrap()
);
b"This is plugin_wasm_test_model_full\0" as *const u8 as *const i8
b"This is plugin_wasm_test_model_full\0" as *const u8 as *const c_char
}

/// # Safety
Expand All @@ -162,7 +162,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetDescription(
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetVersion(
_plugin: *const nanoem_application_plugin_model_io_t,
) -> *const i8 {
) -> *const c_char {
println!(
"{}",
serde_json::to_string(&Output {
Expand All @@ -171,7 +171,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetVersion(
})
.unwrap()
);
b"1.2.3\0" as *const u8 as *const i8
b"1.2.3\0" as *const u8 as *const c_char
}

/// # Safety
Expand Down Expand Up @@ -199,7 +199,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOCountAllFunctions(
pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetFunctionName(
_plugin: *const nanoem_application_plugin_model_io_t,
index: i32,
) -> *const i8 {
) -> *const c_char {
let mut arguments = HashMap::new();
arguments.insert("index".to_owned(), json!(index));
println!(
Expand All @@ -210,7 +210,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetFunctionName(
})
.unwrap()
);
b"function0\0" as *const u8 as *const i8
b"function0\0" as *const u8 as *const c_char
}

/// # Safety
Expand Down Expand Up @@ -729,7 +729,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetUIWindowLayoutData(
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginModelIOSetUIComponentLayoutData(
_plugin: *mut nanoem_application_plugin_model_io_t,
id: *const i8,
id: *const c_char,
data: *const u8,
length: u32,
_reload_layout: *mut u32,
Expand Down Expand Up @@ -758,7 +758,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOSetUIComponentLayoutData(
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetFailureReason(
_plugin: *const nanoem_application_plugin_model_io_t,
) -> *const i8 {
) -> *const c_char {
println!(
"{}",
serde_json::to_string(&Output {
Expand All @@ -767,7 +767,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetFailureReason(
})
.unwrap()
);
b"Failure Reason\0" as *const u8 as *const i8
b"Failure Reason\0" as *const u8 as *const c_char
}

/// # Safety
Expand All @@ -776,7 +776,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetFailureReason(
#[no_mangle]
pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetRecoverySuggestion(
_plugin: *const nanoem_application_plugin_model_io_t,
) -> *const i8 {
) -> *const c_char {
println!(
"{}",
serde_json::to_string(&Output {
Expand All @@ -785,7 +785,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOGetRecoverySuggestion(
})
.unwrap()
);
b"Recovery Suggestion\0" as *const u8 as *const i8
b"Recovery Suggestion\0" as *const u8 as *const c_char
}

/// # Safety
Expand Down
Loading

0 comments on commit 02dda7d

Please sign in to comment.