-
Notifications
You must be signed in to change notification settings - Fork 227
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
The scope of the unsafe block can be appropriately reduced #273
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2727,16 +2727,16 @@ impl <'a> PointerBuilder<'a> { | |
wire_helpers::set_struct_pointer( | ||
self.arena, | ||
self.segment_id, self.cap_table, self.pointer, *value, canonicalize)?; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation |
||
Ok(()) | ||
} | ||
} | ||
|
||
pub fn set_list(&self, value: &ListReader, canonicalize: bool) -> Result<()> { | ||
unsafe { | ||
wire_helpers::set_list_pointer(self.arena, self.segment_id, | ||
self.cap_table, self.pointer, *value, canonicalize)?; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation |
||
Ok(()) | ||
} | ||
} | ||
|
||
pub fn set_text(&self, value: &str) { | ||
|
@@ -3102,33 +3102,33 @@ impl <'a> StructBuilder<'a> { | |
return Ok(()) | ||
} | ||
|
||
unsafe { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we remove this |
||
if self.data_size > shared_data_size { | ||
// Since the target is larger than the source, make sure to zero out the extra bits that the | ||
// source doesn't have. | ||
if self.data_size == 1 { | ||
self.set_bool_field(0, false); | ||
} else { | ||
let unshared = self.data.offset((shared_data_size / BITS_PER_BYTE as u32) as isize); | ||
ptr::write_bytes(unshared, 0, ((self.data_size - shared_data_size) / BITS_PER_BYTE as u32) as usize); | ||
let unshared = unsafe { self.data.offset((shared_data_size / BITS_PER_BYTE as u32) as isize) }; | ||
unsafe { ptr::write_bytes(unshared, 0, ((self.data_size - shared_data_size) / BITS_PER_BYTE as u32) as usize) }; | ||
} | ||
} | ||
|
||
// Copy over the shared part. | ||
if shared_data_size == 1 { | ||
self.set_bool_field(0, other.get_bool_field(0)); | ||
} else { | ||
ptr::copy_nonoverlapping(other.data, self.data, (shared_data_size / BITS_PER_BYTE as u32) as usize); | ||
unsafe { ptr::copy_nonoverlapping(other.data, self.data, (shared_data_size / BITS_PER_BYTE as u32) as usize) }; | ||
} | ||
|
||
// Zero out all pointers in the target. | ||
for i in 0..self.pointer_count as isize { | ||
wire_helpers::zero_object(self.arena, self.segment_id, self.pointers.offset(i) as *mut _); | ||
unsafe { wire_helpers::zero_object(self.arena, self.segment_id, self.pointers.offset(i) as *mut _) }; | ||
} | ||
ptr::write_bytes(self.pointers, 0u8, self.pointer_count as usize); | ||
unsafe { ptr::write_bytes(self.pointers, 0u8, self.pointer_count as usize) }; | ||
|
||
for i in 0..shared_pointer_count as isize { | ||
wire_helpers::copy_pointer(self.arena, | ||
unsafe { wire_helpers::copy_pointer(self.arena, | ||
self.segment_id, | ||
self.cap_table, | ||
self.pointers.offset(i), | ||
|
@@ -3137,9 +3137,9 @@ impl <'a> StructBuilder<'a> { | |
other.cap_table, | ||
other.pointers.offset(i), | ||
other.nesting_limit, | ||
false)?; | ||
false)? }; | ||
} | ||
} | ||
|
||
|
||
Ok(()) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the indentation is wrong here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #305