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

Marked reserve function as unsafe #426

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/webcore/global_arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn serialize_value< 'a >( value: Value ) -> SerializedValue< 'a > {
}

#[inline]
pub fn reserve< 'a, T >( length: usize ) -> RelativeSlice< 'a, T > {
pub unsafe fn reserve< 'a, T >( length: usize ) -> RelativeSlice< 'a, T > {
unsafe {
let offset = reserve_impl( length * mem::size_of::< T >(), mem::align_of::< T >() );
debug_assert_eq!( ARENA.memory.offset( offset as isize ) as usize % mem::align_of::< T >(), 0 );
Expand Down
6 changes: 3 additions & 3 deletions src/webcore/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ impl< T: JsSerialize > JsSerialize for [T] {
#[doc(hidden)]
#[inline]
fn _into_js< 'a >( &'a self ) -> SerializedValue< 'a > {
let mut output = global_arena::reserve( self.len() );
let mut output = unsafe { global_arena::reserve( self.len() ) };
for value in self {
unsafe {
output.append( value._into_js() );
Expand All @@ -734,8 +734,8 @@ impl< T: JsSerialize > JsSerialize for Vec< T > {
__js_serializable_boilerplate!( impl< T > for Vec< T > where T: JsSerialize );

fn object_into_js< 'a, K: AsRef< str >, V: 'a + JsSerialize, I: Iterator< Item = (K, &'a V) > + ExactSizeIterator >( iter: I ) -> SerializedValue< 'a > {
let mut keys = global_arena::reserve( iter.len() );
let mut values = global_arena::reserve( iter.len() );
let mut keys = unsafe { global_arena::reserve( iter.len() ) };
let mut values = unsafe { global_arena::reserve( iter.len() ) };
for (key, value) in iter {
unsafe {
keys.append( key.as_ref()._into_js().as_string().clone() );
Expand Down