MySQL 9.6.0
Source Code Documentation
mysql::debugging Namespace Reference

Classes

class  Object_lifetime_tracker
 Debug facility to log constructor/assignment/destructor usage for a class. More...
 

Typedefs

using Tracker_id = int
 Integral type used to uniquely identify objects. More...
 

Functions

template<int channel = 0>
Tracker_id tracker_get_object_id ()
 The value to use for m_id next time we construct an Allocator. More...
 
template<class Type >
std::string_view type_name ()
 Return the name of the given type (not demangled). More...
 
template<std::invocable< mysql::allocators::Memory_resource > Initializer_t, std::invocable Function_t>
int oom_test (const Initializer_t &initialize, const Function_t &function)
 Repeatedly call function(). More...
 
template<class Object_t >
int oom_test_copyable_object (const Object_t &object, std::invocable< Object_t & > auto function)
 Repeatedly construct copies of object and call function(copy). More...
 
template<class Object_t >
int oom_test_assignable_object (const Object_t &object, std::invocable< Object_t & > auto function)
 Repeatedly construct copies of object and call function(copy). More...
 
void test_eq_one_way (const auto &left, const auto &right, bool equal=true)
 Assert that both (left==right) and !(left!=right) have the same truth values as equal. More...
 
void test_eq (const auto &left, const auto &right, bool equal=true)
 Assert that (left==right), (right==left), !(left!=right), and !(right!=left) all have the same truth values as equal. More...
 
void test_cmp_one_way (const auto &left, const auto &right, auto cmp)
 For all 7 comparison operators, assert that (left OP right) == (cmp OP 0). More...
 
void test_cmp (const auto &left, const auto &right, std::strong_ordering cmp)
 For all 7 comparison operators, assert that (left OP right) == (cmp OP 0), and that (right OP left) == (0 OP cmp). More...
 
void test_cmp (const auto &left, const auto &right, int cmp)
 For all 7 comparison operators, assert that (left OP right) == (cmp OP 0), and that (right OP left) == (0 OP cmp). More...
 

Typedef Documentation

◆ Tracker_id

using mysql::debugging::Tracker_id = typedef int

Integral type used to uniquely identify objects.

Function Documentation

◆ oom_test()

template<std::invocable< mysql::allocators::Memory_resource > Initializer_t, std::invocable Function_t>
int mysql::debugging::oom_test ( const Initializer_t &  initialize,
const Function_t &  function 
)

Repeatedly call function().

In the Nth iteration, simulate out-of-memory error on the Nth allocation. Return as soon as it succeeds.

Template Parameters
Initializer_tType of initialization function.
Function_tType of function to call.
Parameters
initializeFunction called in each iteration, taking the Memory_resource object which will later simulate allocation failures as argument. This may, for instance, create and populate an object that uses the memory_resource. For the duration of the call to initializer, the Memory_resource will behave exactly like std::malloc.
functionFunction to test, which should take no parameters. This function may use the memory_resource that was previously passed to initialize. The Nth time it calls the allocate member, allocate will fail. The function is allowed two ways to report error: (1) If it returns mysql::utils::Return_status, Return_status::ok should indicate success and Return_status::error indicate out-of-memory. Otherwise, function return should indicate success and bad_alloc exception should indicate error.
Returns
The number of iterations until function() succeeded. If function is deterministic, this equals the number of allocations performed by the call to function().

◆ oom_test_assignable_object()

template<class Object_t >
int mysql::debugging::oom_test_assignable_object ( const Object_t &  object,
std::invocable< Object_t & > auto  function 
)

Repeatedly construct copies of object and call function(copy).

In the Nth iteration, simulate out-of-memory error on the Nth allocation. Return as soon as it succeeds.

This is intended for use with non-throwing containers which do not have a copy constructor.

Template Parameters
Object_tType of the object. This must have a constructor taking a Memory_resource as parameter, and a member function assign taking another Object_t as argument. The assign member must not replace the memory resource used by the object to allocate.
Parameters
objectObject to test.
functionFunction to test, which should take an Object& as its only parameter. This function may use the memory_resource that was previously passed to initialize. The Nth time it calls the allocate member, allocate will fail. The function is allowed two ways to report error: (1) If it returns mysql::utils::Return_status, Return_status::ok should indicate success and Return_status::error indicate out-of-memory. Otherwise, function return should indicate success and bad_alloc exception should indicate error.
Returns
The number of iterations until function(copy) succeeded. If function is deterministic, this equals the number of allocations performed by the call to function(copy).

◆ oom_test_copyable_object()

template<class Object_t >
int mysql::debugging::oom_test_copyable_object ( const Object_t &  object,
std::invocable< Object_t & > auto  function 
)

Repeatedly construct copies of object and call function(copy).

In the Nth iteration, simulate out-of-memory error on the Nth allocation. Return as soon as it succeeds.

Template Parameters
Object_tType of the object. This must have a constructor taking (const Object_t& , Memory_resource) parameters.
Parameters
objectObject to test.
functionFunction to test, which should take an Object& as its only parameter. This function may use the memory_resource that was previously passed to initialize. The Nth time it calls the allocate member, allocate will fail. The function is allowed two ways to report error: (1) If it returns mysql::utils::Return_status, Return_status::ok should indicate success and Return_status::error indicate out-of-memory. Otherwise, function return should indicate success and bad_alloc exception should indicate error.
Returns
The number of iterations until function(copy) succeeded. If function is deterministic, this equals the number of allocations performed by the call to function(copy).

◆ test_cmp() [1/2]

void mysql::debugging::test_cmp ( const auto &  left,
const auto &  right,
int  cmp 
)

For all 7 comparison operators, assert that (left OP right) == (cmp OP 0), and that (right OP left) == (0 OP cmp).

This overload is for when cmp is of type int.

Parameters
leftLeft-hand-side operand.
rightRight-hand-side operand.
cmpExpected outcome: -1 if left<right, 0 if left==right, and 1 if left>right.

(Despite the parameter names, this will also test the case where left and right are swapped and cmp reversed).

◆ test_cmp() [2/2]

void mysql::debugging::test_cmp ( const auto &  left,
const auto &  right,
std::strong_ordering  cmp 
)

For all 7 comparison operators, assert that (left OP right) == (cmp OP 0), and that (right OP left) == (0 OP cmp).

Parameters
leftLeft-hand-side operand.
rightRight-hand-side operand.
cmpExpected outcome.

(Despite the parameter names, this will also test the case where left and right are swapped and cmp reversed).

◆ test_cmp_one_way()

void mysql::debugging::test_cmp_one_way ( const auto &  left,
const auto &  right,
auto  cmp 
)

For all 7 comparison operators, assert that (left OP right) == (cmp OP 0).

Parameters
leftLeft-hand-side operand.
rightRight-hand-side operand.
cmpExpected outcome. This must be of a type that can be compared with 0: typically either int or std::strong_ordering.

◆ test_eq()

void mysql::debugging::test_eq ( const auto &  left,
const auto &  right,
bool  equal = true 
)

Assert that (left==right), (right==left), !(left!=right), and !(right!=left) all have the same truth values as equal.

Parameters
leftLeft-hand-side operand.
rightRight-hand-side operand.
equalIf true (the default), left and right are expected to be equal; otherwise they are expected to be different.

(Despite the parameter names, this will also test the case where left and right are swapped).

◆ test_eq_one_way()

void mysql::debugging::test_eq_one_way ( const auto &  left,
const auto &  right,
bool  equal = true 
)

Assert that both (left==right) and !(left!=right) have the same truth values as equal.

Parameters
leftLeft-hand-side operand.
rightRight-hand-side operand.
equalIf true (the default), left and right are expected to be equal; otherwise they are expected to be different.

◆ tracker_get_object_id()

template<int channel = 0>
Tracker_id mysql::debugging::tracker_get_object_id ( )

The value to use for m_id next time we construct an Allocator.

Not a member variable of Object_lifetime_tracker because we need one global instance, not one per specialization.

Template Parameters
channelIdentifies a unique sequence of object ids.

◆ type_name()

template<class Type >
std::string_view mysql::debugging::type_name ( )

Return the name of the given type (not demangled).