Add pdfium::WrapRetain<>() type deducing wrapper Provide consistency with unique_ptrs. Use it in one spot. Change-Id: I74f95c2e316d5550d603143e49c4b39a710e277e Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/52910 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/retain_ptr.h b/core/fxcrt/retain_ptr.h index 02faff6..edd2663 100644 --- a/core/fxcrt/retain_ptr.h +++ b/core/fxcrt/retain_ptr.h
@@ -130,6 +130,12 @@ return RetainPtr<T>(new T(std::forward<Args>(args)...)); } +// Type-deducing wrapper to make a RetainPtr from an ordinary pointer. +template <typename T> +RetainPtr<T> WrapRetain(T* that) { + return RetainPtr<T>(that); +} + } // namespace pdfium #endif // CORE_FXCRT_RETAIN_PTR_H_
diff --git a/xfa/fgas/font/cfgas_gefont.cpp b/xfa/fgas/font/cfgas_gefont.cpp index 07f9fce..fb5944d 100644 --- a/xfa/fgas/font/cfgas_gefont.cpp +++ b/xfa/fgas/font/cfgas_gefont.cpp
@@ -210,7 +210,7 @@ bool bRecursive) { int32_t iGlyphIndex = m_pFontEncoding->GlyphFromCharCode(wUnicode); if (iGlyphIndex > 0) - return {iGlyphIndex, RetainPtr<CFGAS_GEFont>(this)}; + return {iGlyphIndex, pdfium::WrapRetain(this)}; const FGAS_FONTUSB* pFontUSB = FGAS_GetUnicodeBitField(wUnicode); if (!pFontUSB) @@ -267,6 +267,6 @@ RetainPtr<CFGAS_GEFont> CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) { iGlyphIndex = static_cast<uint32_t>(iGlyphIndex) >> 24; if (iGlyphIndex == 0) - return RetainPtr<CFGAS_GEFont>(this); + return pdfium::WrapRetain(this); return m_SubstFonts[iGlyphIndex - 1]; }