@@ -58,33 +58,17 @@ unsafe impl GlobalAlloc for System {
58
58
}
59
59
}
60
60
61
- cfg_if:: cfg_if! {
62
- // We use posix_memalign wherever possible, but not all targets have that function.
63
- if #[ cfg( any(
64
- target_os = "redox" ,
65
- target_os = "espidf" ,
66
- target_os = "horizon" ,
67
- target_os = "vita" ,
68
- ) ) ] {
69
- #[ inline]
70
- unsafe fn aligned_malloc( layout: & Layout ) -> * mut u8 {
71
- libc:: memalign( layout. align( ) , layout. size( ) ) as * mut u8
72
- }
73
- } else {
74
- #[ inline]
75
- unsafe fn aligned_malloc( layout: & Layout ) -> * mut u8 {
76
- let mut out = ptr:: null_mut( ) ;
77
- // We prefer posix_memalign over aligned_malloc since with aligned_malloc,
78
- // implementations are making almost arbitrary choices for which alignments are
79
- // "supported", making it hard to use. For instance, some implementations require the
80
- // size to be a multiple of the alignment (wasi emmalloc), while others require the
81
- // alignment to be at least the pointer size (Illumos, macOS) -- which may or may not be
82
- // standards-compliant, but that does not help us.
83
- // posix_memalign only has one, clear requirement: that the alignment be a multiple of
84
- // `sizeof(void*)`. Since these are all powers of 2, we can just use max.
85
- let align = layout. align( ) . max( crate :: mem:: size_of:: <usize >( ) ) ;
86
- let ret = libc:: posix_memalign( & mut out, align, layout. size( ) ) ;
87
- if ret != 0 { ptr:: null_mut( ) } else { out as * mut u8 }
88
- }
89
- }
61
+ unsafe fn aligned_malloc ( layout : & Layout ) -> * mut u8 {
62
+ let mut out = ptr:: null_mut ( ) ;
63
+ // We prefer posix_memalign over aligned_malloc since it is more widely available, and since
64
+ // with aligned_malloc, implementations are making almost arbitrary choices for which alignments
65
+ // are "supported", making it hard to use. For instance, some implementations require the size
66
+ // to be a multiple of the alignment (wasi emmalloc), while others require the alignment to be
67
+ // at least the pointer size (Illumos, macOS) -- which may or may not be standards-compliant,
68
+ // but that does not help us.
69
+ // posix_memalign only has one, clear requirement: that the alignment be a multiple of
70
+ // `sizeof(void*)`. Since these are all powers of 2, we can just use max.
71
+ let align = layout. align ( ) . max ( crate :: mem:: size_of :: < usize > ( ) ) ;
72
+ let ret = libc:: posix_memalign ( & mut out, align, layout. size ( ) ) ;
73
+ if ret != 0 { ptr:: null_mut ( ) } else { out as * mut u8 }
90
74
}
0 commit comments