示例#1
0
int
eary_expand(EArray *ary, size_t ndd)
{
  if (ary->cap > SIZE_MAX / EARY_MAG)
    return -1;

  if (ary->cap == 0)
    ary->cap = EARY_DEFAULT_CAP;

  size_t ns = ary->cap * EARY_MAG;
  while (ndd > ns) {
    if (ns > SIZE_MAX / EARY_MAG)
      return -1;
    ns *= EARY_MAG;
  }

  void *p = scm_realloc(ary->vec, ary->rs * ns);
  if (p == NULL)
    return -1;

  ary->vec = p;
  ary->cap = ns;

  return 0;
}
示例#2
0
static void
add_heap(void)
{
    ScmObjHeap heap;
    ScmCell *cell;
    ScmObj next;

    SCM_BEGIN_GC_SUBCONTEXT();

    if (l_n_heaps_max <= l_n_heaps)
        scm_fatal_error("heap exhausted");

    l_heaps = scm_realloc(l_heaps, sizeof(ScmObjHeap) * (l_n_heaps + 1));
    heap = scm_malloc_aligned(sizeof(ScmCell) * l_heap_size);
    l_heaps[l_n_heaps++] = heap;

    /* update the enclosure */
    if (l_heaps_highest < &heap[l_heap_size])
        l_heaps_highest = &heap[l_heap_size];
    if (&heap[0] < l_heaps_lowest)
        l_heaps_lowest = &heap[0];

    /* link as address-increasing order */
    next = l_freelist;
    for (cell = &heap[l_heap_size - 1]; cell >= &heap[0]; cell--)
        next = SCM_CELL_RECLAIM_CELL(cell, next);
    l_freelist = next;

    SCM_END_GC_SUBCONTEXT();
}
示例#3
0
static void
stringbuf_grow (struct stringbuf *buf)
{
  size_t ptroff = buf->ptr - buf->buf;
  buf->buf_len *= 2; 
  buf->buf = scm_realloc (buf->buf, buf->buf_len);
  buf->ptr = buf->buf + ptroff;
}
示例#4
0
int
eary_contract(EArray *ary)
{
  if (ary->used >= ary->cap)
    return 0;

  void *p = scm_realloc(ary->vec, ary->rs * ary->used);
  if (p == NULL) return -1;

  ary->vec = p;
  ary->cap = ary->used;
  return 0;
}
示例#5
0
/* var must be initialized with a valid ScmObj before invocation */
SCM_EXPORT void
scm_gc_protect(ScmObj *var)
{
    ScmObj **slot;
    size_t new_size;

    if (l_n_empty_protected_vars) {
        slot = locate_protected_var(NULL);
        l_n_empty_protected_vars--;
    } else {
        new_size = sizeof(ScmObj *) * (l_protected_vars_size + 1);
        l_protected_vars = scm_realloc(l_protected_vars, new_size);
        slot = &l_protected_vars[l_protected_vars_size++];
    }
    *slot = var;
}