use void * to try to fix CResult

This commit is contained in:
j-berman 2024-05-24 19:12:08 -07:00
parent af4de996cb
commit d6ca63618e
2 changed files with 17 additions and 15 deletions

View file

@ -72,9 +72,8 @@ struct SelenePoint {
// ----- End deps C bindings ----- // ----- End deps C bindings -----
template<typename T>
struct CResult { struct CResult {
T* value; void* value;
void* err; void* err;
}; };
@ -111,17 +110,12 @@ HeliosScalar helios_zero_scalar();
SeleneScalar selene_zero_scalar(); SeleneScalar selene_zero_scalar();
CResult<HeliosPoint> hash_grow_helios(HeliosPoint existing_hash, CResult hash_grow_helios(HeliosPoint existing_hash,
uintptr_t offset, uintptr_t offset,
HeliosScalar existing_child_at_offset, HeliosScalar existing_child_at_offset,
HeliosScalarSlice new_children); HeliosScalarSlice new_children);
CResult<HeliosPoint> hash_trim_helios(HeliosPoint existing_hash, CResult hash_grow_selene(SelenePoint existing_hash,
uintptr_t offset,
HeliosScalarSlice children,
HeliosScalar child_to_grow_back);
CResult<SelenePoint> hash_grow_selene(SelenePoint existing_hash,
uintptr_t offset, uintptr_t offset,
SeleneScalar existing_child_at_offset, SeleneScalar existing_child_at_offset,
SeleneScalarSlice new_children); SeleneScalarSlice new_children);

View file

@ -51,14 +51,18 @@ Helios::Point Helios::hash_grow(
const Helios::Scalar &existing_child_at_offset, const Helios::Scalar &existing_child_at_offset,
const Helios::Chunk &new_children) const const Helios::Chunk &new_children) const
{ {
fcmp_rust::CResult<Helios::Point> result = fcmp_rust::hash_grow_helios( auto result = fcmp_rust::hash_grow_helios(
existing_hash, existing_hash,
offset, offset,
existing_child_at_offset, existing_child_at_offset,
new_children); new_children);
if (result.err != nullptr) {
if (result.err != nullptr)
{
free(result.err);
throw std::runtime_error("failed to hash grow"); throw std::runtime_error("failed to hash grow");
} }
typename Helios::Point res; typename Helios::Point res;
memcpy(&res, result.value, sizeof(typename Selene::Point)); memcpy(&res, result.value, sizeof(typename Selene::Point));
free(result.value); free(result.value);
@ -88,14 +92,18 @@ Selene::Point Selene::hash_grow(
const Selene::Scalar &existing_child_at_offset, const Selene::Scalar &existing_child_at_offset,
const Selene::Chunk &new_children) const const Selene::Chunk &new_children) const
{ {
fcmp_rust::CResult<Selene::Point> result = fcmp_rust::hash_grow_selene( auto result = fcmp_rust::hash_grow_selene(
existing_hash, existing_hash,
offset, offset,
existing_child_at_offset, existing_child_at_offset,
new_children); new_children);
if (result.err != nullptr) {
if (result.err != nullptr)
{
free(result.err);
throw std::runtime_error("failed to hash grow"); throw std::runtime_error("failed to hash grow");
} }
typename Selene::Point res; typename Selene::Point res;
memcpy(&res, result.value, sizeof(typename Selene::Point)); memcpy(&res, result.value, sizeof(typename Selene::Point));
free(result.value); free(result.value);