##// END OF EJS Templates
revlog-native: introduced ABI version in capsule...
Georges Racinet -
r44523:f5d2720f default
parent child Browse files
Show More
@@ -38,6 +38,7 b' typedef struct {'
38 } nodetreenode;
38 } nodetreenode;
39
39
40 typedef struct {
40 typedef struct {
41 int abi_version;
41 int (*index_parents)(PyObject *, int, int *);
42 int (*index_parents)(PyObject *, int, int *);
42 } Revlog_CAPI;
43 } Revlog_CAPI;
43
44
@@ -3037,6 +3038,9 b' static PyTypeObject rustlazyancestorsTyp'
3037 #endif /* WITH_RUST */
3038 #endif /* WITH_RUST */
3038
3039
3039 static Revlog_CAPI CAPI = {
3040 static Revlog_CAPI CAPI = {
3041 /* increment the abi_version field upon each change in the Revlog_CAPI
3042 struct or in the ABI of the listed functions */
3043 1,
3040 HgRevlogIndex_GetParents,
3044 HgRevlogIndex_GetParents,
3041 };
3045 };
3042
3046
@@ -10,12 +10,15 b''
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,
@@ -66,9 +69,20 b' pub struct Index {'
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
General Comments 0
You need to be logged in to leave comments. Login now