Nvwa
1.1
|
Namespace of the nvwa project. More...
Classes | |
class | bad_optional_access |
Class for bad optional access exception. More... | |
class | bool_array |
Class to represent a packed boolean array. More... | |
class | breadth_first_iteration |
Iteration class for breadth-first traversal. More... | |
class | class_level_lock |
Helper class for class-level locking. More... | |
class | class_level_lock< _Host, false > |
Partial specialization that makes null locking. More... | |
class | debug_new_counter |
Counter class for on-exit leakage check. More... | |
class | debug_new_recorder |
Recorder class to remember the call context. More... | |
struct | delete_object |
Functor to delete objects pointed by a container of pointers. More... | |
class | depth_first_iteration |
Iteration class for depth-first traversal. More... | |
struct | dereference |
Functor to return objects pointed by a container of pointers. More... | |
struct | dereference_less |
Functor to compare objects pointed by a container of pointers. More... | |
class | fast_mutex |
Class for non-reentrant fast mutexes. More... | |
class | fast_mutex_autolock |
RAII lock class for fast_mutex. More... | |
class | fc_queue |
Class to represent a fixed-capacity queue. More... | |
class | file_line_reader |
Class to allow iteration over all lines of a text file. More... | |
class | fixed_mem_pool |
Class template to manipulate a fixed-size memory pool. More... | |
class | in_order_iteration |
Iteration class for in-order traversal. More... | |
class | istream_line_reader |
Class to allow iteration over all lines from an input stream. More... | |
class | mem_pool_base |
Base class for memory pools. More... | |
class | mmap_line_reader |
Class to allow iteration over all lines of a mmappable file. More... | |
struct | new_ptr_list_t |
Structure to store the position information where new occurs. More... | |
class | object_level_lock |
Helper class for object-level locking. More... | |
class | optional |
Class for optional values. More... | |
struct | output_object |
Functor to output objects pointed by a container of pointers. More... | |
struct | smart_ptr |
Declaration of policy class to generate the smart pointer type. More... | |
struct | smart_ptr< _Tp, storage_policy::shared > |
Partial specialization to get std::shared_ptr. More... | |
struct | smart_ptr< _Tp, storage_policy::unique > |
Partial specialization to get std::unique_ptr. More... | |
class | static_mem_pool |
Singleton class template to manage the allocation/deallocation of memory blocks of one specific size. More... | |
class | static_mem_pool_set |
Singleton class to maintain a set of existing instantiations of static_mem_pool. More... | |
class | tree |
Basic tree (node) class template that owns all its children. More... | |
Typedefs | |
typedef void(* | stacktrace_print_callback_t) (FILE *fp, void **stacktrace) |
Callback type for stack trace printing. More... | |
typedef bool(* | leak_whitelist_callback_t) (char const *file, int line, void *addr, void **stacktrace) |
Callback type for the leak whitelist function. More... | |
Enumerations | |
enum | storage_policy { storage_policy::unique, storage_policy::shared } |
_Policy class for how to store members. More... | |
Functions | |
int | check_leaks () |
Checks for memory leaks. More... | |
int | check_mem_corruption () |
Checks for heap corruption. More... | |
static bool | print_position_from_addr (const void *addr) |
Tries printing the position information from an instruction address. More... | |
static void | print_position (const void *ptr, int line) |
Prints the position information of a memory operation point. More... | |
static void | print_stacktrace (void **stacktrace) |
Prints the stack backtrace. More... | |
static bool | is_leak_whitelisted (new_ptr_list_t *ptr) |
Checks whether a leak should be ignored. More... | |
static void * | alloc_mem (size_t size, const char *file, int line, bool is_array) |
Allocates memory and initializes control data. More... | |
static void | free_pointer (void *usr_ptr, void *addr, bool is_array) |
Frees memory and adjusts pointers. More... | |
void | swap (bool_array &lhs, bool_array &rhs) noexcept |
Exchanges the content of two bool_arrays. More... | |
template<class _Tp , class _Alloc > | |
void | swap (fc_queue< _Tp, _Alloc > &lhs, fc_queue< _Tp, _Alloc > &rhs) |
Exchanges the elements of two queues. More... | |
template<storage_policy _Policy = NVWA_TREE_DEFAULT_STORAGE_POLICY, typename _Tp > | |
tree< typename std::decay< _Tp >::type, _Policy >::tree_ptr | create_tree (_Tp &&value) |
Creates a tree without any children. More... | |
template<storage_policy _Policy = NVWA_TREE_DEFAULT_STORAGE_POLICY, typename _Tp , typename... Args> | |
tree< typename std::decay< _Tp >::type, _Policy >::tree_ptr | create_tree (_Tp &&value, Args &&... args) |
Creates a tree with children. More... | |
template<typename _Fn > | |
auto | lift_optional (_Fn &&f) |
Lifts a function so that it takes optionals and returns an optional. More... | |
template<typename _Fn , typename... _Opt> | |
constexpr auto | apply (_Fn &&f, _Opt &&... args) -> decltype(has_value(args...), optional< std::decay_t< decltype(f(std::forward< _Opt >(args).value()...))>>()) |
Applies a function to the values of optionals if they are all valid. More... | |
template<typename _Fn , class _Tuple > | |
constexpr auto | apply (_Fn &&f, _Tuple &&t) -> decltype(detail::tuple_apply_impl(std::forward< _Fn >(f), std::forward< _Tuple >(t), std::make_index_sequence< std::tuple_size< std::decay_t< _Tuple >>::value >())) |
Applies the function with all elements of the typle as arguments. More... | |
template<typename _Fn , typename _T1 , typename _T2 > | |
constexpr auto | fmap (_Fn &&f, const std::pair< _T1, _T2 > &args) |
Applies a function to both elements of a pair, and makes the results a pair. More... | |
template<typename _Fn , typename... _Targs> | |
constexpr auto | fmap (_Fn &&f, const std::tuple< _Targs... > &args) |
Applies a function to all elements of a tuple, and makes the results a tuple. More... | |
template<template< typename, typename > class _OutCont = std::vector, template< typename > class _Alloc = std::allocator, typename _Fn , class _Rng > | |
constexpr auto | fmap (_Fn &&f, _Rng &&inputs) -> decltype(detail::adl_begin(inputs), detail::adl_end(inputs), _OutCont< std::decay_t< decltype(f(*detail::adl_begin(inputs)))>, _Alloc< std::decay_t< decltype(f(*detail::adl_begin(inputs)))>>>()) |
Applies a function to each element in the input range. More... | |
template<typename _Rs , typename _Fn , typename... _Targs> | |
constexpr auto | reduce (_Fn &&f, const std::tuple< _Targs... > &args, _Rs &&value) |
Applies a function cumulatively to all elements of a tuple. More... | |
template<typename _Fn , class _Rng > | |
constexpr auto | reduce (_Fn &&f, _Rng &&inputs) |
Applies a function cumulatively to elements in the input range. More... | |
template<typename _Rs , typename _Fn , typename _Iter > | |
constexpr _Rs && | reduce (_Fn &&f, _Rs &&value, _Iter begin, _Iter end) |
Applies a function cumulatively to a range. More... | |
template<typename _Rs , typename _Fn , class _Rng > | |
constexpr auto | reduce (_Fn &&f, _Rng &&inputs, _Rs &&initval) -> decltype(f(initval, *detail::adl_begin(inputs))) |
Applies a function cumulatively to elements in the input range. More... | |
template<typename _T1 , typename _T2 , typename _Fn > | |
constexpr auto | wrap_args_as_pair (_Fn &&f) |
Makes a two-argument function accept a pair instead. More... | |
template<typename _Tuple , typename _Fn > | |
constexpr auto | wrap_args_as_tuple (_Fn &&f) |
Makes a function accept a tuple as its arguments. More... | |
template<typename _Tp > | |
constexpr _Tp | pipeline (_Tp &&data) |
Returns the data intact to terminate the recursion. | |
template<typename _Tp , typename _Fn , typename... _Fargs> | |
decltype(auto) constexpr | pipeline (_Tp &&data, _Fn &&f, _Fargs &&... args) |
Applies the functions in the arguments to the data consecutively. More... | |
auto | compose () |
Constructs a function (object) that composes the passed functions. More... | |
template<typename _Fn > | |
auto | compose (_Fn f) |
Constructs a function (object) that composes the passed functions. More... | |
template<typename _Fn , typename... _Fargs> | |
auto | compose (_Fn f, _Fargs... args) |
Constructs a function (object) that composes the passed functions. More... | |
template<typename _Rs , typename _Tp > | |
std::function< _Rs(_Tp)> | fix_simple (std::function< _Rs(std::function< _Rs(_Tp)>, _Tp)> f) |
Generates the fixed point using the simple fixed-point combinator. More... | |
template<typename _Rs , typename _Tp > | |
std::function< _Rs(_Tp)> | fix_simple (std::function< std::function< _Rs(_Tp)>(std::function< _Rs(_Tp)>)> f) |
Generates the fixed point using the simple fixed-point combinator. More... | |
template<typename _Rs , typename _Tp > | |
std::function< _Rs(_Tp)> | fix_curry (std::function< std::function< _Rs(_Tp)>(std::function< _Rs(_Tp)>)> f) |
Generates the fixed point using the Curry-style fixed-point combinator. More... | |
template<typename _Rs , typename... _Targs> | |
auto | make_curry (std::function< _Rs(_Targs...)> f) |
Makes a curried function. More... | |
template<typename _Rs , typename... _Targs> | |
auto | make_curry (_Rs(*f)(_Targs...)) |
Makes a curried function. More... | |
template<typename _FnType , typename _Fn > | |
auto | make_curry (_Fn &&f) |
Makes a curried function. More... | |
Variables | |
bool | new_autocheck_flag = true |
Flag to control whether nvwa::check_leaks will be automatically called on program exit. | |
bool | new_verbose_flag = false |
Flag to control whether verbose messages are output. | |
FILE * | new_output_fp = stderr |
Pointer to the output stream. More... | |
const char * | new_progname = _DEBUG_NEW_PROGNAME |
Pointer to the program name. More... | |
stacktrace_print_callback_t | stacktrace_print_callback = nullptr |
Pointer to the callback used to print the stack backtrace in case of a memory problem. More... | |
leak_whitelist_callback_t | leak_whitelist_callback = nullptr |
Pointer to the callback used to filter out false positives from leak reports. More... | |
static debug_new_counter | __debug_new_count |
Counting object for each file including debug_new.h. More... | |
const size_t | PLATFORM_MEM_ALIGNMENT = sizeof(size_t) * 2 |
The platform memory alignment. More... | |
static const unsigned | DEBUG_NEW_MAGIC = 0x4442474E |
Definition of the constant magic number used for error detection. | |
static const int | ALIGNED_LIST_ITEM_SIZE = ALIGN(sizeof(new_ptr_list_t)) |
The extra memory allocated by operator new . | |
static new_ptr_list_t | new_ptr_list |
List of all new'd pointers. | |
static fast_mutex | new_ptr_lock |
The mutex guard to protect simultaneous access to the pointer list. | |
static fast_mutex | new_output_lock |
The mutex guard to protect simultaneous output to new_output_fp. | |
static size_t | total_mem_alloc = 0 |
Total memory allocated in bytes. | |
const size_t | BUFFER_SIZE = 256 |
Size of buffer. More... | |
Namespace of the nvwa project.
Most functions and global variables are defined in this namespace.
typedef bool(* nvwa::leak_whitelist_callback_t) (char const *file, int line, void *addr, void **stacktrace) |
Callback type for the leak whitelist function.
file, address, and backtrace might be null depending on library configuration, platform, and amount of runtime information available. line can be 0 when line number info is not available at runtime.
file | null-terminated string of the file name |
line | line number |
addr | address of code where leakage happens |
stacktrace | pointer to the stack trace array (null-terminated) |
true
if the leak should be whitelisted; false
otherwise typedef void(* nvwa::stacktrace_print_callback_t) (FILE *fp, void **stacktrace) |
Callback type for stack trace printing.
fp | pointer to the output stream |
stacktrace | pointer to the stack trace array (null-terminated) |
|
strong |
|
static |
Allocates memory and initializes control data.
size | size of the required memory block |
file | null-terminated string of the file name |
line | line number |
is_array | boolean value whether this is an array operation |
constexpr auto nvwa::apply | ( | _Fn && | f, |
_Opt &&... | args | ||
) | -> decltype( has_value(args...), optional< std::decay_t<decltype(f(std::forward<_Opt>(args).value()...))>>()) |
Applies a function to the values of optionals if they are all valid.
If any of the optionals are invalid, the result is invalid too.
f | the function to apply |
args | optionals whose values will be passed to f |
constexpr auto nvwa::apply | ( | _Fn && | f, |
_Tuple && | t | ||
) | -> decltype(detail::tuple_apply_impl( std::forward<_Fn>(f), std::forward<_Tuple>(t), std::make_index_sequence< std::tuple_size<std::decay_t<_Tuple>>::value>())) |
Applies the function with all elements of the typle as arguments.
It is exactly like the C++17 std::apply.
f | the function to apply |
t | the tuple that can expand to the function arguments |
int nvwa::check_leaks | ( | ) |
Checks for memory leaks.
int nvwa::check_mem_corruption | ( | ) |
Checks for heap corruption.
auto nvwa::compose | ( | ) |
Constructs a function (object) that composes the passed functions.
auto nvwa::compose | ( | _Fn | f | ) |
Constructs a function (object) that composes the passed functions.
f | the function to compose |
auto nvwa::compose | ( | _Fn | f, |
_Fargs... | args | ||
) |
Constructs a function (object) that composes the passed functions.
f | the last function to compose |
args | the other functions to compose |
tree<typename std::decay<_Tp>::type, _Policy>::tree_ptr nvwa::create_tree | ( | _Tp && | value | ) |
Creates a tree without any children.
value | the value to assign to the tree node |
tree<typename std::decay<_Tp>::type, _Policy>::tree_ptr nvwa::create_tree | ( | _Tp && | value, |
Args &&... | args | ||
) |
Creates a tree with children.
value | the value to assign to the tree node |
args | the unique_ptrs to children of the tree |
std::function<_Rs(_Tp)> nvwa::fix_curry | ( | std::function< std::function< _Rs(_Tp)>(std::function< _Rs(_Tp)>)> | f | ) |
Generates the fixed point using the Curry-style fixed-point combinator.
This function takes a curried function of one parameter.
f | the second-order function to combine with |
std::function<_Rs(_Tp)> nvwa::fix_simple | ( | std::function< _Rs(std::function< _Rs(_Tp)>, _Tp)> | f | ) |
Generates the fixed point using the simple fixed-point combinator.
This function takes a non-curried function of two parameters.
f | the second-order function to combine with |
std::function<_Rs(_Tp)> nvwa::fix_simple | ( | std::function< std::function< _Rs(_Tp)>(std::function< _Rs(_Tp)>)> | f | ) |
Generates the fixed point using the simple fixed-point combinator.
This function takes a curried function of one parameter.
f | the second-order function to combine with |
constexpr auto nvwa::fmap | ( | _Fn && | f, |
const std::pair< _T1, _T2 > & | args | ||
) |
Applies a function to both elements of a pair, and makes the results a pair.
f | the function to apply |
args | pair of arguments to pass |
constexpr auto nvwa::fmap | ( | _Fn && | f, |
const std::tuple< _Targs... > & | args | ||
) |
Applies a function to all elements of a tuple, and makes the results a tuple.
f | the function to apply |
args | tuple of arguments to pass |
constexpr auto nvwa::fmap | ( | _Fn && | f, |
_Rng && | inputs | ||
) | -> decltype( detail::adl_begin(inputs), detail::adl_end(inputs), _OutCont< std::decay_t<decltype(f(*detail::adl_begin(inputs)))>, _Alloc<std::decay_t<decltype(f(*detail::adl_begin(inputs)))>>>()) |
Applies a function to each element in the input range.
This is similar to std::transform
, but the style is more functional and more suitable for chaining operations.
f | the function to apply |
inputs | the input range |
push_back
, and the input range shall support iteration.
|
static |
Frees memory and adjusts pointers.
usr_ptr | pointer to the previously allocated memory |
addr | pointer to the caller |
is_array | flag indicating whether it is invoked by a delete[] call |
|
static |
Checks whether a leak should be ignored.
Its runtime performance depends on the callback nvwa::leak_whitelist_callback.
ptr | pointer to a new_ptr_list_t struct |
true
if the leak should be whitelisted; false
otherwise auto nvwa::lift_optional | ( | _Fn && | f | ) |
Lifts a function so that it takes optionals and returns an optional.
f | function to lift |
auto nvwa::make_curry | ( | std::function< _Rs(_Targs...)> | f | ) |
Makes a curried function.
The returned function takes one argument at a time, and return a function that takes the next argument until all arguments are exhausted, in which case it returns the final result. This overload takes an std::function and can deduce its argument types and return type.
f | the function to be curried as a std::function |
auto nvwa::make_curry | ( | _Rs(*)(_Targs...) | f | ) |
Makes a curried function.
The returned function takes one argument at a time, and return a function that takes the next argument until all arguments are exhausted, in which case it returns the final result. This overload takes a pointer to function and can deduce its argument types and return type.
f | the function to be curried as a function pointer |
auto nvwa::make_curry | ( | _Fn && | f | ) |
Makes a curried function.
The returned function takes one argument at a time, and return a function that takes the next argument until all arguments are exhausted, in which case it returns the final result. This overload takes a generic function object, and the function type must be specified when this function template is instantiated.
f | the function to be curried as a function pointer |
decltype(auto) constexpr nvwa::pipeline | ( | _Tp && | data, |
_Fn && | f, | ||
_Fargs &&... | args | ||
) |
Applies the functions in the arguments to the data consecutively.
data | the data to operate on |
f | the first function to apply |
args | the rest functions to apply |
|
static |
Prints the position information of a memory operation point.
When _DEBUG_NEW_USE_ADDR2LINE
is defined to a non-zero value, this function will try to convert a given caller address to file/line information with addr2line.
ptr | source file name if line is non-zero; caller address otherwise |
line | source line number if non-zero; indication that ptr is the caller address otherwise |
|
static |
Tries printing the position information from an instruction address.
This is the version that uses addr2line.
addr | the instruction address to convert and print |
true
if the address is converted successfully (and the result is printed); false
if no useful information is got (and nothing is printed)
|
static |
Prints the stack backtrace.
When nvwa::stacktrace_print_callback is not null, it is used for printing the stacktrace items. Default implementation of call stack printing is very spartan—only stack frame pointers are printed—but even that output is still useful. Just do address lookup in LLDB etc.
stacktrace | pointer to the stack trace array |
constexpr auto nvwa::reduce | ( | _Fn && | f, |
const std::tuple< _Targs... > & | args, | ||
_Rs && | value | ||
) |
Applies a function cumulatively to all elements of a tuple.
f | the function to apply |
value | the first argument to be passed to the function |
args | the input tuple |
constexpr auto nvwa::reduce | ( | _Fn && | f, |
_Rng && | inputs | ||
) |
Applies a function cumulatively to elements in the input range.
This is similar to std::accumulate
, but the style is more functional and more suitable for chaining operations.
f | the function to apply |
inputs | the input range |
constexpr _Rs&& nvwa::reduce | ( | _Fn && | f, |
_Rs && | value, | ||
_Iter | begin, | ||
_Iter | end | ||
) |
Applies a function cumulatively to a range.
This is similar to std::accumulate
, but the interface is different, and f is allowed to have arguments of different types (the first argument shall have the same type as the function return type). Perfect forwarding allows the result to be a reference type.
f | the function to apply |
value | the first argument to be passed to f |
begin | beginning of the range |
end | end of the range |
constexpr auto nvwa::reduce | ( | _Fn && | f, |
_Rng && | inputs, | ||
_Rs && | initval | ||
) | -> decltype(f(initval, *detail::adl_begin(inputs))) |
Applies a function cumulatively to elements in the input range.
This is similar to std::accumulate
, but the style is more functional and more suitable for chaining operations. This implementation allows the two arguments of f to have different types (the first argument shall have the same type as the function return type). Perfect forwarding allows the result to be a reference type, and it is possible to write code like:
f | the function to apply |
inputs | the input range |
initval | initial value for the cumulative calculation |
|
inlinenoexcept |
Exchanges the content of two bool_arrays.
lhs | the first bool_array to exchange |
rhs | the second bool_array to exchange |
void nvwa::swap | ( | fc_queue< _Tp, _Alloc > & | lhs, |
fc_queue< _Tp, _Alloc > & | rhs | ||
) |
Exchanges the elements of two queues.
lhs | the first queue to exchange |
rhs | the second queue to exchange |
constexpr auto nvwa::wrap_args_as_pair | ( | _Fn && | f | ) |
Makes a two-argument function accept a pair instead.
f | a function that accepts two arguments |
constexpr auto nvwa::wrap_args_as_tuple | ( | _Fn && | f | ) |
Makes a function accept a tuple as its arguments.
The tuple shall contain exactly the same type/number of argument as the function needs.
f | a function that accepts two arguments |
|
static |
Counting object for each file including debug_new.h.
const size_t nvwa::BUFFER_SIZE = 256 |
Size of buffer.
leak_whitelist_callback_t nvwa::leak_whitelist_callback = nullptr |
Pointer to the callback used to filter out false positives from leak reports.
A null value means the lack of filtering.
FILE * nvwa::new_output_fp = stderr |
Pointer to the output stream.
The default output is stderr, and one may change it to a user stream if needed (say, new_verbose_flag is true
and there are a lot of (de)allocations).
const char * nvwa::new_progname = _DEBUG_NEW_PROGNAME |
Pointer to the program name.
Its initial value is the macro _DEBUG_NEW_PROGNAME. You should try to assign the program path to it early in your application. Assigning argv[0]
to it in main is one way. If you use bash or ksh (or similar), the following statement is probably what you want: `new_progname = getenv("_");
'.
const size_t nvwa::PLATFORM_MEM_ALIGNMENT = sizeof(size_t) * 2 |
The platform memory alignment.
The current value works well in platforms I have tested: Windows XP, Windows 7 x64, and Mac OS X Leopard. It may be smaller than the real alignment, but must be bigger than sizeof(size_t)
for it work. nvwa::debug_new_recorder uses it to detect misaligned pointer returned by `new NonPODType[size]
'.
stacktrace_print_callback_t nvwa::stacktrace_print_callback = nullptr |
Pointer to the callback used to print the stack backtrace in case of a memory problem.
A null value causes the default stack trace printing routine to be used.