@@ -173,15 +173,15 @@ extern "C" {
173
173
/// function or stderr by default.
174
174
///
175
175
/// Most detailed when using a debug build.
176
- pub fn mi_stats_print ( _: * const c_void ) ;
176
+ pub fn mi_stats_print ( _: * mut c_void ) ;
177
177
178
178
/// Print the main statistics.
179
179
///
180
180
/// Pass `None` for `out` to use the default. If `out` is provided, `arc` is
181
181
/// passed as it's second parameter.
182
182
///
183
183
/// Most detailed when using a debug build.
184
- pub fn mi_stats_print_out ( out : Option < mi_output_fun > , arg : * mut c_void ) ;
184
+ pub fn mi_stats_print_out ( out : mi_output_fun , arg : * mut c_void ) ;
185
185
186
186
/// Reset statistics.
187
187
///
@@ -193,12 +193,23 @@ extern "C" {
193
193
/// Note: This function is thread safe.
194
194
pub fn mi_stats_merge ( ) ;
195
195
196
+ /// Return the mimalloc version number.
197
+ ///
198
+ /// For example version 1.6.3 would return the number `163`.
199
+ pub fn mi_version ( ) -> c_int ;
200
+
196
201
/// Initialize mimalloc on a thread.
197
202
///
198
203
/// Should not be used as on most systems (pthreads, windows) this is done
199
204
/// automatically.
200
205
pub fn mi_thread_init ( ) ;
201
206
207
+ /// Initialize the process.
208
+ ///
209
+ /// Should not be used on most systems, as it's called by thread_init or the
210
+ /// process loader.
211
+ pub fn mi_process_init ( ) ;
212
+
202
213
/// Uninitialize mimalloc on a thread.
203
214
///
204
215
/// Should not be used as on most systems (pthreads, windows) this is done
@@ -216,7 +227,7 @@ extern "C" {
216
227
/// Most detailed when using a debug build.
217
228
///
218
229
/// Note: This function is thread safe.
219
- pub fn mi_thread_stats_print_out ( out : Option < mi_output_fun > , arg : * mut c_void ) ;
230
+ pub fn mi_thread_stats_print_out ( out : mi_output_fun , arg : * mut c_void ) ;
220
231
221
232
/// Register an output function.
222
233
///
@@ -227,7 +238,7 @@ extern "C" {
227
238
/// like verbose or warning messages.
228
239
///
229
240
/// Note: This function is thread safe.
230
- pub fn mi_register_output ( out : Option < mi_output_fun > , arg : * mut c_void ) ;
241
+ pub fn mi_register_output ( out : mi_output_fun , arg : * mut c_void ) ;
231
242
232
243
/// Register a deferred free function.
233
244
///
@@ -255,7 +266,7 @@ extern "C" {
255
266
/// At most one `deferred_free` function can be active.
256
267
///
257
268
/// Note: This function is thread safe.
258
- pub fn mi_register_deferred_free ( out : Option < mi_deferred_free_fun > , arg : * mut c_void ) ;
269
+ pub fn mi_register_deferred_free ( out : mi_deferred_free_fun , arg : * mut c_void ) ;
259
270
260
271
/// Register an error callback function.
261
272
///
@@ -278,13 +289,13 @@ extern "C" {
278
289
/// - `EINVAL` (22): Trying to free or re-allocate an invalid pointer.
279
290
///
280
291
/// Note: This function is thread safe.
281
- pub fn mi_register_error ( out : Option < mi_error_fun > , arg : * mut c_void ) ;
292
+ pub fn mi_register_error ( out : mi_error_fun , arg : * mut c_void ) ;
282
293
}
283
294
284
295
/// An output callback. Must be thread-safe.
285
296
///
286
297
/// See [`mi_stats_print_out`], [`mi_thread_stats_print_out`], [`mi_register_output`]
287
- pub type mi_output_fun = unsafe extern "C" fn ( msg : * const c_char , arg : * mut c_void ) ;
298
+ pub type mi_output_fun = Option < unsafe extern "C" fn ( msg : * const c_char , arg : * mut c_void ) > ;
288
299
289
300
/// Type of deferred free functions. Must be thread-safe.
290
301
///
@@ -294,27 +305,22 @@ pub type mi_output_fun = unsafe extern "C" fn(msg: *const c_char, arg: *mut c_vo
294
305
///
295
306
/// See [`mi_register_deferred_free`]
296
307
pub type mi_deferred_free_fun =
297
- unsafe extern "C" fn ( force : bool , heartbeat : c_ulonglong , arg : * mut c_void ) ;
308
+ Option < unsafe extern "C" fn ( force : bool , heartbeat : c_ulonglong , arg : * mut c_void ) > ;
298
309
299
310
/// Type of error callback functions. Must be thread-safe.
300
311
///
301
312
/// - `err`: Error code (see [`mi_register_error`] for a list).
302
313
/// - `arg`: Argument that was passed at registration to hold extra state.
303
314
///
304
315
/// See [`mi_register_error`]
305
- pub type mi_error_fun = unsafe extern "C" fn ( code : c_int , arg : * mut c_void ) ;
306
-
307
- /// Runtime options. Only exists to make ctest happy since this was defined as
308
- /// `typedef enum mi_option_e { ... } mi_option_t;`...
309
- #[ doc( hidden) ]
310
- pub type mi_option_e = c_int ;
316
+ pub type mi_error_fun = Option < unsafe extern "C" fn ( code : c_int , arg : * mut c_void ) > ;
311
317
312
318
/// Runtime options. All options are false by default.
313
319
///
314
320
/// Note: Currently experimental options (values > `mi_option_verbose` are not
315
321
/// given named constants), as they may change and make exposing a stable API
316
322
/// difficult.
317
- pub type mi_option_t = mi_option_e ;
323
+ pub type mi_option_t = c_int ;
318
324
319
325
// Note: mimalloc doc website seems to have the order of show_stats and
320
326
// show_errors reversed as of 1.6.3, however what I have here is correct:
@@ -336,7 +342,7 @@ extern "C" {
336
342
/// Returns true if the provided option is enabled.
337
343
///
338
344
/// Note: this function is not thread safe.
339
- pub fn mi_option_enabled ( option : mi_option_t ) -> bool ;
345
+ pub fn mi_option_is_enabled ( option : mi_option_t ) -> bool ;
340
346
341
347
/// Enable or disable the given option.
342
348
///
@@ -391,14 +397,8 @@ extern "C" {
391
397
///
392
398
/// Note: this function is not thread safe.
393
399
pub fn mi_option_set_default ( option : mi_option_t , value : c_long ) ;
394
-
395
400
}
396
401
397
- #[ doc( hidden) ]
398
- pub type mi_heap_s = mi_heap_t ;
399
- #[ doc( hidden) ]
400
- pub type mi_heap_area_s = mi_heap_area_t ;
401
-
402
402
/// First-class heaps that can be destroyed in one go.
403
403
///
404
404
/// Note: The pointers allocated out of a heap can be be freed using
@@ -424,17 +424,13 @@ pub type mi_heap_area_s = mi_heap_area_t;
424
424
/// mi::mi_heap_delete(h);
425
425
/// }
426
426
/// ```
427
- #[ repr( C ) ]
428
- pub struct mi_heap_t {
429
- _priv : [ u8 ; 0 ] ,
430
- }
427
+ pub enum mi_heap_t { }
431
428
432
429
/// An area of heap space contains blocks of a single size.
433
430
///
434
431
/// The bytes in freed blocks are `committed - used`.
435
432
#[ repr( C ) ]
436
433
#[ derive( Debug , Clone , Copy ) ]
437
- #[ non_exhaustive]
438
434
pub struct mi_heap_area_t {
439
435
/// Start of the area containing heap blocks.
440
436
pub blocks : * mut c_void ,
@@ -448,34 +444,22 @@ pub struct mi_heap_area_t {
448
444
pub block_size : usize ,
449
445
}
450
446
451
- // Provide a default impl so that the `non_exhaustive` bound is not too painful.
452
- impl Default for mi_heap_area_t {
453
- #[ inline]
454
- fn default ( ) -> Self {
455
- Self {
456
- blocks : core:: ptr:: null_mut ( ) ,
457
- reserved : 0 ,
458
- committed : 0 ,
459
- used : 0 ,
460
- block_size : 0 ,
461
- }
462
- }
463
- }
464
-
465
447
/// Visitor function passed to [`mi_heap_visit_blocks`]
466
448
///
467
449
/// Should return `true` to continue, and `false` to stop visiting (i.e. break)
468
450
///
469
451
/// This function is always first called for every `area` with `block` as a null
470
452
/// pointer. If `visit_all_blocks` was `true`, the function is then called for
471
453
/// every allocated block in that area.
472
- pub type mi_block_visit_fun = unsafe extern "C" fn (
473
- heap : * const mi_heap_t ,
474
- area : * const mi_heap_area_t ,
475
- block : * mut c_void ,
476
- block_size : usize ,
477
- arg : * mut c_void ,
478
- ) -> bool ;
454
+ pub type mi_block_visit_fun = Option <
455
+ unsafe extern "C" fn (
456
+ heap : * const mi_heap_t ,
457
+ area : * const mi_heap_area_t ,
458
+ block : * mut c_void ,
459
+ block_size : usize ,
460
+ arg : * mut c_void ,
461
+ ) -> bool ,
462
+ > ;
479
463
480
464
extern "C" {
481
465
/// Create a new heap that can be used for allocation.
@@ -517,7 +501,7 @@ extern "C" {
517
501
518
502
/// Release outstanding resources in a specific heap.
519
503
///
520
- /// Similar to to [`mi_collect`], but takes the heap to collect as an argument .
504
+ /// See also [`mi_collect`].
521
505
pub fn mi_heap_collect ( heap : * mut mi_heap_t , force : bool ) ;
522
506
523
507
/// Equivalent to [`mi_malloc`](crate::mi_malloc), but allocates out of the
@@ -689,6 +673,8 @@ extern "C" {
689
673
/// `arg` is an extra argument passed into the `visitor`.
690
674
///
691
675
/// Returns `true` if all areas and blocks were visited.
676
+ ///
677
+ /// Passing a `None` visitor is allowed, and is a no-op.
692
678
pub fn mi_heap_visit_blocks (
693
679
heap : * const mi_heap_t ,
694
680
visit_all_blocks : bool ,
0 commit comments