From a8c0c30046396ce3fdc858bfe72a19f3c85af5e2 Mon Sep 17 00:00:00 2001 From: Haris shakeel Date: Mon, 15 Jun 2026 13:30:51 +0500 Subject: [PATCH] Merge pull request #29262 from Haris-bin-shakeel:fix-objc-volumetype-5x objc: Fix VolumeType enum name clash on MacOS #29262 ### Pull Request Readiness Checklist - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable - [ ] The feature is well documented and sample code can be built with the project CMake **Problem** When the ObjC wrapper is generated, the global enum `cv::VolumeType` from the ptcloud module is emitted as `typedef NS_ENUM(int, VolumeType)`. macOS defines `typedef OSType VolumeType` in CoreServices, which leads to a typedef-redefinition error during the framework build. **Fix** `add_enum()` in `gen_objc.py` now handles namespace-global enums by falling back to a module-level lookup (`self.Module`) when the enum has no enclosing class. A new `gen_dict.json` entry maps `VolumeType` -> `PtcloudVolumeType`, and the import generation automatically uses the renamed enum. Fixes #29260 --- modules/objc/generator/gen_objc.py | 9 +++++++-- modules/ptcloud/misc/objc/gen_dict.json | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 modules/ptcloud/misc/objc/gen_dict.json diff --git a/modules/objc/generator/gen_objc.py b/modules/objc/generator/gen_objc.py index 78fe9454bc..9544702564 100755 --- a/modules/objc/generator/gen_objc.py +++ b/modules/objc/generator/gen_objc.py @@ -847,9 +847,14 @@ class ObjectiveCWrapperGenerator(object): objc_type = enumType.rsplit(".", 1)[-1] if objc_type in enum_ignore_list: return - if constinfo.classname in enum_fix: + original_objc_type = objc_type + if not constinfo.classname or constinfo.classname == objc_type: + module_fix = enum_fix.get(self.Module, {}) + objc_type = module_fix.get(objc_type, objc_type) + objc_type = enum_fix.get(objc_type, objc_type) + elif constinfo.classname in enum_fix: objc_type = enum_fix[constinfo.classname].get(objc_type, objc_type) - import_module = constinfo.classname if constinfo.classname and constinfo.classname != objc_type else self.Module + import_module = constinfo.classname if constinfo.classname and constinfo.classname != original_objc_type else self.Module type_dict[ctype] = { "cast_from" : "int", "cast_to" : get_cname(enumType), "objc_type" : objc_type, diff --git a/modules/ptcloud/misc/objc/gen_dict.json b/modules/ptcloud/misc/objc/gen_dict.json new file mode 100644 index 0000000000..22a5288d0f --- /dev/null +++ b/modules/ptcloud/misc/objc/gen_dict.json @@ -0,0 +1,7 @@ +{ + "enum_fix": { + "Ptcloud": { + "VolumeType": "CV_VolumeType" + } + } +}