Exemplo n.º 1
0
void
cf_buf_builder_reserve_internal(cf_buf_builder **bb_r, size_t sz)
{
	cf_buf_builder *bb = *bb_r;
	size_t new_sz = get_new_size(bb->alloc_sz, bb->used_sz, sz);

	if (new_sz > bb->alloc_sz) {
		if (bb->alloc_sz - bb->used_sz < MAX_BACKOFF) {
			bb = cf_realloc(bb, new_sz);
		}
		else {
			// Only possible if buffer was reset. Avoids potential expensive
			// copy within realloc.
			cf_buf_builder	*_t = cf_malloc(new_sz);

			memcpy(_t->buf, bb->buf, bb->used_sz);
			_t->used_sz = bb->used_sz;
			cf_free(bb);
			bb = _t;
		}

		bb->alloc_sz = new_sz - sizeof(cf_buf_builder);
		*bb_r = bb;
	}
}
Exemplo n.º 2
0
AList_WS* new_list_size(size_t initial_size) {

	AList_WS* new_list = (AList_WS*)(malloc(sizeof(AList_WS)));
	assert(new_list != NULL /* ** OUT OF MEMORY ** */);

	size_t safe_size = get_new_size(initial_size);
	increase_size_to(new_list, safe_size);

	new_list->current_size = 1;

	return new_list;
}
Exemplo n.º 3
0
char				*ft_strtrim(char const *s)
{
	char			*ret;
	unsigned int	size;
	unsigned int	i;

	size = get_new_size(s);
	if (!(ret = (char *)malloc(sizeof(char) * (size + 1))))
		return (NULL);
	ft_memset(ret, 0, size + 1);
	while (is_trim(*s))
		s++;
	i = 0;
	while (i < size)
		ret[i++] = *s++;
	ret[i] = '\0';
	return (ret);
}
Exemplo n.º 4
0
static char	*get_new_word(t_bin *bin)
{
  int		size;
  char		*word;
  int		i;

  size = get_new_size(bin);
  if ((word = xmalloc(sizeof(char) * (size + 1))) == NULL)
    return (NULL);
  i = 0;
  while (i < size)
    {
      word[i] = bin->next->name[i];
      i = i + 1;
    }
  word[i] = '\0';
  return (word);
}
Exemplo n.º 5
0
void
cf_dyn_buf_reserve_internal(cf_dyn_buf *db, size_t sz)
{
	size_t new_sz = get_new_size(db->alloc_sz, db->used_sz, sz);

	if (new_sz > db->alloc_sz) {
		uint8_t	*_t;

		if (db->is_stack) {
			_t = cf_malloc(new_sz);
			memcpy(_t, db->buf, db->used_sz);
			db->is_stack = false;
		}
		else {
			_t = cf_realloc(db->buf, new_sz);
		}

		db->buf = _t;
		db->alloc_sz = new_sz;
	}
}
Exemplo n.º 6
0
int add_to_table(struct ffi_instruction *ins, struct offset_table *tbl){
    enum type st = (enum type) ins->type;
    enum dstru_types dt = ffi_dstru_bridge(st);
    struct offset_member temp;
    int pad_size, new_size;

    new_size = get_new_size(st, tbl);
    pad_size = get_offset(dt, tbl);

#ifdef DEBUG
    printf("add_to_table(): new_size: %d pad_size: %d\n", new_size, pad_size);
#endif 

    temp.offset = pad_size;
    temp.size = dstru_sizeof(dt, NULL);
    temp.scalar_type = st;
    temp.flags = NORMAL;
    temp.subtable = NULL;

    tbl->structure_size = new_size;
    table_add_entry(tbl, temp);

    return 0;
}
Exemplo n.º 7
0
void increase_size(AList_WS* list) {
	assert(list->current_size_limit < SIZE_LIMIT /* **  SIZE LIMIT REACHED ** */);
	increase_size_to(list, get_new_size(list->current_size_limit));
}