binarybana commented on a change in pull request #5328:
URL: https://github.com/apache/incubator-tvm/pull/5328#discussion_r411052316



##########
File path: rust/tvm-rt/src/object.rs
##########
@@ -0,0 +1,226 @@
+use std::ffi::{CString};
+use crate::Function;
+use tvm_sys::{TVMRetValue, TVMArgValue};
+use tvm_sys::ffi::{TVMObjectRetain, TVMObjectFree, TVMObjectTypeKey2Index};
+use std::ptr::NonNull;
+use std::convert::TryFrom;
+use std::convert::TryInto;
+
+type Deleter<T> = unsafe extern fn(object: *mut T) -> ();
+
+#[derive(Debug)]
+#[repr(C)]
+pub struct Object {
+    pub type_index: u32,
+    pub ref_count: i32,
+    pub fdeleter: Deleter<Object>,
+}
+
+unsafe extern fn delete<T: IsObject>(object: *mut Object) {
+    let typed_object: *mut T =
+        std::mem::transmute(object);
+    T::typed_delete(typed_object);
+}
+
+impl Object {
+    fn new(type_index: u32, deleter: Deleter<Object>) -> Object {
+        Object {
+            type_index,
+            // Note: do not touch this field directly again, this is
+            // a critical section, we write a 1 to the atomic which will now
+            // be managed by the C++ atomics.
+            // In the future we should probably use C-atomcis.
+            ref_count: 1,
+            fdeleter: deleter,
+        }
+    }
+
+    fn get_type_index(type_key: &'static str) -> u32 {
+        let cstring = CString::new(type_key).expect("type key must not contain 
null characters");
+        if type_key == "Object" {
+            return 0;
+        } else {
+            let mut index = 0;
+            unsafe {
+                let index_ptr = std::mem::transmute(&mut index);

Review comment:
       I assume this is temporary, but thought I'd put a note here in case you 
forgot to replace this with a safe and normal `as *mut u32` conversion.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to