Пример #1
0
/** Add a player's alias list to the player list htab.
 * \param player dbref of player to add.
 * \param alias list of names ot use as hash table keys for player,
 * semicolon-separated.
 */
void
add_player_alias(dbref player, const char *alias)
{
  char tbuf1[BUFFER_LEN], *s, *sp;
  if (!hft_initialized)
    init_hft();
  if (!alias) {
    add_player(player);
    return;
  }
  mush_strncpy(tbuf1, alias, BUFFER_LEN);
  s = trim_space_sep(tbuf1, ALIAS_DELIMITER);
  while (s) {
    sp = split_token(&s, ALIAS_DELIMITER);
    while (sp && *sp && *sp == ' ')
      sp++;
    if (sp && *sp) {
      dbref *p;
      p = slab_malloc(player_dbref_slab, NULL);
      if (!p)
        mush_panic("Unable to allocate memory in plyrlist!");
      *p = player;
      hashadd(strupper(sp), p, &htab_player_list);
    }
  }
}
Пример #2
0
static lock_list *
next_free_lock(const void *hint)
{
  if (lock_slab == NULL) {
    lock_slab = slab_create("locks", sizeof(lock_list));
    slab_set_opt(lock_slab, SLAB_ALLOC_BEST_FIT, 1);
  }
  return slab_malloc(lock_slab, hint);
}
Пример #3
0
char *
slab_strdup(const char *file, unsigned int line, const char *src)
{
    char *target;
    size_t len;

    len = strlen(src) + 1;
    target = slab_malloc(file, line, len);
    memcpy(target, src, len);
    return target;
}
Пример #4
0
/** Add a player to the player list htab.
 * \param player dbref of player to add.
 */
void
add_player(dbref player)
{
  dbref *p;
  if (!hft_initialized)
    init_hft();
  p = slab_malloc(player_dbref_slab, NULL);
  if (!p)
    mush_panic("Unable to allocate memory in plyrlist!");
  *p = player;
  hashadd(strupper(Name(player)), p, &htab_player_list);
}
Пример #5
0
void *
slab_realloc(const char *file, unsigned int line, void *ptr, size_t size)
{
    alloc_header_t *orig;
    void *newblock;
    size_t osize;

    if (!ptr)
        return slab_malloc(file, line, size);

    verify(ptr);
    orig = (alloc_header_t*)ptr - 1;
#if SLAB_DEBUG & SLAB_DEBUG_HEADER
    osize = orig->size;
#else
    osize = *orig;
#endif
    if (osize >= size)
        return ptr;
    newblock = slab_malloc(file, line, size);
    memcpy(newblock, ptr, osize);
    slab_free(file, line, ptr);
    return newblock;
}
Пример #6
0
/* Allocate a new reference count struct. Consider moving away from
   slabs; the struct size is pretty big with the skip list fields
   added. But see comment for memcheck_slab's declaration. */
static MEM *
alloc_memcheck_node(const char *ref)
{
  MEM *newcheck;

  if (!memcheck_slab)
    memcheck_slab = slab_create("mem check references", sizeof(MEM));

  newcheck = slab_malloc(memcheck_slab, NULL);
  memset(newcheck, 0, sizeof *newcheck);
  mush_strncpy(newcheck->ref_name, ref, REF_NAME_LEN);
  newcheck->link_count = pick_link_count(MAX_LINKS);
  newcheck->ref_count = 1;
  return newcheck;
}
Пример #7
0
/** Insert a new element into the map.
 * \param im the map to insert into.
 * \param key the key
 * \param data Pointer to data to store under this key.
 * \return true on success, false on failure (Usually a duplicate key)
 */
bool
im_insert(intmap *im, im_key key, void *data)
{
  patricia *here, *newnode, *prev = NULL;
  int bit, prevbit = 0;

  newnode = slab_malloc(intmap_slab, im->root);
  newnode->key = key;
  newnode->data = data;
  newnode->links[0] = newnode->links[1] = newnode;

  /* First key added to tree */
  if (!im->root) {
    newnode->bit = 0;
    im->root = newnode;
    im->count += 1;
    assert(im->count == 1);
    return true;
  }

  here = pat_search(im->root, key, -1);
  if (here && here->key == key) {
    /* Duplicate key fails */
    slab_free(intmap_slab, newnode);
    return false;
  }

  /* Not a duplicate, so key and here->key /will/ differ in at least one
     bit. No need to make sure that bit doesn't go > 31 */
  for (bit = 0; digit(key, bit) == digit(here->key, bit); bit++) ;

  newnode->bit = bit;

  if (bit < im->root->bit) {
    newnode->links[digit(im->root->key, bit)] = im->root;
    im->root = newnode;
    im->count += 1;
    assert(im->count > 1);
    return true;
  }

  for (here = im->root;;) {
    int i;
    if (here->bit == bit) {
      newnode->bit = bit + 1;
      here->links[digit(key, bit)] = newnode;
      im->count += 1;
      assert(im->count > 1);
      return true;
    }
    if (here->bit > bit || (prev && here->bit <= prev->bit)) {
      prev->links[prevbit] = newnode;
      newnode->links[digit(here->key, bit)] = here;
      im->count += 1;
      assert(im->count > 1);
      return true;
    }

    prev = here;
    i = digit(key, here->bit);
    here = prev->links[i];
    prevbit = i;
  }

  /* Not reached */
  assert(0);
  return false;
}
Пример #8
0
void* calloc(size_t nmemb, size_t size)
{
	void *ptr = slab_malloc(nmemb * size);
	if (ptr) memset(ptr, 0, nmemb * size);
	return ptr;
}
Пример #9
0
void* malloc(size_t size)
{
	return slab_malloc(size);
}