isl_rs/bindings/
cell.rs

1// Automatically generated by isl_bindings_generator.
2// LICENSE: MIT
3
4use super::{BasicSet, Context, Error, LibISLError};
5use libc::uintptr_t;
6
7/// Wraps `isl_cell`.
8pub struct Cell {
9    pub ptr: uintptr_t,
10    pub should_free_on_drop: bool,
11}
12
13extern "C" {
14
15    fn isl_cell_free(cell: uintptr_t) -> uintptr_t;
16
17    fn isl_cell_get_ctx(cell: uintptr_t) -> uintptr_t;
18
19    fn isl_cell_get_domain(cell: uintptr_t) -> uintptr_t;
20
21}
22
23impl Cell {
24    /// Wraps `isl_cell_free`.
25    pub fn free(self) -> Result<Cell, LibISLError> {
26        let cell = self;
27        let isl_rs_ctx = cell.get_ctx();
28        let mut cell = cell;
29        cell.do_not_free_on_drop();
30        let cell = cell.ptr;
31        let isl_rs_result = unsafe { isl_cell_free(cell) };
32        let isl_rs_result = Cell { ptr: isl_rs_result,
33                                   should_free_on_drop: true };
34        let err = isl_rs_ctx.last_error();
35        if err != Error::None_ {
36            let err_msg = isl_rs_ctx.last_error_msg();
37            isl_rs_ctx.reset_error();
38            return Err(LibISLError::new(err, err_msg));
39        }
40        Ok(isl_rs_result)
41    }
42
43    /// Wraps `isl_cell_get_ctx`.
44    pub fn get_ctx(&self) -> Context {
45        let cell = self;
46        let cell = cell.ptr;
47        let isl_rs_result = unsafe { isl_cell_get_ctx(cell) };
48        let isl_rs_result = Context { ptr: isl_rs_result,
49                                      should_free_on_drop: false };
50        isl_rs_result
51    }
52
53    /// Wraps `isl_cell_get_domain`.
54    pub fn get_domain(&self) -> Result<BasicSet, LibISLError> {
55        let cell = self;
56        let isl_rs_ctx = cell.get_ctx();
57        let cell = cell.ptr;
58        let isl_rs_result = unsafe { isl_cell_get_domain(cell) };
59        let isl_rs_result = BasicSet { ptr: isl_rs_result,
60                                       should_free_on_drop: true };
61        let err = isl_rs_ctx.last_error();
62        if err != Error::None_ {
63            let err_msg = isl_rs_ctx.last_error_msg();
64            isl_rs_ctx.reset_error();
65            return Err(LibISLError::new(err, err_msg));
66        }
67        Ok(isl_rs_result)
68    }
69
70    /// Does not call isl_cell_free() on being dropped. (For internal use only.)
71    pub fn do_not_free_on_drop(&mut self) {
72        self.should_free_on_drop = false;
73    }
74}
75
76impl Drop for Cell {
77    fn drop(&mut self) {
78        if self.should_free_on_drop {
79            unsafe {
80                isl_cell_free(self.ptr);
81            }
82        }
83    }
84}