1
1
//! Low level memory allocation.
2
- #[ cfg( not( target_os = "windows" ) ) ]
2
+ #[ cfg( not( any ( target_family = "unix" , target_os = "windows" ) ) ) ]
3
3
extern crate alloc;
4
+ #[ cfg( target_family = "unix" ) ]
5
+ use crate :: os:: unix:: alloc:: {
6
+ nstd_os_unix_alloc_allocate, nstd_os_unix_alloc_allocate_zeroed, nstd_os_unix_alloc_deallocate,
7
+ nstd_os_unix_alloc_reallocate,
8
+ } ;
4
9
#[ cfg( target_os = "windows" ) ]
5
10
use crate :: os:: windows:: alloc:: {
6
11
nstd_os_windows_alloc_allocate, nstd_os_windows_alloc_allocate_zeroed,
@@ -70,12 +75,16 @@ impl NSTDAllocError {
70
75
#[ inline]
71
76
#[ cfg_attr( feature = "clib" , no_mangle) ]
72
77
pub unsafe extern "C" fn nstd_alloc_allocate ( size : NSTDUInt ) -> NSTDAnyMut {
73
- #[ cfg( not( target_os = "windows" ) ) ]
78
+ #[ cfg( not( any ( target_family = "unix" , target_os = "windows" ) ) ) ]
74
79
{
75
80
use alloc:: alloc:: Layout ;
76
81
let layout = Layout :: from_size_align_unchecked ( size, 1 ) ;
77
82
alloc:: alloc:: alloc ( layout) . cast ( )
78
83
}
84
+ #[ cfg( target_family = "unix" ) ]
85
+ {
86
+ nstd_os_unix_alloc_allocate ( size)
87
+ }
79
88
#[ cfg( target_os = "windows" ) ]
80
89
{
81
90
nstd_os_windows_alloc_allocate ( size)
@@ -114,12 +123,16 @@ pub unsafe extern "C" fn nstd_alloc_allocate(size: NSTDUInt) -> NSTDAnyMut {
114
123
#[ inline]
115
124
#[ cfg_attr( feature = "clib" , no_mangle) ]
116
125
pub unsafe extern "C" fn nstd_alloc_allocate_zeroed ( size : NSTDUInt ) -> NSTDAnyMut {
117
- #[ cfg( not( target_os = "windows" ) ) ]
126
+ #[ cfg( not( any ( target_family = "unix" , target_os = "windows" ) ) ) ]
118
127
{
119
128
use alloc:: alloc:: Layout ;
120
129
let layout = Layout :: from_size_align_unchecked ( size, 1 ) ;
121
130
alloc:: alloc:: alloc_zeroed ( layout) . cast ( )
122
131
}
132
+ #[ cfg( target_family = "unix" ) ]
133
+ {
134
+ nstd_os_unix_alloc_allocate_zeroed ( size)
135
+ }
123
136
#[ cfg( target_os = "windows" ) ]
124
137
{
125
138
nstd_os_windows_alloc_allocate_zeroed ( size)
@@ -175,13 +188,16 @@ pub unsafe extern "C" fn nstd_alloc_allocate_zeroed(size: NSTDUInt) -> NSTDAnyMu
175
188
/// ```
176
189
#[ inline]
177
190
#[ cfg_attr( feature = "clib" , no_mangle) ]
178
- #[ cfg_attr( target_os = "windows" , allow( unused_variables) ) ]
191
+ #[ cfg_attr(
192
+ any( target_family = "unix" , target_os = "windows" ) ,
193
+ allow( unused_variables)
194
+ ) ]
179
195
pub unsafe extern "C" fn nstd_alloc_reallocate (
180
196
ptr : & mut NSTDAnyMut ,
181
197
size : NSTDUInt ,
182
198
new_size : NSTDUInt ,
183
199
) -> NSTDAllocError {
184
- #[ cfg( not( target_os = "windows" ) ) ]
200
+ #[ cfg( not( any ( target_family = "unix" , target_os = "windows" ) ) ) ]
185
201
{
186
202
use alloc:: alloc:: Layout ;
187
203
let layout = Layout :: from_size_align_unchecked ( size, 1 ) ;
@@ -192,6 +208,13 @@ pub unsafe extern "C" fn nstd_alloc_reallocate(
192
208
}
193
209
NSTDAllocError :: NSTD_ALLOC_ERROR_OUT_OF_MEMORY
194
210
}
211
+ #[ cfg( target_family = "unix" ) ]
212
+ {
213
+ match nstd_os_unix_alloc_reallocate ( ptr, new_size) {
214
+ 0 => NSTDAllocError :: NSTD_ALLOC_ERROR_NONE ,
215
+ _ => NSTDAllocError :: NSTD_ALLOC_ERROR_OUT_OF_MEMORY ,
216
+ }
217
+ }
195
218
#[ cfg( target_os = "windows" ) ]
196
219
{
197
220
NSTDAllocError :: from_windows ( nstd_os_windows_alloc_reallocate ( ptr, new_size) )
@@ -225,16 +248,23 @@ pub unsafe extern "C" fn nstd_alloc_reallocate(
225
248
/// ```
226
249
#[ inline]
227
250
#[ cfg_attr( feature = "clib" , no_mangle) ]
228
- #[ cfg_attr( target_os = "windows" , allow( unused_variables) ) ]
251
+ #[ cfg_attr(
252
+ any( target_family = "unix" , target_os = "windows" ) ,
253
+ allow( unused_variables)
254
+ ) ]
229
255
pub unsafe extern "C" fn nstd_alloc_deallocate ( ptr : & mut NSTDAnyMut , size : NSTDUInt ) {
230
- #[ cfg( not( target_os = "windows" ) ) ]
256
+ #[ cfg( not( any ( target_family = "unix" , target_os = "windows" ) ) ) ]
231
257
{
232
258
use crate :: NSTD_NULL ;
233
259
use alloc:: alloc:: Layout ;
234
260
let layout = Layout :: from_size_align_unchecked ( size, 1 ) ;
235
261
alloc:: alloc:: dealloc ( ( * ptr) . cast ( ) , layout) ;
236
262
* ptr = NSTD_NULL ;
237
263
}
264
+ #[ cfg( target_family = "unix" ) ]
265
+ {
266
+ nstd_os_unix_alloc_deallocate ( ptr) ;
267
+ }
238
268
#[ cfg( target_os = "windows" ) ]
239
269
{
240
270
nstd_os_windows_alloc_deallocate ( ptr) ;
0 commit comments