Skip to content

Commit 6d94c7a

Browse files
Cast pointers std::os::raw::c_void (shortened to std_c_void) instead of using libc::c_void
1 parent e664732 commit 6d94c7a

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

src/buffer.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use std::ops::Range;
1717
use std::ops::RangeFrom;
1818
use std::ops::RangeFull;
1919
use std::ops::RangeTo;
20+
use std::os::raw::c_void as std_c_void;
2021
use std::ptr;
2122
use std::slice;
2223
use super::BufferTrait;
@@ -65,7 +66,7 @@ impl<T: TensorType> Buffer<T> {
6566
let msg = CStr::from_ptr(c_msg);
6667
panic!("Failed to allocate: {}", msg.to_str().unwrap());
6768
}
68-
(*inner).data = ptr;
69+
(*inner).data = ptr as *mut std_c_void;
6970
(*inner).length = len;
7071
(*inner).data_deallocator = Some(deallocator);
7172
Buffer {
@@ -81,7 +82,7 @@ impl<T: TensorType> Buffer<T> {
8182
/// The underlying data is *not* freed when the buffer is destroyed.
8283
pub unsafe fn from_ptr(ptr: *mut T, len: usize) -> Self {
8384
let inner = tf::TF_NewBuffer();
84-
(*inner).data = ptr as *const c_void;
85+
(*inner).data = ptr as *const std_c_void;
8586
(*inner).length = len;
8687
Buffer {
8788
inner: inner,
@@ -155,8 +156,8 @@ impl<T: TensorType> BufferTrait for Buffer<T> {
155156
}
156157
}
157158

158-
unsafe extern "C" fn deallocator(data: *mut c_void, _length: size_t) {
159-
libc::free(data);
159+
unsafe extern "C" fn deallocator(data: *mut std_c_void, _length: size_t) {
160+
libc::free(data as *mut c_void);
160161
}
161162

162163
impl<T: TensorType> Drop for Buffer<T> {

src/graph.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std;
99
use std::ffi::CStr;
1010
use std::ffi::CString;
1111
use std::ffi::NulError;
12+
use std::os::raw::c_void as std_c_void;
1213
use std::ptr;
1314
use std::str::Utf8Error;
1415
use std::sync::Arc;
@@ -606,7 +607,7 @@ impl<'a> OperationDescription<'a> {
606607
unsafe {
607608
tf::TF_SetAttrString(self.inner,
608609
c_attr_name.as_ptr(),
609-
c_value.as_ptr() as *const c_void,
610+
c_value.as_ptr() as *const std_c_void,
610611
c_value.len() as size_t);
611612
}
612613
Ok(())
@@ -625,7 +626,7 @@ impl<'a> OperationDescription<'a> {
625626
unsafe {
626627
tf::TF_SetAttrStringList(self.inner,
627628
c_attr_name.as_ptr(),
628-
ptrs.as_ptr(),
629+
ptrs.as_ptr() as *const *const std_c_void,
629630
lens.as_ptr(),
630631
ptrs.len() as c_int);
631632
}
@@ -821,7 +822,7 @@ impl<'a> OperationDescription<'a> {
821822
unsafe {
822823
tf::TF_SetAttrTensorShapeProto(self.inner,
823824
c_attr_name.as_ptr(),
824-
value.as_ptr() as *const c_void,
825+
value.as_ptr() as *const std_c_void,
825826
value.len() as size_t,
826827
status.inner());
827828
}
@@ -843,7 +844,7 @@ impl<'a> OperationDescription<'a> {
843844
unsafe {
844845
tf::TF_SetAttrTensorShapeProtoList(self.inner,
845846
c_attr_name.as_ptr(),
846-
ptrs.as_ptr(),
847+
ptrs.as_ptr() as *const *const std_c_void,
847848
lens.as_ptr(),
848849
ptrs.len() as c_int,
849850
status.inner());
@@ -893,7 +894,7 @@ impl<'a> OperationDescription<'a> {
893894
unsafe {
894895
tf::TF_SetAttrValueProto(self.inner,
895896
c_attr_name.as_ptr(),
896-
value.as_ptr() as *const c_void,
897+
value.as_ptr() as *const std_c_void,
897898
// Allow trivial_numeric_casts because usize is not
898899
// necessarily size_t.
899900
value.len() as size_t,

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use std::ops::Deref;
3030
use std::ops::DerefMut;
3131
use std::ops::Drop;
3232
use std::ops::Index;
33+
use std::os::raw::c_void as std_c_void;
3334
use std::str::Utf8Error;
3435

3536
////////////////////////
@@ -844,9 +845,9 @@ pub struct Tensor<T: TensorType> {
844845
owned: bool,
845846
}
846847

847-
unsafe extern "C" fn noop_deallocator(_: *mut c_void, _: size_t, _: *mut c_void) -> () {}
848+
unsafe extern "C" fn noop_deallocator(_: *mut std_c_void, _: size_t, _: *mut std_c_void) -> () {}
848849

849-
unsafe extern "C" fn deallocator(_: *mut c_void, _: size_t, buffer: *mut c_void) -> () {
850+
unsafe extern "C" fn deallocator(_: *mut std_c_void, _: size_t, buffer: *mut std_c_void) -> () {
850851
tf::TF_DeleteBuffer(buffer as *mut tf::TF_Buffer);
851852
}
852853

0 commit comments

Comments
 (0)