Esempio n. 1
0
void kill_stack(void)
{
  n_free(stack_stack);
  n_free(stack_frames);
  stack_stack = 0;
  stack_frames = 0;
}
Esempio n. 2
0
void init_stack(offset initialstack_stack_size, zword initialframe_size)
{
  n_free(stack_stack);
  stack_stack = (zword *) n_malloc(sizeof(*stack_stack) * 
				   initialstack_stack_size);
  stack_pointer = 0;
  stack_min = 0;
  stack_max = initialstack_stack_size;

  n_free(stack_frames);
  stack_frames = (Stack_frame *) n_malloc(sizeof(*stack_frames) *
					  initialframe_size);
  frame_count = 0;
  if(stacklimit && initialframe_size > stacklimit)
    frame_max = stacklimit;
  else
    frame_max = initialframe_size;

  stack_frames[frame_count].stack_stack_start = 0;
  stack_frames[frame_count].return_PC = 0;
  stack_frames[frame_count].num_locals = 0;
  stack_frames[frame_count].arguments = 0;
  stack_frames[frame_count].result_variable = -2;
  local_vars = stack_stack + stack_frames[frame_count].stack_stack_start;
}
Esempio n. 3
0
void mymap_kill(void)
{
  n_free(mymap);
  mymap = NULL;    
  n_free(mymapnode);
  mymapnode = NULL;
}
Esempio n. 4
0
static void set_game_filename(const char *name)
{
  n_free(game_filename);
  game_filename = 0;

#if defined(_GNU_SOURCE)
  game_filename = canonicalize_file_name(name);
#else
#if defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE)
  game_filename = (char *) n_malloc(PATH_MAX);
  if(!realpath(name, game_filename)) {
    n_free(game_filename);
    game_filename = 0;
  }
#else
#ifdef __DJGPP__
  game_filename = (char *) n_malloc(FILENAME_MAX);
  _fixpath(name, game_filename);
#endif
#endif
#endif

  if(!game_filename)
    game_filename = n_strdup(name);
}
Esempio n. 5
0
void automap_kill(void)
{
  mymap_kill();
  n_free(loc_exp);
  loc_exp = NULL;
  LEdestruct(all_edges, n_free(all_edges->node));
  n_hash_free_table(&rooms, n_free);
  z_kill_window(automap_win);
}
Esempio n. 6
0
strid_t startup_findfile(void)
{
  static DIR *dir = NULL;
  static char *pathstart = NULL;
  static char *path = NULL;
  strid_t stream;
  struct dirent *d;
  char *name = NULL;

  if(!pathstart) {
    char *p = search_path;
    if(!p)
      return 0;
    pathstart = n_strdup(p);
    if(!(path = n_strtok(pathstart, ":"))) {
      n_free(pathstart);
      pathstart = 0;
      return 0;
    }
  }

  do {
    if(!dir) {
      dir = opendir(path);
      if(!dir) {
	n_free(pathstart);
	pathstart = 0;
	return 0;
      }
    }
    d = readdir(dir);
    if(!d) {
      closedir(dir);
      dir = NULL;
      if(!(path = n_strtok(NULL, ":"))) {
	n_free(pathstart);
	pathstart = 0;
	return 0;
      }
    }
  } while(!dir);

  name = (char *) n_malloc(n_strlen(path) + n_strlen(d->d_name) + 2);
  n_strcpy(name, path);
  n_strcat(name, "/");
  n_strcat(name, d->d_name);
  stream = glkunix_stream_open_pathname(name, fileusage_Data |
					fileusage_BinaryMode, 0);
  if(stream)
    set_game_filename(name);
  n_free(name);
  return stream;
}
Esempio n. 7
0
void CMeshShape::Detach()
{
	n_assert(IsAttached());
	n_assert(pVBuffer);
	n_assert(pIBuffer);

	dGeomTriMeshDataDestroy(ODETriMeshDataID);

	n_free(pVBuffer);
	n_free(pIBuffer);
	pVBuffer = NULL;
	pIBuffer = NULL;

	CShape::Detach();
};
Esempio n. 8
0
File: undo.c Progetto: BPaden/garglk
/* Frees old undo slots if possible in order to reduce memory consumption.
   Will never free the most recent @save_undo */
BOOL free_undo(void)
{
  move_difference *p, *g = NULL;
  for(p = movelist; p; p=p->next)
    if(p->next)
      g = p;
  if(g == NULL)
    return FALSE;

  n_free(g->next->delta);
  n_free(g->next->stackchunk);
  n_free(g->next);
  g->next = NULL;
  return TRUE;
}
Esempio n. 9
0
bool CDataServer::CopyFile(const nString& SrcPath, const nString& DestPath)
{
	//???mangle here for perf reasons?

	if (IsFileReadOnly(DestPath))
		SetFileReadOnly(DestPath, false);

	CFileStream Src, Dest;
	if (!Src.Open(SrcPath, SAM_READ, SAP_SEQUENTIAL)) FAIL;
	if (!Dest.Open(DestPath, SAM_WRITE, SAP_SEQUENTIAL))
	{
		Src.Close();
		FAIL;
	}

	int Size = Src.GetSize();
	char* pBuffer = (char*)n_malloc(Size);
	int RealSize = Src.Read(pBuffer, Size);
	n_assert(RealSize == Size);
	Src.Close();

	RealSize = Dest.Write(pBuffer, Size);
	n_assert(RealSize == Size);
	Dest.Close();
	n_free(pBuffer);

	OK;
}
Esempio n. 10
0
void mymap_init(int width, int height)
{
  int i;
  int max;
  mapwidth = width * 2;
  mapheight = height * 2;
  max = mapwidth * mapheight;
  n_free(mymap);
  n_free(mymapnode);
  mymap = (char *) n_malloc(max);
  mymapnode = (loc_node **) n_malloc(max * sizeof(*mymapnode));
  for(i = 0; i < max; i++) {
    mymap[i] = ' ';
    mymapnode[i] = NULL;
  }
}
Esempio n. 11
0
File: node.c Progetto: tycho/pearpc
/*
 * NAME:	join()
 * DESCRIPTION:	combine two nodes into a single node
 */
static
int join(node *left, node *right, byte *record, int *flag)
{
  int i, offset;

  /* copy records and offsets */

  memcpy(HFS_NODEREC(*left, left->nd.ndNRecs),
	 HFS_NODEREC(*right, 0), NODEUSED(*right));

  offset = left->roff[left->nd.ndNRecs] - right->roff[0];

  for (i = 1; i <= right->nd.ndNRecs; ++i)
    left->roff[++left->nd.ndNRecs] = offset + right->roff[i];

  if (bt_putnode(left) == -1)
    goto fail;

  /* eliminate node and update link pointers */

  if (n_free(right) == -1)
    goto fail;

  HFS_SETKEYLEN(record, 0);
  *flag = 1;

  return 0;

fail:
  return -1;
}
Esempio n. 12
0
File: undo.c Progetto: BPaden/garglk
BOOL fast_saveundo(void)
{
  strid_t stack;
  glui32 stack_size;
  /* Avoids realloc() in hopes that'll make it a teensy bit faster */
  if(automap_undoslot.z_memsize < dynamic_size) {
    n_free(automap_undoslot.z_mem);
    automap_undoslot.z_mem = n_malloc(dynamic_size);
    automap_undoslot.z_memsize = dynamic_size;
  }
  n_memcpy(automap_undoslot.z_mem, z_memory, dynamic_size);

  automap_undoslot.PC = oldPC;

  automap_undoslot.stacklength = stack_size = get_quetzal_stack_size();
  if(automap_undoslot.stackchunksize < stack_size) {
    free(automap_undoslot.stackchunk);
    automap_undoslot.stackchunk = (zbyte *) n_malloc(stack_size);
    automap_undoslot.stackchunksize = stack_size;
  }
  
  stack = glk_stream_open_memory((char *) automap_undoslot.stackchunk,
				 automap_undoslot.stacklength,
				 filemode_Write, 0);
  if(!stack)
    return FALSE;
  if(!quetzal_stack_save(stack)) {
    glk_stream_close(stack, NULL);
    return FALSE;
  }
  glk_stream_close(stack, NULL);
  return TRUE;
}
Esempio n. 13
0
struct poclidek_ctx *poclidek_new(struct poldek_ctx *ctx) 
{
    struct poclidek_ctx *cctx = n_calloc(1, sizeof(*cctx));
    if (poclidek_init(cctx, ctx))
        return cctx;
    n_free(cctx);
    return NULL;
}
Esempio n. 14
0
void
n_module_destroy(NModule* self) {
	if (self != NULL) {
		n_register_array_destroy(&self->registers);
		n_instruction_array_destroy(&self->code);
		n_free(self);
	}
}
Esempio n. 15
0
void CMemStream::Close()
{
	n_assert(IsOpen());
	if (IsMapped()) Unmap();
	if (SelfAlloc && pBuffer) n_free(pBuffer);
	pBuffer = NULL;
	Flags.Clear(IS_OPEN);
	//CStream::Close();
}
Esempio n. 16
0
static void room_remove(loc_node *room)
{
  unsigned n;
  if(room) {
    const char *preface = room->real ? "" : "fake";
    for(n = 0; n < NUM_DIRS; n++)
      automap_remove_edge(room->outgoing[n]);
    n_free(n_hash_del(n_static_number(preface, room->number), &rooms));
  }
}
Esempio n. 17
0
void n_tuple_free(tn_alloc *na, tn_tuple *tu)
{
    if (tu->_refcnt > 0) {
        tu->_refcnt--;
        return;
    }
    tu->size = 0;
    if (na)
        na->na_free(na, tu);
    else
        n_free(tu);
}
Esempio n. 18
0
File: pipe.c Progetto: dancahill/nsp
void pipe_murder(nsp_state *N, obj_t *cobj)
{
#define __FN__ __FILE__ ":pipe_murder()"
	//	PIPE_CONN *conn;

	n_warn(N, __FN__, "reaper is claiming another lost soul");
	if ((cobj->val->type != NT_CDATA) || (cobj->val->d.str == NULL) || (nc_strcmp(cobj->val->d.str, "pipe-conn") != 0))
		n_error(N, NE_SYNTAX, __FN__, "expected a pipe conn");
	//	conn=(PIPE_CONN *)cobj->val->d.str;
	n_free(N, (void *)&cobj->val->d.str, sizeof(PIPE_CONN) + 1);
	return;
#undef __FN__
}
Esempio n. 19
0
static QuviError _http_metainfo(_quvi_http_metainfo_t qmi)
{
  _quvi_net_t n;
  QuviError rc;
  _quvi_t q;

  q = qmi->handle.quvi;
  n = n_new(q, qmi->url.input->str);

  if (q->cb.http_metainfo != NULL)
    rc = q->cb.http_metainfo(n);
  else
    rc = c_http_metainfo(q, n); /* Query using cURL (default). */

  if (rc == QUVI_OK)
    {
      rc = l_exec_util_to_file_ext(q, n->http_metainfo.content_type->str,
                                   qmi->file_ext);
      if (rc == QUVI_OK)
        {
          g_string_assign(qmi->content_type, n->http_metainfo.content_type->str);
          qmi->length_bytes = n->http_metainfo.content_length;
        }

      if (q->cb.status != NULL)
        {
          const glong p = q_makelong(QUVI_CALLBACK_STATUS_HTTP_QUERY_METAINFO,
                                     QUVI_CALLBACK_STATUS_DONE);

          if (q->cb.status(p, 0, q->cb.userdata.status) != QUVI_OK)
            rc = QUVI_ERROR_CALLBACK_ABORTED;
        }
    }
  else
    {
      /* Save returned error message. */
      if (n->status.errmsg->len >0)
        g_string_assign(q->status.errmsg, n->status.errmsg->str);
      else
        {
          g_string_assign(q->status.errmsg,
                          "unknown error: http_metainfo: callback returned "
                          "an empty errmsg");
        }
    }

  q->status.resp_code = n->status.resp_code;
  n_free(n);

  return (rc);
}
Esempio n. 20
0
/*
 * NAME:	node->merge()
 * DESCRIPTION:	combine two nodes into a single node
 */
int n_merge(node *right, node *left, unsigned char *record, int *flag)
{
  int i, offset;

  /* copy records and offsets */

  memcpy(HFS_NODEREC(*left, left->nd.ndNRecs), HFS_NODEREC(*right, 0),
	 right->roff[right->nd.ndNRecs] - right->roff[0]);

  offset = left->roff[left->nd.ndNRecs] - right->roff[0];

  for (i = 1; i <= (int)right->nd.ndNRecs; ++i)
    left->roff[++left->nd.ndNRecs] = offset + right->roff[i];

  /* update link pointers */

  left->nd.ndFLink = right->nd.ndFLink;

  if (bt_putnode(left) < 0)
    return -1;

  if (right->bt->hdr.bthLNode == right->nnum)
    {
      right->bt->hdr.bthLNode = left->nnum;
      right->bt->flags |= HFS_UPDATE_BTHDR;
    }

  if (right->nd.ndFLink)
    {
      node n;

      n.bt   = right->bt;
      n.nnum = right->nd.ndFLink;

      if (bt_getnode(&n) < 0)
	return -1;

      n.nd.ndBLink = left->nnum;

      if (bt_putnode(&n) < 0)
	return -1;
    }

  n_free(right);

  HFS_RECKEYLEN(record) = 0;
  *flag = 1;

  return 0;
}
Esempio n. 21
0
File: undo.c Progetto: BPaden/garglk
void kill_undo(void)
{
  n_free(prevstate);
  prevstate = 0;

  while(movelist) {
    n_free(movelist->delta);
    n_free(movelist->stackchunk);
    LEremove(movelist);
  }
  move_index = 0;

#ifdef DEBUGGING
  n_free(automap_undoslot.z_mem);
  n_free(automap_undoslot.stackchunk);
  automap_undoslot.z_mem = NULL;
  automap_undoslot.z_memsize = 0;
  automap_undoslot.PC = 0;
  automap_undoslot.stackchunk = NULL;
  automap_undoslot.stackchunksize = 0;
  automap_undoslot.stacklength = 0;
#endif
}
Esempio n. 22
0
File: tcp.c Progetto: dancahill/nsp
/*
 * this is the function that terminates orphans
 */
void tcp_murder(nsp_state *N, obj_t *cobj)
{
#define __FN__ __FILE__ ":tcp_murder()"
	TCP_SOCKET *sock;

	n_warn(N, __FN__, "reaper is claiming another lost soul");
	if (cobj->val->type != NT_CDATA || cobj->val->d.str == NULL || strcmp(cobj->val->d.str, "sock4") != 0)
		n_error(N, NE_SYNTAX, __FN__, "expected a socket");
	sock = (TCP_SOCKET *)cobj->val->d.str;
	tcp_close(N, sock, 1);
	n_free(N, (void *)&cobj->val->d.str, sizeof(TCP_SOCKET) + 1);
	cobj->val->size = 0;
	return;
#undef __FN__
}
Esempio n. 23
0
void mysql_murder(nsp_state *N, obj_t *cobj)
{
#define __FN__ __FILE__ ":mysql_murder()"
	MYSQL_CONN *conn;

	n_warn(N, __FN__, "reaper is claiming another lost soul");
	if ((cobj->val->type != NT_CDATA) || (cobj->val->d.str == NULL) || (nc_strcmp(cobj->val->d.str, "mysql-conn") != 0))
		n_error(N, NE_SYNTAX, __FN__, "expected a mysql conn");
	conn = (MYSQL_CONN *)cobj->val->d.str;
	mysqlDisconnect(N, conn);
	n_free(N, (void *)&cobj->val->d.str, sizeof(MYSQL_CONN) + 1);
	cobj->val->size = 0;
	return;
#undef __FN__
}
Esempio n. 24
0
static void automap_remove_edge(edge *e)
{
  unsigned n, i;
  edgelist *p, *t;
  if(e == NULL)
    return;
  for(n = 0; n < 2; n++) {
    loc_node *thisdest = e->dest[n];
    if(thisdest)
      for(i = 0; i < NUM_DIRS; i++) {
	if(thisdest->outgoing[i] == e)
	  thisdest->outgoing[i] = NULL;
      }
  }
  LEsearchremove(all_edges, p, t, p->node == e, n_free(p->node));
}
Esempio n. 25
0
File: node.c Progetto: tycho/pearpc
/*
 * NAME:	node->delete()
 * DESCRIPTION:	remove a record from a node
 */
int n_delete(node *np, byte *record, int *flag)
{
  byte *rec;

  rec = HFS_NODEREC(*np, np->rnum);

  HFS_SETKEYLEN(rec, 0);
  compact(np);

  if (np->nd.ndNRecs == 0)
    {
      if (n_free(np) == -1)
	goto fail;

      HFS_SETKEYLEN(record, 0);
      *flag = 1;

      return 0;
    }

  /* see if we can join with our left sibling */

  if (np->nd.ndBLink > 0)
    {
      node left;

      if (bt_getnode(&left, np->bt, np->nd.ndBLink) == -1)
	goto fail;

      if (np->nd.ndNRecs + left.nd.ndNRecs <= HFS_MAX_NRECS &&
	  NODEUSED(*np) + 2 * np->nd.ndNRecs <= NODEFREE(left))
	return join(&left, np, record, flag);
    }

  if (np->rnum == 0)
    {
      /* special case: first record changed; update parent record key */

      n_index(np, record, 0);
      *flag = 1;
    }

  return bt_putnode(np);

fail:
  return -1;
}
Esempio n. 26
0
strid_t startup_open(const char *name)
{
  strid_t str;
  char *s;

  str = glkunix_stream_open_pathname((char *) name, fileusage_Data | fileusage_BinaryMode, 0);
  if(str) {
    set_game_filename(name);
#ifdef USE_GARGLK_FEATURES
    s = strrchr(name, '\\');
    if (!s) s = strrchr(name, '/');
    garglk_set_story_name(s ? s + 1 : name);
#endif
  } else {
    char *path = search_path;
    if(path) {
      char *p;
      char *newname = (char *) n_malloc(strlen(path) + strlen(name) + 2);
      path = n_strdup(path);
      for(p = n_strtok(path, ":"); p; p = n_strtok(NULL, ":")) {
	n_strcpy(newname, p);
	n_strcat(newname, "/");
	n_strcat(newname, name);
	str = glkunix_stream_open_pathname((char *) newname, fileusage_Data |
					   fileusage_BinaryMode, 0);
	if(str) {
	  set_game_filename(newname);
#ifdef USE_GARGLK_FEATURES
	  s = strrchr(newname, '\\');
	  if (!s) s = strrchr(newname, '/');
	  garglk_set_story_name(s ? s + 1 : newname);
#endif
	  break;
        }
      }
      n_free(path);
    }
  }

  if(!str)
    fprintf(stderr, "Cannot open '%s'\n", name);

  return str;
}
Esempio n. 27
0
void SoundManager::set_channels(unsigned int count) {
	count = Mix_AllocateChannels(count);
	if (!SoundManager::_initialized) {
		SoundManager::initialize();
		channels = UniqueArray<Channel>(count);
		free_channels = SizedStack<int>(count);
		for (int i = count - 1; i >= 0; --i) {
			free_channels.push(i);
		}
	} else {
		UniqueArray<Channel> n_channels(count);
		std::memcpy(n_channels.begin(), channels.end(), min(n_channels.size(), channels.size()));
		channels = std::move(n_channels);
		SizedStack<int> n_free(count);
		std::memcpy(n_free.begin(), free_channels.begin(), min(free_channels.count(), n_free.size()));
		for (int i = count - 1; i >= (int)free_channels.size(); --i) {
			n_free.push(i);
		}
		free_channels = std::move(n_free);
	}
}
Esempio n. 28
0
NTypeRegistry*
n_type_registry_new(NError* error) {
	NTypeRegistry* self = n_alloc_unmanaged(sizeof(NTypeRegistry));

	n_error_clear(error);
	if (self == NULL) {
		n_error_set(error, N_E_BAD_ALLOCATION);
		n_error_set_msg(error, "self");
		return NULL;
	}

	n_type_array_init(&self->types, 64);

	if (n_type_array_elements(&self->types) == NULL) {
		n_free(self);
		n_error_set(error, N_E_BAD_ALLOCATION);
		n_error_set_msg(error, "types");
		return NULL;
	}

	return self;
}
Esempio n. 29
0
strid_t intd_filehandle_open(strid_t savefile, glui32 operating_id,
                             glui32 contents_id, glui32 interp_id,
                             glui32 length)
{
  char *name;
  strid_t str;
  if(operating_id != 0x554e4958 /* 'UNIX' */)
    return 0;
  if(contents_id != 0)
    return 0;
  if(interp_id != 0x20202020 /* '    ' */)
    return 0;

  name = (char *) n_malloc(length+1);
  glk_get_buffer_stream(savefile, name, length);
  name[length] = 0;
  str = glkunix_stream_open_pathname(name, fileusage_Data |
				     fileusage_BinaryMode, 0);
  if(str)
    set_game_filename(name);
  n_free(name);
  return str;
}
Esempio n. 30
0
void capreq_free(struct capreq *cr) 
{
    if ((cr->cr_relflags & __NAALLOC) == 0)
        n_free(cr);
}