Freeciv-3.2
Loading...
Searching...
No Matches
Macros | Functions
mem.h File Reference
#include <stdlib.h>
#include "log.h"
#include "support.h"

Go to the source code of this file.

Macros

#define fc_malloc(sz)
 
#define fc_realloc(ptr, sz)
 
#define fc_calloc(n, esz)
 
#define FC_FREE(ptr)   do { free(ptr); (ptr) = NULL; } while (FALSE)
 
#define fc_strdup(str)   real_fc_strdup((str), "strdup", __FC_LINE__, __FILE__)
 

Functions

voidfc_real_malloc (size_t size, const char *called_as, int line, const char *file) fc__warn_unused_result
 
voidfc_real_realloc (void *ptr, size_t size, const char *called_as, int line, const char *file) fc__warn_unused_result
 
voidfc_real_calloc (size_t nelem, size_t elsize, const char *called_as, int line, const char *file) fc__warn_unused_result
 
charreal_fc_strdup (const char *str, const char *called_as, int line, const char *file) fc__warn_unused_result
 

Macro Definition Documentation

◆ fc_calloc

#define fc_calloc (   n,
  esz 
)
Value:
fc_real_calloc((n), (esz), "calloc", \
#define n
Definition astring.c:77
char * incite_cost
Definition comments.c:75
#define __FC_LINE__
Definition log.h:40
void * fc_real_calloc(size_t nelem, size_t elsize, const char *called_as, int line, const char *file) fc__warn_unused_result
Definition mem.c:132

Definition at line 38 of file mem.h.

◆ FC_FREE

#define FC_FREE (   ptr)    do { free(ptr); (ptr) = NULL; } while (FALSE)

Definition at line 41 of file mem.h.

◆ fc_malloc

#define fc_malloc (   sz)
Value:
fc_real_malloc((sz), "malloc", \
void * fc_real_malloc(size_t size, const char *called_as, int line, const char *file) fc__warn_unused_result
Definition mem.c:73

Definition at line 34 of file mem.h.

◆ fc_realloc

#define fc_realloc (   ptr,
  sz 
)
Value:
fc_real_realloc((ptr), (sz), "realloc", \
void * fc_real_realloc(void *ptr, size_t size, const char *called_as, int line, const char *file) fc__warn_unused_result
Definition mem.c:101

Definition at line 36 of file mem.h.

◆ fc_strdup

#define fc_strdup (   str)    real_fc_strdup((str), "strdup", __FC_LINE__, __FILE__)

Definition at line 43 of file mem.h.

Function Documentation

◆ fc_real_calloc()

void * fc_real_calloc ( size_t  nelem,
size_t  elsize,
const char called_as,
int  line,
const char file 
)

Function used by fc_calloc macro, calloc() replacement No need to check return value.

I'm pretty sure only the product of nelem and elsize can ever matter here, and not their individual values. (As a matter of C.) Except this function doesn't support calloc-ing more memory than can be expressing using a single size_t, but that's not likely to be a problem.

Definition at line 132 of file mem.c.

◆ fc_real_malloc()

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

Function used by fc_malloc macro, malloc() replacement

There's no need for the caller to check return value; this function will always return a valid pointer (even for a 0-byte malloc).

Definition at line 73 of file mem.c.

Referenced by fc_real_calloc(), fc_real_realloc(), and real_fc_strdup().

◆ fc_real_realloc()

void * fc_real_realloc ( void ptr,
size_t  size,
const char called_as,
int  line,
const char file 
)

Function used by fc_realloc macro, realloc() replacement No need to check return value.

Definition at line 101 of file mem.c.

◆ real_fc_strdup()

char * real_fc_strdup ( const char str,
const char called_as,
int  line,
const char file 
)

Function used by fc_strdup macro, strdup() replacement No need to check return value.

Definition at line 148 of file mem.c.