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(rs-port): wrong implemenetation for user data in MetacallFuture #527

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions source/ports/rs_port/src/metacall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
cstring_enum, parsers,
types::{MetacallError, MetacallNull, MetacallValue},
};
use std::ffi::c_void;
use std::{ffi::c_void, fmt::Debug};

// Used for documentation.
#[allow(unused_imports)]
Expand Down Expand Up @@ -38,22 +38,22 @@ fn metacall_inner(
/// ```
/// let sum = metacall::metacall_untyped("sum", [1, 2]).unwrap();
/// ```
pub fn metacall_untyped(
pub fn metacall_untyped<T: 'static + Debug>(
func: impl ToString,
args: impl IntoIterator<Item = impl MetacallValue>,
) -> Result<Box<dyn MetacallValue>, MetacallError> {
Ok(parsers::raw_to_metacallobj_untyped(metacall_inner(
Ok(parsers::raw_to_metacallobj_untyped::<T>(metacall_inner(
func, args,
)?))
}
/// Calls a function same as [metacall_untyped](metacall_untyped) without passing any arguments. For example: ...
/// ```
/// let greet = metacall::metacall_untyped_no_arg("sum").unwrap();
/// ```
pub fn metacall_untyped_no_arg(
pub fn metacall_untyped_no_arg<T: 'static + Debug>(
func: impl ToString,
) -> Result<Box<dyn MetacallValue>, MetacallError> {
metacall_untyped(func, [] as [MetacallNull; 0])
metacall_untyped::<T>(func, [] as [MetacallNull; 0])
}
/// Calls a function with arguments. The generic parameter is the return type of the function
/// you're calling. Checkout [MetacallValue](MetacallValue) for possible types.
Expand Down
20 changes: 13 additions & 7 deletions source/ports/rs_port/src/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
MetacallObject, MetacallPointer, MetacallThrowable, MetacallValue,
},
};
use std::{collections::HashMap, ffi::c_void};
use std::{collections::HashMap, ffi::c_void, fmt::Debug};

fn metacallobj_result_wrap<T: MetacallValue>(
v: Result<T, Box<dyn MetacallValue>>,
Expand All @@ -30,7 +30,7 @@ pub fn raw_to_metacallobj<T: MetacallValue>(ret: *mut c_void) -> Result<T, Box<d
if unsafe { metacall_value_id(ret) } == T::get_metacall_id() {
<T>::from_metacall_raw(ret)
} else {
Err(raw_to_metacallobj_untyped(ret))
Err(raw_to_metacallobj_untyped::<T>(ret))
}
}
pub fn raw_to_metacallobj_leak<T: MetacallValue>(
Expand All @@ -49,11 +49,11 @@ pub fn raw_to_metacallobj_leak<T: MetacallValue>(
if unsafe { metacall_value_id(ret) } == T::get_metacall_id() {
<T>::from_metacall_raw_leak(ret)
} else {
Err(raw_to_metacallobj_untyped_leak(ret))
Err(raw_to_metacallobj_untyped_leak::<T>(ret))
}
}

pub fn raw_to_metacallobj_untyped(ret: *mut c_void) -> Box<dyn MetacallValue> {
pub fn raw_to_metacallobj_untyped<T: Debug + 'static>(ret: *mut c_void) -> Box<dyn MetacallValue> {
match (ret.is_null(), unsafe { metacall_value_id(ret) }) {
(true, _) => metacallobj_result_wrap(MetacallNull::from_metacall_raw(ret)),
(_, 0) => metacallobj_result_wrap(bool::from_metacall_raw(ret)),
Expand All @@ -68,7 +68,9 @@ pub fn raw_to_metacallobj_untyped(ret: *mut c_void) -> Box<dyn MetacallValue> {
(_, 9) => metacallobj_result_wrap(<Vec<MetacallNull>>::from_metacall_raw(ret)),
(_, 10) => metacallobj_result_wrap(<HashMap<String, MetacallNull>>::from_metacall_raw(ret)),
(_, 11) => metacallobj_result_wrap(<MetacallPointer>::from_metacall_raw(ret)),
(_, 12) => metacallobj_result_wrap(MetacallFuture::from_metacall_raw(ret)),
(_, 12) => {
metacallobj_result_wrap::<MetacallFuture<T>>(MetacallFuture::from_metacall_raw(ret))
}
(_, 13) => metacallobj_result_wrap(MetacallFunction::from_metacall_raw(ret)),
(_, 14) => metacallobj_result_wrap(MetacallNull::from_metacall_raw(ret)),
(_, 15) => metacallobj_result_wrap(MetacallClass::from_metacall_raw(ret)),
Expand All @@ -78,7 +80,9 @@ pub fn raw_to_metacallobj_untyped(ret: *mut c_void) -> Box<dyn MetacallValue> {
_ => metacallobj_result_wrap(MetacallNull::from_metacall_raw(ret)),
}
}
pub fn raw_to_metacallobj_untyped_leak(ret: *mut c_void) -> Box<dyn MetacallValue> {
pub fn raw_to_metacallobj_untyped_leak<T: Debug + 'static>(
ret: *mut c_void,
) -> Box<dyn MetacallValue> {
match (ret.is_null(), unsafe { metacall_value_id(ret) }) {
(true, _) => metacallobj_result_wrap(MetacallNull::from_metacall_raw_leak(ret)),
(_, 0) => metacallobj_result_wrap(bool::from_metacall_raw_leak(ret)),
Expand All @@ -95,7 +99,9 @@ pub fn raw_to_metacallobj_untyped_leak(ret: *mut c_void) -> Box<dyn MetacallValu
metacallobj_result_wrap(<HashMap<String, MetacallNull>>::from_metacall_raw_leak(ret))
}
(_, 11) => metacallobj_result_wrap(<MetacallPointer>::from_metacall_raw_leak(ret)),
(_, 12) => metacallobj_result_wrap(MetacallFuture::from_metacall_raw_leak(ret)),
(_, 12) => metacallobj_result_wrap::<MetacallFuture<T>>(
MetacallFuture::from_metacall_raw_leak(ret),
),
(_, 13) => metacallobj_result_wrap(MetacallFunction::from_metacall_raw_leak(ret)),
(_, 14) => metacallobj_result_wrap(MetacallNull::from_metacall_raw_leak(ret)),
(_, 15) => metacallobj_result_wrap(MetacallClass::from_metacall_raw_leak(ret)),
Expand Down
8 changes: 4 additions & 4 deletions source/ports/rs_port/src/types/metacall_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ impl MetacallClass {
Ok(unsafe { metacall_class_static_get(self.value_to_class(), c_name.as_ptr()) })
}
/// Gets static attribute from a class without type casting([MetacallValue](MetacallValue)).
pub fn get_attribute_untyped(
pub fn get_attribute_untyped<T: 'static + Debug>(
&self,
name: impl ToString,
) -> Result<Box<dyn MetacallValue>, MetacallGetAttributeError> {
Ok(parsers::raw_to_metacallobj_untyped(
Ok(parsers::raw_to_metacallobj_untyped::<T>(
self.get_attribute_inner(name)?,
))
}
Expand Down Expand Up @@ -180,7 +180,7 @@ impl MetacallClass {
name: impl ToString,
args: impl IntoIterator<Item = T>,
) -> Result<Box<dyn MetacallValue>, MetacallError> {
Ok(parsers::raw_to_metacallobj_untyped(
Ok(parsers::raw_to_metacallobj_untyped::<T>(
self.call_method_inner::<T>(name, args)?,
))
}
Expand All @@ -190,7 +190,7 @@ impl MetacallClass {
&self,
name: impl ToString,
) -> Result<Box<dyn MetacallValue>, MetacallError> {
Ok(parsers::raw_to_metacallobj_untyped(
Ok(parsers::raw_to_metacallobj_untyped::<T>(
self.call_method_inner::<T>(name, [])?,
))
}
Expand Down
4 changes: 2 additions & 2 deletions source/ports/rs_port/src/types/metacall_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ impl MetacallFunction {
&self,
args: impl IntoIterator<Item = T>,
) -> Box<dyn MetacallValue> {
parsers::raw_to_metacallobj_untyped(self.call_inner(args))
parsers::raw_to_metacallobj_untyped::<T>(self.call_inner(args))
}
/// Calls the function without passing arguments and witout type
/// casting([MetacallValue](MetacallValue)).
pub fn call_untyped_no_arg<T: MetacallValue>(&self) -> Box<dyn MetacallValue> {
parsers::raw_to_metacallobj_untyped(self.call_inner([] as [MetacallNull; 0]))
parsers::raw_to_metacallobj_untyped::<T>(self.call_inner([] as [MetacallNull; 0]))
}
/// Calls the function with arguments.
pub fn call<T: MetacallValue, U: MetacallValue>(
Expand Down
Loading
Loading