Touch up merge for cross-compilation fixes

This commit is contained in:
j-berman 2024-07-25 18:06:53 -07:00
parent 23be5f6c28
commit aadea07b51
2 changed files with 27 additions and 19 deletions

View File

@ -176,7 +176,7 @@ pub extern "C" fn hash_trim_helios(
offset: usize, offset: usize,
children: HeliosScalarSlice, children: HeliosScalarSlice,
child_to_grow_back: HeliosScalar, child_to_grow_back: HeliosScalar,
) -> CResult<HeliosPoint, io::Error> { ) -> CResult<HeliosPoint, ()> {
let hash = hash_trim( let hash = hash_trim(
helios_generators(), helios_generators(),
existing_hash, existing_hash,
@ -188,10 +188,7 @@ pub extern "C" fn hash_trim_helios(
if let Some(hash) = hash { if let Some(hash) = hash {
CResult::ok(hash) CResult::ok(hash)
} else { } else {
CResult::err( CResult::err(())
HeliosPoint::identity(),
io::Error::new(io::ErrorKind::Other, "failed to trim hash"),
)
} }
} }
@ -223,7 +220,7 @@ pub extern "C" fn hash_trim_selene(
offset: usize, offset: usize,
children: SeleneScalarSlice, children: SeleneScalarSlice,
child_to_grow_back: SeleneScalar, child_to_grow_back: SeleneScalar,
) -> CResult<SelenePoint, io::Error> { ) -> CResult<SelenePoint, ()> {
let hash = hash_trim( let hash = hash_trim(
selene_generators(), selene_generators(),
existing_hash, existing_hash,
@ -235,10 +232,7 @@ pub extern "C" fn hash_trim_selene(
if let Some(hash) = hash { if let Some(hash) = hash {
CResult::ok(hash) CResult::ok(hash)
} else { } else {
CResult::err( CResult::err(())
SelenePoint::identity(),
io::Error::new(io::ErrorKind::Other, "failed to trim hash"),
)
} }
} }

View File

@ -64,7 +64,7 @@ Helios::Point Helios::hash_grow(
} }
typename Helios::Point res; typename Helios::Point res;
memcpy(&res, result.value, sizeof(typename Selene::Point)); memcpy(&res, result.value, sizeof(typename Helios::Point));
free(result.value); free(result.value);
return res; return res;
} }
@ -75,15 +75,22 @@ Helios::Point Helios::hash_trim(
const Helios::Chunk &children, const Helios::Chunk &children,
const Helios::Scalar &child_to_grow_back) const const Helios::Scalar &child_to_grow_back) const
{ {
fcmp_rust::CResult<Helios::Point> res = fcmp_rust::hash_trim_helios( auto result = fcmp_rust::hash_trim_helios(
existing_hash, existing_hash,
offset, offset,
children, children,
child_to_grow_back); child_to_grow_back);
if (res.err != 0) {
throw std::runtime_error("failed to hash trim"); if (result.err != nullptr)
{
free(result.err);
throw std::runtime_error("failed to hash trim");
} }
return res.value;
typename Helios::Point res;
memcpy(&res, result.value, sizeof(typename Helios::Point));
free(result.value);
return res;
} }
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
Selene::Point Selene::hash_grow( Selene::Point Selene::hash_grow(
@ -116,15 +123,22 @@ Selene::Point Selene::hash_trim(
const Selene::Chunk &children, const Selene::Chunk &children,
const Selene::Scalar &child_to_grow_back) const const Selene::Scalar &child_to_grow_back) const
{ {
fcmp_rust::CResult<Selene::Point> res = fcmp_rust::hash_trim_selene( auto result = fcmp_rust::hash_trim_selene(
existing_hash, existing_hash,
offset, offset,
children, children,
child_to_grow_back); child_to_grow_back);
if (res.err != 0) {
throw std::runtime_error("failed to hash trim"); if (result.err != nullptr)
{
free(result.err);
throw std::runtime_error("failed to hash trim");
} }
return res.value;
typename Selene::Point res;
memcpy(&res, result.value, sizeof(typename Selene::Point));
free(result.value);
return res;
} }
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
Helios::Scalar Helios::zero_scalar() const Helios::Scalar Helios::zero_scalar() const