libonion
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions
Low level OS functions. Encapsulates some low level functions to allow other OS implementations (Boehm GC)

Functions

void onion_low_initialize_memory_allocation (onion_low_malloc_sigt *mallocrout, onion_low_scalar_malloc_sigt *scalarmallocrout, onion_low_calloc_sigt *callocrout, onion_low_realloc_sigt *reallocrout, onion_low_strdup_sigt *strduprout, onion_low_free_sigt *freerout, onion_low_memoryfailure_sigt *memoryfailurerout)
 Our configurator for memory routines.To be called once before any other onion processing at initialization. All the routines should be explicitly provided.
void * onion_low_malloc (size_t sz)
 NEVER FAILING MEMORY ALLOCATORS.
void * onion_low_scalar_malloc (size_t sz)
 Our malloc wrapper for scalar data which does not contain any pointers inside.Knowing that a given zone does not contain any pointer can be useful, e.g. to Hans Boehm's conservative garbage collector on http://hboehm.info/gc/ using GC_MALLOC_ATOMIC....
void * onion_low_calloc (size_t nmemb, size_t size)
 Our calloc wrapper for any kind of data, even scalar one.
void * onion_low_realloc (void *ptr, size_t size)
 Our realloc wrapper for any kind of data, even scalar one.
char * onion_low_strdup (const char *str)
 Our strdup wrapper.
void * onion_low_try_malloc (size_t sz)
 POSSIBLY FAILING MEMORY ALLOCATORS.
void * onion_low_try_scalar_malloc (size_t sz)
 Our malloc wrapper for scalar data which does not contain any pointers inside. May return NULL on fail.
void * onion_low_try_calloc (size_t nmemb, size_t size)
 Our calloc wrapper for any kind of data, even scalar one. May return NULL on fail.
void * onion_low_try_realloc (void *ptr, size_t size)
 Our realloc wrapper for any kind of data, even scalar one. May return NULL on fail.
char * onion_low_try_strdup (const char *str)
 Our strdup wrapper. May return NULL on fail.
void onion_low_free (void *ptr)
 Our free wrapper for any kind of data, even scalar one.
typedef void * onion_low_malloc_sigt (size_t sz)
 Signatures of user configurable memory routine replacement.
typedef void onion_low_memoryfailure_sigt (const char *msg)
 The memory failure handler is called with a short message.It generally should not return, i.e. should exit, abort, or perhaps setjmp....
typedef void * onion_low_scalar_malloc_sigt (size_t sz)
typedef void * onion_low_calloc_sigt (size_t nmemb, size_t size)
typedef void * onion_low_realloc_sigt (void *ptr, size_t size)
typedef char * onion_low_strdup_sigt (const char *ptr)
typedef void onion_low_free_sigt (void *ptr)

Detailed Description

File low.h provides low level utilities, notably wrapping memory allocation and thread creation. Adventurous users could even customize them during early initialization, e.g. when using Hans Boehm conservative garbage collector from http://hboehm.info/gc/ or when using their own malloc variant so we specialize general data - which might contain pointers and could be allocated with GC_MALLOC into scalar data which is guaranteed to be pointer free and could be allocated with GC_MALLOC_ATOMIC ...

If your server does not use an alternative implementation, feel free not to use this functions, but if it might use it, please use them.

Typedef Documentation

typedef void* onion_low_calloc_sigt(size_t nmemb, size_t size)
typedef void onion_low_free_sigt(void *ptr)
typedef void* onion_low_malloc_sigt(size_t sz)

Signatures of user configurable memory routine replacement.

typedef void onion_low_memoryfailure_sigt(const char *msg)

The memory failure handler is called with a short message.It generally should not return, i.e. should exit, abort, or perhaps setjmp....

typedef void* onion_low_realloc_sigt(void *ptr, size_t size)
typedef void* onion_low_scalar_malloc_sigt(size_t sz)
typedef char* onion_low_strdup_sigt(const char *ptr)

Function Documentation

void* onion_low_calloc ( size_t  nmemb,
size_t  size 
)
void onion_low_free ( void *  ptr)
void onion_low_initialize_memory_allocation ( onion_low_malloc_sigt mallocrout,
onion_low_scalar_malloc_sigt scalarmallocrout,
onion_low_calloc_sigt callocrout,
onion_low_realloc_sigt reallocrout,
onion_low_strdup_sigt strduprout,
onion_low_free_sigt freerout,
onion_low_memoryfailure_sigt memoryfailurerout 
)

Our configurator for memory routines.To be called once before any other onion processing at initialization. All the routines should be explicitly provided.

void* onion_low_malloc ( size_t  sz)

NEVER FAILING MEMORY ALLOCATORS.

These allocators should not fail: if memory is exhausted, they invoke the memory failure routine then abort with a short failure message. Our malloc wrapper for any kind of data, including data containing pointers.

References MEMORY_FAILURE.

Referenced by onion_add_listen_point(), onion_base64_encode(), onion_block_t::onion_block_new(), onion_handler_auth_pam(), onion_handler_export_local_new(), onion_handler_opack(), onion_handler_path(), onion_handler_static(), onion_handler_webdav(), onion_listen(), onion_ptr_list_add(), onion_response_t::onion_response_new(), onion_sessions_mem_new(), onion_sessions_redis_new(), onion_sessions_sqlite3_new(), onion_url_add_handler(), onion_url_add_static(), and onion_websocket_t::onion_websocket_new().

void* onion_low_realloc ( void *  ptr,
size_t  size 
)

Our realloc wrapper for any kind of data, even scalar one.

References MEMORY_FAILURE.

Referenced by onion_add_listen_point(), onion_block_t::onion_block_add_char(), and onion_block_t::onion_block_min_maxsize().

void* onion_low_scalar_malloc ( size_t  sz)

Our malloc wrapper for scalar data which does not contain any pointers inside.Knowing that a given zone does not contain any pointer can be useful, e.g. to Hans Boehm's conservative garbage collector on http://hboehm.info/gc/ using GC_MALLOC_ATOMIC....

References MEMORY_FAILURE.

Referenced by onion_base64_decode(), onion_block_t::onion_block_add_data(), onion_block_t::onion_block_new(), onion_c_quote_new(), onion_html_quote(), onion_quote_new(), onion_response_t::onion_response_vprintf(), onion_sessions_t::onion_sessions_generate_id(), onion_url_handler(), and onion_websocket_t::onion_websocket_vprintf().

char* onion_low_strdup ( const char *  str)
void* onion_low_try_calloc ( size_t  nmemb,
size_t  size 
)

Our calloc wrapper for any kind of data, even scalar one. May return NULL on fail.

void* onion_low_try_malloc ( size_t  sz)

POSSIBLY FAILING MEMORY ALLOCATORS.

These allocators could fail by returning NULL. Their caller is requested to handle that failure.Our malloc wrapper for any kind of data, including data containing pointers. May return NULL on fail.

void* onion_low_try_realloc ( void *  ptr,
size_t  size 
)

Our realloc wrapper for any kind of data, even scalar one. May return NULL on fail.

void* onion_low_try_scalar_malloc ( size_t  sz)

Our malloc wrapper for scalar data which does not contain any pointers inside. May return NULL on fail.

char* onion_low_try_strdup ( const char *  str)

Our strdup wrapper. May return NULL on fail.