--- a/rust/hg-cpython/src/cindex.rs Tue May 04 11:19:48 2021 +0200
+++ b/rust/hg-cpython/src/cindex.rs Tue May 04 14:16:26 2021 +0200
@@ -11,8 +11,8 @@
//! but this will take some time to get there.
use cpython::{
- exc::ImportError, ObjectProtocol, PyClone, PyErr, PyObject, PyResult,
- PyTuple, Python, PythonObject,
+ exc::ImportError, exc::TypeError, ObjectProtocol, PyClone, PyErr,
+ PyObject, PyResult, PyTuple, Python, PythonObject,
};
use hg::revlog::{Node, RevlogIndex};
use hg::{Graph, GraphError, Revision, WORKING_DIRECTORY_REVISION};
@@ -90,6 +90,13 @@
),
));
}
+ let compat: u64 = index.getattr(py, "rust_ext_compat")?.extract(py)?;
+ if compat == 0 {
+ return Err(PyErr::new::<TypeError, _>(
+ py,
+ "index object not compatible with Rust",
+ ));
+ }
Ok(Index { index, capi })
}