Beispiel #1
0
void ParamPaths_init(void) {
  register int i0, i1;
  _mid = _register_module(&ParamPaths_md.md, &ParamPaths__NewFilesDesc_td.td);
  {
    char *_mem, *_var;
    _mem = GC_malloc(_not_zero(20)+8);
    if (!_mem) _new_failed(_P(18198));
    _var = _mem+8;
    ((_Type*)_var)[-1] = &ParamPaths__PathsSectionDesc_td.td;
    i0 = (int)_var;
  }
  ParamPaths__paths = (void*)i0;
  i1 = (int)ParamPaths__paths;
  i0 = i1 + 16;
  *(unsigned char*)i0 = 0;
  i1 = (int)ParamPaths__paths;
  i0 = i1 + 12;
  *(void**)i0 = (void*)0;
  {
    char *_mem, *_var;
    _mem = GC_malloc(_not_zero(20)+8);
    if (!_mem) _new_failed(_P(18272));
    _var = _mem+8;
    ((_Type*)_var)[-1] = &ParamPaths__NewFilesDesc_td.td;
    i0 = (int)_var;
  }
  ParamPaths__newFiles = (void*)i0;
  i0 = (int)ParamPaths__paths;
  i1 = i0 + 16;
  *(unsigned char*)i1 = 0;
  i0 = (int)ParamPaths__newFiles;
  i1 = i0 + 12;
  *(void**)i1 = (void*)0;
}
Beispiel #2
0
lstrvec* 
lstrvec_alloc(int size)
{
    lstrvec* vec = GC_malloc(sizeof(lstrvec));
    vec->size = size;
    if (size != 0)
        vec->xs   = GC_malloc(size * sizeof(char*));
    return vec;
}
Beispiel #3
0
static int
regmatch_sub_anytime(struct MatchingContext2 *c, Regex *regex,
		     regexchar * pat2,
		     char *str, char *end_p, int iter_limit, int firstp)
{
    switch (c->label) {
    case 1:
	goto label1;
    case 2:
	goto label2;
    case 3:
	goto label3;
    }
    c->ctx = GC_malloc(sizeof(struct MatchingContext1));
    c->ctx2 = GC_malloc(sizeof(struct MatchingContext2));
    c->ctx->label = 0;
    c->regex = regex;
    c->n_any = 0;
    c->str = str;
    c->firstp = firstp;
    for (;;) {
	c->ctx->label = 0;
	while (regmatch_iter(c->ctx, c->regex->re, c->str, end_p, c->firstp)) {
	    c->n_any = c->ctx->lastpos - c->str;
	    if (c->n_any <= 0)
		continue;
	    c->firstp = 0;
	    if (RE_MODE(pat2) == RE_ENDMARK) {
		c->lastpos = c->str + c->n_any;
		YIELD(1, c, 1);
	    }
	    else if (regmatch(pat2, c->str + c->n_any, end_p,
			      c->firstp, &c->lastpos) == 1) {
		YIELD(1, c, 2);
	    }
	    if (iter_limit == 1)
		continue;
	    c->ctx2->label = 0;
	    while (regmatch_sub_anytime(c->ctx2, regex, pat2,
					c->str + c->n_any, end_p,
					iter_limit - 1, c->firstp)) {

		c->lastpos = c->ctx2->lastpos;
		YIELD(1, c, 3);
	    }
	}
	if (c->regex->alt_regex == NULL)
	    break;
	c->regex = c->regex->alt_regex;
    }
    return 0;
}
Beispiel #4
0
TreeNode*
alloc_tree_node(int type)
{
    TreeNode* tn = GC_malloc(sizeof(TreeNode));
    tn->type = type;
    return tn;
}
Beispiel #5
0
Datei: gc.c Projekt: GJDuck/SMCHR
/*
 * GC strdup()
 */
extern char *GC_strdup(const char *str)
{
    size_t len = strlen(str);
    char *copy = (char *)GC_malloc(len+1);
    strcpy(copy, str);
    return copy;
}
Beispiel #6
0
static struct stack_block *mem_block_alloc(size_t min_size)
{
	struct stack_block *block;
	size_t prev_size, alloc_size;

	prev_size = current_block == NULL ? 0 : current_block->size;
	alloc_size = nearest_power(prev_size + min_size);

#ifndef USE_GC
	block = malloc(SIZEOF_MEMBLOCK + alloc_size);
#else
	block = GC_malloc(SIZEOF_MEMBLOCK + alloc_size);
#endif
	if (unlikely(block == NULL)) {
		if (outofmem) {
			if (min_size > outofmem_area.block.left)
				abort();
			return &outofmem_area.block;
		}
		outofmem = TRUE;
		i_panic("data stack: Out of memory when allocating %"
			PRIuSIZE_T" bytes", alloc_size + SIZEOF_MEMBLOCK);
	}
	block->size = alloc_size;
	block->left = 0;
	block->lowwater = block->size;
	block->next = NULL;

#ifdef DEBUG
	memset(STACK_BLOCK_DATA(block), CLEAR_CHR, alloc_size);
#endif
	return block;
}
Beispiel #7
0
static void *pool_system_malloc(pool_t pool ATTR_UNUSED, size_t size)
{
	void *mem;
#ifdef DEBUG
	int old_errno = errno;
#endif

	if (unlikely(size == 0 || size > SSIZE_T_MAX))
		i_panic("Trying to allocate %"PRIuSIZE_T" bytes", size);

#ifndef USE_GC
	mem = calloc(size, 1);
#else
	mem = GC_malloc(size);
#endif
	if (unlikely(mem == NULL)) {
		i_fatal_status(FATAL_OUTOFMEM, "pool_system_malloc(%"PRIuSIZE_T
			       "): Out of memory", size);
	}
#ifdef DEBUG
	/* we rely on errno not changing. it shouldn't. */
	i_assert(errno == old_errno);
#endif
	return mem;
}
Beispiel #8
0
static value_t*
alloc_value (ptable_t *ptable, size_t size)
{
	value_t *v = GC_malloc (size);
	v->ptable = ptable;
	return v;
}
Beispiel #9
0
ParamPaths__Path ParamPaths__ParsePatterns_PathList_NewPath(unsigned char* str, int str_0d) {
  register int i0, i1, i2;
  {
    char *_mem, *_var;
    _mem = GC_malloc(_not_zero(8)+8);
    if (!_mem) _new_failed(_P(6224));
    _var = _mem+8;
    ((_Type*)_var)[-1] = &ParamPaths__PathDesc_td.td;
    i0 = (int)_var;
  }
  i2 = Strings__Length((const unsigned char*)(int)str, str_0d);
  i1 = i0 + 4;
  i2++;
  {
    char *_mem, *_var;
    int* _dim_ptr;
    if(i2 < 0) _invalid_length(i2, _P(6281));
    _mem = GC_malloc_atomic(_not_zero(i2*1)+8);
    if (!_mem) _new_failed(_P(6244));
    _var = _mem+8;
    _dim_ptr = (void*)(_var-4);
    *(--_dim_ptr) = i2;
    i2 = (int)_var;
  }
  *(void**)i1 = (void*)i2;
  i1 = (int)*(void**)i1;
  i2 = *(int*)(i1-8);
  _string_copy(i1, (int)str, i2);
  *(void**)i0 = (void*)0;
  return (void*)i0;
}
scm *run_lisp(struct sexp a_sexp) {
  switch (a_sexp.type) {
  case LIST:;
    // Get the first element (which should be a symbol representing a function) and evaluate it
    scm *callee = run_lisp(a_sexp.list[0]);
    assert(callee->type == SCM_FN);
    
    scm *args = NULL;
    struct sexp *remaining = a_sexp.list + 1;

    while (remaining->type != END_OF_LIST) {
      args = append(args, run_lisp(*remaining));
      remaining++;
    }
    
    return callee->fn(args);
  case SYMBOL:;
    char *name = a_sexp.symbol;
    if (strcmp(name, "+") == 0) {
      return &_plus_scm;
    }
    assert(0 && "Stuff ain't implemented yet!");
    break;
  case INTEGER:;
    scm *val = GC_malloc(sizeof(scm));
    val->type = SCM_INT;
    val->integer = a_sexp.integer;

    return val;
  default:
    assert(0 && "Whoops...");
  }
}
Beispiel #11
0
ss_INLINE
void* ss_malloc(size_t s)
{
  ss_malloc_bytes += s;
  ss_malloc_objects ++;
  return GC_malloc(s);
}
Beispiel #12
0
void *api_call_method(int numargs, void *obj, void *initptr, va_list vl)
{
    ffi_cif cif;
    ffi_type *args[numargs + 1];
    void *values[numargs + 1];
    void **val_heap = (void**)GC_malloc((numargs + 1) * sizeof(void*)); /*new void*[numargs + 1];*/
    void *rv;
    args[0] = &ffi_type_pointer;
    values[0] = &val_heap[0];
    for (int i = 0; i < numargs; i++)
    {
        args[i + 1] = &ffi_type_pointer;
        values[i + 1] = (void*)&val_heap[i + 1];
    }
    int rc = ffi_prep_cif(&cif, FFI_DEFAULT_ABI, numargs + 1, &ffi_type_pointer, args);
    assert(rc == FFI_OK);
    val_heap[0] = (void*)obj;
    for (int i = 0; i < numargs; i++)
    {
        val_heap[i + 1] = va_arg(vl, void*);
    }
    ffi_call(&cif, (void(*)())initptr, &rv, values);
    va_end(vl);
    GC_free(val_heap);
    /*delete[] val_heap;*/
    return rv;
}
Beispiel #13
0
END_TEST


START_TEST(test_message_send) {
  message * msg;
  int * sock = GC_malloc(sizeof(int) * 2);
  socketpair(AF_UNIX, SOCK_STREAM, 0, sock);
  msg = message_create_echo(MESSAGE_TYPE_REQUEST, "hey");
  message_send(sock[0], msg);
  char * header_buf = GC_malloc(8);
  char * data = GC_malloc(7);
  ck_assert_int_eq(recv(sock[1], header_buf, 8, MSG_DONTWAIT), 8);
  ck_assert_int_eq(memcmp(header_buf, "\x00\x00\x00\x07\xfb\x65\x78\xa3", 8), 0);
  ck_assert_int_eq(recv(sock[1], data, 7, MSG_DONTWAIT), 7);
  ck_assert_int_eq(memcmp(data, "\x93\x00\x01\xa3hey", 7), 0);
}
sinfo_t __init_new_thread_stack
   (caps_t c, int len,void *(*f)(void *) , 
    void *targ,int arg_len) {
  len = merge_caps(c,len); // sum caps
 // it should be at least 16 or we'll be
  ssinfo_t ss = __get_stack_size(len,arg_len,stack_space);
  sinfo_t i = (sinfo_t) GC_malloc(ss.real_size);
  i->tid = _next_tid();
  i->thread = f;
  i->info = ss;
  i->h = create_hashtable(25);
  
//  fprintf(stderr,"\nthread_malloc: %p", i);

  memcpy(i+1,targ,arg_len);
  struct _XTreeHandle *r = (struct _XTreeHandle *)
                        (((char *)(i+1)) + arg_len);
  // fill-in the new tree and transfer capabilities
  __treecopy(c,r,len,i->tid,&i->h);

  // set stack guard page so as to handle, page faults.
  // Here we simply quit.
//  char *guard = (char *) ALIGN_PG(((char *) i) + ss.end_offset);

//  if(mprotect(guard,1024,1))
//    errquit("__init_new_thread: mprotect failed");
 
   //i->info.end_offset = (unsigned long long)guard -
 // 	 							   (unsigned long long)i;
  //assert(i->info.end_offset+1024 <= i->info.real_size);
  return i;
}
Beispiel #15
0
GC_PTR GC_local_malloc(size_t bytes)
{
    if (EXPECT(!SMALL_ENOUGH(bytes),0)) {
        return(GC_malloc(bytes));
    } else {
	int index = INDEX_FROM_BYTES(bytes);
	ptr_t * my_fl;
	ptr_t my_entry;
#	if defined(REDIRECT_MALLOC) && !defined(USE_PTHREAD_SPECIFIC)
	GC_key_t k = GC_thread_key;
#	endif
	void * tsd;

#	if defined(REDIRECT_MALLOC) && !defined(USE_PTHREAD_SPECIFIC)
	    if (EXPECT(0 == k, 0)) {
		/* This can happen if we get called when the world is	*/
		/* being initialized.  Whether we can actually complete	*/
		/* the initialization then is unclear.			*/
		GC_init_parallel();
		k = GC_thread_key;
	    }
#	endif
	tsd = GC_getspecific(GC_thread_key);
#	ifdef GC_ASSERTIONS
	  LOCK();
	  GC_ASSERT(tsd == (void *)GC_lookup_thread(pthread_self()));
	  UNLOCK();
#	endif
	my_fl = ((GC_thread)tsd) -> normal_freelists + index;
	my_entry = *my_fl;
	if (EXPECT((word)my_entry >= HBLKSIZE, 1)) {
	    ptr_t next = obj_link(my_entry);
	    GC_PTR result = (GC_PTR)my_entry;
	    *my_fl = next;
	    obj_link(my_entry) = 0;
	    PREFETCH_FOR_WRITE(next);
	    return result;
	} else if ((word)my_entry - 1 < DIRECT_GRANULES) {
	    *my_fl = my_entry + index + 1;
            return GC_malloc(bytes);
	} else {
	    GC_generic_malloc_many(BYTES_FROM_INDEX(index), NORMAL, my_fl);
	    if (*my_fl == 0) return GC_oom_fn(bytes);
	    return GC_local_malloc(bytes);
	}
    }
}
Beispiel #16
0
 static void* allocate(std::size_t n)
 {
     IMMER_GC_INIT_GUARD_;
     auto p = GC_malloc(n);
     if (IMMER_UNLIKELY(!p))
         throw std::bad_alloc{};
     return p;
 }
Beispiel #17
0
GEN box_DF(double a) {
  dfloat_t *val = GC_malloc(sizeof(dfloat_t));

  val->descriptor = dfloat_key;
  val->dval = a;

  return (GEN)val;
}
Beispiel #18
0
/* This makes sure that the garbage collector sees all allocations, even those
	that we can't be bothered collecting, especially standard STL objects */
void* operator new(size_t n)
{
#ifdef DONT_COLLECT_STL
  return GC_malloc_uncollectable(n);	// Don't collect, but mark
#else
  return GC_malloc(n);				// Collect everything
#endif
}
Beispiel #19
0
GEN box_SI(LONG a) {
  integer_t *val = GC_malloc(sizeof(integer_t));

  val->descriptor = integer_key;
  val->ival = a;

  return (GEN)val;
}
Beispiel #20
0
message * message_create(message_type type, message_action action) {
  message * mess = GC_malloc(sizeof(message));
  mess->type = type;
  mess->action = action;
  mess->to_msgpack = message_to_msgpack_base;

  return mess;
}
Beispiel #21
0
static ptable_t*
alloc_ptable (int type)
{
	ptable_t *ptable = GC_malloc (sizeof (ptable_t));
	ptable->type = type;
	ptable->entries = &empty_ptable_entry;
	return ptable;
}
Beispiel #22
0
void *
objc_malloc (size_t size)
{
  void *res = (void *)(GC_malloc (size));
  if (! res)
    _objc_abort ("Virtual memory exhausted\n");
  return res;
}
Beispiel #23
0
static environment_t*
alloc_env (environment_t *up, int num_bindings)
{
	environment_t *env = GC_malloc (sizeof (environment_t) + num_bindings * sizeof (value_t*));
	env->up = up;
	env->num_bindings = num_bindings;
	return env;
}
Beispiel #24
0
unsigned long int* T() {
  unsigned long int* aux;
  aux = GC_malloc(SIZE, sizeof(unsigned long int) );
  int i;
  for(i = 0; i < SIZE; i++) {
    aux[i] = Z( i );
  }
  return init( aux , 0 , (unsigned long int) 9876 );
}
Beispiel #25
0
GEN CONS(GEN fst, GEN snd) {
  cons_t *val = GC_malloc(sizeof(cons_t));

  val->descriptor = cons_key;
  val->fst = fst;
  val->snd = snd;

  return (GEN)val;
}
Beispiel #26
0
smap*
smap_alloc(int64_t size, stype* ktype, stype* vtype)
{
    smap* map = GC_malloc(sizeof(smap));
    map->size  = size;
    map->ktype = ktype;
    map->vtype = vtype;

    if (size == 0) {
        map->data = 0
    }
    else {
        int64_t item_size = ktype->size + vtype->size;
        map->data = GC_malloc(2 * item_size);
    }

    return map;
}
Beispiel #27
0
void *safe_malloc(size_t size) {
    void *result = GC_malloc(size);
    if(!result) {
        perror("malloc");
        exit(EXIT_FAILURE);
    }

    return result;
}
Beispiel #28
0
static value_t*
make_string_from_unichar (gunichar c)
{
	gchar *buf = GC_malloc (7);
	string_t *s = (string_t*) alloc_value (PTABLE_NAME (cljc_DOT_core_SLASH_String), sizeof (string_t));
	buf [g_unichar_to_utf8 (c, buf)] = '\0';
	s->utf8 = buf;
	return &s->val;
}
Beispiel #29
0
half_edge alloc_half_edge(void* v) {
  half_edge e = (half_edge) GC_malloc(sizeof(struct half_edge_cell));
  e->vertex = v;
  e->opp = NULL;
  e->next = NULL;
  e->prev = NULL;
  e->visited = 0;
  return e;
}
Beispiel #30
0
unsigned long int jsort() {
  unsigned long int* aux;
  aux = GC_malloc(SIZE, sizeof(unsigned long int) );
  int i;
  for(i = 0; i < SIZE; i++) {
    aux[i] = J( i );
  }
  return insort( aux )[0];
}