Botan 3.14.1
Crypto and TLS for C&
Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType > Struct Template Reference

#include <ffi_util.h>

Inheritance diagram for Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >:
Botan_FFI::botan_ffi_obj_base

Public Types

using element_type = T
using smart_pointer_type = PtrType<T>

Public Member Functions

bool appears_to_be_valid_ffi_handle () const
 botan_ffi_obj (botan_ffi_obj &&other)=delete
 botan_ffi_obj (const botan_ffi_obj &other)=delete
 botan_ffi_obj (smart_pointer_type obj)
bool is_shared () const final
bool magic_ok () const
botan_ffi_obj & operator= (botan_ffi_obj &&other)=delete
botan_ffi_obj & operator= (const botan_ffi_obj &other)=delete
T * unsafe_get () const
 Retrieve the raw pointer to the underlying object. May be nullptr.
smart_pointer_type & unsafe_get_sp ()
 Retrieve the smart pointer to the underlying object. May be invalid.
const smart_pointer_type & unsafe_get_sp () const
 Retrieve the smart pointer to the underlying object. May be invalid.
size_t use_count () const final
virtual ~botan_ffi_obj ()

Protected Member Functions

void invalidate_magic ()
uint32_t magic () const

Detailed Description

template<typename T, uint32_t MAGIC, template< typename... Args > typename PtrType>
requires ffi_object_smart_pointer<PtrType<T>>
struct Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >

Base class for all FFI object handles wrapped around some specific type in the library. The inner type is managed by a configurable smart pointer type (e.g. std::unique_ptr or std::shared_ptr).

Definition at line 116 of file ffi_util.h.

Member Typedef Documentation

◆ element_type

template<typename T, uint32_t MAGIC, template< typename... Args > typename PtrType>
using Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >::element_type = T

Definition at line 118 of file ffi_util.h.

◆ smart_pointer_type

template<typename T, uint32_t MAGIC, template< typename... Args > typename PtrType>
using Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >::smart_pointer_type = PtrType<T>

Definition at line 119 of file ffi_util.h.

Constructor & Destructor Documentation

◆ botan_ffi_obj() [1/3]

template<typename T, uint32_t MAGIC, template< typename... Args > typename PtrType>
Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >::botan_ffi_obj ( smart_pointer_type obj)
inlineexplicit

◆ ~botan_ffi_obj()

template<typename T, uint32_t MAGIC, template< typename... Args > typename PtrType>
virtual Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >::~botan_ffi_obj ( )
inlinevirtual

Definition at line 124 of file ffi_util.h.

124 {
126 m_obj.reset(); // NOLINT(*-ambiguous-smartptr-reset-call)
127 }

References Botan_FFI::botan_ffi_obj_base::invalidate_magic().

◆ botan_ffi_obj() [2/3]

template<typename T, uint32_t MAGIC, template< typename... Args > typename PtrType>
Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >::botan_ffi_obj ( const botan_ffi_obj< T, MAGIC, PtrType > & other)
delete

References botan_ffi_obj().

◆ botan_ffi_obj() [3/3]

template<typename T, uint32_t MAGIC, template< typename... Args > typename PtrType>
Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >::botan_ffi_obj ( botan_ffi_obj< T, MAGIC, PtrType > && other)
delete

References botan_ffi_obj().

Member Function Documentation

◆ appears_to_be_valid_ffi_handle()

bool Botan_FFI::botan_ffi_obj_base::appears_to_be_valid_ffi_handle ( ) const
inlineinherited

Heuristic, type-agnostic check whether some casted void* pointer plausibly points to a live FFI object handle. This deliberately does not use virtual dispatch, so that the check works without relying on a potentially bogus vtable.

Note
Calling this on any pointer that isn't actually a Botan FFI object handle is undefined behavior. This is really just a best effort check to avoid dereferencing a pointer that is definitely not a valid FFI object handle.
Returns
false if the this-pointer definitely does not reference an alive FFI object handle. In contrast, returns true if it plausibly references an alive FFI object with the possibility of false-positives.

Definition at line 97 of file ffi_util.h.

97{ return m_magic != 0 && m_magic == m_magic_expected; }

◆ invalidate_magic()

void Botan_FFI::botan_ffi_obj_base::invalidate_magic ( )
inlineprotectedinherited

Definition at line 100 of file ffi_util.h.

100{ m_magic = 0; }

Referenced by Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >::~botan_ffi_obj().

◆ is_shared()

template<typename T, uint32_t MAGIC, template< typename... Args > typename PtrType>
bool Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >::is_shared ( ) const
inlinefinalvirtual
Returns
true if the underlying type is managed via a shared_ptr

Implements Botan_FFI::botan_ffi_obj_base.

Definition at line 136 of file ffi_util.h.

◆ magic()

uint32_t Botan_FFI::botan_ffi_obj_base::magic ( ) const
inlineprotectedinherited

Definition at line 102 of file ffi_util.h.

102{ return m_magic; }

Referenced by botan_ffi_obj_base(), and Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >::magic_ok().

◆ magic_ok()

template<typename T, uint32_t MAGIC, template< typename... Args > typename PtrType>
bool Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >::magic_ok ( ) const
inline

Definition at line 134 of file ffi_util.h.

134{ return magic() == MAGIC; }

References Botan_FFI::botan_ffi_obj_base::magic().

◆ operator=() [1/2]

template<typename T, uint32_t MAGIC, template< typename... Args > typename PtrType>
botan_ffi_obj & Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >::operator= ( botan_ffi_obj< T, MAGIC, PtrType > && other)
delete

References botan_ffi_obj().

◆ operator=() [2/2]

template<typename T, uint32_t MAGIC, template< typename... Args > typename PtrType>
botan_ffi_obj & Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >::operator= ( const botan_ffi_obj< T, MAGIC, PtrType > & other)
delete

References botan_ffi_obj().

◆ unsafe_get()

template<typename T, uint32_t MAGIC, template< typename... Args > typename PtrType>
T * Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >::unsafe_get ( ) const
inline

Retrieve the raw pointer to the underlying object. May be nullptr.

Definition at line 147 of file ffi_util.h.

147{ return m_obj.get(); }

◆ unsafe_get_sp() [1/2]

template<typename T, uint32_t MAGIC, template< typename... Args > typename PtrType>
smart_pointer_type & Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >::unsafe_get_sp ( )
inline

Retrieve the smart pointer to the underlying object. May be invalid.

Definition at line 150 of file ffi_util.h.

150{ return m_obj; }

◆ unsafe_get_sp() [2/2]

template<typename T, uint32_t MAGIC, template< typename... Args > typename PtrType>
const smart_pointer_type & Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >::unsafe_get_sp ( ) const
inline

Retrieve the smart pointer to the underlying object. May be invalid.

Definition at line 153 of file ffi_util.h.

153{ return m_obj; }

◆ use_count()

template<typename T, uint32_t MAGIC, template< typename... Args > typename PtrType>
size_t Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >::use_count ( ) const
inlinefinalvirtual
Returns
internal reference count of the underlying object

Implements Botan_FFI::botan_ffi_obj_base.

Definition at line 138 of file ffi_util.h.

138 {
140 return static_cast<size_t>(m_obj.use_count());
141 } else {
142 return 1; // unique_ptr always has an implicit use count of 1
143 }
144 }

The documentation for this struct was generated from the following file: