From 9ce0e5130503ae65108f3921c6711fb7ff45c5e9 Mon Sep 17 00:00:00 2001 From: Giles Payne Date: Sun, 20 Mar 2022 18:47:26 +0900 Subject: [PATCH] Objective-C wrapper header fix-ups to avoid clashes with system macros --- modules/core/misc/objc/gen_dict.json | 20 ++++++++++++++++++++ modules/objc/generator/gen_objc.py | 13 +++++++++++++ 2 files changed, 33 insertions(+) diff --git a/modules/core/misc/objc/gen_dict.json b/modules/core/misc/objc/gen_dict.json index 9ade8ccb9f..58300255dc 100644 --- a/modules/core/misc/objc/gen_dict.json +++ b/modules/core/misc/objc/gen_dict.json @@ -78,6 +78,26 @@ "(void)divide:(double)scale src2:(Mat*)src2 dst:(Mat*)dst dtype:(int)dtype" : { "src2" : {"name" : "src"} } } }, + "header_fix" : { + "Core": { + "pow" : { + "prolog" : "#pragma push_macro(\"pow\")\n#undef pow", + "epilog" : "#pragma pop_macro(\"pow\")" + }, + "sqrt" : { + "prolog" : "#pragma push_macro(\"sqrt\")\n#undef sqrt", + "epilog" : "#pragma pop_macro(\"sqrt\")" + }, + "exp" : { + "prolog" : "#pragma push_macro(\"exp\")\n#undef exp", + "epilog" : "#pragma pop_macro(\"exp\")" + }, + "log" : { + "prolog" : "#pragma push_macro(\"log\")\n#undef log", + "epilog" : "#pragma pop_macro(\"log\")" + } + } + }, "type_dict" : { "Algorithm": { "objc_type": "Algorithm*" diff --git a/modules/objc/generator/gen_objc.py b/modules/objc/generator/gen_objc.py index 3e3ff8a2b0..83029312b9 100755 --- a/modules/objc/generator/gen_objc.py +++ b/modules/objc/generator/gen_objc.py @@ -82,6 +82,9 @@ ManualFuncs = {} # { class : { func : { arg_name : {"ctype" : ctype, "attrib" : [attrib]} } } } func_arg_fix = {} +# { class : { func : { prolog : "", epilog : "" } } } +header_fix = {} + # { class : { enum: fixed_enum } } enum_fix = {} @@ -479,6 +482,9 @@ class FuncInfo(GeneralInfo): self.ctype = re.sub(r"^CvTermCriteria", "TermCriteria", decl[1] or "") self.args = [] func_fix_map = func_arg_fix.get(self.classname or module, {}).get(self.objc_name, {}) + header_fixes = header_fix.get(self.classname or module, {}).get(self.objc_name, {}) + self.prolog = header_fixes.get('prolog', None) + self.epilog = header_fixes.get('epilog', None) for a in decl[3]: arg = a[:] arg_fix_map = func_fix_map.get(arg[1], {}) @@ -1170,6 +1176,9 @@ class ObjectiveCWrapperGenerator(object): objc_name = fi.objc_name if not constructor else ("init" + ("With" + (args[0].name[0].upper() + args[0].name[1:]) if len(args) > 0 else "")) ) + if fi.prolog is not None: + method_declarations.write("\n%s\n\n" % fi.prolog) + method_declarations.write( Template( """$prototype$swift_name$deprecation_decl; @@ -1181,6 +1190,9 @@ class ObjectiveCWrapperGenerator(object): ) ) + if fi.epilog is not None: + method_declarations.write("%s\n\n" % fi.epilog) + method_implementations.write( Template( """$prototype {$prologue $ret_val$obj_deref$cv_name($cv_args)$tail;$epilogue$ret @@ -1646,6 +1658,7 @@ if __name__ == "__main__": AdditionalImports[module] = gen_type_dict.get("AdditionalImports", {}) ManualFuncs.update(gen_type_dict.get("ManualFuncs", {})) func_arg_fix.update(gen_type_dict.get("func_arg_fix", {})) + header_fix.update(gen_type_dict.get("header_fix", {})) enum_fix.update(gen_type_dict.get("enum_fix", {})) const_fix.update(gen_type_dict.get("const_fix", {})) namespaces_dict.update(gen_type_dict.get("namespaces_dict", {}))