1
- use std:: slice;
2
- use std:: vec:: Vec ;
3
- use std:: ptr;
4
1
use std:: alloc:: { self , Layout } ;
5
2
use std:: mem;
3
+ use std:: ptr;
4
+ use std:: slice;
5
+ use std:: vec:: Vec ;
6
6
7
7
use crate :: JsValue ;
8
8
@@ -34,9 +34,7 @@ impl Slab {
34
34
if ret == self . data . len ( ) {
35
35
if self . data . len ( ) == self . data . capacity ( ) {
36
36
let extra = 128 ;
37
- let r = unsafe {
38
- __wbindgen_anyref_table_grow ( extra)
39
- } ;
37
+ let r = unsafe { __wbindgen_anyref_table_grow ( extra) } ;
40
38
if r == -1 {
41
39
internal_error ( "table grow failure" )
42
40
}
@@ -59,16 +57,8 @@ impl Slab {
59
57
if ptr. is_null ( ) {
60
58
internal_error ( "allocation failure" ) ;
61
59
}
62
- ptr:: copy_nonoverlapping (
63
- self . data . as_ptr ( ) ,
64
- ptr,
65
- self . data . len ( ) ,
66
- ) ;
67
- let new_vec = Vec :: from_raw_parts (
68
- ptr,
69
- self . data . len ( ) ,
70
- new_cap,
71
- ) ;
60
+ ptr:: copy_nonoverlapping ( self . data . as_ptr ( ) , ptr, self . data . len ( ) ) ;
61
+ let new_vec = Vec :: from_raw_parts ( ptr, self . data . len ( ) , new_cap) ;
72
62
let mut old = mem:: replace ( & mut self . data , new_vec) ;
73
63
old. set_len ( 0 ) ;
74
64
}
@@ -149,19 +139,19 @@ fn internal_error(msg: &str) -> ! {
149
139
// implementation that will be replaced once #55518 lands on stable.
150
140
#[ cfg( target_feature = "atomics" ) ]
151
141
mod tl {
152
- use std:: * ; // hack to get `thread_local!` to work
153
142
use super :: Slab ;
154
143
use std:: cell:: Cell ;
144
+ use std:: * ; // hack to get `thread_local!` to work
155
145
156
146
thread_local ! ( pub static HEAP_SLAB : Cell <Slab > = Cell :: new( Slab :: new( ) ) ) ;
157
147
}
158
148
159
149
#[ cfg( not( target_feature = "atomics" ) ) ]
160
150
mod tl {
151
+ use super :: Slab ;
161
152
use std:: alloc:: { self , Layout } ;
162
153
use std:: cell:: Cell ;
163
154
use std:: ptr;
164
- use super :: Slab ;
165
155
166
156
pub struct HeapSlab ;
167
157
pub static HEAP_SLAB : HeapSlab = HeapSlab ;
@@ -186,34 +176,38 @@ mod tl {
186
176
}
187
177
188
178
#[ no_mangle]
189
- pub extern fn __wbindgen_anyref_table_alloc ( ) -> usize {
190
- tl:: HEAP_SLAB . try_with ( |slot| {
191
- let mut slab = slot. replace ( Slab :: new ( ) ) ;
192
- let ret = slab. alloc ( ) ;
193
- slot. replace ( slab) ;
194
- ret
195
- } ) . unwrap_or_else ( |_| internal_error ( "tls access failure" ) )
179
+ pub extern "C" fn __wbindgen_anyref_table_alloc ( ) -> usize {
180
+ tl:: HEAP_SLAB
181
+ . try_with ( |slot| {
182
+ let mut slab = slot. replace ( Slab :: new ( ) ) ;
183
+ let ret = slab. alloc ( ) ;
184
+ slot. replace ( slab) ;
185
+ ret
186
+ } )
187
+ . unwrap_or_else ( |_| internal_error ( "tls access failure" ) )
196
188
}
197
189
198
190
#[ no_mangle]
199
- pub extern fn __wbindgen_anyref_table_dealloc ( idx : usize ) {
191
+ pub extern "C" fn __wbindgen_anyref_table_dealloc ( idx : usize ) {
200
192
if idx < super :: JSIDX_RESERVED as usize {
201
- return
193
+ return ;
202
194
}
203
195
// clear this value from the table so while the table slot is un-allocated
204
196
// we don't keep around a strong reference to a potentially large object
205
197
unsafe {
206
198
__wbindgen_anyref_table_set_null ( idx) ;
207
199
}
208
- tl:: HEAP_SLAB . try_with ( |slot| {
209
- let mut slab = slot. replace ( Slab :: new ( ) ) ;
210
- slab. dealloc ( idx) ;
211
- slot. replace ( slab) ;
212
- } ) . unwrap_or_else ( |_| internal_error ( "tls access failure" ) )
200
+ tl:: HEAP_SLAB
201
+ . try_with ( |slot| {
202
+ let mut slab = slot. replace ( Slab :: new ( ) ) ;
203
+ slab. dealloc ( idx) ;
204
+ slot. replace ( slab) ;
205
+ } )
206
+ . unwrap_or_else ( |_| internal_error ( "tls access failure" ) )
213
207
}
214
208
215
209
#[ no_mangle]
216
- pub unsafe extern fn __wbindgen_drop_anyref_slice ( ptr : * mut JsValue , len : usize ) {
210
+ pub unsafe extern "C" fn __wbindgen_drop_anyref_slice ( ptr : * mut JsValue , len : usize ) {
217
211
for slot in slice:: from_raw_parts_mut ( ptr, len) {
218
212
__wbindgen_anyref_table_dealloc ( slot. idx as usize ) ;
219
213
}
@@ -235,5 +229,4 @@ pub unsafe extern "C" fn __wbindgen_anyref_heap_live_count_impl() -> u32 {
235
229
236
230
// see comment in module above this in `link_mem_intrinsics`
237
231
#[ inline( never) ]
238
- pub fn link_intrinsics ( ) {
239
- }
232
+ pub fn link_intrinsics ( ) { }
0 commit comments