YAZ  5.34.0
Macros | Functions
xmalloc.h File Reference

Header for memory handling functions. More...

#include <stddef.h>
#include <yaz/yconfig.h>

Go to the source code of this file.

Macros

#define xrealloc(o, x)   xrealloc_f(o, x, __FILE__, __LINE__)
 utility macro which calls xrealloc_f More...
 
#define xmalloc(x)   xmalloc_f(x, __FILE__, __LINE__)
 utility macro which calls malloc_f More...
 
#define xcalloc(x, y)   xcalloc_f(x,y, __FILE__, __LINE__)
 utility macro which calls xcalloc_f More...
 
#define xfree(x)   xfree_f(x, __FILE__, __LINE__)
 utility macro which calls xfree_f More...
 
#define xstrdup(s)   xstrdup_f(s, __FILE__, __LINE__)
 utility macro which calls xstrdup_f More...
 
#define xstrndup(s, n)   xstrndup_f(s, n, __FILE__, __LINE__)
 utility macro which calls xstrndup_f More...
 
#define xmalloc_trav(s)   xmalloc_trav_f(s, __FILE__, __LINE__)
 utility macro which calls malloc_trav_f More...
 

Functions

void * xrealloc_f (void *o, size_t size, const char *file, int line)
 realloc More...
 
void * xmalloc_f (size_t size, const char *file, int line)
 malloc More...
 
void * xcalloc_f (size_t nmemb, size_t size, const char *file, int line)
 calloc More...
 
char * xstrdup_f (const char *p, const char *file, int line)
 strdup More...
 
char * xstrndup_f (const char *p, size_t n, const char *file, int line)
 strndup More...
 
void xfree_f (void *p, const char *file, int line)
 free More...
 
void xmalloc_trav_f (const char *s, const char *file, int line)
 logs all xmalloc buffers More...
 

Detailed Description

Header for memory handling functions.

This is a set of wrapper functions for the memory allocation routines from stdlib.h.. Such as malloc, free, realloc etc. These functions calls exit if memory allocation fails.

Definition in file xmalloc.h.

Macro Definition Documentation

◆ xcalloc

#define xcalloc (   x,
  y 
)    xcalloc_f(x,y, __FILE__, __LINE__)

utility macro which calls xcalloc_f

Definition at line 51 of file xmalloc.h.

◆ xfree

#define xfree (   x)    xfree_f(x, __FILE__, __LINE__)

utility macro which calls xfree_f

Definition at line 53 of file xmalloc.h.

◆ xmalloc

#define xmalloc (   x)    xmalloc_f(x, __FILE__, __LINE__)

utility macro which calls malloc_f

Definition at line 49 of file xmalloc.h.

◆ xmalloc_trav

#define xmalloc_trav (   s)    xmalloc_trav_f(s, __FILE__, __LINE__)

utility macro which calls malloc_trav_f

Definition at line 59 of file xmalloc.h.

◆ xrealloc

#define xrealloc (   o,
 
)    xrealloc_f(o, x, __FILE__, __LINE__)

utility macro which calls xrealloc_f

Definition at line 47 of file xmalloc.h.

◆ xstrdup

#define xstrdup (   s)    xstrdup_f(s, __FILE__, __LINE__)

utility macro which calls xstrdup_f

Definition at line 55 of file xmalloc.h.

◆ xstrndup

#define xstrndup (   s,
 
)    xstrndup_f(s, n, __FILE__, __LINE__)

utility macro which calls xstrndup_f

Definition at line 57 of file xmalloc.h.

Function Documentation

◆ xcalloc_f()

void* xcalloc_f ( size_t  nmemb,
size_t  size,
const char *  file,
int  line 
)

calloc

Parameters
nmembnumber of members
sizesize of member
filefname location of use
lineline location of use
Returns
buffer

This function is invoked via macro xcalloc in which file and line are set automatically.

Definition at line 302 of file xmalloc.c.

References log_level, log_level_initialized, xcalloc_d, xmalloc_fatal(), yaz_log(), yaz_log_module_level(), and YLOG_FATAL.

◆ xfree_f()

void xfree_f ( void *  p,
const char *  file,
int  line 
)

free

Parameters
pstring to be freed (might be NULL)
filefname location of use
lineline location of use

This function is invoked via macro xfree in which file and line are set automatically.

Definition at line 341 of file xmalloc.c.

References log_level, xfree_d, and yaz_log().

◆ xmalloc_f()

void* xmalloc_f ( size_t  size,
const char *  file,
int  line 
)

malloc

Parameters
sizesize of buffer to be allocated
filefname location of use
lineline location of use
Returns
buffer

This function is invoked via macro xmalloc in which file and line are set automatically.

Definition at line 279 of file xmalloc.c.

References log_level, log_level_initialized, xmalloc_d, xmalloc_fatal(), yaz_log(), yaz_log_module_level(), and YLOG_FATAL.

Referenced by xstrndup_f().

◆ xmalloc_trav_f()

void xmalloc_trav_f ( const char *  s,
const char *  file,
int  line 
)

logs all xmalloc buffers

Parameters
snot used
filefname location of use
lineline location of use

This function is invoked via macro xmalloc_trav in which file and line are set automatically. Only if TRACE_XMALLOC > 1 this function does any real work!

Definition at line 240 of file xmalloc.c.

References log_level, log_level_initialized, xmalloc_trav_d, and yaz_log_module_level().

◆ xrealloc_f()

void* xrealloc_f ( void *  o,
size_t  size,
const char *  file,
int  line 
)

realloc

Parameters
obuffer to be reallocated
sizesize of buffer to be allocated
filefname location of use
lineline location of use
Returns
buffer

This function is invoked via macro xrealloc in which file and line are set automatically.

Definition at line 257 of file xmalloc.c.

References log_level, log_level_initialized, xmalloc_fatal(), xrealloc_d, yaz_log(), yaz_log_module_level(), and YLOG_FATAL.

◆ xstrdup_f()

char* xstrdup_f ( const char *  p,
const char *  file,
int  line 
)

strdup

Parameters
pstring to be cloned
filefname location of use
lineline location of use
Returns
resulting string

This function is invoked via macro xstrdup in which file and line are set automatically.

Definition at line 324 of file xmalloc.c.

References log_level, log_level_initialized, xmalloc_d, yaz_log(), and yaz_log_module_level().

Referenced by xstrndup_f().

◆ xstrndup_f()

char* xstrndup_f ( const char *  p,
size_t  n,
const char *  file,
int  line 
)

strndup

Parameters
pstring to be cloned
nmax size of resulting string (excluding 0)
filefname location of use
lineline location of use
Returns
resulting string

This function is invoked via macro xstrndup in which file and line are set automatically.

Definition at line 350 of file xmalloc.c.

References xmalloc_f(), and xstrdup_f().