コード例 #1
0
ファイル: xdlrc.c プロジェクト: EgoIncarnate/antares
char *xdlrc_get_token(struct xdlrc_tokenizer *t)
{
	char *end;
	char *ret;
	
	if(t->start == NULL) {
		if(!xdlrc_newline(t)) return NULL;
	}
	while(1) {
		while(isspace(*t->start))
			t->start++;
		if(!xdlrc_is_eol(*t->start))
			break;
		if(!xdlrc_newline(t)) return NULL;
	}
	if((*t->start == '(') || (*t->start == ')')) {
		ret = alloc_size(2);
		ret[0] = *t->start;
		ret[1] = 0;
		t->start++;
	} else {
		end = t->start;
		while(!isspace(*end) && !xdlrc_is_eol(*end) && (*end != '(') && (*end != ')'))
			end++;
		ret = alloc_size(end-t->start+1);
		memcpy(ret, t->start, end-t->start);
		ret[end-t->start] = 0;
		t->start = end;
	}
	return ret;
}
コード例 #2
0
ファイル: resmgr.c プロジェクト: EgoIncarnate/antares
static void alloc_csr(struct resmgr_control_set_resources *csr)
{
	int i;
	
	csr->slicex = alloc_size(RESMGR_SLICE_STATE_COUNT*sizeof(struct rtree_node *));
	for(i=0;i<RESMGR_SLICE_STATE_COUNT;i++)
		csr->slicex[i] = rtree_new_root();
	csr->slicel = alloc_size(RESMGR_SLICE_STATE_COUNT*sizeof(struct rtree_node *));
	for(i=0;i<RESMGR_SLICE_STATE_COUNT;i++)
		csr->slicel[i] = rtree_new_root();
	csr->slicem = alloc_size(RESMGR_SLICE_STATE_COUNT*sizeof(struct rtree_node *));
	for(i=0;i<RESMGR_SLICE_STATE_COUNT;i++)
		csr->slicem[i] = rtree_new_root();
}
コード例 #3
0
ファイル: resmgr.c プロジェクト: EgoIncarnate/antares
struct resmgr *resmgr_new(struct anetlist *a, struct db *db)
{
	struct resmgr *r;
	int i;
	
	r = alloc_type(struct resmgr);
	
	r->a = a;
	r->db = db;
	r->prng = alloc_type0(mt_state);
	mts_seed32(r->prng, 0);
	
	r->n_control_sets = 0;
	r->control_sets = NULL;
	populate_control_sets(r, a);
	printf("Number of unique control sets:\t%d\n", r->n_control_sets);
	
	alloc_csr(&r->slices);
	r->slices_cs = alloc_size(r->n_control_sets*sizeof(struct resmgr_control_set_resources *));
	for(i=0;i<r->n_control_sets;i++)
		alloc_csr(&r->slices_cs[i]);
	r->free_iobm = rtree_new_root();
	r->free_iobs = rtree_new_root();
	r->used_resources = rtree_new_root();
	populate_resources(r);
	printf("Available SLICEXs:\t\t%d\n", r->slices.slicex[0]->count);
	printf("Available SLICELs:\t\t%d\n", r->slices.slicel[0]->count);
	printf("Available SLICEMs:\t\t%d\n", r->slices.slicem[0]->count);
	printf("Available IOBMs:\t\t%d\n", r->free_iobm->count);
	printf("Available IOBSs:\t\t%d\n", r->free_iobs->count);
	
	return r;
}
コード例 #4
0
ファイル: flow_bc.c プロジェクト: hnil/opm-core
/* ---------------------------------------------------------------------- */
static int
expand_tables(size_t                         nbc,
              size_t                         nf ,
              struct FlowBoundaryConditions *fbc)
/* ---------------------------------------------------------------------- */
{
    int     ok_cond, ok_face;
    size_t  alloc_sz;
    void   *p1, *p2, *p3, *p4;

    ok_cond = nbc <= fbc->cond_cpty;
    ok_face = nf  <= fbc->face_cpty;

    if (! ok_cond) {
        alloc_sz = alloc_size(nbc, fbc->cond_cpty);

        p1 = realloc(fbc->type    , (alloc_sz + 0) * sizeof *fbc->type    );
        p2 = realloc(fbc->value   , (alloc_sz + 0) * sizeof *fbc->value   );
        p3 = realloc(fbc->cond_pos, (alloc_sz + 1) * sizeof *fbc->cond_pos);

        ok_cond = (p1 != NULL) && (p2 != NULL) && (p3 != NULL);

        if (p1 != NULL) { fbc->type     = p1; }
        if (p2 != NULL) { fbc->value    = p2; }
        if (p3 != NULL) { fbc->cond_pos = p3; }

        if (ok_cond) {
            fbc->cond_cpty = alloc_sz;
        }
    }

    if (! ok_face) {
        alloc_sz = alloc_size(nf, fbc->face_cpty);

        p4 = realloc(fbc->face, alloc_sz * sizeof *fbc->face);

        ok_face = p4 != NULL;

        if (ok_face) {
            fbc->face      = p4;
            fbc->face_cpty = alloc_sz;
        }
    }

    return ok_cond && ok_face;
}
コード例 #5
0
ファイル: wrapped-inl.hpp プロジェクト: kawatab/keves
WrappedKev* WrappedKev::make(ZONE* zone, KevesValue form, KevesValue local_vars,
			     KevesValue free_vars, KevesValue global_vars) {
  auto ctor = [form, local_vars, free_vars, global_vars](void *ptr) {
    return new(ptr) WrappedKev(form, local_vars, free_vars, global_vars);
  };

  return zone->make(ctor, alloc_size(nullptr));
}
コード例 #6
0
ファイル: structure.c プロジェクト: EgoIncarnate/llhdl
static struct llhdl_node *alloc_base_node(int payload_size, int type)
{
	struct llhdl_node *n;

	n = alloc_size(sizeof(int)+sizeof(void *)+payload_size);
	n->type = type;
	n->user = NULL;
	return n;
}
コード例 #7
0
ファイル: verilog.c プロジェクト: EgoIncarnate/llhdl
static struct verilog_statement *alloc_base_statement(int extra, int type)
{
	struct verilog_statement *s;
	
	s = alloc_size(sizeof(int)+sizeof(void *)+extra);
	s->type = type;
	s->next = NULL;
	return s;
}
コード例 #8
0
ファイル: tmisc.cpp プロジェクト: nianhuaxpj/ipmsg
void vfree(void *d)
{
	if (!d) return;

	size_t	size = valloc_size(d);

	if (size == -1) {
		Debug("vfree non vfree (%x)\n", d);
		free(d);
		return;
	}
	Debug(" vfree %x %d %d\n", valloc_base(d), alloc_size(size), size);

#ifdef NON_FREE
	VirtualFree(valloc_base(d), alloc_size(size), MEM_DECOMMIT);
#else
	VirtualFree(valloc_base(d), 0, MEM_RELEASE);
#endif
}
コード例 #9
0
ファイル: verilog.c プロジェクト: EgoIncarnate/llhdl
struct verilog_node *verilog_new_op_node(int type)
{
	struct verilog_node *n;
	int arity;
	int i;

	arity = verilog_get_node_arity(type);
	n = alloc_size(sizeof(int)+arity*sizeof(void *));
	n->type = type;
	for(i=0;i<arity;i++)
		n->branches[i] = NULL;
	return n;
}
コード例 #10
0
ファイル: tmisc.cpp プロジェクト: nianhuaxpj/ipmsg
void *valloc(size_t size)
{
	size_t	s = alloc_size(size);
	void	*d = VirtualAlloc(0, s, MEM_RESERVE, PAGE_NOACCESS);

	if (!d || !VirtualAlloc(d, s - PAGE_SIZE, MEM_COMMIT, PAGE_READWRITE)) {
		Debug("valloc error(%x %d %d)\n", d, s, size);
		return NULL;
	}

	((DWORD *)d)[0]  = VALLOC_SIG;
	((size_t *)d)[1] = size;

	Debug("valloc (%x %d %d)\n", d, s, size);

	return (void *)((u_char *)d + s - PAGE_SIZE - align_size(size, ALLOC_ALIGN));
}
コード例 #11
0
ファイル: mbuddy.c プロジェクト: chixq/snippets
void
bar(int depth)
{
  int index = rand() % MAX_SLOT;

  printf("bar(%d)\n", depth);

  ptrs[index] = realloc(ptrs[index], alloc_size());

  if (depth < MAX_DEPTH && rand() % 2) {
    (*functions[rand() % MAX_FUNC])(depth + 1);
  }

  if (rand() % 2) { /* 3/4 ratio, free the resource */
    free(ptrs[index]);
    ptrs[index] = 0;
  }
}
コード例 #12
0
ファイル: asestrbuf.cpp プロジェクト: ahiguti/ase
void
ase_string_buffer::reset(size_type initial_alloc_size)
{
  const size_t len = (initial_alloc_size > alloc_size_min)
    ? initial_alloc_size : alloc_size_min;
  if (len != alloc_size()) {
    value_type *p = static_cast<value_type *>(
      X_MALLOC(len * sizeof(value_type)));
    if (!p) {
      throw std::bad_alloc();
    }
    X_FREE(bufalloc);
    bufalloc = p;
    bufalloc_end = bufalloc + len;
  }
  buf_end = bufalloc;
  assert_valid();
}
コード例 #13
0
ファイル: mbuddy.c プロジェクト: chixq/snippets
void
car(int depth)
{
  int index = rand() % MAX_SLOT;

  printf("car(%d)\n", depth);

  if (rand() % 5 == 0)
    dir = !dir;

  if (dir) {
    int amount = alloc_size();
    printf("car(%d) -- resizing ptrs[%d] to %d\n", depth, index, amount);
    ptrs[index] = realloc(ptrs[index], amount);
  }
  else {
    printf("car(%d) -- freeing ptrs[%d]\n", depth, index);
    free(ptrs[index]);
    ptrs[index] = 0;
  }
}
コード例 #14
0
ファイル: mbuddy.c プロジェクト: chixq/snippets
void
foo(int depth)
{
  int index = rand() % MAX_SLOT;

  printf("foo(%d)\n", depth);

  if (ptrs[index]) {
    free(ptrs[index]);
    ptrs[index] = 0;
  }

  ptrs[index] = malloc(alloc_size());

  if (depth < MAX_DEPTH && rand() % 2) {
    (*functions[rand() % MAX_FUNC])(depth + 1);
  }

  if (rand() % 4 == 0) { /* 3/4 ratio, free the resource */
    free(ptrs[index]);
    ptrs[index] = 0;
  }
}
コード例 #15
0
ファイル: verilog.c プロジェクト: EgoIncarnate/llhdl
struct verilog_signal *verilog_new_update_signal(struct verilog_module *m, int type, const char *name, int vectorsize, int sign)
{
	struct verilog_signal *s;
	int len;

	s = verilog_find_signal(m, name);
	if(s != NULL) {
		s->type = type;
		if(s->vectorsize != vectorsize) return NULL;
		if(s->sign != sign) return NULL;
		return s;
	}
	len = strlen(name)+1;
	s = alloc_size(sizeof(struct verilog_signal)+len);
	s->type = type;
	s->vectorsize = vectorsize;
	s->sign = sign;
	s->next = m->shead;
	s->llhdl_signal = NULL;
	memcpy(s->name, name, len);
	m->shead = s;
	return s;
}
コード例 #16
0
ファイル: resmgr.c プロジェクト: EgoIncarnate/antares
static void populate_resources(struct resmgr *r)
{
	int i, j;
	struct tile *tile;
	struct tile_type *tile_type;
	char *site_name;
	int site_index;
	
	for(i=0;i<r->db->chip.w*r->db->chip.h;i++) {
		tile = &r->db->chip.tiles[i];
		tile_type = &r->db->tile_types[tile->type];
		tile->user = alloc_size(tile_type->n_sites*sizeof(struct resmgr_site *));
		for(j=0;j<tile_type->n_sites;j++) {
			site_name = r->db->site_types[tile_type->sites[j]].name;
			site_index = resmgr_get_site_index(site_name);
			switch(site_index) {
				case RESMGR_SITE_SLICEX:
					add_site(r, r->slices.slicex[0], i, j, RESMGR_BEL_COUNT_SLICEX);
					break;
				case RESMGR_SITE_SLICEL:
					add_site(r, r->slices.slicel[0], i, j, RESMGR_BEL_COUNT_SLICELM);
					break;
				case RESMGR_SITE_SLICEM:
					add_site(r, r->slices.slicem[0], i, j, RESMGR_BEL_COUNT_SLICELM);
					break;
				case RESMGR_SITE_IOBM:
					add_site(r, r->free_iobm, i, j, 1);
					break;
				case RESMGR_SITE_IOBS:
					add_site(r, r->free_iobs, i, j, 1);
					break;
				default:
					break;
			}
		}
	}
}
コード例 #17
0
/* { dg-do compile } */
/* { dg-options "-O2 -Wall" } */

extern void abort (void);

#include "../gcc.c-torture/execute/builtins/chk.h"

extern char *mallocminus1(int size) __attribute__((alloc_size(-1))); /* { dg-warning "parameter outside range" } */
extern char *malloc0(int size) __attribute__((alloc_size(0))); /* { dg-warning "parameter outside range" } */
extern char *malloc1(int size) __attribute__((alloc_size(1)));
extern char *malloc2(int empty, int size) __attribute__((alloc_size(2)));
extern char *calloc1(int size, int elements) __attribute__((alloc_size(1,2)));
extern char *calloc2(int size, int empty, int elements) __attribute__((alloc_size(1,3)));
extern char *balloc1(void *size) __attribute__((alloc_size(1)));

void
test (void)
{
  char *p;

  p = malloc0 (6);
  strcpy (p, "Hello");
  p = malloc1 (6);
  strcpy (p, "Hello");
  strcpy (p, "Hello World"); /* { dg-warning "will always overflow" "strcpy" } */
  p = malloc2 (__INT_MAX__ >= 1700000 ? 424242 : __INT_MAX__ / 4, 6);
  strcpy (p, "World");
  strcpy (p, "Hello World"); /* { dg-warning "will always overflow" "strcpy" } */
  p = calloc1 (2, 5);
  strcpy (p, "World");
  strcpy (p, "Hello World"); /* { dg-warning "will always overflow" "strcpy" } */
コード例 #18
0
ファイル: wells.c プロジェクト: GitPaean/opm-core
/* ---------------------------------------------------------------------- */
int
add_well(enum WellType  type     ,
         double         depth_ref,
         int            nperf    ,
         const double  *comp_frac, /* Injection fraction or NULL */
         const int     *cells    ,
         const double  *WI       , /* Well index per perf (or NULL) */
         const char    *name     , /* Well name (or NULL) */
         struct Wells  *W        )
/* ---------------------------------------------------------------------- */
{
    int ok, nw, np, nperf_tot, off;
    int nwalloc, nperfalloc;

    struct WellMgmt *m;

    assert (W != NULL);

    nw        = W->number_of_wells;
    nperf_tot = W->well_connpos[nw];

    m = W->data;

    ok = (nw < m->well_cpty) && (nperf_tot + nperf <= m->perf_cpty);

    if (! ok) {
        nwalloc    = alloc_size(nw       , 1    , m->well_cpty);
        nperfalloc = alloc_size(nperf_tot, nperf, m->perf_cpty);

        ok = wells_reserve(nwalloc, nperfalloc, W);
    }

    off = W->well_connpos[nw];

    if (ok && (nperf > 0)) {
        assert (cells != NULL);

        memcpy(W->well_cells + off,
               cells, nperf * sizeof *W->well_cells);

        if (WI != NULL) {
            memcpy(W->WI + off, WI, nperf * sizeof *W->WI);
        }
    }

    if (ok) {
        W->type     [nw] = type     ;
        W->depth_ref[nw] = depth_ref;

        if (name != NULL) {
             /* May return NULL, but that's fine for the current
              * purpose. */
            W->name [nw] = dup_string(name);
        }

        np = W->number_of_phases;
        if (comp_frac != NULL) {
            memcpy(W->comp_frac + np*nw, comp_frac, np * sizeof *W->comp_frac);
        }

        W->well_connpos[nw + 1]  = off + nperf;
        W->number_of_wells      += 1;
    }

    return ok;
}
コード例 #19
0
ファイル: pcialloc.c プロジェクト: JoeAltmaier/Odyssey
int
pci_allocate()
{
	int i, j;
	int nic_size, rac_size, ssd_size;
	node_t *node;
	int	p, q, r, s;
	node_t	*pnode, *qnode, *rnode, *snode;

	nodebuf_index = 0;
	create_onboard_nodes();
	create_pci_nodes(NODE_BRIDGE_A);
	create_pci_nodes(NODE_BRIDGE_B);
	create_pci_nodes(NODE_BRIDGE_C);
	create_pci_nodes(NODE_BRIDGE_D);
	
	for(i=0; i < treenode->node_count; i++) {
		treenode->nic_count	+= treenode->orgnodes[i]->nic_count;
		treenode->rac_count	+= treenode->orgnodes[i]->rac_count;
		treenode->ssd_count	+= treenode->orgnodes[i]->ssd_count;
	}
#ifndef	PCI_STATIC
	if(alloc_size(treenode, &nic_size, &rac_size, &ssd_size))
		printf("Allocate Successful, NIC : %dMB, RAC : %dMB, SSD : %dMB\n\r", 
				nic_size * 64, rac_size * 64, ssd_size * 64);
	else
		printf("Allocate not Successful\n\r");
#else
	alloc_size(treenode, &nic_size, &rac_size, &ssd_size);
#endif

	for(i=0; i < treenode->node_count; i++) {
		node = treenode->orgnodes[i];
		for(j=0; j < node->node_count; j++) {
			if ( node->orgnodes[j]->node_type == NODE_NIC) {
				node->orgnodes[j]->mem_size = nic_size;
			}
			if ( node->orgnodes[j]->node_type == NODE_RAC) {
				node->orgnodes[j]->mem_size = rac_size;
			}
			if ( node->orgnodes[j]->node_type == NODE_SSD) {
				node->orgnodes[j]->mem_size = ssd_size;
			}
		}
	}
	
	/* Try diff permutations and see bounday condition fits */
	for(i=0; i < pcount[treenode->node_count]; i++) {
		perm(treenode->orgnodes, treenode->permnodes, treenode->node_count, i);
		pnode = get_nonleaf(treenode, 0);
		for(p=0; p < pcount[pnode->node_count]; p++) {
			perm(pnode->orgnodes, pnode->permnodes, pnode->node_count, p);
			qnode = get_nonleaf(treenode, 1);
			for(q=0; q < pcount[qnode->node_count]; q++) {
				perm(qnode->orgnodes, qnode->permnodes, qnode->node_count, q);
				rnode = get_nonleaf(treenode, 2);
				for(r=0; r < pcount[rnode->node_count]; r++) {
					perm(rnode->orgnodes,rnode->permnodes,rnode->node_count, r);
					snode = get_nonleaf(treenode, 3);
					for(s=0; s < pcount[snode->node_count]; s++) {
						perm(snode->orgnodes,snode->permnodes,
												snode->node_count, s);
						tcount++;
						mstart = 0;
						assign_bounds(treenode);
						if ( mstart  <= 32) {
							return(1);
								
						}

					}
				}
			}
		}
	}
	return(0);
}
コード例 #20
0
ファイル: alloc-size.c プロジェクト: JaredCJR/clang
// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm %s -o - 2>&1 | FileCheck %s

#define NULL ((void *)0)

int gi;

typedef unsigned long size_t;

// CHECK-DAG-RE: define void @my_malloc({{.*}}) #[[MALLOC_ATTR_NUMBER:[0-9]+]]
// N.B. LLVM's allocsize arguments are base-0, whereas ours are base-1 (for
// compat with GCC)
// CHECK-DAG-RE: attributes #[[MALLOC_ATTR_NUMBER]] = {.*allocsize(0).*}
void *my_malloc(size_t) __attribute__((alloc_size(1)));

// CHECK-DAG-RE: define void @my_calloc({{.*}}) #[[CALLOC_ATTR_NUMBER:[0-9]+]]
// CHECK-DAG-RE: attributes #[[CALLOC_ATTR_NUMBER]] = {.*allocsize(0, 1).*}
void *my_calloc(size_t, size_t) __attribute__((alloc_size(1, 2)));

// CHECK-LABEL: @test1
void test1() {
  void *const vp = my_malloc(100);
  // CHECK: store i32 100
  gi = __builtin_object_size(vp, 0);
  // CHECK: store i32 100
  gi = __builtin_object_size(vp, 1);
  // CHECK: store i32 100
  gi = __builtin_object_size(vp, 2);
  // CHECK: store i32 100
  gi = __builtin_object_size(vp, 3);

  void *const arr = my_calloc(100, 5);
コード例 #21
0
ファイル: alloc_size.c プロジェクト: Chxnew/minix
// RUN: %clang_cc1 -fsyntax-only -verify %s

void* my_malloc(unsigned char) __attribute__((alloc_size(1)));
void* my_calloc(unsigned char, short) __attribute__((alloc_size(1,2)));
void* my_realloc(void*, unsigned) __attribute__((alloc_size(2)));


void* fn1(int) __attribute__((alloc_size("xpto"))); // expected-error{{'alloc_size' attribute requires parameter 1 to be an integer constant}}

void* fn2(void*) __attribute__((alloc_size(1))); // expected-error{{'alloc_size' attribute requires an integer constant}}

void* fn3(unsigned) __attribute__((alloc_size(0))); // expected-error{{attribute parameter 1 is out of bounds}}
void* fn4(unsigned) __attribute__((alloc_size(2))); // expected-error{{attribute parameter 1 is out of bounds}}

void fn5(unsigned) __attribute__((alloc_size(1))); // expected-warning{{only applies to functions that return a pointer}}
char fn6(unsigned) __attribute__((alloc_size(1))); // expected-warning{{only applies to functions that return a pointer}}

void* fn7(unsigned) __attribute__((alloc_size)); // expected-error {{attribute takes at least 1 argument}}

void *fn8(int, int) __attribute__((alloc_size(1, 1))); // OK

void* fn9(unsigned) __attribute__((alloc_size(12345678901234567890123))); // expected-error {{integer constant is larger than the largest unsigned integer type}} // expected-error {{attribute parameter 1 is out of bounds}}

void* fn10(size_t, size_t) __attribute__((alloc_size(1,2))); // expected-error{{redefinition of parameter}} \
                                                             // expected-error{{a parameter list without types is only allowed in a function definition}} \
                                                             // expected-error{{attribute parameter 1 is out of bounds}}
void* fn11() __attribute__((alloc_size(1))); // expected-error{{attribute parameter 1 is out of bounds}}
コード例 #22
0
ファイル: ast-dump-attr.cpp プロジェクト: AndroidMarv/clang
void TestBool(void *, int)
__attribute__((pointer_with_type_tag(bool1,1,2)));
// CHECK: FunctionDecl{{.*}}TestBool
// CHECK:   ArgumentWithTypeTagAttr{{.*}} IsPointer

void TestUnsigned(void *, int)
__attribute__((pointer_with_type_tag(unsigned1,1,2)));
// CHECK: FunctionDecl{{.*}}TestUnsigned
// CHECK:   ArgumentWithTypeTagAttr{{.*}} 0 1

void TestInt(void) __attribute__((constructor(123)));
// CHECK:      FunctionDecl{{.*}}TestInt
// CHECK-NEXT:   ConstructorAttr{{.*}} 123

int TestString __attribute__((alias("alias1")));
// CHECK:      VarDecl{{.*}}TestString
// CHECK-NEXT:   AliasAttr{{.*}} "alias1"

extern struct s1 TestType
__attribute__((type_tag_for_datatype(ident1,int)));
// CHECK:      VarDecl{{.*}}TestType
// CHECK-NEXT:   TypeTagForDatatypeAttr{{.*}} int

void *TestVariadicUnsigned1(int) __attribute__((alloc_size(1)));
// CHECK: FunctionDecl{{.*}}TestVariadicUnsigned1
// CHECK:   AllocSizeAttr{{.*}} 0

void *TestVariadicUnsigned2(int, int) __attribute__((alloc_size(1,2)));
// CHECK: FunctionDecl{{.*}}TestVariadicUnsigned2
// CHECK:   AllocSizeAttr{{.*}} 0 1