2. Common Facilities

The common facilities encompass error handling, memory management, and tracing. These are consolidated in a thread-local global variable named vrtql. As this variable is thread-local, each thread maintains its independent copy.

2.1. Error Handling

Error handling in the API is facilitated through the usage of a code and a human-readable string. These are encapsulated within an instance of the vrtql_error_value structure, kept in vrtql.e member. Error handling is done through the vrtql.error() and vrtql.process_error() function pointers. The vrtql.error() function submits an error for processing and the vrtql.process_error() takes action on the error. You can customize both of these handlers by assiging them to different functions. The default implementation for vrtql.error() is vrtql_error_default_submit() whereas the default implementation for vrtql.process_error() is vrtql_error_default_process().

2.2. Tracing

Tracing is a mechanism for logging debug information and is managed by the vrtql.trace() function. Tracing outputs log messages associated with different severity levels (DEBUG, INFO, WARNING, ERROR), with the level determined by the first parameter of vrtql.tracelevel. The default level is zero which disables all tracing. Other levels are defined by the vrtql_tl_t enum.

2.3. Memory Management

The library provides memory management functions that include error handling mechanisms. These functions are vrtql.malloc(), vrtql.calloc(), vrtql.realloc() and vrtql.free(). These all call the underlying OS functions but you can provide alternate implementations by assiging new functions.