Mercurial > public > mercurial-scm > hg
comparison rust/hg-cpython/src/cindex.rs @ 46412:7d0405e458a0 stable
persistent-nodemap: Fix Rust declarations for Revlog_CAPI signatures
Use Rust?s `libc::ssize_t` as the closest match to C?s `Py_ssize_t`.
See details in test comment.
Going forward we should find a way to have such Rust declarations
auto-generated from C headers at build time,
or auto-checked against them in a test.
Differential Revision: https://phab.mercurial-scm.org/D9901
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Thu, 28 Jan 2021 13:15:34 +0100 |
parents | 26114bd6ec60 |
children | 9d1a8829f959 |
comparison
equal
deleted
inserted
replaced
46411:3df00f905458 | 46412:7d0405e458a0 |
---|---|
14 exc::ImportError, ObjectProtocol, PyClone, PyErr, PyObject, PyResult, | 14 exc::ImportError, ObjectProtocol, PyClone, PyErr, PyObject, PyResult, |
15 PyTuple, Python, PythonObject, | 15 PyTuple, Python, PythonObject, |
16 }; | 16 }; |
17 use hg::revlog::{Node, RevlogIndex}; | 17 use hg::revlog::{Node, RevlogIndex}; |
18 use hg::{Graph, GraphError, Revision, WORKING_DIRECTORY_REVISION}; | 18 use hg::{Graph, GraphError, Revision, WORKING_DIRECTORY_REVISION}; |
19 use libc::c_int; | 19 use libc::{c_int, ssize_t}; |
20 | 20 |
21 const REVLOG_CABI_VERSION: c_int = 2; | 21 const REVLOG_CABI_VERSION: c_int = 2; |
22 | 22 |
23 #[repr(C)] | 23 #[repr(C)] |
24 pub struct Revlog_CAPI { | 24 pub struct Revlog_CAPI { |
25 abi_version: c_int, | 25 abi_version: c_int, |
26 index_length: | 26 index_length: |
27 unsafe extern "C" fn(index: *mut revlog_capi::RawPyObject) -> c_int, | 27 unsafe extern "C" fn(index: *mut revlog_capi::RawPyObject) -> ssize_t, |
28 index_node: unsafe extern "C" fn( | 28 index_node: unsafe extern "C" fn( |
29 index: *mut revlog_capi::RawPyObject, | 29 index: *mut revlog_capi::RawPyObject, |
30 rev: c_int, | 30 rev: ssize_t, |
31 ) -> *const Node, | 31 ) -> *const Node, |
32 index_parents: unsafe extern "C" fn( | 32 index_parents: unsafe extern "C" fn( |
33 index: *mut revlog_capi::RawPyObject, | 33 index: *mut revlog_capi::RawPyObject, |
34 rev: c_int, | 34 rev: c_int, |
35 ps: *mut [c_int; 2], | 35 ps: *mut [c_int; 2], |
155 unsafe { (self.capi.index_length)(self.index.as_ptr()) as usize } | 155 unsafe { (self.capi.index_length)(self.index.as_ptr()) as usize } |
156 } | 156 } |
157 | 157 |
158 fn node(&self, rev: Revision) -> Option<&Node> { | 158 fn node(&self, rev: Revision) -> Option<&Node> { |
159 let raw = unsafe { | 159 let raw = unsafe { |
160 (self.capi.index_node)(self.index.as_ptr(), rev as c_int) | 160 (self.capi.index_node)(self.index.as_ptr(), rev as ssize_t) |
161 }; | 161 }; |
162 if raw.is_null() { | 162 if raw.is_null() { |
163 None | 163 None |
164 } else { | 164 } else { |
165 // TODO it would be much better for the C layer to give us | 165 // TODO it would be much better for the C layer to give us |