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

Issue #199: Put the closure in heap to avoid the stack overflowed in Debug #200

Closed
wants to merge 7 commits into from
9 changes: 7 additions & 2 deletions src/component/cyfs-base/src/codec/raw/raw_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ impl<'de, T: RawEncode + RawDecode<'de>> RawDecode<'de> for Vec<T> {

// HashSet<T>

impl<T: RawEncode> RawEncode for HashSet<T> {
impl<T: RawEncode + std::cmp::Ord> RawEncode for HashSet<T> {
fn raw_measure(&self, purpose: &Option<RawEncodePurpose>) -> BuckyResult<usize> {
let ulen = USize(self.len());
let mut bytes = ulen.raw_measure(purpose).unwrap();
Expand All @@ -757,7 +757,12 @@ impl<T: RawEncode> RawEncode for HashSet<T> {
) -> BuckyResult<&'a mut [u8]> {
let ulen = USize(self.len());
let mut buf = ulen.raw_encode(buf, purpose)?;
for e in self {

// stable sort
let mut values: Vec<&T> = self.iter().collect();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the change mentioned by #256, it should not be in this pull request

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort the values in ascending order, and encode the elements into the buffer. for Issue #256

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean it should be included in a new request for issue #256, and in the entire pull request, it seems, this is the only substantive change?

values.sort();

for e in values {
buf = e.raw_encode(buf, purpose)?;
}
Ok(buf)
Expand Down
22 changes: 17 additions & 5 deletions src/component/cyfs-base/src/objects/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,23 @@ impl AnyNamedObject {
))
}

fn raw_decode_group<'de>(buf: &'de [u8]) -> Result<(Self, &'de [u8]), BuckyError> {
let (group, buf) = Group::raw_decode(buf).map_err(|e| {
log::error!("AnyNamedObject::raw_decode/group error:{}", e);
fn raw_decode_simple_group<'de>(buf: &'de [u8]) -> Result<(Self, &'de [u8]), BuckyError> {
let (simple_group, buf) = SimpleGroup::raw_decode(buf).map_err(|e| {
log::error!("AnyNamedObject::raw_decode/simple_group error:{}", e);
e
})?;
Ok((AnyNamedObject::Standard(StandardObject::Group(group)), buf))
return Ok((
AnyNamedObject::Standard(StandardObject::SimpleGroup(simple_group)),
buf,
));
}

fn raw_decode_org<'de>(buf: &'de [u8]) -> Result<(Self, &'de [u8]), BuckyError> {
let (org, buf) = Org::raw_decode(buf).map_err(|e| {
log::error!("AnyNamedObject::raw_decode/org error:{}", e);
e
})?;
return Ok((AnyNamedObject::Standard(StandardObject::Org(org)), buf));
}

fn raw_decode_union_account<'de>(buf: &'de [u8]) -> Result<(Self, &'de [u8]), BuckyError> {
Expand Down Expand Up @@ -520,7 +531,6 @@ impl<'de> RawDecode<'de> for AnyNamedObject {
ObjectTypeCode::Device => Self::raw_decode_device(buf),
ObjectTypeCode::People => Self::raw_decode_people(buf),
ObjectTypeCode::AppGroup => Self::raw_decode_app_group(buf),
ObjectTypeCode::Group => Self::raw_decode_group(buf),
ObjectTypeCode::UnionAccount => Self::raw_decode_union_account(buf),
ObjectTypeCode::Chunk => {
unreachable!();
Expand All @@ -536,6 +546,8 @@ impl<'de> RawDecode<'de> for AnyNamedObject {
ObjectTypeCode::Custom => {
Self::raw_decode_custom(buf, obj_type_info.is_decapp_object())
}
ObjectTypeCode::SimpleGroup => Self::raw_decode_simple_group(buf),
ObjectTypeCode::Org => Self::raw_decode_org(buf),
}
}
}
Expand Down
Loading