19
19
issue = "27783" ) ]
20
20
#![ feature( allocator) ]
21
21
#![ feature( staged_api) ]
22
- #![ cfg_attr( target_os = "redox" , feature( libc) ) ]
23
- #![ cfg_attr( unix, feature( libc) ) ]
22
+ #![ cfg_attr( any( unix, target_os = "redox" ) , feature( libc) ) ]
24
23
25
24
// The minimum alignment guaranteed by the architecture. This value is used to
26
25
// add fast paths for low alignment values. In practice, the alignment is a
@@ -72,49 +71,7 @@ pub extern "C" fn __rust_usable_size(size: usize, align: usize) -> usize {
72
71
imp:: usable_size ( size, align)
73
72
}
74
73
75
- #[ cfg( target_os = "redox" ) ]
76
- mod imp {
77
- extern crate libc;
78
-
79
- use core:: cmp;
80
- use core:: ptr;
81
- use MIN_ALIGN ;
82
-
83
- pub unsafe fn allocate ( size : usize , _align : usize ) -> * mut u8 {
84
- libc:: malloc ( size as libc:: size_t ) as * mut u8
85
- }
86
-
87
- pub unsafe fn reallocate ( ptr : * mut u8 , old_size : usize , size : usize , align : usize ) -> * mut u8 {
88
- if align <= MIN_ALIGN {
89
- libc:: realloc ( ptr as * mut libc:: c_void , size as libc:: size_t ) as * mut u8
90
- } else {
91
- let new_ptr = allocate ( size, align) ;
92
- if !new_ptr. is_null ( ) {
93
- ptr:: copy ( ptr, new_ptr, cmp:: min ( size, old_size) ) ;
94
- deallocate ( ptr, old_size, align) ;
95
- }
96
- new_ptr
97
- }
98
- }
99
-
100
- pub unsafe fn reallocate_inplace ( _ptr : * mut u8 ,
101
- old_size : usize ,
102
- _size : usize ,
103
- _align : usize )
104
- -> usize {
105
- old_size
106
- }
107
-
108
- pub unsafe fn deallocate ( ptr : * mut u8 , _old_size : usize , _align : usize ) {
109
- libc:: free ( ptr as * mut libc:: c_void )
110
- }
111
-
112
- pub fn usable_size ( size : usize , _align : usize ) -> usize {
113
- size
114
- }
115
- }
116
-
117
- #[ cfg( any( unix) ) ]
74
+ #[ cfg( any( unix, target_os = "redox" ) ) ]
118
75
mod imp {
119
76
extern crate libc;
120
77
@@ -130,7 +87,7 @@ mod imp {
130
87
}
131
88
}
132
89
133
- #[ cfg( target_os = "android" ) ]
90
+ #[ cfg( any ( target_os = "android" , target_os = "redox" ) ) ]
134
91
unsafe fn aligned_malloc ( size : usize , align : usize ) -> * mut u8 {
135
92
// On android we currently target API level 9 which unfortunately
136
93
// doesn't have the `posix_memalign` API used below. Instead we use
@@ -152,7 +109,7 @@ mod imp {
152
109
libc:: memalign ( align as libc:: size_t , size as libc:: size_t ) as * mut u8
153
110
}
154
111
155
- #[ cfg( not( target_os = "android" ) ) ]
112
+ #[ cfg( not( any ( target_os = "android" , target_os = "redox" ) ) ) ]
156
113
unsafe fn aligned_malloc ( size : usize , align : usize ) -> * mut u8 {
157
114
let mut out = ptr:: null_mut ( ) ;
158
115
let ret = libc:: posix_memalign ( & mut out, align as libc:: size_t , size as libc:: size_t ) ;
0 commit comments