Back to index

lightning-sunbird  0.9+nobinonly
Defines | Typedefs | Functions
xpt_arena.h File Reference
#include "prtypes.h"
#include <stdlib.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


#define XPT_PUBLIC_DATA(t)   t
#define XPT_MALLOC(_arena, _bytes)   XPT_ArenaMalloc((_arena), (_bytes))
#define XPT_FREE(_arena, _ptr)   ((void)0)
#define XPT_STRDUP(_arena, _s)   XPT_ArenaStrDup((_arena), (_s))
#define XPT_CALLOC(_arena, _size)   XPT_MALLOC((_arena), (_size))
#define XPT_NEW(_arena, _struct)   ((_struct *) XPT_MALLOC((_arena), sizeof(_struct)))
#define XPT_NEWZAP(_arena, _struct)   XPT_NEW((_arena), _struct)
#define XPT_DELETE(_arena, _ptr)   do{XPT_FREE((_arena), (_ptr)); ((_ptr)) = NULL;}while(0)
#define XPT_FREEIF(_arena, _ptr)   do{if ((_ptr)) XPT_FREE((_arena), (_ptr));}while(0)
#define XPT_ASSERT(_expr)   ((void)0)




 XPT_NewArena (PRUint32 block_size, size_t alignment, const char *name)
 XPT_DestroyArena (XPTArena *arena)
 XPT_DumpStats (XPTArena *arena)
 XPT_ArenaMalloc (XPTArena *arena, size_t size)
 XPT_ArenaStrDup (XPTArena *arena, const char *s)
 XPT_NotifyDoneLoading (XPTArena *arena)
 XPT_ArenaFree (XPTArena *arena, void *block)

Define Documentation

#define XPT_ASSERT (   _expr)    ((void)0)

Definition at line 129 of file xpt_arena.h.

#define XPT_CALLOC (   _arena,
)    XPT_MALLOC((_arena), (_size))

Definition at line 115 of file xpt_arena.h.

#define XPT_DELETE (   _arena,
)    do{XPT_FREE((_arena), (_ptr)); ((_ptr)) = NULL;}while(0)

Definition at line 118 of file xpt_arena.h.

#define XPT_FREE (   _arena,
)    ((void)0)

Definition at line 108 of file xpt_arena.h.

#define XPT_FREEIF (   _arena,
)    do{if ((_ptr)) XPT_FREE((_arena), (_ptr));}while(0)

Definition at line 119 of file xpt_arena.h.

Definition at line 67 of file xpt_arena.h.

Definition at line 68 of file xpt_arena.h.

#define XPT_MALLOC (   _arena,
)    XPT_ArenaMalloc((_arena), (_bytes))

Definition at line 101 of file xpt_arena.h.

#define XPT_NEW (   _arena,
)    ((_struct *) XPT_MALLOC((_arena), sizeof(_struct)))

Definition at line 116 of file xpt_arena.h.

#define XPT_NEWZAP (   _arena,
)    XPT_NEW((_arena), _struct)

Definition at line 117 of file xpt_arena.h.

Definition at line 63 of file xpt_arena.h.

#define XPT_PUBLIC_DATA (   t)    t

Definition at line 64 of file xpt_arena.h.

#define XPT_STRDUP (   _arena,
)    XPT_ArenaStrDup((_arena), (_s))

Definition at line 112 of file xpt_arena.h.

Typedef Documentation

typedef typedefPR_BEGIN_EXTERN_C struct XPTArena

Definition at line 76 of file xpt_arena.h.

Function Documentation

XPT_ArenaFree ( XPTArena arena,
void block 

Definition at line 294 of file xpt_arena.c.

XPT_ArenaMalloc ( XPTArena arena,
size_t  size 

Definition at line 196 of file xpt_arena.c.

    PRUint8 *cur;
    size_t bytes;

    if (!size)
        return NULL;

    if (!arena) {
        return NULL;

    bytes = ALIGN_RND(size, arena->alignment);
    LOG_MALLOC(arena, size, bytes);

    if (bytes > arena->space) {
        BLK_HDR* new_block;
        size_t block_header_size = ALIGN_RND(sizeof(BLK_HDR), arena->alignment);
        size_t new_space = arena->block_size;
        if (bytes > new_space - block_header_size)
            new_space += bytes;

        new_block = (BLK_HDR*) calloc(new_space/arena->alignment, 
        if (!new_block) {
            arena->next = NULL;
            arena->space = 0;
            return NULL;

        LOG_REAL_MALLOC(arena, new_space);

        /* link block into the list of blocks for use when we destroy */
        new_block->next = arena->first;
        arena->first = new_block;

        /* save other block header info */
        new_block->size = new_space;

        /* set info for current block */
        arena->next  = ((PRUint8*)new_block) + block_header_size;
        arena->space = new_space - block_header_size;

#ifdef DEBUG
        /* mark block for corruption check */
        memset(arena->next, 0xcd, arena->space);
#ifdef DEBUG
        /* do corruption check */
        size_t i;
        for (i = 0; i < bytes; ++i) {
            XPT_ASSERT(arena->next[i] == 0xcd);        
        /* we guarantee that the block will be filled with zeros */
        memset(arena->next, 0, bytes);

    cur = arena->next;
    arena->next  += bytes;
    arena->space -= bytes;
    return cur;    

Here is the call graph for this function:

Here is the caller graph for this function:

XPT_ArenaStrDup ( XPTArena arena,
const char *  s 

Definition at line 269 of file xpt_arena.c.

    size_t len;
    char* cur;

    if (!s)
        return NULL;

    len = strlen(s)+1;
    cur = XPT_ArenaMalloc(arena, len);
    memcpy(cur, s, len);
    return cur;

Here is the call graph for this function:

XPT_DestroyArena ( XPTArena arena)

Definition at line 169 of file xpt_arena.c.

    BLK_HDR* cur;
    BLK_HDR* next;
    cur = arena->first;
    while (cur) {
        next = cur->next;
        cur = next;

Here is the caller graph for this function:

XPT_DumpStats ( XPTArena arena)

Definition at line 184 of file xpt_arena.c.


Here is the caller graph for this function:

XPT_NewArena ( PRUint32  block_size,
size_t  alignment,
const char *  name 

Definition at line 137 of file xpt_arena.c.

    XPTArena *arena = calloc(1, sizeof(XPTArena));
    if (arena) {
        if (alignment > sizeof(double))
            alignment = sizeof(double);
        arena->alignment = alignment;

        if (block_size < XPT_MIN_BLOCK_SIZE)
            block_size = XPT_MIN_BLOCK_SIZE;
        arena->block_size = ALIGN_RND(block_size, alignment);

        /* must have room for at least one item! */
        XPT_ASSERT(arena->block_size >= 
                   ALIGN_RND(sizeof(BLK_HDR), alignment) +
                   ALIGN_RND(1, alignment));

        if (name) {
            arena->name = XPT_STRDUP(arena, name);           
            /* fudge the stats since we are using space in the arena */
            arena->LOG_MallocCallCount = 0;
            arena->LOG_MallocTotalBytesRequested = 0;
            arena->LOG_MallocTotalBytesUsed = 0;
#endif /* XPT_ARENA_LOGGING */
    return arena;        

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 284 of file xpt_arena.c.

    if (arena) {