1use std::ffi::c_char;
2
3use pkgcraft::restrict::{parse, Restrict};
4use pkgcraft::utils::hash;
5
6use crate::macros::*;
7use crate::panic::ffi_catch_panic;
8
9#[no_mangle]
16pub unsafe extern "C" fn pkgcraft_restrict_parse_dep(s: *const c_char) -> *mut Restrict {
17 ffi_catch_panic! {
18 let s = try_str_from_ptr!(s);
19 let restrict = unwrap_or_panic!(parse::dep(s));
20 Box::into_raw(Box::new(restrict))
21 }
22}
23
24#[no_mangle]
31pub unsafe extern "C" fn pkgcraft_restrict_parse_pkg(s: *const c_char) -> *mut Restrict {
32 ffi_catch_panic! {
33 let s = try_str_from_ptr!(s);
34 let restrict = unwrap_or_panic!(parse::pkg(s));
35 Box::into_raw(Box::new(restrict))
36 }
37}
38
39#[no_mangle]
44pub unsafe extern "C" fn pkgcraft_restrict_eq(r1: *mut Restrict, r2: *mut Restrict) -> bool {
45 let r1 = try_ref_from_ptr!(r1);
46 let r2 = try_ref_from_ptr!(r2);
47 r1.eq(r2)
48}
49
50#[no_mangle]
55pub unsafe extern "C" fn pkgcraft_restrict_hash(r: *mut Restrict) -> u64 {
56 let restrict = try_ref_from_ptr!(r);
57 hash(restrict)
58}
59
60#[no_mangle]
65pub unsafe extern "C" fn pkgcraft_restrict_and(
66 r1: *mut Restrict,
67 r2: *mut Restrict,
68) -> *mut Restrict {
69 let r1 = try_ref_from_ptr!(r1);
70 let r2 = try_ref_from_ptr!(r2);
71 Box::into_raw(Box::new(r1.clone() & r2.clone()))
72}
73
74#[no_mangle]
79pub unsafe extern "C" fn pkgcraft_restrict_or(
80 r1: *mut Restrict,
81 r2: *mut Restrict,
82) -> *mut Restrict {
83 let r1 = try_ref_from_ptr!(r1);
84 let r2 = try_ref_from_ptr!(r2);
85 Box::into_raw(Box::new(r1.clone() | r2.clone()))
86}
87
88#[no_mangle]
93pub unsafe extern "C" fn pkgcraft_restrict_xor(
94 r1: *mut Restrict,
95 r2: *mut Restrict,
96) -> *mut Restrict {
97 let r1 = try_ref_from_ptr!(r1);
98 let r2 = try_ref_from_ptr!(r2);
99 Box::into_raw(Box::new(r1.clone() ^ r2.clone()))
100}
101
102#[no_mangle]
107pub unsafe extern "C" fn pkgcraft_restrict_not(r: *mut Restrict) -> *mut Restrict {
108 let r = try_ref_from_ptr!(r);
109 Box::into_raw(Box::new(!r.clone()))
110}
111
112#[no_mangle]
117pub unsafe extern "C" fn pkgcraft_restrict_free(r: *mut Restrict) {
118 if !r.is_null() {
119 unsafe { drop(Box::from_raw(r)) };
120 }
121}