示例#1
0
文件: user.c 项目: kstephens/tredmill
/**
 * API: Reallocate a node of a given size.
 *
 * May return the same pointer, a different pointer or 0.
 *
 * - Begin timing stats,
 * - Clear some stack words,
 * - Remember current stack pointer,
 * - Save the registers and stack pointers, 
 * - Call "inner" routines,
 * - End timing stats.
 */
void *tm_realloc(void *oldptr, size_t size)
{
  void *ptr = 0;

  if ( oldptr == 0 )
    return tm_alloc(size);

  if ( size == 0 ) {
    tm_free(oldptr);
    return 0;
  }

#if tm_TIME_STAT
  tm_time_stat_begin(&tm.ts_alloc);
#endif

  _tm_clear_some_stack_words();
  _tm_set_stack_ptr(&ptr);
  ptr = _tm_realloc_inner(oldptr, size);

#if tm_TIME_STAT
  tm_time_stat_end(&tm.ts_alloc);
#endif

  return ptr;
}
示例#2
0
tm_obj stream_new(FILE* fp){
	tm_stream* st = tm_alloc(sizeof(tm_stream));
	st->fp = fp;
	st->name = obj_none;
	tm_obj o;
	o.type = TM_STREAM;
	o.value.stream = st;
	return gc_track(o);
}