Show More
@@ -2710,27 +2710,15 b' struct rustlazyancestorsObjectStruct {' | |||
|
2710 | 2710 | }; |
|
2711 | 2711 | |
|
2712 | 2712 | /* FFI exposed from Rust code */ |
|
2713 | rustlazyancestorsObject * | |
|
2714 | rustlazyancestors_init(indexObject *index, | |
|
2715 | /* to pass index_get_parents() */ | |
|
2716 | int (*)(indexObject *, Py_ssize_t, int *, int), | |
|
2717 | /* intrevs vector */ | |
|
2718 | Py_ssize_t initrevslen, long *initrevs, long stoprev, | |
|
2719 | int inclusive); | |
|
2713 | rustlazyancestorsObject *rustlazyancestors_init(indexObject *index, | |
|
2714 | /* intrevs vector */ | |
|
2715 | Py_ssize_t initrevslen, | |
|
2716 | long *initrevs, long stoprev, | |
|
2717 | int inclusive); | |
|
2720 | 2718 | void rustlazyancestors_drop(rustlazyancestorsObject *self); |
|
2721 | 2719 | int rustlazyancestors_next(rustlazyancestorsObject *self); |
|
2722 | 2720 | int rustlazyancestors_contains(rustlazyancestorsObject *self, long rev); |
|
2723 | 2721 | |
|
2724 | static int index_get_parents_checked(indexObject *self, Py_ssize_t rev, int *ps, | |
|
2725 | int maxrev) | |
|
2726 | { | |
|
2727 | if (rev < 0 || rev >= index_length(self)) { | |
|
2728 | PyErr_SetString(PyExc_ValueError, "rev out of range"); | |
|
2729 | return -1; | |
|
2730 | } | |
|
2731 | return index_get_parents(self, rev, ps, maxrev); | |
|
2732 | } | |
|
2733 | ||
|
2734 | 2722 | /* CPython instance methods */ |
|
2735 | 2723 | static int rustla_init(rustlazyancestorsObject *self, PyObject *args) |
|
2736 | 2724 | { |
@@ -2768,12 +2756,12 b' static int rustla_init(rustlazyancestors' | |||
|
2768 | 2756 | if (PyErr_Occurred()) |
|
2769 | 2757 | goto bail; |
|
2770 | 2758 | |
|
2771 | self->iter = rustlazyancestors_init(index, index_get_parents, linit, | |
|
2772 | initrevs, stoprev, inclusive); | |
|
2759 | self->iter = | |
|
2760 | rustlazyancestors_init(index, linit, initrevs, stoprev, inclusive); | |
|
2773 | 2761 | if (self->iter == NULL) { |
|
2774 | 2762 | /* if this is because of GraphError::ParentOutOfRange |
|
2775 |
* |
|
|
2776 | * ValueError */ | |
|
2763 | * HgRevlogIndex_GetParents() has already set the proper | |
|
2764 | * exception */ | |
|
2777 | 2765 | goto bail; |
|
2778 | 2766 | } |
|
2779 | 2767 |
@@ -16,9 +16,14 b' use std::ptr::null_mut;' | |||
|
16 | 16 | use std::slice; |
|
17 | 17 | |
|
18 | 18 | type IndexPtr = *mut c_void; |
|
19 | type IndexParentsFn = | |
|
20 | unsafe extern "C" fn(index: IndexPtr, rev: ssize_t, ps: *mut [c_int; 2], max_rev: c_int) | |
|
21 | -> c_int; | |
|
19 | ||
|
20 | extern "C" { | |
|
21 | fn HgRevlogIndex_GetParents( | |
|
22 | op: IndexPtr, | |
|
23 | rev: c_int, | |
|
24 | parents: *mut [c_int; 2], | |
|
25 | ) -> c_int; | |
|
26 | } | |
|
22 | 27 | |
|
23 | 28 | /// A Graph backed up by objects and functions from revlog.c |
|
24 | 29 | /// |
@@ -27,14 +32,12 b' type IndexParentsFn =' | |||
|
27 | 32 | /// - the `index_get_parents()` function (`parents` member) |
|
28 | 33 | pub struct Index { |
|
29 | 34 | index: IndexPtr, |
|
30 | parents: IndexParentsFn, | |
|
31 | 35 | } |
|
32 | 36 | |
|
33 | 37 | impl Index { |
|
34 |
pub fn new(index: IndexPtr |
|
|
38 | pub fn new(index: IndexPtr) -> Self { | |
|
35 | 39 | Index { |
|
36 | 40 | index: index, |
|
37 | parents: parents, | |
|
38 | 41 | } |
|
39 | 42 | } |
|
40 | 43 | } |
@@ -44,7 +47,7 b' impl Graph for Index {' | |||
|
44 | 47 | fn parents(&self, rev: Revision) -> Result<(Revision, Revision), GraphError> { |
|
45 | 48 | let mut res: [c_int; 2] = [0; 2]; |
|
46 | 49 | let code = |
|
47 |
unsafe { |
|
|
50 | unsafe { HgRevlogIndex_GetParents(self.index, rev, &mut res as *mut [c_int; 2]) }; | |
|
48 | 51 | match code { |
|
49 | 52 | 0 => Ok((res[0], res[1])), |
|
50 | 53 | _ => Err(GraphError::ParentOutOfRange(rev)), |
@@ -59,7 +62,6 b' impl Graph for Index {' | |||
|
59 | 62 | #[no_mangle] |
|
60 | 63 | pub extern "C" fn rustlazyancestors_init( |
|
61 | 64 | index: IndexPtr, |
|
62 | parents: IndexParentsFn, | |
|
63 | 65 | initrevslen: ssize_t, |
|
64 | 66 | initrevs: *mut c_long, |
|
65 | 67 | stoprev: c_long, |
@@ -68,7 +70,7 b' pub extern "C" fn rustlazyancestors_init' | |||
|
68 | 70 | assert!(initrevslen >= 0); |
|
69 | 71 | unsafe { |
|
70 | 72 | raw_init( |
|
71 |
Index::new(index |
|
|
73 | Index::new(index), | |
|
72 | 74 | initrevslen as usize, |
|
73 | 75 | initrevs, |
|
74 | 76 | stoprev, |
General Comments 0
You need to be logged in to leave comments.
Login now