@@ -10,7 +10,9 @@ use std::fmt;
1010use std:: fmt:: Debug ;
1111use std:: fmt:: Display ;
1212use std:: fmt:: Formatter ;
13+ use std:: mem;
1314use std:: ops:: Drop ;
15+ use std:: os:: raw;
1416
1517use libtensorflow_sys as tf;
1618
@@ -60,21 +62,21 @@ macro_rules! c_enum {
6062 ( $enum_name: ident { $( $name: ident = $num: expr) ,* } ) => {
6163 #[ derive( PartialEq , Eq , PartialOrd , Ord , Debug ) ]
6264 pub enum $enum_name {
63- UnrecognizedEnumValue ( :: libc :: c_uint) ,
65+ UnrecognizedEnumValue ( raw :: c_uint) ,
6466 $( $name) ,*
6567 }
6668
6769 impl $enum_name {
6870 #[ allow( dead_code) ]
69- fn from_int( value: :: libc :: c_uint) -> $enum_name {
71+ fn from_int( value: raw :: c_uint) -> $enum_name {
7072 match value {
7173 $( $num => $enum_name:: $name, ) *
7274 c => $enum_name:: UnrecognizedEnumValue ( c) ,
7375 }
7476 }
7577
7678 #[ allow( dead_code) ]
77- fn to_int( & self ) -> :: libc :: c_uint {
79+ fn to_int( & self ) -> raw :: c_uint {
7880 match self {
7981 & $enum_name:: UnrecognizedEnumValue ( c) => c,
8082 $( & $enum_name:: $name => $num) ,*
@@ -157,7 +159,7 @@ impl Status {
157159
158160 pub fn code ( & self ) -> Code {
159161 unsafe {
160- Code :: from_int ( tf:: TF_GetCode ( self . inner ) )
162+ Code :: from_int ( tf:: TF_GetCode ( self . inner ) as u32 )
161163 }
162164 }
163165
@@ -168,7 +170,7 @@ impl Status {
168170 pub fn set ( & mut self , code : Code , msg : & str ) -> std:: result:: Result < ( ) , NulError > {
169171 let message = try!( CString :: new ( msg) ) . as_ptr ( ) ;
170172 unsafe {
171- tf:: TF_SetStatus ( self . inner , code. to_int ( ) , message) ;
173+ tf:: TF_SetStatus ( self . inner , mem :: transmute ( code. to_int ( ) ) , message) ;
172174 }
173175 Ok ( ( ) )
174176 }
@@ -221,7 +223,7 @@ impl SessionOptions {
221223 pub fn set_config ( & mut self , config : & [ u8 ] ) -> Result < ( ) > {
222224 let status = Status :: new ( ) ;
223225 unsafe {
224- tf:: TF_SetConfig ( self . inner , config. as_ptr ( ) as * const libc :: c_void , config. len ( ) , status. inner ) ;
226+ tf:: TF_SetConfig ( self . inner , config. as_ptr ( ) as * const raw :: c_void , config. len ( ) , status. inner ) ;
225227 }
226228 if status. is_ok ( ) {
227229 Ok ( ( ) )
@@ -264,7 +266,7 @@ impl Session {
264266 pub fn extend_graph ( & mut self , proto : & [ u8 ] ) -> Status {
265267 let status = Status :: new ( ) ;
266268 unsafe {
267- tf:: TF_ExtendGraph ( self . inner , proto. as_ptr ( ) as * const libc :: c_void , proto. len ( ) , status. inner ) ;
269+ tf:: TF_ExtendGraph ( self . inner , proto. as_ptr ( ) as * const raw :: c_void , proto. len ( ) , status. inner ) ;
268270 }
269271 status
270272 }
@@ -286,7 +288,7 @@ pub type Result<T> = std::result::Result<T, Status>;
286288
287289////////////////////////
288290
289- trait TensorType : Default + Clone {
291+ pub trait TensorType : Default + Clone {
290292 // TODO: Use associated constants when/if available
291293 fn data_type ( ) -> DataType ;
292294}
@@ -326,9 +328,9 @@ pub struct Tensor<T> {
326328 dims : Vec < u64 > ,
327329}
328330
329- extern "C" fn noop_deallocator ( _data : * mut :: libc :: c_void ,
331+ unsafe extern "C" fn noop_deallocator ( _data : * mut raw :: c_void ,
330332 _len : :: libc:: size_t ,
331- _arg : * mut :: libc :: c_void ) -> ( ) {
333+ _arg : * mut raw :: c_void ) -> ( ) {
332334}
333335
334336// TODO: Replace with Iterator::product once that's stable
@@ -356,10 +358,10 @@ impl<T: TensorType> Tensor<T> {
356358 return None
357359 }
358360 let inner = unsafe {
359- tf:: TF_NewTensor ( T :: data_type ( ) . to_int ( ) ,
361+ tf:: TF_NewTensor ( mem :: transmute ( T :: data_type ( ) . to_int ( ) ) ,
360362 dims. as_ptr ( ) as * mut i64 ,
361363 dims. len ( ) as i32 ,
362- data. as_ptr ( ) as * mut libc :: c_void ,
364+ data. as_ptr ( ) as * mut raw :: c_void ,
363365 data. len ( ) ,
364366 Some ( noop_deallocator) ,
365367 std:: ptr:: null_mut ( ) )
0 commit comments