Back to index

texmacs  1.0.7.15
Defines | Functions
mem.h File Reference
#include <stdlib.h>

Go to the source code of this file.

Defines

#define MEM_ADD(p)   mem_add(p)
#define MEM_REMOVE(p)   mem_remove(p)
#define NEW(n, type)   (type *) MEM_ADD(new(((size_t)(n))*sizeof(type)))
#define RENEW(p, n, type)   (type *) MEM_ADD(renew(MEM_REMOVE(p),(n)*sizeof(type)))
#define RELEASE(p)   free(MEM_REMOVE(p))
#define kpse_path_search(x, y, z)   (char *) MEM_ADD(kpse_path_search(x,y,z))
#define kpse_find_file(x, y, z)   (char *) MEM_ADD(kpse_find_file(x,y,z))
#define kpse_find_glyph(x, y, z, w)   (char *) MEM_ADD(kpse_find_glyph(x,y,z,w))

Functions

void * new (size_t size)
void * renew (void *p, size_t size)
void mem_debug_init (void)
void mem_debug_check (void)
void * mem_add (void *ptr)
void * mem_remove (void *ptr)

Define Documentation

#define kpse_find_file (   x,
  y,
 
)    (char *) MEM_ADD(kpse_find_file(x,y,z))

Definition at line 61 of file mem.h.

#define kpse_find_glyph (   x,
  y,
  z,
 
)    (char *) MEM_ADD(kpse_find_glyph(x,y,z,w))

Definition at line 62 of file mem.h.

#define kpse_path_search (   x,
  y,
 
)    (char *) MEM_ADD(kpse_path_search(x,y,z))

Definition at line 60 of file mem.h.

#define MEM_ADD (   p)    mem_add(p)

Definition at line 49 of file mem.h.

#define MEM_REMOVE (   p)    mem_remove(p)

Definition at line 50 of file mem.h.

#define NEW (   n,
  type 
)    (type *) MEM_ADD(new(((size_t)(n))*sizeof(type)))

Definition at line 55 of file mem.h.

#define RELEASE (   p)    free(MEM_REMOVE(p))

Definition at line 57 of file mem.h.

#define RENEW (   p,
  n,
  type 
)    (type *) MEM_ADD(renew(MEM_REMOVE(p),(n)*sizeof(type)))

Definition at line 56 of file mem.h.


Function Documentation

void* mem_add ( void *  ptr)

Definition at line 131 of file mem.c.

                         {
  if (ptr)
    mem_count++;

  return ptr;
}
void mem_debug_check ( void  )

Definition at line 125 of file mem.c.

{
  if (mem_count)
    WARN("%ld memory objects still allocated\n", mem_count);
}

Here is the call graph for this function:

void mem_debug_init ( void  )

Definition at line 120 of file mem.c.

{
  mem_count = 0;
}
void* mem_remove ( void *  ptr)

Definition at line 138 of file mem.c.

                            {
  if (ptr)
    mem_count--;

  return ptr;
}
void* new ( size_t  size)

Definition at line 148 of file mem.c.

{
  void *result = malloc (size);
  if (!result) {
    ERROR("Out of memory - asked for %lu bytes\n", (unsigned long) size);
  }

  return result;
}
void* renew ( void *  p,
size_t  size 
)

Definition at line 158 of file mem.c.

{
  if (size) {
    void *result = realloc (mem, size);
    if (!result) {
      ERROR("Out of memory - asked for %lu bytes\n", (unsigned long) size);
    }
    return result;
  } else {
    /* realloc may not return NULL if size == 0 */
    free(mem);
    return NULL;
  }
}