Example #1
0
static unsigned int
ffi_alloc_interface (rep_ffi_interface *iface)
{
    unsigned int i;

    /* FIXME: this is O(N), it should be hashed. */

    for (i = 0; i < n_ffi_interfaces; i++)
    {
	if (ffi_interfaces_equal_p (iface, ffi_interfaces[i]))
	{
	    rep_free (iface);
	    return i;
	}
    }

    i = n_ffi_interfaces++;

    if (i >= n_alloc_ffi_interfaces)
    {
	n_alloc_ffi_interfaces = MAX (n_alloc_ffi_interfaces * 2, 256);
	ffi_interfaces = rep_realloc (ffi_interfaces,
				      sizeof (ffi_interfaces[0])
				      * n_alloc_ffi_interfaces);
    }

    ffi_interfaces[i] = iface;

    return i;
}
static void
free_table (table *x)
{
    int i;
    for (i = 0; i < x->total_buckets; i++)
    {
	node *n, *next;
	for (n = x->buckets[i]; n != 0; n = next)
	{
	    next = n->next;
	    rep_free (n);
	}
    }
    if (x->total_buckets > 0)
	rep_free (x->buckets);
    rep_FREE_CELL (x);
}
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;
}
static void
free_structure (rep_struct *x)
{
    int i;
    cache_invalidate_struct (x);
    for (i = 0; i < x->total_buckets; i++)
    {
	rep_struct_node *n, *next;
	for (n = x->buckets[i]; n != 0; n = next)
	{
	    next = n->next;
	    rep_free (n);
	}
    }
    if (x->total_buckets > 0)
	rep_free (x->buckets);
    rep_FREE_CELL (x);
}
Example #5
0
static void
free_node (pixmap_cache_node *n, bool dealloc)
{
    if (n->p1 != 0)
	XFreePixmap (dpy, n->p1);
    if (n->p2 != 0)
	XFreePixmap (dpy, n->p2);
    if (dealloc)
	rep_free (n);
}
void
rep_db_kill(void)
{
    struct debug_buf *db = db_chain;
    rep_db_spew_all();
    db_chain = NULL;
    while(db != NULL)
    {
	struct debug_buf *next = db->next;
	rep_free(db);
	db = next;
    }
}
void
rep_db_free(void *_db)
{
    struct debug_buf *db = _db;
    struct debug_buf **x = &db_chain;
    while(*x != NULL)
    {
	if(*x == db)
	{
	    *x = db->next;
	    break;
	}
	x = &((*x)->next);
    }
    rep_free(db);
}
Example #8
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
}
static void
remove_binding (rep_struct *s, repv var)
{
    if (s->total_buckets != 0)
    {
	rep_struct_node **n;
	for (n = &(s->buckets[rep_STRUCT_HASH (var, s->total_buckets)]);
	     *n != 0; n = &((*n)->next))
	{
	    if ((*n)->symbol == var)
	    {
		rep_struct_node *next = (*n)->next;
		rep_free (*n);
		*n = next;
		cache_invalidate_symbol (var);
		return;
	    }
	}
    }
}
Example #10
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;
}