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