rust/hg-cpython/src/cindex.rs
changeset 47268 9d1a8829f959
parent 46412 7d0405e458a0
child 48518 8e8737a1fa7d
--- 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 })
     }