Ignore:
Timestamp:
Apr 18, 2011, 3:03:52 PM (11 years ago)
Author:
Sam Hocevar
Message:

lisp: always align the lisp allocator results, even on x86 or architectures
that have hardware realignment. Get rid of now useless bus_type.h.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/lisp/lisp.cpp

    r502 r504  
    1818
    1919#define TYPE_CHECKING 1
    20 #include "bus_type.h"
    2120
    2221#include "lisp.h"
     
    4847
    4948uint8_t *space[4], *free_space[4];
    50 int space_size[4], print_level=0, trace_level=0, trace_print_level=1000;
     49size_t space_size[4];
     50int print_level = 0, trace_level = 0, trace_print_level = 1000;
    5151int total_user_functions;
    5252
     
    172172}
    173173
    174 static int get_free_size(int which_space)
    175 {
    176     return space_size[which_space]
    177             - (free_space[which_space] - space[which_space]);
    178 }
    179 
    180 void *lmalloc(int size, int which_space)
    181 {
    182 #ifdef WORD_ALIGN
    183   size=(size+3)&(~3);
    184 #endif
    185 
    186   if (size > get_free_size(which_space))
    187   {
    188     int fart = 1;
    189 
    190     if (which_space == PERM_SPACE || which_space == TMP_SPACE)
    191     {
    192       collect_space(which_space);
    193       if (size <= get_free_size(which_space))
    194         fart = 0;
    195     }
    196 
    197     if (fart)
    198     {
    199       lbreak("lisp: cannot malloc %d bytes in space #%d\n", size, which_space);
    200       exit(0);
    201     }
    202   }
    203   void *ret = (void *)free_space[which_space];
    204   free_space[which_space] += size;
    205   return ret;
     174static size_t get_free_size(int which_space)
     175{
     176    size_t used = free_space[which_space] - space[which_space];
     177    return space_size[which_space] > used ? space_size[which_space] - used : 0;
     178}
     179
     180static void *lmalloc(size_t size, int which_space)
     181{
     182    // Align allocation
     183    size = (size + sizeof(intptr_t) - 1) & ~(sizeof(intptr_t) - 1);
     184
     185    // Collect garbage if necessary
     186    if (size > get_free_size(which_space))
     187    {
     188        if (which_space == PERM_SPACE || which_space == TMP_SPACE)
     189            collect_space(which_space);
     190
     191        if (size > get_free_size(which_space))
     192        {
     193            lbreak("lisp: cannot find %d bytes in space #%d\n",
     194                   size, which_space);
     195            exit(0);
     196        }
     197    }
     198
     199    void *ret = (void *)free_space[which_space];
     200    free_space[which_space] += size;
     201    return ret;
    206202}
    207203
     
    31473143}
    31483144
    3149 void resize_perm(int new_size)
     3145void resize_perm(size_t new_size)
    31503146{
    31513147  if (new_size<((char *)free_space[PERM_SPACE]-(char *)space[PERM_SPACE]))
     
    31613157}
    31623158
    3163 void resize_tmp(int new_size)
     3159void resize_tmp(size_t new_size)
    31643160{
    31653161  if (new_size<((char *)free_space[TMP_SPACE]-(char *)space[TMP_SPACE]))
Note: See TracChangeset for help on using the changeset viewer.