Ejemplo n.º 1
0
void* MemoryPoolStaticMalloc::realloc(void *p_memory,size_t p_bytes) {

	#if DEFAULT_ALIGNMENT == 1

		return _realloc(p_memory,p_bytes);
	#else
		if (!p_memory)
			return alloc(p_bytes);

		int total = p_bytes + DEFAULT_ALIGNMENT;
		uint8_t* mem = (uint8_t*)p_memory;
		int ofs = *(mem-1);
		mem = mem - ofs;
		uint8_t* ptr = (uint8_t*)_realloc(mem, total);
		ERR_FAIL_COND_V(ptr == NULL, NULL);
		int new_ofs = (DEFAULT_ALIGNMENT - ((uintptr_t)ptr & (DEFAULT_ALIGNMENT - 1)));
		if (new_ofs != ofs) {

			//printf("realloc moving %i bytes\n", p_bytes);
			movemem((ptr + new_ofs), (ptr + ofs), p_bytes);
			ptr[new_ofs-1] = new_ofs;
		};
		return ptr + new_ofs;
	#endif
};
Ejemplo n.º 2
0
void *
realloc (void *ptr, size_t size)
{
  size_t previous_size, sizeof_size_t;
  char *where_size_was_stored;
  void *res;

  if (ptr == 0)
    res = malloc (size);
  else if (size == 0)
    {
      free (ptr);
      res = 0;
    }
  else
    {
      switch (wrapper_state)
	{
	default:
	  print ("*** ccmalloc: non valid wrapper state in realloc()\n");
	  exit (1);
	  res = 0;
	  break;

	case WRAPPER_UNINITIALIZED:
	  print ("*** realloc() in wrapper called before malloc()\n");
	  exit (1);
	  res = 0;
	  break;

	case WRAPPER_INITIALIZING:
	  sizeof_size_t = sizeof (size_t);
	  wrapper_align (sizeof_size_t);
	  where_size_was_stored = (char *) ptr;
	  where_size_was_stored -= sizeof_size_t;
	  previous_size = *(size_t *) where_size_was_stored;
	  res = _realloc (ptr, size, previous_size);
	  break;

	case WRAPPER_INITIALIZED:
	  if (ccmalloc_size (ptr, &previous_size))
	    {
	      res = _realloc (ptr, size, previous_size);
	    }
	  else
	    {
	      ccmalloc_die_or_continue
		("*** realloc(0x%x) called with non valid argument\n",
		 (unsigned) ptr);
	      res = malloc (size);
	    }
	  break;
	}
    }

  return res;
}
Ejemplo n.º 3
0
/**
 * Add char to string
 *
 * @param	string	Pointer to string structure as target
 * @param	text	Character for add
 * @return	New pointer to structure
 */
TString* string_add( TString * string, char * text )
{

	unsigned int len = strlen(text);

	unsigned int total_len = len+(string->length)+1;

	if( total_len > string->allocated )
	{
		string->allocated = total_len;
		string = _realloc(string, sizeof(TString) + (sizeof(char)*(string->allocated)));
		if(string == NULL)
		{
			fprintf(stderr, "%s", strerror(errno));
			return 0;
		}
	}


	strncat(string->data, text, len);

	string->length += len;

	return string;
}
Ejemplo n.º 4
0
 /** reset for a re-use. shrinks if > 128MB */
 void AlignedBuilder::reset() {
     _len = 0;
     RARELY {
         const unsigned sizeCap = 128*1024*1024;
         if (_p._size > sizeCap)
             _realloc(sizeCap, _len);
     }
 }
Ejemplo n.º 5
0
static int _sparseIntegerSet_insert(struct diana *diana, struct _sparseIntegerSet *is, unsigned int i) {
	if(i >= is->capacity) {
		unsigned int newCapacity = (i + 1) * 1.5;
		_realloc(diana, is->dense, is->capacity * sizeof(unsigned int), newCapacity * sizeof(unsigned int), (void **)&is->dense);
		_realloc(diana, is->sparse, is->capacity * sizeof(unsigned int), newCapacity * sizeof(unsigned int), (void **)&is->sparse);
		is->capacity = newCapacity;
	}
	unsigned int a = is->sparse[i];
	unsigned int n = is->population;
	if(a >= n || is->dense[a] != i) {
		is->sparse[i] = n;
		is->dense[n] = i;
		is->population = n + 1;
		return 0;
	}
	return 1;
}
Ejemplo n.º 6
0
void str_buttons(char *str, int **buttons, int *nbuttons) {
	*nbuttons = 0;
	while(str) {
		*buttons = (int *) _realloc((void *) *buttons, sizeof(int) * (*nbuttons + 1));
		(*buttons)[*nbuttons] = str_wbutton(eat(&str, " \t"));
		if((*buttons)[*nbuttons] != B_NONE)
			(*nbuttons)++;
	}
}
/*------------------------------------------------------------------*/
void AzIntArr::put(int int_val) 
{
  int num_max = a.size(); 
  if (num >= num_max) {
    _realloc(); 
  }
  ints[num] = int_val; 
  ++num; 
}
Ejemplo n.º 8
0
 bool seek(size_t position)
 {
     if(m_pData + position > m_pEnd)
     {
         if(!_realloc(position))
             return false;
     }
     m_pPointer = m_pData + position;
     return true;
 }
Ejemplo n.º 9
0
void StringBTree::TrieToStr::convertTrie(const ToolBox::Trie<unsigned> &trie)
{
  _strLen = 0;
  assert(trie.getInitialNode() != 0x0);
  unsigned strSize = _computeSize(*trie.getInitialNode());
  _realloc(strSize);
  _strPosition = 0;
  _handleTrieNode(*trie.getInitialNode());
  _strLen = _strPosition;
}
Ejemplo n.º 10
0
Archivo: mpz.c Proyecto: dkutilek/mpint
// Assignment
void
mpz_set (mpz_t rop, mpz_t op)
{
  if (rop[0].len != op[0].len)
    {
      rop[0].value = _realloc (rop[0].value, WORD_SIZE * rop[0].len,
          WORD_SIZE * op[0].len);
    }
  memcpy (rop[0].value, op[0].value, WORD_SIZE * op[0].len);
  rop[0].len = op[0].len;
}
Ejemplo n.º 11
0
uint
printer_start_enum(void)
{
  DWORD size = 0, num = 0;
  while (!EnumPrintersW(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS,
                        0, 4, (LPBYTE)printer_info, size, &size, &num)
         && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
    printer_info = _realloc(printer_info, size);

  return num;
}
Ejemplo n.º 12
0
static int _parse_pes(PES_BUFFER *p, uint8_t *buf, unsigned len)
{
    int result = 0;

    if (len < 6) {
        BD_DEBUG(DBG_DECODE, "invalid BDAV TS (PES header not in single TS packet)\n");
        return -1;
    }
    if (buf[0] || buf[1] || buf[2] != 1) {
        BD_DEBUG(DBG_DECODE, "invalid PES header (00 00 01)");
        return -1;
    }

    // Parse PES header
    unsigned pes_pid    = buf[3];
    unsigned pes_length = buf[4] << 8 | buf[5];
    unsigned hdr_len    = 6;

    if (pes_pid != 0xbf) {

        if (len < 9) {
            BD_DEBUG(DBG_DECODE, "invalid BDAV TS (PES header not in single TS packet)\n");
            return -1;
        }

        unsigned pts_exists = buf[7] & 0x80;
        unsigned dts_exists = buf[7] & 0x40;
        hdr_len += buf[8] + 3;

        if (len < hdr_len) {
            BD_DEBUG(DBG_DECODE, "invalid BDAV TS (PES header not in single TS packet)\n");
            return -1;
        }

        if (pts_exists) {
            p->pts = _parse_timestamp(buf + 9);
        }
        if (dts_exists) {
            p->dts = _parse_timestamp(buf + 14);
        }
    }

    result = pes_length + 6 - hdr_len;

    if (_realloc(p, BD_MAX(result, 0x100)) < 0) {
        return -1;
    }

    p->len = len - hdr_len;
    memcpy(p->buf, buf + hdr_len, p->len);

    return result;
}
Ejemplo n.º 13
0
void screens_get(void) {
	#if defined(USE_XINERAMA) || defined(DEBUG)
	int i;
	#endif
	#ifdef USE_XINERAMA
	int event, error;
	XineramaScreenInfo *screeninfo;
	if(XineramaQueryExtension(dpy, &event, &error)) {
		screeninfo = XineramaQueryScreens(dpy, &nscreens);
		if(nscreens) {
			screens = _realloc((void *) screens, nscreens * sizeof(screen_dimensions));
			for(i = 0; i < nscreens; i++) {
				screens[i].x = screeninfo[i].x_org;
				screens[i].y = screeninfo[i].y_org;
				screens[i].width = screeninfo[i].width;
				screens[i].height = screeninfo[i].height;
			}
			XFree((void *) screeninfo);
			goto ok;
		}
	}
	#endif
	nscreens = 1;
	screens = _realloc(screens, sizeof(screen_dimensions));
	screens[0].x = 0;
	screens[0].y = 0;
	screens[0].width = XDisplayWidth(dpy, screen);
	screens[0].height = XDisplayHeight(dpy, screen);
	ok:
	screens_update_current();
	ewmh_update_geometry();
	ewmh_update_strut();
	if(wlist_screen > nscreens)
		wlist_screen = nscreens - 1;
	#ifdef DEBUG
	printf(NAME ": screens_get(): loaded screen info\n");
	for(i = 0; i < nscreens; i++)
		printf("\tscreen %i: %ix%i+%i+%i\n", i, screens[i].width, screens[i].height, screens[i].x, screens[i].y);
	#endif
}
Ejemplo n.º 14
0
size_t _writeDataToBuffer(char * ptr, size_t size, size_t nmemb, void * userdata)
{   data_t * data = (data_t * )userdata;
	size_t s = size * nmemb;

	data->size += s;
	data->buffer = _realloc(data->buffer, data->size + 1);
	data->buffer[data->size] = '\0';

	if ( ptr )
    {   memcpy(data->buffer + data->offset, ptr, s);
		data->offset += s;
	}

	return s;
}
Ejemplo n.º 15
0
static int _add_ts(PES_BUFFER *p, uint8_t *buf, unsigned len)
{
    // realloc
    if (p->size < p->len + len) {
        if (_realloc(p, p->size * 2) < 0) {
            return -1;
        }
    }

    // append
    memcpy(p->buf + p->len, buf, len);
    p->len += len;

    return 0;
}
/*------------------------------------------------------------------*/
void AzIntArr::insert(int idx, int val)
{
  int num_max = a.size(); 
  if (num >= num_max) {
    _realloc(); 
  }

  int ix; 
  for (ix = num - 1; ix >= idx; --ix) {
    ints[ix+1] = ints[ix]; 
  }

  ints[idx] = val; 
  ++num; 
}
Ejemplo n.º 17
0
 /** reset with a hint as to the upcoming needed size specified */
 void AlignedBuilder::reset(unsigned sz) { 
     _len = 0;
     unsigned Q = 32 * 1024 * 1024 - 1;
     unsigned want = (sz+Q) & (~Q);
     if( _p._size == want ) {
         return;
     }        
     if( _p._size > want ) {
         if( _p._size <= 64 * 1024 * 1024 )
             return;
         bool downsize = false;
         RARELY { downsize = true; }
         if( !downsize )
             return;
     }
     _realloc(want, _len);
 }
Ejemplo n.º 18
0
/**
 * Add one character to string structire
 *
 * @param	string	Pointer to string structure as target
 * @param	c	character for add
 * @return	0 ... error, 1 ... success
 */
int string_add_chr( TString * string, char c )
{
	if( string->allocated < (string->length+1))
	{
		string->allocated += ALLOC_SIZE;
		string = _realloc(string, sizeof(TString) + (sizeof(char)*(string->allocated)));

		if(string == NULL)
		{
			fprintf(stderr, "%s", strerror(errno));
			return 0;
		}
	}

	string->data[ string->length ] = c;
	string->length++;
	string->data[ string->length ] = '\0';

	return 1;
}
Ejemplo n.º 19
0
void * _mempage_heap_realloc(struct mempage_heap * _heap, void * mem, size_t size){
	if (size == 0){
		_free(mem);
		return 0;
	}

	size_t oldsize = *(size_t *)((char*)mem - sizeof(size_t));
	if (oldsize > size){
		return mem;
	}
	
	void * tmp = _realloc(mem, size);
	if (tmp == 0){
		tmp = _mempage_heap_alloc(_heap, size);
		memcpy(tmp, mem, oldsize);
		_free(mem);
	}

	return tmp;
}
Ejemplo n.º 20
0
size_t
varyad_push(struct varyad **v, void *data, size_t size, int realloc)
{
    if (_avail(*v) < size + sizeof(size_t)) {
        if (!realloc) {
            errno = ENOMEM;
            return 0;
        } else {
            struct varyad *const tmp = _realloc(*v);
            if (!tmp) {
                return 0;
            } else {
                *v = tmp;
            }
        }
    }
    const size_t off = (*v)->rank ? _size(*v, (*v)->rank-1) : 0;
    memcpy(_head(*v) + off, data, size);
    _set_size(*v, (*v)->rank++, off + size);
    return (*v)->size;
}
Ejemplo n.º 21
0
 /* "slow"/infrequent portion of 'grow()'  */
 void NOINLINE_DECL AlignedBuilder::growReallocate(unsigned oldLen) {
     dassert( _len > _p._size );
     unsigned a = _p._size;
     verify( a );
     while( 1 ) {
         if( a < 128 * 1024 * 1024 )
             a *= 2;
         else if( sizeof(int*) == 4 )
             a += 32 * 1024 * 1024;
         else 
             a += 64 * 1024 * 1024;
         DEV if( a > 256*1024*1024 ) { 
             log() << "dur AlignedBuilder too big, aborting in _DEBUG build" << endl;
             abort();
         }
         wassert( a <= 256*1024*1024 );
         verify( a <= 512*1024*1024 );
         if( _len < a )
             break;
     }
     _realloc(a, oldLen);
 }
Ejemplo n.º 22
0
void cfg_set_opt(char *key, char *value, int initial) {
	#ifdef USE_XFT
	XftFont *newxftfont;
	#endif
	XFontStruct *newfont;
	long i;
	if(strcmp(key, "resetkeys") == 0)
		keys_free();
	if(!value)
		return;
	if(strcmp(key, "key") == 0)
		key_bind(value);
	if(strcmp(key, "exec") == 0 && initial)
		spawn(value);
	if(strcmp(key, "exec_onload") == 0)
		spawn(value);
	if(strcmp(key, "background") == 0)
		str_color(value, &bg);
	if(strcmp(key, "inactive_background") == 0)
		str_color(value, &ibg);
	if(strcmp(key, "foreground") == 0)
		str_color(value, &fg);
	if(strcmp(key, "inactive_foreground") == 0)
		str_color(value, &ifg);
	if(strcmp(key, "border_color") == 0)
		str_color(value, &bfg);
	if(strcmp(key, "inactive_border_color") == 0)
		str_color(value, &ibfg);
	if(strcmp(key, "font") == 0) {
		newfont = XLoadQueryFont(dpy, value);
		if(newfont) {
			if(font)
				XFreeFont(dpy, font);
			#ifdef USE_XFT
			if(xftfont) {
				XftFontClose(dpy, xftfont);
				xftfont = NULL;
			}
			#endif
			font = newfont;
		}
		#ifdef USE_XFT
		else {
			newxftfont = XftFontOpenName(dpy, screen, value);
			if(newxftfont) {
				if(xftfont)
					XftFontClose(dpy, xftfont);
				if(font) {
					XFreeFont(dpy, font);
					font = NULL;
				}
				xftfont = newxftfont;
			}
		}
		#endif
	}
	if(strcmp(key, "border_width") == 0) {
		i = strtol(value, NULL, 0);
		if(i >= 0)
		  border_width = i;
	}
	if(strcmp(key, "border_spacing") == 0) {
		i = strtol(value, NULL, 0);
		if(i >= 0)
			border_spacing = i;
	}
	if(strcmp(key, "title_spacing") == 0) {
		i = strtol(value, NULL, 0);
		if(i >= 0)
			title_spacing = i;
	}
	if(strcmp(key, "button_spacing") == 0) {
		i = strtol(value, NULL, 0);
		if(i >= 0)
			button_spacing = i;
	}
	if(strcmp(key, "wlist_margin") == 0) {
		i = strtol(value, NULL, 0);
		if(i >= 0)
			wlist_margin = i;
	}
	if(strcmp(key, "wlist_maxwidth") == 0) {
		i = strtol(value, NULL, 0);
		if(i >= 0)
			wlist_maxwidth = i;
	}
	if(strcmp(key, "doubleclick_time") == 0) {
		i = strtol(value, NULL, 0);
		if(i > 0)
			doubleclick_time = i;
	}
	if(strcmp(key, "snap") == 0)
		snapat = strtol(value, NULL, 0);
	if(strcmp(key, "desktops") == 0) {
		i = strtol(value, NULL, 0);
		if(i > 0)
			dc = i;
	}
	if(strcmp(key, "ewmh_screen") == 0) {
		i = strtol(value, NULL, 0);
		if(i > 0)
			ewmh_screen = i;
	}
	if(strcmp(key, "button1") == 0)
	 	str_action(value, &button1);
	if(strcmp(key, "button2") == 0)
		str_action(value, &button2);
	if(strcmp(key, "button3") == 0)
		str_action(value, &button3);
	if(strcmp(key, "button4") == 0)
		str_action(value, &button4);
	if(strcmp(key, "button5") == 0)
		str_action(value, &button5);
	if(strcmp(key, "double1") == 0)
		str_action(value, &double1);
	if(strcmp(key, "double2") == 0)
		str_action(value, &double2);
	if(strcmp(key, "double3") == 0)
		str_action(value, &double3);
	if(strcmp(key, "double4") == 0)
		str_action(value, &double4);
	if(strcmp(key, "double5") == 0)
		str_action(value, &double5);
	if(strcmp(key, "root_button1") == 0)
	 	str_action(value, &root_button1);
	if(strcmp(key, "root_button2") == 0)
		str_action(value, &root_button2);
	if(strcmp(key, "root_button3") == 0)
		str_action(value, &root_button3);
	if(strcmp(key, "root_button4") == 0)
		str_action(value, &root_button4);
	if(strcmp(key, "root_button5") == 0)
		str_action(value, &root_button5);
	if(strcmp(key, "root_double1") == 0)
		str_action(value, &root_double1);
	if(strcmp(key, "root_double2") == 0)
		str_action(value, &root_double2);
	if(strcmp(key, "root_double3") == 0)
		str_action(value, &root_double3);
	if(strcmp(key, "root_double4") == 0)
		str_action(value, &root_double4);
	if(strcmp(key, "root_double5") == 0)
		str_action(value, &double5);
	if(strcmp(key, "click_focus") == 0)
		str_bool(value, &click_focus);
	if(strcmp(key, "click_raise") == 0)
		str_bool(value, &click_raise);
	if(strcmp(key, "focus_new") == 0)
		str_bool(value, &focus_new);
	if(strcmp(key, "fullscreen_stacking") == 0)
		str_fsstacking(value, &fullscreen_stacking);
	if(strcmp(key, "taskbar_ontop") == 0)
		str_bool(value, &taskbar_ontop);
	if(strcmp(key, "center_title") == 0)
		str_bool(value, &center_title);
	if(strcmp(key, "center_wlist_items") == 0)
		str_bool(value, &center_wlist_items);
	if(strcmp(key, "map_center") == 0)
		str_bool(value, &map_center);
	if(strcmp(key, "drag_warp") == 0)
		str_bool(value, &drag_warp);
	if(strcmp(key, "allow_focus_stealing") == 0)
		str_bool(value, &allow_focus_stealing);
	if(strcmp(key, "correct_center") == 0)
		str_bool(value, &correct_center);
	if(strcmp(key, "correct_center_unmanaged") == 0)
		str_bool(value, &correct_center_unmanaged);
	if(strcmp(key, "correct_center_separate") == 0)
		str_bool(value, &correct_center_separate);
	if(strcmp(key, "click_root") == 0)
		str_bool(value, &click_root);
	if(strcmp(key, "mouse_modifier") == 0)
		str_key(&value, &mousemodmask);
	if(strcmp(key, "no_snap_modifier") == 0)
		str_key(&value, &nosnapmodmask);
	if(strcmp(key, "ignore_modifier") == 0) {
		if(mod_ignore) {
			nmod_ignore = 0;
			free((void *) mod_ignore);
			mod_ignore = NULL;
		}
		while(value) {
			mod_ignore = (unsigned int *) _realloc((void *) mod_ignore, (nmod_ignore + nmod_ignore + 1) * sizeof(unsigned int));
			skiprealloc:
			mod_ignore[nmod_ignore] = str_modifier(eat(&value, " \t"));
			if(mod_ignore[nmod_ignore] == None)
				goto skiprealloc;
			for(i = 0; i < nmod_ignore; i++)
				mod_ignore[nmod_ignore + 1 + i] = mod_ignore[i] | mod_ignore[nmod_ignore];
			nmod_ignore += nmod_ignore + 1;
		}
	}
	if(strcmp(key, "buttons_left") == 0)
		str_buttons(value, &buttons_left, &nbuttons_left);
	if(strcmp(key, "buttons_right") == 0)
		str_buttons(value, &buttons_right, &nbuttons_right);
}
Ejemplo n.º 23
0
_16b *s16_realloc(string16 *s16, size_t size)
{
	return _realloc(s16, size);
}
NS_EXPORT_(__ptr_t) realloc(__ptr_t ptr, size_t size)
{
    return _realloc(ptr, size);
}
Ejemplo n.º 25
0
 inline void     ensureCapacity(unsigned max)        { if (maxLen <= curLen + max) _realloc(curLen + max); }
Ejemplo n.º 26
0
void *
nandfsrealloc(void *p, ulong size)
{
	return _realloc(p, size, getcallerpc(&p));
}