Repository navigation
fix(macos): declare UIImagePNGRepresentation and UIImageJPEGRepresentation extern "C" - #3140
Open
Bron Davies (brondavies) wants to merge 1 commit into
Open
Bron Davies (brondavies) wants to merge 1 commit into
Bron Davies (brondavies) wants to merge 1 commit into
Conversation
…ation extern "C" They are defined in RCTUIImage.m, an Objective-C file, so their symbols are C. Declared without extern "C", an Objective-C++ caller looks for C++-mangled names and fails to link on macOS (react-native-svg's RNSVGSvgView.mm, for one). The other two functions in RCTUIImage.h are already declared this way. RCTImageLoader.mm kept a copy of both functions from when React-RCTImage could not depend on RCTUIKit (microsoft#1611). As C++ its copies had mangled names and never clashed; declared extern "C" they would be duplicate symbols. React-Core depends on React-RCTUIKit now, so the copy goes and the image loader uses RCTUIKit's.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Fixes #3137.
UIImagePNGRepresentationandUIImageJPEGRepresentationare defined inRCTUIImage.m(Objective-C), so their symbols are C, butRCTUIImage.hdeclared them withoutextern "C". An Objective-C++ caller then asks for C++-mangled names and fails to link on macOS (react-native-svg'sRNSVGSvgView.mm, for one). They now sit in anextern "C"block, likeUIImageGetScaleandUIImageGetCGImageRefabove them.That on its own breaks RNTester's link:
RCTImageLoader.mmkept a copy of both functions from when React-RCTImage couldn't depend on RCTUIKit (#1611). As C++ the copies had mangled names and never clashed; declaredextern "C"they become duplicate symbols. React-Core depends on React-RCTUIKit now (React-Core.podspec), andRCTImageLoader.mmalready seesRCTUIImage.h, so the copy is removed and the image loader uses RCTUIKit's implementation, which is the same code.Test Plan:
mainthe link fails with"UIImagePNGRepresentation(NSImage*)", referenced from: _main in caller.oand ld's note that_UIImagePNGRepresentationis inRCTUIImage.o, possibly missingextern "C". With this change it links.duplicate symbol '_UIImagePNGRepresentation'(and JPEG) inRCTImageLoader.oandRCTUIImage.o; with the copy removed,nmshows oneT _UIImagePNGRepresentationand oneT _UIImageJPEGRepresentationinRNTester-macOS.debug.dylib.Not built for iOS or visionOS: both changes are inside
TARGET_OS_OSX.