Skip to content

Commit 0cf56fd

Browse files
committed
Deglobalize FORCE_INFALLIBLE & switch to function matcher
1 parent 3e1165d commit 0cf56fd

File tree

3 files changed

+62
-52
lines changed

3 files changed

+62
-52
lines changed

binding-generator/src/func.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,11 @@ impl<'tu, 'ge> Func<'tu, 'ge> {
384384

385385
pub fn return_kind(&self) -> ReturnKind {
386386
match self {
387-
Self::Clang { entity, .. } => {
387+
Self::Clang { entity, gen_env, .. } => {
388388
let is_infallible = matches!(
389389
entity.get_exception_specification(),
390390
Some(ExceptionSpecification::BasicNoexcept) | Some(ExceptionSpecification::Unevaluated)
391-
) || settings::FORCE_INFALLIBLE.contains(&self.func_id());
391+
) || gen_env.settings.force_infallible.get(&mut self.matcher()).is_some();
392392
if is_infallible {
393393
let return_type_ref = self.return_type_ref();
394394
if return_type_ref.kind().return_as_naked(return_type_ref.type_hint()) {

binding-generator/src/settings.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub use argument_names::{ARGUMENT_NAMES_MULTIPLE_SLICE, ARGUMENT_NAMES_NOT_SLICE
4545
pub use argument_override::{arg_override_factory, return_override_factory, ArgOverride, ReturnOverride, ARG_OVERRIDE_SELF};
4646
pub use element_exclude_kind::ELEMENT_EXCLUDE_KIND;
4747
pub use element_export_tweak::ELEMENT_EXPORT_TWEAK;
48-
pub use force_infallible::FORCE_INFALLIBLE;
48+
pub use force_infallible::{force_infallible_factory, ForceInfallible};
4949
pub use func_cfg_attr::FUNC_CFG_ATTR;
5050
pub use func_exclude::FUNC_EXCLUDE;
5151
pub use func_inject::{func_inject_factory, FuncFactory, FuncInject};
@@ -87,6 +87,7 @@ pub type TypeRefFactory = fn() -> TypeRef<'static, 'static>;
8787
pub struct Settings {
8888
pub arg_override: ArgOverride,
8989
pub return_override: ReturnOverride,
90+
pub force_infallible: ForceInfallible,
9091
pub func_inject: FuncInject,
9192
pub func_rename: FuncRename,
9293
pub func_specialize: FuncSpecialize,
@@ -99,6 +100,7 @@ impl Settings {
99100
Self {
100101
arg_override: ArgOverride::empty(),
101102
return_override: ReturnOverride::empty(),
103+
force_infallible: ForceInfallible::empty(),
102104
func_inject: FuncInject::default(),
103105
func_rename: FuncRename::default(),
104106
func_specialize: FuncMatcher::empty(),
@@ -111,6 +113,7 @@ impl Settings {
111113
Self {
112114
arg_override: arg_override_factory(module),
113115
return_override: return_override_factory(module),
116+
force_infallible: force_infallible_factory(module),
114117
func_inject: func_inject_factory(module),
115118
func_rename: func_rename_factory(module),
116119
func_specialize: func_specialize_factory(module),
Lines changed: 56 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,62 @@
1-
use std::collections::HashSet;
1+
use std::collections::HashMap;
22

3-
use once_cell::sync::Lazy;
3+
use crate::func::FuncMatcher;
44

5-
use crate::FuncId;
5+
pub type ForceInfallible = FuncMatcher<'static, ()>;
66

7-
pub static FORCE_INFALLIBLE: Lazy<HashSet<FuncId>> = Lazy::new(|| {
8-
HashSet::from([
7+
pub fn force_infallible_factory(module: &str) -> ForceInfallible {
8+
match module {
9+
"core" => core_factory(),
10+
_ => ForceInfallible::empty(),
11+
}
12+
}
13+
14+
fn core_factory() -> ForceInfallible {
15+
FuncMatcher::create(HashMap::from([
916
// just returns static/constant data
10-
FuncId::new_mut("cv::noArray", []),
11-
FuncId::new_mut("cv::getVersionMajor", []),
12-
FuncId::new_mut("cv::getVersionMinor", []),
13-
FuncId::new_mut("cv::getVersionRevision", []),
17+
("cv::noArray", vec![(pred!(mut, []), ())]),
18+
("cv::getVersionMajor", vec![(pred!(mut, []), ())]),
19+
("cv::getVersionMinor", vec![(pred!(mut, []), ())]),
20+
("cv::getVersionRevision", vec![(pred!(mut, []), ())]),
1421
// not doing anything that can cause an exception
15-
FuncId::new_const("cv::Mat::empty", []),
16-
FuncId::new_const("cv::Mat::total", []),
17-
FuncId::new_const("cv::Mat::isContinuous", []),
18-
FuncId::new_const("cv::Mat::isSubmatrix", []),
19-
FuncId::new_const("cv::Mat::elemSize1", []),
20-
FuncId::new_const("cv::Mat::type", []),
21-
FuncId::new_const("cv::Mat::depth", []),
22-
FuncId::new_const("cv::Mat::channels", []),
23-
FuncId::new_const("cv::UMat::empty", []),
24-
FuncId::new_const("cv::UMat::total", []),
25-
FuncId::new_const("cv::UMat::isContinuous", []),
26-
FuncId::new_const("cv::UMat::isSubmatrix", []),
27-
FuncId::new_const("cv::UMat::elemSize1", []),
28-
FuncId::new_const("cv::UMat::type", []),
29-
FuncId::new_const("cv::UMat::depth", []),
30-
FuncId::new_const("cv::UMat::channels", []),
31-
FuncId::new_const("cv::SparseMat::elemSize", []),
32-
FuncId::new_const("cv::SparseMat::elemSize1", []),
33-
FuncId::new_const("cv::SparseMat::type", []),
34-
FuncId::new_const("cv::SparseMat::depth", []),
35-
FuncId::new_const("cv::SparseMat::channels", []),
22+
("cv::Mat::empty", vec![(pred!(const, []), ())]),
23+
("cv::Mat::total", vec![(pred!(const, []), ())]),
24+
("cv::Mat::isContinuous", vec![(pred!(const, []), ())]),
25+
("cv::Mat::isSubmatrix", vec![(pred!(const, []), ())]),
26+
("cv::Mat::elemSize1", vec![(pred!(const, []), ())]),
27+
("cv::Mat::type", vec![(pred!(const, []), ())]),
28+
("cv::Mat::depth", vec![(pred!(const, []), ())]),
29+
("cv::Mat::channels", vec![(pred!(const, []), ())]),
30+
("cv::UMat::empty", vec![(pred!(const, []), ())]),
31+
("cv::UMat::total", vec![(pred!(const, []), ())]),
32+
("cv::UMat::isContinuous", vec![(pred!(const, []), ())]),
33+
("cv::UMat::isSubmatrix", vec![(pred!(const, []), ())]),
34+
("cv::UMat::elemSize1", vec![(pred!(const, []), ())]),
35+
("cv::UMat::type", vec![(pred!(const, []), ())]),
36+
("cv::UMat::depth", vec![(pred!(const, []), ())]),
37+
("cv::UMat::channels", vec![(pred!(const, []), ())]),
38+
("cv::SparseMat::elemSize", vec![(pred!(const, []), ())]),
39+
("cv::SparseMat::elemSize1", vec![(pred!(const, []), ())]),
40+
("cv::SparseMat::type", vec![(pred!(const, []), ())]),
41+
("cv::SparseMat::depth", vec![(pred!(const, []), ())]),
42+
("cv::SparseMat::channels", vec![(pred!(const, []), ())]),
3643
// marked CV_NOEXCEPT since OpenCV 4.5.2, propagate those changes to earlier versions
37-
FuncId::new_mut("cv::Mat::Mat", []),
38-
FuncId::new_mut("cv::MatSize::MatSize", ["_p"]),
39-
FuncId::new_const("cv::MatSize::dims", []),
40-
FuncId::new_const("cv::MatSize::operator const int*", []),
41-
FuncId::new_mut("cv::MatStep::MatStep", []),
42-
FuncId::new_mut("cv::MatStep::operator[]", ["i"]),
43-
FuncId::new_mut("cv::UMat::UMat", ["usageFlags"]),
44-
FuncId::new_mut("cv::ocl::Context::Context", []),
45-
FuncId::new_mut("cv::ocl::Device::Device", []),
46-
FuncId::new_mut("cv::ocl::Image2D::Image2D", []),
47-
FuncId::new_mut("cv::ocl::Kernel::Kernel", []),
48-
FuncId::new_mut("cv::ocl::KernelArg::KernelArg", []),
49-
FuncId::new_mut("cv::ocl::Platform::Platform", []),
50-
FuncId::new_mut("cv::ocl::PlatformInfo::PlatformInfo", []),
51-
FuncId::new_mut("cv::ocl::Program::Program", []),
52-
FuncId::new_mut("cv::ocl::ProgramSource::ProgramSource", []),
53-
FuncId::new_mut("cv::ocl::Queue::Queue", []),
54-
])
55-
});
44+
("cv::Mat::Mat", vec![(pred!(mut, []), ())]),
45+
("cv::MatSize::MatSize", vec![(pred!(mut, ["_p"]), ())]),
46+
("cv::MatSize::dims", vec![(pred!(const, []), ())]),
47+
("cv::MatSize::operator const int*", vec![(pred!(const, []), ())]),
48+
("cv::MatStep::MatStep", vec![(pred!(mut, []), ())]),
49+
("cv::MatStep::operator[]", vec![(pred!(mut, ["i"]), ())]),
50+
("cv::UMat::UMat", vec![(pred!(mut, ["usageFlags"]), ())]),
51+
("cv::ocl::Context::Context", vec![(pred!(mut, []), ())]),
52+
("cv::ocl::Device::Device", vec![(pred!(mut, []), ())]),
53+
("cv::ocl::Image2D::Image2D", vec![(pred!(mut, []), ())]),
54+
("cv::ocl::Kernel::Kernel", vec![(pred!(mut, []), ())]),
55+
("cv::ocl::KernelArg::KernelArg", vec![(pred!(mut, []), ())]),
56+
("cv::ocl::Platform::Platform", vec![(pred!(mut, []), ())]),
57+
("cv::ocl::PlatformInfo::PlatformInfo", vec![(pred!(mut, []), ())]),
58+
("cv::ocl::Program::Program", vec![(pred!(mut, []), ())]),
59+
("cv::ocl::ProgramSource::ProgramSource", vec![(pred!(mut, []), ())]),
60+
("cv::ocl::Queue::Queue", vec![(pred!(mut, []), ())]),
61+
]))
62+
}

0 commit comments

Comments
 (0)