Back to index

python3.2  3.2.2
Classes | Defines | Typedefs | Functions | Variables
malloc_closure.c File Reference
#include <Python.h>
#include <ffi.h>
#include <sys/mman.h>
#include <unistd.h>
#include "ctypes.h"

Go to the source code of this file.

Classes

union  _tagITEM

Defines

#define BLOCKSIZE   _pagesize

Typedefs

typedef union _tagITEM ITEM

Functions

static void more_core (void)
void ffi_closure_free (void *p)
voidffi_closure_alloc (size_t ignored, void **codeloc)

Variables

static ITEMfree_list
static int _pagesize

Class Documentation

union _tagITEM

Definition at line 25 of file malloc_closure.c.

Collaboration diagram for _tagITEM:
Class Members
ffi_closure closure
union _tagITEM * next

Define Documentation

#define BLOCKSIZE   _pagesize

Definition at line 19 of file malloc_closure.c.


Typedef Documentation

typedef union _tagITEM ITEM

Function Documentation

void* ffi_closure_alloc ( size_t  ignored,
void **  codeloc 
)

Definition at line 100 of file malloc_closure.c.

{
    ITEM *item;
    if (!free_list)
        more_core();
    if (!free_list)
        return NULL;
    item = free_list;
    free_list = item->next;
    *codeloc = (void *)item;
    return (void *)item;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 92 of file malloc_closure.c.

{
    ITEM *item = (ITEM *)p;
    item->next = free_list;
    free_list = item;
}

Here is the caller graph for this function:

static void more_core ( void  ) [static]

Definition at line 33 of file malloc_closure.c.

{
    ITEM *item;
    int count, i;

/* determine the pagesize */
#ifdef MS_WIN32
    if (!_pagesize) {
        SYSTEM_INFO systeminfo;
        GetSystemInfo(&systeminfo);
        _pagesize = systeminfo.dwPageSize;
    }
#else
    if (!_pagesize) {
#ifdef _SC_PAGESIZE
        _pagesize = sysconf(_SC_PAGESIZE);
#else
        _pagesize = getpagesize();
#endif
    }
#endif

    /* calculate the number of nodes to allocate */
    count = BLOCKSIZE / sizeof(ITEM);

    /* allocate a memory block */
#ifdef MS_WIN32
    item = (ITEM *)VirtualAlloc(NULL,
                                           count * sizeof(ITEM),
                                           MEM_COMMIT,
                                           PAGE_EXECUTE_READWRITE);
    if (item == NULL)
        return;
#else
    item = (ITEM *)mmap(NULL,
                        count * sizeof(ITEM),
                        PROT_READ | PROT_WRITE | PROT_EXEC,
                        MAP_PRIVATE | MAP_ANONYMOUS,
                        -1,
                        0);
    if (item == (void *)MAP_FAILED)
        return;
#endif

#ifdef MALLOC_CLOSURE_DEBUG
    printf("block at %p allocated (%d bytes), %d ITEMs\n",
           item, count * sizeof(ITEM), count);
#endif
    /* put them into the free list */
    for (i = 0; i < count; ++i) {
        item->next = free_list;
        free_list = item;
        ++item;
    }
}

Here is the caller graph for this function:


Variable Documentation

int _pagesize [static]

Definition at line 31 of file malloc_closure.c.

ITEM* free_list [static]

Definition at line 30 of file malloc_closure.c.