##// END OF EJS Templates
persistent-nodemap: Fix Rust declarations for Revlog_CAPI signatures...
Simon Sapin -
r47141:7d0405e4 stable
parent child Browse files
Show More
@@ -16,7 +16,7 b' use cpython::{'
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
@@ -24,10 +24,10 b' const REVLOG_CABI_VERSION: c_int = 2;'
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,
@@ -157,7 +157,7 b' impl RevlogIndex for Index {'
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
@@ -33,10 +33,18 b' Unlock further check (we are here to tes'
33
33
34 #if rust
34 #if rust
35
35
36 Reported bug: some Rust code panics when handling the null revision
36 Regression test for a previous bug in Rust/C FFI for the `Revlog_CAPI` capsule:
37 in places where `mercurial/cext/revlog.c` function signatures use `Py_ssize_t`
38 (64 bits on Linux x86_64), corresponding declarations in `rust/hg-cpython/src/cindex.rs`
39 incorrectly used `libc::c_int` (32 bits).
40 As a result, -1 passed from Rust for the null revision became 4294967295 in C.
37
41
38 $ hg log -r 00000000 2>&1 | grep panicked
42 $ hg log -r 00000000
39 thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', hg-cpython/src/revlog.rs:* (glob)
43 changeset: -1:000000000000
44 tag: tip
45 user:
46 date: Thu Jan 01 00:00:00 1970 +0000
47
40
48
41 #endif
49 #endif
42
50
General Comments 0
You need to be logged in to leave comments. Login now