YAZ  4.2.57
Macros | Functions | Variables
xmalloc.c File Reference

Implements malloc interface. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <yaz/log.h>
#include <yaz/xmalloc.h>

Go to the source code of this file.

Macros

#define TRACE_XMALLOC   1
#define xrealloc_d(o, x, f, l)   realloc(o, x)
#define xmalloc_d(x, f, l)   malloc(x)
#define xcalloc_d(x, y, f, l)   calloc(x,y)
#define xfree_d(x, f, l)   free(x)
#define xmalloc_trav_d(f, l)

Functions

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

Variables

static int log_level = 0
static int log_level_initialized = 0

Detailed Description

Implements malloc interface.

Definition in file xmalloc.c.

Macro Definition Documentation

#define TRACE_XMALLOC   1

Definition at line 22 of file xmalloc.c.

#define xcalloc_d (   x,
  y,
  f,
 
)    calloc(x,y)

Definition at line 231 of file xmalloc.c.

Referenced by xcalloc_f().

#define xfree_d (   x,
  f,
 
)    free(x)

Definition at line 232 of file xmalloc.c.

Referenced by xfree_f().

#define xmalloc_d (   x,
  f,
 
)    malloc(x)

Definition at line 230 of file xmalloc.c.

Referenced by xmalloc_f(), and xstrdup_f().

#define xmalloc_trav_d (   f,
 
)

Definition at line 233 of file xmalloc.c.

Referenced by xmalloc_trav_f().

#define xrealloc_d (   o,
  x,
  f,
 
)    realloc(o, x)

Definition at line 229 of file xmalloc.c.

Referenced by xrealloc_f().

Function Documentation

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 297 of file xmalloc.c.

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

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 336 of file xmalloc.c.

References log_level, xfree_d, and yaz_log().

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 274 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().

void xmalloc_fatal ( void  )

Definition at line 247 of file xmalloc.c.

Referenced by xcalloc_f(), xmalloc_f(), and xrealloc_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 236 of file xmalloc.c.

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

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 252 of file xmalloc.c.

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

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 319 of file xmalloc.c.

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

Referenced by 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 345 of file xmalloc.c.

References xmalloc_f(), and xstrdup_f().

Variable Documentation

int log_level = 0
static

Definition at line 25 of file xmalloc.c.

Referenced by xcalloc_f(), xfree_f(), xmalloc_f(), xmalloc_trav_f(), xrealloc_f(), and xstrdup_f().

int log_level_initialized = 0
static

Definition at line 26 of file xmalloc.c.

Referenced by xcalloc_f(), xmalloc_f(), xmalloc_trav_f(), xrealloc_f(), and xstrdup_f().