Skip to content

Conversation

@jonsimantov
Copy link
Contributor

@jonsimantov jonsimantov commented Jun 27, 2023

Description

Provide details of the change, and generalize the change in the PR title above.

Switch from firebase::UniquePtr (and flatbuffers::UniquePtr) to std::unique_ptr, and from firebase::SharedPtr to std::shared_ptr. Also updates the use of MakeUnique / MakeShared to their std::make_unique and std::make_shared equivalents.

This also removes app/meta/move.h, which provided Move() and Forward<>(); it will now use std::move and std::forward, in the header, instead. Firestore uses these a lot.

The purpose of this PR is to clean up our code base, using modern C++ smart pointers instead of our own equivalents, to make it easier to maintain in the future.

This PR also replaces rare usage of firebase::compat::Atomic with std::atomic (mainly in a Firestore test, since the main usage used to be inside our own SharedPtr class that is now deleted).

Important: buried in this change is a modification to database/src/desktop/query_desktop.cc, since the Callback mechanism does not work with move-only types (such as std::unique_ptr). This change wraps the unique_ptr inside a shared_ptr, thus making it copyable. Inside the callback, it releases the raw pointer from the unique_ptr and wraps it in a new unique_ptr. This ensures that there is never a time in which the pointer memory is not managed somewhere (it's either owned by the shared_ptr's unique_ptr prior to the callback, or by the newly created unique_ptr after the callback).


Testing

Describe how you've tested these changes. Link any manually triggered Integration tests or CPP binary SDK Packaging Github Action workflows, if applicable.

Running integration tests in this PR, as well as the unit tests.


Type of Change

Place an x the applicable box:

  • Bug fix. Add the issue # below if applicable.
  • New feature. A non-breaking change which adds functionality.
  • Other, such as a build process or documentation change.

Notes

  • Bug fixes and feature changes require an update to the Release Notes section of release_build_files/readme.md.
  • Read the contribution guidelines CONTRIBUTING.md.
  • Changes to the public API require an internal API review. If you'd like to help us make Firebase APIs better, please propose your change in a feature request so that we can discuss it together.
@jonsimantov jonsimantov added tests-requested: quick Trigger a quick set of integration tests. skip-release-notes Skip release notes check labels Jun 27, 2023
@github-actions github-actions bot added tests: in-progress This PR's integration tests are in progress. and removed tests-requested: quick Trigger a quick set of integration tests. labels Jun 27, 2023
@github-actions
Copy link

github-actions bot commented Jun 27, 2023

Integration test with FLAKINESS (succeeded after retry)

Requested by @a-maurice on commit 6a59781
Last updated: Wed Jul 5 17:14 PDT 2023
View integration test log & download artifacts

Failures Configs
gma [TEST] [FLAKINESS] [iOS] [macos] [1/2 ios_device: ios_target]
(1 failed tests)  CRASH/TIMEOUT

Add flaky tests to go/fpl-cpp-flake-tracker

@github-actions github-actions bot added the tests: failed This PR's integration tests failed. label Jun 27, 2023
@firebase-workflow-trigger firebase-workflow-trigger bot removed the tests: in-progress This PR's integration tests are in progress. label Jun 27, 2023
@jonsimantov jonsimantov added the tests-requested: quick Trigger a quick set of integration tests. label Jun 28, 2023
@github-actions github-actions bot added tests: in-progress This PR's integration tests are in progress. and removed tests-requested: quick Trigger a quick set of integration tests. tests: failed This PR's integration tests failed. labels Jun 28, 2023
@github-actions github-actions bot added the tests: failed This PR's integration tests failed. label Jun 28, 2023
@jonsimantov jonsimantov added the tests-requested: quick Trigger a quick set of integration tests. label Jun 29, 2023
@github-actions github-actions bot removed tests-requested: quick Trigger a quick set of integration tests. tests: failed This PR's integration tests failed. labels Jun 29, 2023
@github-actions github-actions bot added the tests: failed This PR's integration tests failed. label Jun 29, 2023
@jonsimantov jonsimantov added the tests-requested: quick Trigger a quick set of integration tests. label Jun 29, 2023
@github-actions github-actions bot removed tests-requested: quick Trigger a quick set of integration tests. tests: failed This PR's integration tests failed. labels Jun 29, 2023
Copy link
Contributor

@dconeybe dconeybe left a comment

Choose a reason for hiding this comment

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

LGTM for Firestore. I'll leave the formal LGTM to another reviewer with context to review the rest of the code.

@github-actions github-actions bot added the tests: succeeded This PR's integration tests succeeded. label Jun 30, 2023
@firebase-workflow-trigger firebase-workflow-trigger bot removed the tests: in-progress This PR's integration tests are in progress. label Jun 30, 2023
@jonsimantov
Copy link
Contributor Author

This is ready for review, all integration and unit tests should now be working.


// Safe reference to this. Set in constructor and cleared in destructor
// Should be safe to be copied in any thread because the SharedPtr never
// Should be safe to be copied in any thread because the std::shared_ptr never
Copy link
Contributor

Choose a reason for hiding this comment

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

Any idea what shared_ptr this is referring to?

@a-maurice a-maurice enabled auto-merge (squash) July 5, 2023 20:40
@a-maurice a-maurice merged commit 6a59781 into main Jul 5, 2023
@github-actions github-actions bot added tests: in-progress This PR's integration tests are in progress. tests: succeeded This PR's integration tests succeeded. and removed tests: succeeded This PR's integration tests succeeded. labels Jul 5, 2023
@firebase-workflow-trigger firebase-workflow-trigger bot removed the tests: in-progress This PR's integration tests are in progress. label Jul 6, 2023
tom-andersen pushed a commit that referenced this pull request Jul 17, 2023
…of our own. (#1365) * Remove headers from CMake file. * Find-and-replace change. * Format code. * Find and replace for std::atomic. * Format code. * Update to Dec 2022 release of boringssl. In this release, the "src" directory is removed from boringssl, so there are some CMake and patch changes necessary for compatibility. * Re-add patch file. * Switch to std::make_unique. * Fix make_shared, std::move, and class initialization. * WIP. * Fix more move syntax. * Fix more std::move issues. Revert Firestore. * Remove debug output * Fix Android Firestore test, and Storage assignment. * Make the callback safer via shared_ptr. * Fix lint errors. * Format code. * More lint fixes. * More lint. * Additional lint warning fixes. * Fix Firestore test. * Fix more lints. * Lint lint lint. * Change RequestDataPtr to a unique_ptr since STLPort is no longer used. * Remove Move() and Forward(), replacing with std::move() and std::foward<>(). * Format code and lint fixes. * Change firebase::Move explicitly to std::move. * Remove lint warnings for headers. * More lint warnings on includes. * Format code. * Return back to shared pointer. * Add note about NewCallback and link to TODO. * Fix lint error. * Fix a lingering firebase::Move. * Fix optional_test to mock Move correctly again. * Revert prereqs script, python3 change will be made elsewhere. * Lint. * Remove references to atomic_test. * Fix Move -> std::move once more * Fix a seg fault race condition on Linux by using a unique_ptr. This code always wanted to use a unique_ptr, but was previously using a SharedPtr because of STLPort. However, even without STLPort, there is still an issue switching it to a unique_ptr, which is that std::priority_queue is misdesigned and does not return a mutable reference in C++14. Because of this, if we want to std::move from a priority queue, we need to do a const cast. * Empty commit. * Fix test error. * Fix test compilation error. * Fix additional test build error. * Vector initializer lists use copy semantics. Switch to push_back since these are just tests. * Fix Forward --> std::forward from the merged Firestore change. * Add callback tests for shared_ptr wrapping a unique_ptr.
@firebase firebase locked and limited conversation to collaborators Aug 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

skip-release-notes Skip release notes check tests: succeeded This PR's integration tests succeeded.

4 participants