opencv_binding_generator/settings/
func_unsafe.rs

1use std::collections::HashMap;
2
3use crate::func::FuncMatcher;
4use crate::SupportedModule;
5
6pub type FuncUnsafe = FuncMatcher<'static, ()>;
7
8/// set of functions that should have unsafe in their declaration, element is Func.identifier()
9pub fn func_unsafe_factory(module: SupportedModule) -> FuncUnsafe {
10	match module {
11		SupportedModule::Core => core_factory(),
12		SupportedModule::Dnn => dnn_factory(),
13		_ => FuncUnsafe::empty(),
14	}
15}
16
17fn core_factory() -> FuncUnsafe {
18	FuncMatcher::create(HashMap::from([
19		// allocates uninitialized memory
20		(
21			"cv::Mat::Mat",
22			vec![
23				(pred!(mut, ["size", "type"]), ()),
24				(pred!(mut, ["sizes", "type"]), ()),
25				(pred!(mut, ["ndims", "sizes", "type"]), ()),
26				(pred!(mut, ["rows", "cols", "type"]), ()),
27			],
28		),
29		(
30			"cv::Mat::create",
31			vec![
32				(pred!(mut, ["size", "type"]), ()),
33				(pred!(mut, ["sizes", "type"]), ()),
34				(pred!(mut, ["ndims", "sizes", "type"]), ()),
35				(pred!(mut, ["rows", "cols", "type"]), ()),
36			],
37		),
38		(
39			"cv::UMat::UMat",
40			vec![
41				(pred!(mut, ["size", "type", "usageFlags"]), ()),
42				(pred!(mut, ["ndims", "sizes", "type", "usageFlags"]), ()),
43				(pred!(mut, ["rows", "cols", "type", "usageFlags"]), ()),
44			],
45		),
46		(
47			"cv::UMat::create",
48			vec![
49				(pred!(mut, ["size", "type", "usageFlags"]), ()),
50				(pred!(mut, ["size", "type", "usageFlags"]), ()),
51				(pred!(mut, ["ndims", "sizes", "type", "usageFlags"]), ()),
52				(pred!(mut, ["sizes", "type", "usageFlags"]), ()),
53				(pred!(mut, ["rows", "cols", "type", "usageFlags"]), ()),
54			],
55		),
56		("cv::_OutputArray::createSameSize", vec![(pred!(const, ["arr", "mtype"]), ())]),
57		// manual manipulation of reference counter
58		("cv::Mat::addref", vec![(pred!(mut, []), ())]),
59		("cv::Mat::release", vec![(pred!(mut, []), ())]),
60		("cv::SparseMat::addref", vec![(pred!(mut, []), ())]),
61		("cv::SparseMat::release", vec![(pred!(mut, []), ())]),
62		("cv::UMat::addref", vec![(pred!(mut, []), ())]),
63		("cv::UMat::release", vec![(pred!(mut, []), ())]),
64		// takes reference and stores it for the lifetime of an object (fixme: add lifetime management)
65		(
66			"cv::cuda::GpuMat::GpuMat",
67			vec![
68				(pred!(mut, ["allocator"]), ()),
69				(pred!(mut, ["size", "type", "allocator"]), ()),
70				(pred!(mut, ["size", "type", "s", "allocator"]), ()),
71				(pred!(mut, ["arr", "allocator"]), ()),
72				(pred!(mut, ["rows", "cols", "type", "allocator"]), ()),
73				(pred!(mut, ["rows", "cols", "type", "s", "allocator"]), ()),
74			],
75		),
76	]))
77}
78
79fn dnn_factory() -> FuncUnsafe {
80	FuncMatcher::create(HashMap::from([
81		// pointer to internal data
82		(
83			"cv::dnn::Dict::ptr",
84			vec![(pred!(const, ["key"]), ()), (pred!(mut, ["key"]), ())],
85		),
86	]))
87}