mirror of
https://github.com/monero-project/monero.git
synced 2025-02-13 05:01:27 -05:00
Use a pointer for the value in CResult
Some toolchains complained CResult was an incomplete type. This attempts to resolve that. Do not merge unless it actually fixes things.
This commit is contained in:
parent
b585a7f408
commit
af4de996cb
@ -74,7 +74,7 @@ struct SelenePoint {
|
||||
|
||||
template<typename T>
|
||||
struct CResult {
|
||||
T value;
|
||||
T* value;
|
||||
void* err;
|
||||
};
|
||||
|
||||
|
@ -130,19 +130,19 @@ impl<'a, T> From<Slice<T>> for &'a [T] {
|
||||
|
||||
#[repr(C)]
|
||||
pub struct CResult<T, E> {
|
||||
value: T,
|
||||
value: *const T,
|
||||
err: *const E,
|
||||
}
|
||||
impl<T, E> CResult<T, E> {
|
||||
fn ok(value: T) -> Self {
|
||||
CResult {
|
||||
value,
|
||||
value: Box::into_raw(Box::new(value)),
|
||||
err: core::ptr::null(),
|
||||
}
|
||||
}
|
||||
fn err(default: T, err: E) -> Self {
|
||||
fn err(err: E) -> Self {
|
||||
CResult {
|
||||
value: default,
|
||||
value: core::ptr::null(),
|
||||
err: Box::into_raw(Box::new(err)),
|
||||
}
|
||||
}
|
||||
@ -166,10 +166,7 @@ pub extern "C" fn hash_grow_helios(
|
||||
if let Some(hash) = hash {
|
||||
CResult::ok(hash)
|
||||
} else {
|
||||
CResult::err(
|
||||
HeliosPoint::identity(),
|
||||
io::Error::new(io::ErrorKind::Other, "failed to grow hash"),
|
||||
)
|
||||
CResult::err(io::Error::new(io::ErrorKind::Other, "failed to grow hash"))
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,10 +213,7 @@ pub extern "C" fn hash_grow_selene(
|
||||
if let Some(hash) = hash {
|
||||
CResult::ok(hash)
|
||||
} else {
|
||||
CResult::err(
|
||||
SelenePoint::identity(),
|
||||
io::Error::new(io::ErrorKind::Other, "failed to grow hash"),
|
||||
)
|
||||
CResult::err(io::Error::new(io::ErrorKind::Other, "failed to grow hash"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,15 +51,18 @@ Helios::Point Helios::hash_grow(
|
||||
const Helios::Scalar &existing_child_at_offset,
|
||||
const Helios::Chunk &new_children) const
|
||||
{
|
||||
fcmp_rust::CResult<Helios::Point> res = fcmp_rust::hash_grow_helios(
|
||||
fcmp_rust::CResult<Helios::Point> result = fcmp_rust::hash_grow_helios(
|
||||
existing_hash,
|
||||
offset,
|
||||
existing_child_at_offset,
|
||||
new_children);
|
||||
if (res.err != 0) {
|
||||
if (result.err != nullptr) {
|
||||
throw std::runtime_error("failed to hash grow");
|
||||
}
|
||||
return res.value;
|
||||
typename Helios::Point res;
|
||||
memcpy(&res, result.value, sizeof(typename Selene::Point));
|
||||
free(result.value);
|
||||
return res;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
Helios::Point Helios::hash_trim(
|
||||
@ -85,15 +88,18 @@ Selene::Point Selene::hash_grow(
|
||||
const Selene::Scalar &existing_child_at_offset,
|
||||
const Selene::Chunk &new_children) const
|
||||
{
|
||||
fcmp_rust::CResult<Selene::Point> res = fcmp_rust::hash_grow_selene(
|
||||
fcmp_rust::CResult<Selene::Point> result = fcmp_rust::hash_grow_selene(
|
||||
existing_hash,
|
||||
offset,
|
||||
existing_child_at_offset,
|
||||
new_children);
|
||||
if (res.err != 0) {
|
||||
if (result.err != nullptr) {
|
||||
throw std::runtime_error("failed to hash grow");
|
||||
}
|
||||
return res.value;
|
||||
typename Selene::Point res;
|
||||
memcpy(&res, result.value, sizeof(typename Selene::Point));
|
||||
free(result.value);
|
||||
return res;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
Selene::Point Selene::hash_trim(
|
||||
|
Loading…
x
Reference in New Issue
Block a user