[PATCH 2 of 7] rust-cpython: mark capsule function as unsafe

Yuya Nishihara yuya at tcha.org
Sun Oct 13 09:41:38 EDT 2019


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1570953495 -32400
#      Sun Oct 13 16:58:15 2019 +0900
# Node ID 46a5d47e23a43c12115de6707fe727e52a8a5f74
# Parent  083f70b7b5899755bb28ce16d6fc45eee46e84e4
rust-cpython: mark capsule function as unsafe

diff --git a/rust/hg-cpython/src/dirstate.rs b/rust/hg-cpython/src/dirstate.rs
--- a/rust/hg-cpython/src/dirstate.rs
+++ b/rust/hg-cpython/src/dirstate.rs
@@ -36,7 +36,7 @@ use std::mem::transmute;
 /// 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 @@ pub fn make_dirstate_tuple(
     // 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> {


More information about the Mercurial-devel mailing list