Patchwork [3,of,7] rust-cpython: mark capsule function as unsafe

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 13, 2019, 9:47 a.m.
Message ID <63a1df3aac72e67667eb.1570960026@mimosa>
Download mbox | patch
Permalink /patch/42289/
State New
Headers show

Comments

Yuya Nishihara - Oct. 13, 2019, 9:47 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1570953495 -32400
#      Sun Oct 13 16:58:15 2019 +0900
# Node ID 63a1df3aac72e67667eb7210f364f4b2d892b06f
# Parent  00cd8123f876e03a3af2660c6cf4ba1a77b2bee3
rust-cpython: mark capsule function as unsafe

Patch

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
@@ -35,7 +35,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,
@@ -74,7 +74,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> {