rust-cpython: mark capsule function as unsafe
authorYuya Nishihara <yuya@tcha.org>
Sun, 13 Oct 2019 16:58:15 +0900
changeset 43209 8b355cbef16d
parent 43208 1ca3823aeefd
child 43210 3fec5244aff1
rust-cpython: mark capsule function as unsafe
rust/hg-cpython/src/dirstate.rs
--- a/rust/hg-cpython/src/dirstate.rs	Sun Oct 13 16:55:17 2019 +0900
+++ b/rust/hg-cpython/src/dirstate.rs	Sun Oct 13 16:58:15 2019 +0900
@@ -36,7 +36,7 @@
 /// would be a good idea in the near future to remove it entirely to allow
 /// for a pure Python tuple of the same effective structure to be used,
 /// rendering this type and the capsule below useless.
-type MakeDirstateTupleFn = extern "C" fn(
+type MakeDirstateTupleFn = unsafe extern "C" fn(
     state: c_char,
     mode: c_int,
     size: c_int,
@@ -75,7 +75,11 @@
     // because Into<u8> has a specific implementation while `as c_char` would
     // just do a naive enum cast.
     let state_code: u8 = state.into();
-    Ok(make(state_code as c_char, mode, size, mtime))
+
+    unsafe {
+        let ptr = make(state_code as c_char, mode, size, mtime);
+        Ok(ptr)
+    }
 }
 
 pub fn extract_dirstate(py: Python, dmap: &PyDict) -> Result<StateMap, PyErr> {