diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-01-30 18:10:01 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-01-30 18:10:01 +0000 |
commit | bb1ee53577418429d2e30180bd941f16eea8b340 (patch) | |
tree | a323757e674ebab8ee7da05c169435e1062d1c26 /core/fxcrt | |
parent | 77d8ed02c7e97471ceccee5abbabeb2fdea413c7 (diff) | |
download | pdfium-bb1ee53577418429d2e30180bd941f16eea8b340.tar.xz |
Revert "Revert "Use UnownedPtr instead of T* in MaybeOwned.""
This reverts commit 77d8ed02c7e97471ceccee5abbabeb2fdea413c7.
Reason for revert: <INSERT REASONING HERE>
Original change's description:
> Revert "Use UnownedPtr instead of T* in MaybeOwned."
>
> This reverts commit e563e8352139e4852a955e319023b09f2844aee9.
>
> Reason for revert: <INSERT REASONING HERE>
>
> Original change's description:
> > Use UnownedPtr instead of T* in MaybeOwned.
> >
> > Always check the liftime in the unowned case. Doing so unearthed
> > the following issues:
> >
> > Transient lifetime issue in jbig2_image when doing realloc().
> > Stale (but unused) dictionary pointer in CPDF_Image.
> > Destruction order in error branch in cpdf_dibsource.cpp
> >
> > Change-Id: I12b758aafeefedc7abe1e8b21a18db959929e95f
> > Reviewed-on: https://pdfium-review.googlesource.com/24552
> > Commit-Queue: Tom Sepez <tsepez@chromium.org>
> > Reviewed-by: dsinclair <dsinclair@chromium.org>
>
> TBR=thestig@chromium.org,tsepez@chromium.org,dsinclair@chromium.org
>
> Change-Id: I3c56ee6ab502da90e3adb7507dbc8cc92f090140
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://pdfium-review.googlesource.com/24670
> Reviewed-by: Tom Sepez <tsepez@chromium.org>
> Commit-Queue: Tom Sepez <tsepez@chromium.org>
TBR=thestig@chromium.org,tsepez@chromium.org,dsinclair@chromium.org
Change-Id: I0ccbbeab8be6cadc9b3a5bfefe2aca733654342f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://pdfium-review.googlesource.com/24671
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcrt')
-rw-r--r-- | core/fxcrt/maybe_owned.h | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/core/fxcrt/maybe_owned.h b/core/fxcrt/maybe_owned.h index 11dd68642d..130d2bdc3c 100644 --- a/core/fxcrt/maybe_owned.h +++ b/core/fxcrt/maybe_owned.h @@ -11,6 +11,7 @@ #include "core/fxcrt/fx_memory.h" #include "core/fxcrt/fx_system.h" +#include "core/fxcrt/unowned_ptr.h" namespace fxcrt { @@ -33,25 +34,34 @@ class MaybeOwned { } void Reset(std::unique_ptr<T, D> ptr) { + m_pObj = ptr.get(); m_pOwnedObj = std::move(ptr); - m_pObj = m_pOwnedObj.get(); } void Reset(T* ptr = nullptr) { - m_pOwnedObj.reset(); m_pObj = ptr; + m_pOwnedObj.reset(); } + T* Get() const { return m_pObj.Get(); } bool IsOwned() const { return !!m_pOwnedObj; } - T* Get() const { return m_pObj; } + + // Downgrades to unowned, caller takes ownership. std::unique_ptr<T, D> Release() { ASSERT(IsOwned()); return std::move(m_pOwnedObj); } + // Downgrades to empty, caller takes ownership. + std::unique_ptr<T, D> ReleaseAndClear() { + ASSERT(IsOwned()); + m_pObj = nullptr; + return std::move(m_pOwnedObj); + } + MaybeOwned& operator=(const MaybeOwned& that) = delete; MaybeOwned& operator=(MaybeOwned&& that) { - m_pOwnedObj = std::move(that.m_pOwnedObj); m_pObj = that.m_pObj; + m_pOwnedObj = std::move(that.m_pOwnedObj); that.m_pObj = nullptr; return *this; } @@ -78,11 +88,11 @@ class MaybeOwned { explicit operator bool() const { return !!m_pObj; } T& operator*() const { return *m_pObj; } - T* operator->() const { return m_pObj; } + T* operator->() const { return m_pObj.Get(); } private: std::unique_ptr<T, D> m_pOwnedObj; - T* m_pObj; + UnownedPtr<T> m_pObj; }; } // namespace fxcrt |