fix parsing and returning pointers
MODIFY
build.rs
build.rs
@@ -391,6 +391,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut config = cpp_build::Config::new();
config.flag_if_supported("-Wno-class-memaccess");
+ config.flag_if_supported("-Wignored-qualifiers");
config.include(opencv_header_dir);
config.build("src/lib.rs");
Ok(())

MODIFY
gen_rust.py
gen_rust.py
@@ -461,6 +461,9 @@ func_unsafe_list = {
"cv_Mat_ptr_const_int_int_int",
"cv_Mat_ptr_const_int_X",
"cv_Mat_ptr_const_const_int_X",
+ # pointer to internal data
+ "cv_dnn_Dict_ptr_String",
+ "cv_dnn_Dict_ptr_const_String",
}
# dict of types to replace if cannot be handled automatically
@@ -940,7 +943,7 @@ class FuncInfo(GeneralInfo):
"rust_safe_rv_mut_raw_ptr": template("""
.and_then(|x| ${unsafety_call}{ x.as_mut() }.ok_or_else(|| Error::new(core::StsNullPtr, format!("Function returned Null pointer"))))"""),
- "rust_safe_rv_vector_box_ptr": template(""".map(|ptr| ${rv_rust_full} { ptr })"""),
+ "rust_safe_rv_by_ptr": template(""".map(|ptr| ${rv_rust_full} { ptr })"""),
"rust_safe_rv_other": template(""""""),
@@ -1264,10 +1267,10 @@ class FuncInfo(GeneralInfo):
rv_rust = FuncInfo.TEMPLATES["rust_safe_rv_string"].substitute(template_vars)
else:
rv_rust = FuncInfo.TEMPLATES["rust_safe_rv_string_mut"].substitute(template_vars)
+ elif self.rv_type().is_by_ptr:
+ rv_rust = FuncInfo.TEMPLATES["rust_safe_rv_by_ptr"].substitute(template_vars)
elif isinstance(self.rv_type(), RawPtrTypeInfo):
rv_rust = FuncInfo.TEMPLATES["rust_safe_rv_const_raw_ptr" if self.rv_type().is_const else "rust_safe_rv_mut_raw_ptr"].substitute(template_vars)
- elif self.rv_type().is_by_ptr:
- rv_rust = FuncInfo.TEMPLATES["rust_safe_rv_vector_box_ptr"].substitute(template_vars)
else:
rv_rust = FuncInfo.TEMPLATES["rust_safe_rv_other"].substitute(template_vars)
@@ -2643,6 +2646,8 @@ class RawPtrTypeInfo(TypeInfo):
def cpp_method_return(self, is_constructor):
if self.is_string:
return "return { Error::Code::StsOk, NULL, strdup(ret) };"
+ elif self.is_by_ptr:
+ return "return {{ Error::Code::StsOk, NULL, new {}(*ret) }};".format(self.cpptype)
return super().cpp_method_return(is_constructor)
def __str__(self):

MODIFY
hdr_parser.py
hdr_parser.py
@@ -308,11 +308,11 @@ class CppHeaderParser(object):
while " " in fdecl:
fdecl = fdecl.replace(" ", " ")
fname = fdecl[:fdecl.find("(")].strip()
- fnpos = fname.rfind(" ")
+ fnpos = max((fname.rfind(" "), fname.rfind("*"), fname.rfind("&")))
if fnpos < 0:
fnpos = 0
- fname = fname[fnpos:].strip()
- rettype = fdecl[:fnpos].strip()
+ fname = fname[fnpos + 1:].strip()
+ rettype = fdecl[:fnpos + 1].strip()
if rettype.endswith("operator"):
fname = ("operator " + fname).strip()

fix parsing and returning pointers