Пример #1
0
void			*realloc(void *ptr, size_t size)
{
	int					type;
	int					ret;
	void				*new_ptr;

	if (size == 0)
	{
		size = 1;
		new_ptr = do_realloc(ptr, size, TINY);
		return (new_ptr);
	}
	if (!ptr)
		return (NULL);
	if (pthread_mutex_lock(&g_mutex) < 0)
		return (ptr);
	ret = search_map(&type, ptr, size);
	pthread_mutex_unlock(&g_mutex);
	if (ret == 1)
	{
		new_ptr = do_realloc(ptr, size, type);
		return (new_ptr);
	}
	else if (ret == 0)
		return (ptr);
	return (ptr);
}
Пример #2
0
/* Insert or update ap data in the hash table
 * returns 0 if the ap wasn't present
 * 1 otherwise
 */
char insert_ap(Wifi_AccessPoint * ap)
{
	int key = ap->macaddr[5];
	struct AP_HT_Entry *ht_entry;
	char same;
	struct AP_HT_Entry *to_insert = NULL;

	/* check if there's already an entry in the hash table */
	if (ap_ht[key] == NULL) {
		to_insert = entry_from_ap(ap);
		ap_ht[key] = to_insert;
	} else {
		ht_entry = ap_ht[key];
		/* Check if the AP is already known, walking the linked list */
		while (!(same = macaddr_cmp(ap->macaddr, ht_entry->ap->macaddr))
		       && ht_entry->next)
			ht_entry = ht_entry->next;

		if (same == 0) {
			to_insert = entry_from_ap(ap);
			ht_entry->next = to_insert;
		} else {
			/* AP is already there, just update data */
			ht_entry->tick = curtick;
			ht_entry->ap->channel = ap->channel;
			ht_entry->ap->rssi = ap->rssi;
			ht_entry->ap->flags = ap->flags;
			if (ap->ssid_len == 0) {
				memset(ht_entry->ap->ssid, 0, 32);
			} else {
				memcpy(ht_entry->ap->ssid, ap->ssid,
				       (unsigned char)ap->ssid_len >
				       32 ? 32 : ap->ssid_len);
			}
			return 1;
		}
	}

	if (to_insert) {
		if (to_insert->ap->flags & WFLAG_APDATA_WPA) {
			do_realloc(WPA);
			insert_fast(WPA, to_insert);
		} else {
			if (to_insert->ap->flags & WFLAG_APDATA_WEP) {
				do_realloc(WEP);
				insert_fast(WEP, to_insert);
			} else {
				do_realloc(OPN);
				insert_fast(OPN, to_insert);
			}
		}
	}
	numap++;

	return 0;
}
Пример #3
0
static kGCObject2 *new_ObjectArena2(GcManager *mng, size_t arenasize)
{
    ObjectPageTable_t *oat;
    //KonohaContext *kctx = mng->kctx;
    size_t pageindex = MSGC(2).arena_table.size;
    if(unlikely(!(pageindex < MSGC(2).arena_table.capacity))) {
        size_t oldsize = MSGC(2).arena_table.capacity;
        size_t newsize = oldsize * 2;
        MSGC(2).arena_table.table = (ObjectPageTable_t *)do_realloc(MSGC(2).arena_table.table, oldsize * sizeof(ObjectPageTable_t), newsize * sizeof(ObjectPageTable_t));
        MSGC(2).arena_table.capacity = newsize;
    }
    MSGC(2).arena_table.size += 1;
    DBG_ASSERT(sizeof(ObjectPage2_t) == K_PAGESIZE);
    oat = &MSGC(2).arena_table.table[pageindex];
    ObjectArenaTable_Init2(mng, oat, arenasize);
    kGCObject2 *p = oat->head2->slots;
    p->ref5_tail = (kGCObject2 *)&(oat->bottom2[-1]);

    int i = 0;
    kGCObject2 *tmp = p;
    while(tmp != &oat->head2->slots[PageObjectSize(2)]) {
        tmp = tmp->ref;
        i++;
    }
    assert(i == PageObjectSize(2));
    return p;
}
Пример #4
0
charinfo *
get_charinfo (internal_font_number f, integer c) { 
  sa_tree_item glyph;
  charinfo *ci;
  if (proper_char_index(c)) {
    glyph = get_sa_item(Characters(f), c);
    if (!glyph) {
      /* this could be optimized using controlled growth */
      font_bytes += sizeof(charinfo);
      glyph = ++font_tables[f]->charinfo_count;
      do_realloc(font_tables[f]->charinfo, (glyph+1), charinfo); 
      memset (&(font_tables[f]->charinfo[glyph]),0,sizeof(charinfo));
  	  font_tables[f]->charinfo[glyph].ef = 1000; /* init */
      font_tables[f]->charinfo_size = glyph;
      set_sa_item(font_tables[f]->characters, c, glyph, 1); /* 1= global */
    }
    return &(font_tables[f]->charinfo[glyph]);
  } else if (c == left_boundarychar) {
    if (left_boundary(f)==NULL) {
      ci = xcalloc(1,sizeof(charinfo));
      font_bytes += sizeof(charinfo);
      set_left_boundary(f,ci);
    }
    return left_boundary(f);
  } else if (c == right_boundarychar) {
    if (right_boundary(f)==NULL) {
      ci = xcalloc(1,sizeof(charinfo));
      font_bytes += sizeof(charinfo);
      set_right_boundary(f,ci);
    }
    return right_boundary(f);
  }
  return &(font_tables[f]->charinfo[0]);
}
Пример #5
0
static int add_source (double ra, double dec, double weight, double energy)
{
   Point_Source_Type *p;
   double cosx, cosy, cosz;

   /* Convert to God's units from arc-min */
   ra = ra * (PI/(180.0 * 60.0));
   dec = dec * (PI/(180.0 * 60.0));
   
   if (Max_Num_Points == Num_Points)
     {
	Max_Num_Points += 32;
	p = (Point_Source_Type *)do_realloc ((char *)Point_Sources, Max_Num_Points * sizeof (Point_Source_Type));
	if (p == NULL)
	  {
	     free_sources ();
	     return -1;
	  }
	Point_Sources = p;
     }
   
   p = Point_Sources + Num_Points;
   /* Note the the minus sign is to generate a vector pointing from the
    * source to the origin
    */
   p->cosx = -cos (dec) * cos (ra);
   p->cosy = -cos (dec) * sin(ra);
   p->cosz = -sin (dec);
   
   p->weight = weight;
   p->energy = energy;
   Num_Points += 1;
   
   return 0;
}
Пример #6
0
inline MemRef Allocator::realloc_(ref_type ref, const char* addr, size_t old_size, size_t new_size)
{
#ifdef REALM_DEBUG
    if (ref == m_debug_watch)
        REALM_TERMINATE("Allocator watch: Ref was reallocated");
#endif
    return do_realloc(ref, addr, old_size, new_size);
}
Пример #7
0
/* Emit bytes to the instruction stream:
 */
static unsigned char *reserve( struct x86_function *p, int bytes )
{
   if (p->csr + bytes - p->store > (int) p->size)
      do_realloc(p);

   {
      unsigned char *csr = p->csr;
      p->csr += bytes;
      return csr;
   }
}
Пример #8
0
static void mstack_Push(MarkStack *mstack, kObject *ref)
{
    size_t ntail = (mstack->tail + 1) & mstack->capacity;
    if(unlikely(ntail == 0)) {
        size_t capacity = 1 << mstack->capacity_log2;
        size_t stacksize = sizeof(kObject *) * capacity;
        mstack->stack = (kObject**)do_realloc(mstack->stack, stacksize, stacksize * 2);
        mstack->capacity_log2 += 1;
        mstack->capacity = (1 << mstack->capacity_log2) - 1;
        ntail = (mstack->tail + 1) & mstack->capacity;
    }
    mstack->stack[mstack->tail] = ref;
    mstack->tail = ntail;
}
Пример #9
0
void
set_font_params(internal_font_number f, int b) {
  int i;
  i = font_params(f);
  if (i!=b) {								   
    font_bytes += (b-font_params(f))*sizeof(scaled); 
    do_realloc(param_base(f), (b+1), integer);	
    font_params(f) = b;
    if (b>i) {
      while (i<b) {
	i++;
	set_font_param(f,i,0);
      }
    }
  } 
}
Пример #10
0
void *
realloc (void *ptr, size_t size)
{
	return do_realloc (ptr, size);
}
Пример #11
0
 void reserve_new_slots(size_type num_slots) {
   const size_type new_count = count + num_slots;
   if(new_count > alloced) do_realloc(new_count * expand_multiplier);
   count = new_count;
 }
Пример #12
0
 void push_vertex(vertex const& v, color const& c) {
   if(count == alloced) do_realloc(alloced * expand_multiplier);
   vertices[count].c = c;
   vertices[count].v = v;
   ++count;
 }
Пример #13
0
 void push_vertex(vertex_with_color const& v) {
   if(count == alloced) do_realloc(alloced * expand_multiplier);
   vertices[count] = v;
   ++count;
 }