equal
deleted
inserted
replaced
8 //! Bindings to use the Index defined by the parsers C extension |
8 //! Bindings to use the Index defined by the parsers C extension |
9 //! |
9 //! |
10 //! Ideally, we should use an Index entirely implemented in Rust, |
10 //! Ideally, we should use an Index entirely implemented in Rust, |
11 //! but this will take some time to get there. |
11 //! but this will take some time to get there. |
12 |
12 |
13 use cpython::{PyClone, PyObject, PyResult, Python}; |
13 use cpython::{exc::ImportError, PyClone, PyErr, PyObject, PyResult, Python}; |
14 use hg::{Graph, GraphError, Revision, WORKING_DIRECTORY_REVISION}; |
14 use hg::{Graph, GraphError, Revision, WORKING_DIRECTORY_REVISION}; |
15 use libc::c_int; |
15 use libc::c_int; |
16 |
16 |
|
17 const REVLOG_CABI_VERSION: c_int = 1; |
|
18 |
17 #[repr(C)] |
19 #[repr(C)] |
18 pub struct Revlog_CAPI { |
20 pub struct Revlog_CAPI { |
|
21 abi_version: c_int, |
19 index_parents: unsafe extern "C" fn( |
22 index_parents: unsafe extern "C" fn( |
20 index: *mut revlog_capi::RawPyObject, |
23 index: *mut revlog_capi::RawPyObject, |
21 rev: c_int, |
24 rev: c_int, |
22 ps: *mut [c_int; 2], |
25 ps: *mut [c_int; 2], |
23 ) -> c_int, |
26 ) -> c_int, |
64 capi: &'static Revlog_CAPI, |
67 capi: &'static Revlog_CAPI, |
65 } |
68 } |
66 |
69 |
67 impl Index { |
70 impl Index { |
68 pub fn new(py: Python, index: PyObject) -> PyResult<Self> { |
71 pub fn new(py: Python, index: PyObject) -> PyResult<Self> { |
|
72 let capi = unsafe { revlog_capi::retrieve(py)? }; |
|
73 if capi.abi_version != REVLOG_CABI_VERSION { |
|
74 return Err(PyErr::new::<ImportError, _>( |
|
75 py, |
|
76 format!( |
|
77 "ABI version mismatch: the C ABI revlog version {} \ |
|
78 does not match the {} expected by Rust hg-cpython", |
|
79 capi.abi_version, REVLOG_CABI_VERSION |
|
80 ), |
|
81 )); |
|
82 } |
69 Ok(Index { |
83 Ok(Index { |
70 index: index, |
84 index: index, |
71 capi: unsafe { revlog_capi::retrieve(py)? }, |
85 capi: capi, |
72 }) |
86 }) |
73 } |
87 } |
74 |
88 |
75 /// return a reference to the CPython Index object in this Struct |
89 /// return a reference to the CPython Index object in this Struct |
76 pub fn inner(&self) -> &PyObject { |
90 pub fn inner(&self) -> &PyObject { |