1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use std::ffi::CStr;
use std::os::raw::c_char;
use std::ptr;
use pkgcraft::restrict;
use crate::macros::*;
#[no_mangle]
pub unsafe extern "C" fn pkgcraft_restrict_parse_dep(s: *const c_char) -> *mut restrict::Restrict {
let s = null_ptr_check!(s.as_ref());
let s = unsafe { unwrap_or_return!(CStr::from_ptr(s).to_str(), ptr::null_mut()) };
let restrict = unwrap_or_return!(restrict::parse::dep(s), ptr::null_mut());
Box::into_raw(Box::new(restrict))
}
#[no_mangle]
pub unsafe extern "C" fn pkgcraft_restrict_parse_pkg(s: *const c_char) -> *mut restrict::Restrict {
let s = null_ptr_check!(s.as_ref());
let s = unsafe { unwrap_or_return!(CStr::from_ptr(s).to_str(), ptr::null_mut()) };
let restrict = unwrap_or_return!(restrict::parse::pkg(s), ptr::null_mut());
Box::into_raw(Box::new(restrict))
}
#[no_mangle]
pub unsafe extern "C" fn pkgcraft_restrict_and(
r1: *mut restrict::Restrict,
r2: *mut restrict::Restrict,
) -> *mut restrict::Restrict {
let r1 = null_ptr_check!(r1.as_ref());
let r2 = null_ptr_check!(r2.as_ref());
Box::into_raw(Box::new(r1.clone() & r2.clone()))
}
#[no_mangle]
pub unsafe extern "C" fn pkgcraft_restrict_or(
r1: *mut restrict::Restrict,
r2: *mut restrict::Restrict,
) -> *mut restrict::Restrict {
let r1 = null_ptr_check!(r1.as_ref());
let r2 = null_ptr_check!(r2.as_ref());
Box::into_raw(Box::new(r1.clone() | r2.clone()))
}
#[no_mangle]
pub unsafe extern "C" fn pkgcraft_restrict_xor(
r1: *mut restrict::Restrict,
r2: *mut restrict::Restrict,
) -> *mut restrict::Restrict {
let r1 = null_ptr_check!(r1.as_ref());
let r2 = null_ptr_check!(r2.as_ref());
Box::into_raw(Box::new(r1.clone() ^ r2.clone()))
}
#[no_mangle]
pub unsafe extern "C" fn pkgcraft_restrict_not(
r: *mut restrict::Restrict,
) -> *mut restrict::Restrict {
let r = null_ptr_check!(r.as_ref());
Box::into_raw(Box::new(!r.clone()))
}
#[no_mangle]
pub unsafe extern "C" fn pkgcraft_restrict_free(r: *mut restrict::Restrict) {
if !r.is_null() {
unsafe { drop(Box::from_raw(r)) };
}
}