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

debug disposable #665

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions .github/workflows/ci v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,6 @@ jobs:
with:
fetch-depth: 0

# Work around https://github.com/actions/runner-images/issues/8659
# - name: "Remove GCC 13 from runner image (workaround)"
# shell: bash
# run: |
# sudo apt-get update
# sudo apt-get purge -y g++-13 gcc-13 libstdc++-13-dev
# sudo apt-get install -y --allow-downgrades libstdc++-12-dev libstdc++6=12.* libgcc-s1=12.*

- name: Install Qt
uses: jurplel/install-qt-action@v4
with:
Expand Down Expand Up @@ -146,15 +138,6 @@ jobs:
with:
fetch-depth: 0

# Work around https://github.com/actions/runner-images/issues/8659
# - name: "Remove GCC 13 from runner image (workaround)"
# if: matrix.config.os == 'ubuntu-latest'
# shell: bash
# run: |
# sudo apt-get update
# sudo apt-get purge -y g++-13 gcc-13 libstdc++-13-dev
# sudo apt-get install -y --allow-downgrades libstdc++-12-dev libstdc++6=12.* libgcc-s1=12.*

- name: ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
Expand Down Expand Up @@ -194,7 +177,7 @@ jobs:
uses: lukka/run-cmake@v10
with:
configurePreset: ${{ matrix.config.name }}-${{ matrix.type }}
configurePresetAdditionalArgs: "['-DCMAKE_BUILD_TYPE=${{ matrix.build_type.config }}', '-DCMAKE_CONFIGURATION_TYPES=${{ matrix.build_type.config }}']"
configurePresetAdditionalArgs: "['-DCMAKE_BUILD_TYPE=${{ matrix.build_type.config }}', '-DCMAKE_CONFIGURATION_TYPES=${{ matrix.build_type.config }}', '-DRPP_DEBUG_DISABLE_DISPOSABLES_OPTIMIZATION=1']"
buildPreset: ci-build
buildPresetAdditionalArgs: "['--config ${{ matrix.build_type.config }}']"
testPreset: ${{matrix.build_type.test_preset}}
Expand Down
2 changes: 2 additions & 0 deletions src/rpp/rpp/observables/details/disposable_strategy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ namespace rpp::details::observables
template<typename T, typename Prev>
consteval auto* deduce_updated_disposable_strategy()
{
#ifndef RPP_DEBUG_DISABLE_DISPOSABLES_OPTIMIZATION
if constexpr (has_updated_disposable_strategy<T, Prev>)
return static_cast<typename T::template updated_disposable_strategy<Prev>*>(nullptr);
else
#endif
Comment on lines +96 to +100
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the preprocessor directives to prevent syntax errors

The else statement following the if constexpr is outside of the #ifndef and #endif block. This can lead to a syntax error when RPP_DEBUG_DISABLE_DISPOSABLES_OPTIMIZATION is defined because the else would not have a matching if.

To resolve this issue, adjust the preprocessor directives so that both the if constexpr and the corresponding else are enclosed within the #ifndef block. Here are two ways to fix it:

Option 1: Include else within the #ifndef block

 template<typename T, typename Prev>
 consteval auto* deduce_updated_disposable_strategy()
 {
-#ifndef RPP_DEBUG_DISABLE_DISPOSABLES_OPTIMIZATION
     if constexpr (has_updated_disposable_strategy<T, Prev>)
         return static_cast<typename T::template updated_disposable_strategy<Prev>*>(nullptr);
+    else
+        return static_cast<default_disposable_strategy_selector*>(nullptr);
-#endif
+}
+#else
+    return static_cast<default_disposable_strategy_selector*>(nullptr);
 #endif
 }

Option 2: Move the default return outside the #ifndef block

template<typename T, typename Prev>
consteval auto* deduce_updated_disposable_strategy()
{
#ifndef RPP_DEBUG_DISABLE_DISPOSABLES_OPTIMIZATION
    if constexpr (has_updated_disposable_strategy<T, Prev>)
        return static_cast<typename T::template updated_disposable_strategy<Prev>*>(nullptr);
    else
#endif
    return static_cast<default_disposable_strategy_selector*>(nullptr);
}

return static_cast<default_disposable_strategy_selector*>(nullptr);
}
} // namespace details
Expand Down
2 changes: 2 additions & 0 deletions src/rpp/rpp/observers/details/fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ namespace rpp::details::observers
template<typename T>
consteval auto* deduce_disposable_strategy()
{
#ifndef RPP_DEBUG_DISABLE_DISPOSABLES_OPTIMIZATION
if constexpr (has_disposable_strategy<T>)
return static_cast<typename T::preferred_disposable_strategy*>(nullptr);
else
#endif
return static_cast<dynamic_local_disposable_strategy<0, atomic_bool>*>(nullptr);
}
} // namespace details
Expand Down
1 change: 1 addition & 0 deletions src/tests/utils/disposable_observable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ void test_operator_over_observable_with_disposable(auto&& op)
op(rpp::source::create<T>([](auto&& obs) {
const auto d = rpp::composite_disposable_wrapper::make();
obs.set_upstream(d);
CHECK(!d.is_disposed());
obs.on_completed();
CHECK(d.is_disposed());
})).subscribe([](const auto&) {}, [](const std::exception_ptr&) {});
Expand Down
Loading