5#ifndef CORE_FXCRT_UNOWNED_PTR_H_
6#define CORE_FXCRT_UNOWNED_PTR_H_
41#include "build/build_config.h"
42#include "core/fxcrt/compiler_specific.h"
44#if defined(PDF_USE_PARTITION_ALLOC)
45#include "partition_alloc/partition_alloc_buildflags.h"
46#include "partition_alloc/pointers/raw_ptr.h"
48#if !PA_BUILDFLAG(USE_PARTITION_ALLOC)
49#error "pdf_use_partition_alloc=true requires use_partition_alloc=true"
52#if PA_BUILDFLAG(ENABLE_DANGLING_RAW_PTR_CHECKS) ||
53 PA_BUILDFLAG(USE_RAW_PTR_ASAN_UNOWNED_IMPL)
54#define UNOWNED_PTR_DANGLING_CHECKS
57static_assert(raw_ptr<
int>::kZeroOnConstruct,
"Unsafe build arguments");
58static_assert(raw_ptr<
int>::kZeroOnMove,
"Unsafe build arguments");
61using UnownedPtr = raw_ptr<T>;
71#include "core/fxcrt/unowned_ptr_exclusion.h"
84 explicit constexpr UnownedPtr(T* pObj)
noexcept : m_pObj(pObj) {}
106 : m_pObj(that.ExtractAsDangling()) {}
139 m_pObj =
static_cast<U*>(that);
150 m_pObj = that.ExtractAsDangling();
159 bool operator==(
std::nullptr_t ptr)
const {
return m_pObj ==
nullptr; }
161 return m_pObj ==
static_cast<T*>(that);
164 return std::less<T*>()(m_pObj,
static_cast<T*>(that));
168 T*
get()
const noexcept {
return m_pObj; }
173 explicit operator bool()
const {
return !!m_pObj; }
183using fxcrt::UnownedPtr;
fxcrt::ByteString ByteString
std::vector< RetainPtr< CPDF_Object > >::const_iterator const_iterator
CPDF_Creator(CPDF_Document *pDoc, RetainPtr< IFX_RetainableWriteStream > archive)
bool SetFileVersion(int32_t fileVersion)
bool Create(uint32_t flags)
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
virtual FX_FILESIZE CurrentOffset() const =0
static RetainPtr< IFX_SeekableReadStream > CreateFromFilename(const char *filename)
virtual FX_FILESIZE GetPosition()
virtual bool ReadBlockAtOffset(pdfium::span< uint8_t > buffer, FX_FILESIZE offset)=0
virtual FX_FILESIZE GetSize()=0
bool WriteFilesize(FX_FILESIZE size)
bool WriteByte(uint8_t byte)
bool WriteString(ByteStringView str)
virtual ~IFX_WriteStream()=default
bool WriteDWord(uint32_t i)
virtual bool WriteBlock(pdfium::span< const uint8_t > data)=0
static ByteString Format(const char *pFormat,...)
ByteString & operator=(ByteString &&that) noexcept
UnownedPtr(const UnownedPtr< U > &that)
bool operator==(const UnownedPtr &that) const
operator T*() const noexcept
UnownedPtr(UnownedPtr< U > &&that) noexcept
UnownedPtr & operator=(UnownedPtr< U > &&that) noexcept
constexpr UnownedPtr(const UnownedPtr &that) noexcept=default
constexpr UnownedPtr(T *pObj) noexcept
UnownedPtr & operator=(T *that) noexcept
bool operator==(std::nullptr_t ptr) const
UnownedPtr & operator=(UnownedPtr &&that) noexcept
UnownedPtr & operator=(std::nullptr_t) noexcept
UnownedPtr & operator=(const UnownedPtr< U > &that) noexcept
constexpr UnownedPtr() noexcept=default
bool operator<(const UnownedPtr &that) const
UnownedPtr & operator=(const UnownedPtr &that) noexcept=default
constexpr UnownedPtr(UnownedPtr &&that) noexcept
constexpr UnownedPtr(std::nullptr_t ptr)
#define FPDFCREATE_INCREMENTAL
#define FPDFCREATE_NO_ORIGINAL
void * FX_Random_MT_Start(uint32_t dwSeed)
void FX_Random_MT_Close(void *pContext)
pdfium::CheckedNumeric< FX_FILESIZE > FX_SAFE_FILESIZE
UnownedPtr< T > WrapUnowned(T *that)
fxcrt::ByteStringView ByteStringView
#define UNOWNED_PTR_EXCLUSION