Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dynamic_cast (RTTI) by adding key function to ShadowNodeWrapper again #45290

Conversation

tomekzaw
Copy link
Contributor

@tomekzaw tomekzaw commented Jul 4, 2024

Summary:

This PR restores the virtual destructor for ShadowNodeWrapper which was added in #33500. The class itself was removed in #40864 and reintroduced in #44772, however this time without a virtual destructor.

The virtual destructor here serves as a key function. Without a key function, obj.hasNativeState<ShadowNodeWrapper>(rt) does not work correctly between shared library boundaries on Android and always returns false.

We need this pretty badly in third-party libraries like react-native-reanimated or react-native-gesture-handler.

Changelog:

[ANDROID] [FIXED] - Fix dynamic_cast (RTTI) for ShadowNodeWrapper when accessed by third-party libraries again

Test Plan:

This patch fixes an issue in Reanimated's fabric-example app.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Software Mansion Partner: Software Mansion Partner labels Jul 4, 2024
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jul 4, 2024
@javache
Copy link
Member

javache commented Jul 4, 2024

The entire ShadowNodeWrapper was removed in #40864, but reintroduced in #44772

Thanks for catching this!

@facebook-github-bot
Copy link
Contributor

@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@tomekzaw
Copy link
Contributor Author

tomekzaw commented Jul 4, 2024

@javache Thanks, I've updated the PR description.

@tomekzaw
Copy link
Contributor Author

tomekzaw commented Jul 4, 2024

btw I'm afraid this static_assert does not work as intented, even when I remove ~ShadowNode(), it still holds as jsi::NativeState (the base class) has a virtual destructor

static_assert(
std::has_virtual_destructor<ShadowNode>::value,
"ShadowNode must have a virtual destructor");

class JSI_EXPORT NativeState {
public:
virtual ~NativeState();
};

edit: actually, I suspect that ShadowNode suffers from the same problem as the virtual destructor is inline (so it's not a key function)

tomekzaw and others added 3 commits July 4, 2024 17:31
@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 21,285,099 +5
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 24,481,856 -9
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: a7f5963
Branch: main

@facebook-github-bot
Copy link
Contributor

@javache merged this pull request in ea958c6.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jul 4, 2024
Copy link

github-actions bot commented Jul 4, 2024

This pull request was successfully merged by @tomekzaw in ea958c6.

When will my fix make it into a release? | How to file a pick request?

@tomekzaw
Copy link
Contributor Author

tomekzaw commented Jul 5, 2024

@javache I've pushed some more commits and they have not been merged. Nothing important (just minor changes in the comments). Do I need to submit another PR with these changes?

cipolleschi pushed a commit that referenced this pull request Jul 8, 2024
…gain (#45290)

Summary:
This PR restores the virtual destructor for `ShadowNodeWrapper` which was added in #33500 and unfortunately removed in #40864.

The virtual destructor here serves as a key function. Without a key function, `obj.hasNativeState<ShadowNodeWrapper>(rt)` **does not** work correctly between shared library boundaries on Android and always returns false.

We need this pretty badly in third-party libraries like react-native-reanimated or react-native-gesture-handler.

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[ANDROID] [FIXED] - Fix dynamic_cast (RTTI) for ShadowNodeWrapper when accessed by third-party libraries again

Pull Request resolved: #45290

Test Plan: This patch fixes an issue in Reanimated's fabric-example app.

Reviewed By: fabriziocucci

Differential Revision: D59375554

Pulled By: javache

fbshipit-source-id: 09f3eda89a67c26d6dacca3428e08d1b7138d350
@javache
Copy link
Member

javache commented Jul 9, 2024

Sorry, I missed this and the internal copy of this landed already. I think it's fine as-is, unless you believe the comments are worth a separate PR?

@tomekzaw
Copy link
Contributor Author

@javache No worries, it's fine as-is for us, but anyway I submitted #45357 for the sake of completeness :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. p: Software Mansion Partner: Software Mansion Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants