@@ -83,12 +83,24 @@ pub fn get_type_desc<T>() -> *TypeDesc {
83
83
unsafe { rusti:: get_tydesc :: < T > ( ) as * TypeDesc }
84
84
}
85
85
86
+ /// Returns a pointer to a type descriptor.
87
+ #[ inline( always) ]
88
+ pub fn get_type_desc_val < T > ( _val : & T ) -> * TypeDesc {
89
+ get_type_desc :: < T > ( )
90
+ }
91
+
86
92
/// Returns the size of a type
87
93
#[ inline( always) ]
88
94
pub fn size_of < T > ( ) -> uint {
89
95
unsafe { rusti:: size_of :: < T > ( ) }
90
96
}
91
97
98
+ /// Returns the size of the type that `_val` points to
99
+ #[ inline( always) ]
100
+ pub fn size_of_val < T > ( _val : & T ) -> uint {
101
+ size_of :: < T > ( )
102
+ }
103
+
92
104
/**
93
105
* Returns the size of a type, or 1 if the actual size is zero.
94
106
*
@@ -100,6 +112,13 @@ pub fn nonzero_size_of<T>() -> uint {
100
112
if s == 0 { 1 } else { s }
101
113
}
102
114
115
+ /// Returns the size of the type of the value that `_val` points to
116
+ #[ inline( always) ]
117
+ pub fn nonzero_size_of_val < T > ( _val : & T ) -> uint {
118
+ nonzero_size_of :: < T > ( )
119
+ }
120
+
121
+
103
122
/**
104
123
* Returns the ABI-required minimum alignment of a type
105
124
*
@@ -111,12 +130,26 @@ pub fn min_align_of<T>() -> uint {
111
130
unsafe { rusti:: min_align_of :: < T > ( ) }
112
131
}
113
132
133
+ /// Returns the ABI-required minimum alignment of the type of the value that
134
+ /// `_val` points to
135
+ #[ inline( always) ]
136
+ pub fn min_align_of_val < T > ( _val : & T ) -> uint {
137
+ min_align_of :: < T > ( )
138
+ }
139
+
114
140
/// Returns the preferred alignment of a type
115
141
#[ inline( always) ]
116
142
pub fn pref_align_of < T > ( ) -> uint {
117
143
unsafe { rusti:: pref_align_of :: < T > ( ) }
118
144
}
119
145
146
+ /// Returns the preferred alignment of the type of the value that
147
+ /// `_val` points to
148
+ #[ inline( always) ]
149
+ pub fn pref_align_of_val < T > ( _val : & T ) -> uint {
150
+ pref_align_of :: < T > ( )
151
+ }
152
+
120
153
/// Returns the refcount of a shared box (as just before calling this)
121
154
#[ inline( always) ]
122
155
pub fn refcount < T > ( t : @T ) -> uint {
@@ -162,7 +195,7 @@ pub fn fail_assert(msg: &str, file: &str, line: uint) -> ! {
162
195
#[cfg(test)]
163
196
mod tests {
164
197
use cast;
165
- use sys::{Closure, pref_align_of, size_of, nonzero_size_of} ;
198
+ use sys::* ;
166
199
167
200
#[test]
168
201
fn size_of_basic() {
@@ -188,6 +221,14 @@ mod tests {
188
221
assert ! ( size_of:: <* uint>( ) == 8 u) ;
189
222
}
190
223
224
+ #[ test]
225
+ fn size_of_val_basic ( ) {
226
+ assert_eq ! ( size_of_val( & 1u8 ) , 1 ) ;
227
+ assert_eq ! ( size_of_val( & 1u16 ) , 2 ) ;
228
+ assert_eq ! ( size_of_val( & 1u32 ) , 4 ) ;
229
+ assert_eq ! ( size_of_val( & 1u64 ) , 8 ) ;
230
+ }
231
+
191
232
#[ test]
192
233
fn nonzero_size_of_basic ( ) {
193
234
type Z = [ i8 , ..0 ] ;
@@ -196,6 +237,14 @@ mod tests {
196
237
assert ! ( nonzero_size_of:: <uint>( ) == size_of:: <uint>( ) ) ;
197
238
}
198
239
240
+ #[ test]
241
+ fn nonzero_size_of_val_basic ( ) {
242
+ let z = [ 0u8 , ..0 ] ;
243
+ assert_eq ! ( size_of_val( & z) , 0 u) ;
244
+ assert_eq ! ( nonzero_size_of_val( & z) , 1 u) ;
245
+ assert_eq ! ( nonzero_size_of_val( & 1 u) , size_of_val( & 1 u) ) ;
246
+ }
247
+
199
248
#[ test]
200
249
fn align_of_basic ( ) {
201
250
assert ! ( pref_align_of:: <u8 >( ) == 1 u) ;
@@ -219,6 +268,13 @@ mod tests {
219
268
assert ! ( pref_align_of:: <* uint>( ) == 8 u) ;
220
269
}
221
270
271
+ #[ test]
272
+ fn align_of_val_basic ( ) {
273
+ assert_eq ! ( pref_align_of_val( & 1u8 ) , 1 u) ;
274
+ assert_eq ! ( pref_align_of_val( & 1u16 ) , 2 u) ;
275
+ assert_eq ! ( pref_align_of_val( & 1u32 ) , 4 u) ;
276
+ }
277
+
222
278
#[ test]
223
279
fn synthesize_closure ( ) {
224
280
unsafe {
0 commit comments