Skip to content

fix unicode errors for framework headers#21227

Merged
alalek merged 2 commits intoopencv:4.xfrom
sbwilson:fix_framework_unicode_headers
Dec 10, 2021
Merged

fix unicode errors for framework headers#21227
alalek merged 2 commits intoopencv:4.xfrom
sbwilson:fix_framework_unicode_headers

Conversation

@sbwilson
Copy link
Copy Markdown
Contributor

@sbwilson sbwilson commented Dec 9, 2021

When generating a macos framework using the build_framework.py script, if a different name has been chosen for the framework (using the --framework_name option), the headers must all be updated to use this new name as well. However, this script will throw an exception if the header file included non-ASCII characters, since the files are opened and saved in ASCII mode. This change ensures that headers are read and written as UTF-8 encoded files instead of ascii.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

This would crash if the header file included non-ASCII characters. This change ensures that headers are read and written as UTF-8 encoded files instead of ascii.
Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contribution!

for filename in files:
filepath = os.path.join(dirname, filename)
with open(filepath) as file:
with codecs.open(filepath,"r","utf-8") as file:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In gen_objc.py we using:

with io.open(filepath, encoding="utf-8", errors="ignore") as file:

Please use space after comma.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codecs.open() is used elsewhere in this file, so I chose it for consistency. Spaces have been added.

@alalek alalek merged commit c08954c into opencv:4.x Dec 10, 2021
@sbwilson sbwilson deleted the fix_framework_unicode_headers branch December 10, 2021 19:15
@alalek alalek mentioned this pull request Dec 30, 2021
@alalek alalek mentioned this pull request Feb 22, 2022
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
…eaders

* fix unicode errors for framework headers

This would crash if the header file included non-ASCII characters. This change ensures that headers are read and written as UTF-8 encoded files instead of ascii.

* Adds spaces after commas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants