static rep_struct_node *
lookup_or_add (rep_struct *s, repv var)
{
    rep_struct_node *n = lookup (s, var);
    if (n == 0)
    {
	if (s->total_buckets == 0)
	{
	    s->total_buckets = MIN_BUCKETS;
	    s->buckets = rep_alloc (sizeof (rep_struct_node *)
				    * s->total_buckets);
	    memset (s->buckets, 0,
		    sizeof (rep_struct_node *) * s->total_buckets);
	    rep_data_after_gc += sizeof (rep_struct_node *) * s->total_buckets;
	}

	if (s->total_bindings > s->total_buckets * MAX_MULTIPLIER)
	{
	    int new_total = s->total_buckets * 2;
	    rep_struct_node **buckets
		= rep_alloc (new_total * sizeof (rep_struct_node *));
	    int i;
	    memset (buckets, 0, new_total * sizeof (rep_struct_node *));
	    rep_data_after_gc += new_total * sizeof (rep_struct_node *);
	    for (i = 0; i < s->total_buckets; i++)
	    {
		rep_struct_node *next;
		for (n = s->buckets[i]; n != 0; n = next)
		{
		    next = n->next;
		    n->next = buckets[rep_STRUCT_HASH (n->symbol, new_total)];
		    buckets[rep_STRUCT_HASH (n->symbol, new_total)] = n;
		}
	    }
	    s->total_buckets = new_total;
	    rep_free (s->buckets);
	    s->buckets = buckets;
	}

	n = rep_alloc (sizeof (rep_struct_node));
	rep_data_after_gc += sizeof (rep_struct_node);
	n->symbol = var;
	n->is_constant = 0;
	n->is_exported = (s->car & rep_STF_EXPORT_ALL) != 0;
	n->next = s->buckets[rep_STRUCT_HASH (var, s->total_buckets)];
	s->buckets[rep_STRUCT_HASH (var, s->total_buckets)] = n;
	s->total_bindings++;

	if (structure_exports_inherited_p (s, var))
	{
	    n->is_exported = 1;
	    s->inherited = Fdelq (var, s->inherited);
	}

	cache_invalidate_symbol (var);
    }
    return n;
}
Esempio n. 2
0
void
pixmap_cache_set (Lisp_Image *im, int width, int height,
		  Pixmap p1, Pixmap p2)
{
    int pixel_count = width * height;
    pixmap_cache_node *n = 0;

    while (pixel_count + cached_pixels > max_cached_pixels)
    {
	/* remove oldest node */
	pixmap_cache_node *this = oldest;
	while (this != 0 && this->ref_count > 0)
	    this = this->newer;
	if (this == 0)
	    break;
	delete_node (this, n != 0);
	if (n == 0)
	    n = this;
    }

    if (n == 0)
	n = rep_alloc (sizeof (pixmap_cache_node));

    n->im = im;
    n->width = width;
    n->height = height;
    n->p1 = p1;
    n->p2 = p2;
    n->ref_count = 1;

    prepend_to_image (n);
    append_to_age_list (n);
    cached_pixels += pixel_count;
}
Esempio n. 3
0
/* Create a new extent. All links are null. If CLONEE is non-null, copy
   the START, END, TX and PLIST fields from it. */
static Lisp_Extent *
alloc_extent(Lisp_Extent *clonee)
{
    Lisp_Extent *x = rep_alloc(sizeof(Lisp_Extent));
    if(x == 0)
    {
	rep_mem_error();
	return 0;
    }

    x->car = extent_type;
    x->next = allocated_extents;
    allocated_extents = x;
    clean_node(x);

    if(clonee != 0)
    {
	x->start = clonee->start;
	x->end = clonee->end;
	x->tx = clonee->tx;
	x->plist = clonee->plist;
	x->locals = clonee->locals;
    }
    else
    {
	x->locals = Qnil;
	x->plist = Qnil;
    }

    assert_invariants (x);

    return x;
}
Esempio n. 4
0
static void
new_item_block (void)
{
    origin_block *b;
    int i;
    b = rep_alloc (sizeof (origin_block));
    for (i = 0; i < (BLOCK_SIZE - 1); i++)
	b->items[i].next = &(b->items[i+1]);
    b->items[i].next = free_list;
    free_list = &(b->items[0]);

    b->next = block_list;
    block_list = b;
}
Esempio n. 5
0
/* save the original stack for continuation C */
static void
save_stack (rep_continuation *c)
{
    size_t size;

    FLUSH_REGISTER_WINDOWS;

    /* __builtin_frame_address doesn't give the right thing on athlon64 */

#if defined (__GNUC__) && !defined (BROKEN_ALPHA_GCC) && !defined (__x86_64)
    c->stack_top = __builtin_frame_address (0);
#else
    c->stack_top = (char *) &size;
#endif

#if STACK_DIRECTION < 0
    size = c->stack_bottom - c->stack_top;
#else
    size = c->stack_top - c->stack_bottom;
#endif

    if (c->stack_copy != 0)
    {
	if (c->stack_size < size || (c->stack_size - size) > CONTIN_MAX_SLOP)
	{
	    rep_free (c->stack_copy);
	    rep_data_after_gc -= c->stack_size;
	    c->stack_copy = 0;
	}
    }

    if (c->stack_copy == 0)
    {
	c->stack_size = size;
	c->stack_copy = rep_alloc (size);
	rep_data_after_gc += size;
    }

    c->real_size = size;
#if STACK_DIRECTION < 0
    memcpy (c->stack_copy, c->stack_top, c->real_size);
#else
    memcpy (c->stack_copy, c->stack_bottom, c->real_size);
#endif
}
void *
rep_db_alloc(char *name, int size)
{
    struct debug_buf *db = rep_alloc(DB_SIZE(size));
    if(db == NULL)
    {
	perror("create_debug_buf");
	abort();
    }
    db->name = name;
    db->size = size;
    db->ptr = 0;
    db->wrapped = rep_FALSE;
    db->next = db_chain;
    db_chain = db;

    return db;
}
Esempio n. 7
0
static void
make_argv (repv list, int *argc, char ***argv)
{
    int c = rep_INT (Flength (list)), i;
    char **v;

    v = (char **)rep_alloc ((c+1) * sizeof(char**));
    for (i = 0; i < c; i++, list = rep_CDR (list))
    {
	if (!rep_STRINGP (rep_CAR (list)))
	{
	    rep_free ((char *)v);
	    return;
	}
	v[i] = strdup (rep_STR (rep_CAR (list)));
    }
    v[c] = NULL;
  
    *argv = v;
    *argc = c;
}