From a25bb62b58564c7205fd55f48c3aaebc5a1defe0 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Mon, 10 Jun 2024 16:24:46 +0300 Subject: [PATCH] managed dealloc - api --- .../base/src/api/managed_types/managed_type_api_impl.rs | 6 ++++++ framework/base/src/types/managed/basic/managed_buffer.rs | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/framework/base/src/api/managed_types/managed_type_api_impl.rs b/framework/base/src/api/managed_types/managed_type_api_impl.rs index 1d2ead32ec..985678da17 100644 --- a/framework/base/src/api/managed_types/managed_type_api_impl.rs +++ b/framework/base/src/api/managed_types/managed_type_api_impl.rs @@ -65,4 +65,10 @@ pub trait ManagedTypeApiImpl: fn get_token_ticker_len(&self, token_id_len: usize) -> usize { super::token_identifier_util::get_token_ticker_len(token_id_len) } + + fn drop_managed_buffer(&self, _handle: Self::ManagedBufferHandle) {} + fn drop_big_float(&self, _handle: Self::BigFloatHandle) {} + fn drop_big_int(&self, _handle: Self::BigIntHandle) {} + fn drop_elliptic_curve(&self, _handle: Self::EllipticCurveHandle) {} + fn drop_managed_map(&self, _handle: Self::ManagedMapHandle) {} } diff --git a/framework/base/src/types/managed/basic/managed_buffer.rs b/framework/base/src/types/managed/basic/managed_buffer.rs index d232776b2e..8152080317 100644 --- a/framework/base/src/types/managed/basic/managed_buffer.rs +++ b/framework/base/src/types/managed/basic/managed_buffer.rs @@ -1,8 +1,7 @@ use crate::{ abi::{TypeAbi, TypeAbiFrom, TypeName}, api::{ - use_raw_handle, ErrorApiImpl, HandleConstraints, InvalidSliceError, ManagedBufferApiImpl, - ManagedTypeApi, StaticVarApiImpl, + use_raw_handle, ErrorApiImpl, HandleConstraints, InvalidSliceError, ManagedBufferApiImpl, ManagedTypeApi, ManagedTypeApiImpl, StaticVarApiImpl }, codec::{ DecodeErrorHandler, Empty, EncodeErrorHandler, NestedDecode, NestedDecodeInput, @@ -350,6 +349,12 @@ impl Clone for ManagedBuffer { } } +impl Drop for ManagedBuffer { + fn drop(&mut self) { + M::managed_type_impl().drop_managed_buffer(self.get_handle()); + } +} + impl PartialEq for ManagedBuffer { #[inline] fn eq(&self, other: &Self) -> bool {