示例#1
0
/*{{{ FeriteVariable *ferite_build_object( FeriteScript *script, FeriteClass *nclass) */
FeriteVariable *ferite_build_object( FeriteScript *script, FeriteClass *nclass)
{
	FeriteVariable *ptr = NULL;

	FE_ENTER_FUNCTION;

	if( nclass != NULL )
	{
		FUD(("BUILDOBJECT: Creating an instance of %s\n", nclass->name ));
		ptr = ferite_create_object_variable( script, nclass->name, FE_ALLOC );
		if( script )
			VAO(ptr) = ferite_stack_pop( script, script->objects );
		if( VAO(ptr) == NULL ) {
			VAO(ptr) = fmalloc( sizeof( FeriteObject ) );
			FUD(( "Allocating object %p\n", VAO(ptr) ));
		}
		VAO(ptr)->name = fstrdup( nclass->name );
		VAO(ptr)->klass = nclass;
		
		FUD(("BUILDOBJECT: Creating a duplicate varaible hash\n"));
		VAO(ptr)->variables = ferite_duplicate_object_variable_list( script, nclass );
		
		FUD(("BUILDOBJECT: Linking function list up\n"));
		VAO(ptr)->functions = nclass->object_methods;
		
		VAO(ptr)->oid = nclass->id;
		VAO(ptr)->odata = NULL;
		
		VAO(ptr)->refcount = 1;

		ferite_add_to_gc( script, VAO(ptr) );
	}
	FE_LEAVE_FUNCTION( ptr );
}
示例#2
0
Expression* Expression_new(Variable* var) {
	Expression* ret = fmalloc(sizeof(*ret));
	
	ret->var = var;
	
	return ret;
}
示例#3
0
Vector* Vector_new(ArgList* vals) {
	Vector* ret = fmalloc(sizeof(*ret));
	
	ret->vals = vals;
	
	return ret;
}
示例#4
0
FeriteScript *ferite_thread_create_script( FeriteScript *script )
{
	FeriteScript *new_script = NULL;
	FeriteScript *real_parent = NULL;
 
	FE_ENTER_FUNCTION;

	real_parent = script;


	new_script = fmalloc( sizeof( FeriteScript ) );
	memcpy( new_script, real_parent, sizeof( FeriteScript ) );

	/* Create a lock for this script */
	new_script->gc_lock = aphex_mutex_recursive_create();

	/* Create new cache for this thread */
	ferite_init_cache( new_script );

	/* Create new GC for this thread */
	new_script->gc = NULL;
	new_script->gc_stack = NULL;

	/* If we are here then we have not got any errors or warnings reset! :) */
	new_script->error = NULL;
	new_script->warning = NULL;
	new_script->stack_level = 0;

	/* Hook up the parent */
	new_script->parent = real_parent;

	FE_LEAVE_FUNCTION(new_script);
}
示例#5
0
文件: fft-sdl.c 项目: kninnug/Hark
struct aBuf initABuf(int fftSize, int fftWinInc){
	struct aBuf buf;
	
	buf.length = fftSize;
	buf.fftWinInc = fftWinInc;
	buf.samplerate = 44100;
	
	buf.samples = fmalloc(buf.fftWinInc * sizeof *buf.samples);
	buf.fftIn = fmalloc(buf.length * sizeof *buf.fftIn);
	buf.fftOut = fmalloc(buf.length * sizeof *buf.fftOut);
	
	buf.mutex = PTHREAD_MUTEX_INITIALIZER;
	buf.cond = PTHREAD_COND_INITIALIZER;
	
	return buf;
}
/*
 * alloc, free pubKeyInst
 */
static pubKeyInst *pubKeyInstAlloc(void)
{
	pubKeyInst *pkinst = (pubKeyInst *) fmalloc(sizeof(pubKeyInst));

	bzero(pkinst, sizeof(pubKeyInst));
	return pkinst;
}
giant newGiant(unsigned numDigits) {
    // giant sufficient for 2^numbits+16 sized ops
    int size;
    giant result;

    #if 	WARN_ZERO_GIANT_SIZE
    if(numDigits == 0) {
        printf("newGiant(0)\n");
		#if	GIANTS_VIA_STACK
        numDigits = gstacks[numGstacks-1].totalGiants;
		#else
		/* HACK */
		numDigits = 20;
		#endif
    }
    #endif	// WARN_ZERO_GIANT_SIZE

    size = (numDigits-1) * GIANT_BYTES_PER_DIGIT + sizeof(giantstruct);
    result = (giant)fmalloc(size);
    if(result == NULL) {
    	return NULL;
    }
    result->sign = 0;
    result->capacity = numDigits;
    return result;
}
示例#8
0
文件: http.c 项目: fankux/webc
static inline void _header_item_dup(struct fmap_node *n, void *item) {
    _header_item_free(n->value);

    void *item_target = fmalloc(sizeof(struct http_header_item));
    fmemcpy(item_target, item, sizeof(struct http_header_item));
    n->value = item_target;
}
示例#9
0
/*************************************************************************
* This function sets up the graph from the user input
**************************************************************************/
void SetUpGraph2(GraphType *graph, int nvtxs, int ncon, idxtype *xadj, 
       idxtype *adjncy, float *nvwgt, idxtype *adjwgt)
{
  int i, j, sum;

  InitGraph(graph);

  graph->nvtxs = nvtxs;
  graph->nedges = xadj[nvtxs];
  graph->ncon = ncon;
  graph->xadj = xadj;
  graph->adjncy = adjncy;
  graph->adjwgt = adjwgt;

  graph->nvwgt = fmalloc(nvtxs*ncon, "SetUpGraph2: graph->nvwgt");
  scopy(nvtxs*ncon, nvwgt, graph->nvwgt);

  graph->gdata = idxmalloc(2*nvtxs, "SetUpGraph: gdata");

  /* Compute the initial values of the adjwgtsum */
  graph->adjwgtsum = graph->gdata;
  for (i=0; i<nvtxs; i++) {
    sum = 0;
    for (j=xadj[i]; j<xadj[i+1]; j++)
      sum += adjwgt[j];
    graph->adjwgtsum[i] = sum;
  }

  graph->cmap = graph->gdata+nvtxs;

  graph->label = idxmalloc(nvtxs, "SetUpGraph: label");
  for (i=0; i<nvtxs; i++)
    graph->label[i] = i;

}
示例#10
0
/*************************************************************************
* Setup the various arrays for the splitted graph
**************************************************************************/
void SetUpSplitGraph(GraphType *graph, GraphType *sgraph, int snvtxs, int snedges)
{
  InitGraph(sgraph);
  sgraph->nvtxs = snvtxs;
  sgraph->nedges = snedges;
  sgraph->ncon = graph->ncon;

  /* Allocate memory for the splitted graph */
  if (graph->ncon == 1) {
    sgraph->gdata = idxmalloc(4*snvtxs+1 + 2*snedges, "SetUpSplitGraph: gdata");

    sgraph->xadj        = sgraph->gdata;
    sgraph->vwgt        = sgraph->gdata + snvtxs+1;
    sgraph->adjwgtsum   = sgraph->gdata + 2*snvtxs+1;
    sgraph->cmap        = sgraph->gdata + 3*snvtxs+1;
    sgraph->adjncy      = sgraph->gdata + 4*snvtxs+1;
    sgraph->adjwgt      = sgraph->gdata + 4*snvtxs+1 + snedges;
  }
  else {
    sgraph->gdata = idxmalloc(3*snvtxs+1 + 2*snedges, "SetUpSplitGraph: gdata");

    sgraph->xadj        = sgraph->gdata;
    sgraph->adjwgtsum   = sgraph->gdata + snvtxs+1;
    sgraph->cmap        = sgraph->gdata + 2*snvtxs+1;
    sgraph->adjncy      = sgraph->gdata + 3*snvtxs+1;
    sgraph->adjwgt      = sgraph->gdata + 3*snvtxs+1 + snedges;

    sgraph->nvwgt       = fmalloc(graph->ncon*snvtxs, "SetUpSplitGraph: nvwgt");
  }

  sgraph->label	= idxmalloc(snvtxs, "SetUpSplitGraph: sgraph->label");
}
示例#11
0
/*****************************************************************************
*  This function computes a partitioning using coordinate data.
*****************************************************************************/
void ParMETIS_PartGeomKway(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt,
       idxtype *adjwgt, int *wgtflag, int *numflag, int *ndims, float *xyz, int *nparts,
       int *options, int *edgecut, idxtype *part, MPI_Comm *comm)
{
  int i;
  int ncon = 1;
  float *tpwgts, ubvec[MAXNCON];
  int myoptions[10];

  tpwgts = fmalloc(*nparts*ncon, "tpwgts");
  for (i=0; i<*nparts*ncon; i++)
    tpwgts[i] = 1.0/(float)(*nparts);
  for (i=0; i<ncon; i++)
    ubvec[i] = UNBALANCE_FRACTION;

  if (options[0] == 0) {
    myoptions[0] = 0;
  }
  else {
    myoptions[0] = 1;
    myoptions[PMV3_OPTION_DBGLVL] = options[OPTION_DBGLVL];
    myoptions[PMV3_OPTION_SEED] = GLOBAL_SEED;
  }

  ParMETIS_V3_PartGeomKway(vtxdist, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, ndims, xyz,
  &ncon, nparts, tpwgts, ubvec, myoptions, edgecut, part, comm);

  GKfree((void **)&tpwgts, LTERM);
  return;
}
feeReturn feeCreateECDSAPrivBlob(feePubKey pubKey,
	unsigned char **keyBlob,
	unsigned *keyBlobLen)
{
	pubKeyInst *pkinst = (pubKeyInst *)pubKey;
	if(pkinst == NULL) {
		return FR_BadPubKey;
	}
	if(pkinst->privGiant == NULL) {
		return FR_IncompatibleKey;
	}

	/* 
	 * Return the raw private key bytes padded with zeroes in
	 * the m.s. end to fill exactly one prime-size byte array.
	 */
	unsigned giantBytes = (pkinst->cp->q + 7) / 8;
	unsigned char *blob = fmalloc(giantBytes);
	if(blob == NULL) {
		return FR_Memory;
	}
	serializeGiant(pkinst->privGiant, blob, giantBytes);
	*keyBlob = blob;
	*keyBlobLen = giantBytes;
	return FR_Success;
}
示例#13
0
/*
 * Encode to/from byteRep.
 */
static void ECDSA_encode(
    feeSigFormat format,          // Signature format DER 9.62 / RAW
    unsigned groupBytesLen,
    giant c,
	giant d,
	unsigned char **sigData,		// malloc'd and RETURNED
	unsigned *sigDataLen)			// RETURNED
{
	#if	CRYPTKIT_DER_ENABLE
    if (format==FSF_RAW) {
        feeRAWEncodeECDSASignature(groupBytesLen,c, d, sigData, sigDataLen);
    } else {
        feeDEREncodeECDSASignature(c, d, sigData, sigDataLen);
    }
	#else
	*sigDataLen = lengthOfByteRepSig(c, d);
	*sigData = (unsigned char*) fmalloc(*sigDataLen);
	sigToByteRep(FEE_ECDSA_MAGIC,
		FEE_ECDSA_VERSION,
		FEE_ECDSA_VERSION_MIN,
		c,
		d,
		*sigData);
	#endif
}
示例#14
0
/*****************************************************************************
*  This function computes a repartitioning by LMSR scratch-remap.
*****************************************************************************/
void ParMETIS_RepartMLRemap(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy,
       idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *options,
       int *edgecut, idxtype *part, MPI_Comm *comm)
{
  int i;
  int nparts;
  int ncon = 1;
  float *tpwgts, ubvec[MAXNCON];
  float ipc_factor = 1000.0;
  int myoptions[10];

  MPI_Comm_size(*comm, &nparts);
  tpwgts = fmalloc(nparts*ncon, "tpwgts");
  for (i=0; i<nparts*ncon; i++)
    tpwgts[i] = 1.0/(float)(nparts);
  for (i=0; i<ncon; i++)
    ubvec[i] = UNBALANCE_FRACTION;

  if (options[0] == 0) {
    myoptions[0] = 0;
  }
  else {
    myoptions[0] = 1;
    myoptions[PMV3_OPTION_DBGLVL] = options[OPTION_DBGLVL];
    myoptions[PMV3_OPTION_SEED]   = GLOBAL_SEED;
    myoptions[PMV3_OPTION_PSR]    = PARMETIS_PSR_COUPLED;
  }

  ParMETIS_V3_AdaptiveRepart(vtxdist, xadj, adjncy, vwgt, NULL, adjwgt, wgtflag, numflag,
  &ncon, &nparts, tpwgts, ubvec, &ipc_factor, myoptions, edgecut, part, comm);

  GKfree((void **)&tpwgts, LTERM);
}
示例#15
0
VeThrMutex *veThrMutexCreate() {
  pthread_mutex_t *m;
  
  m = fmalloc(sizeof(pthread_mutex_t));
  pthread_mutex_init(m,NULL);
  return (VeThrMutex *)m;
}
示例#16
0
文件: file.cpp 项目: Kingwl/ray
FILE* fopen(const char* filename, ios_base::openmode mode) noexcept
{
#if defined(__WINDOWS__)
    int flags = O_BINARY;
#else
    int flags = 0;
#endif

    if (mode & ios_base::in && mode & ios_base::out)
        flags |= O_RDWR;
    else if (mode & ios_base::in)
        flags |= O_RDONLY;
    else if (mode & ios_base::out)
        flags |= O_WRONLY | O_CREAT | O_TRUNC;

    if (mode & ios_base::app)     flags |= O_APPEND;
    if (mode & ios_base::trunc)   flags |= O_TRUNC;

    int access = PP_DEFAULT;

#if defined(__WINDOWS__)
    access |= PP_IRUSR | PP_IWUSR;
#endif

    return fmalloc(_NAME open(filename, flags, access));
}
static sigInst *sinstAlloc()
{
	sigInst *sinst = (sigInst*) fmalloc(sizeof(sigInst));

	bzero(sinst, sizeof(sigInst));
	return sinst;
}
示例#18
0
static void mallocData(
    FeeData *fd,
    unsigned numBytes)
{
    fd->data = (unsigned char *)fmalloc(numBytes);
    fd->length = numBytes;
}
示例#19
0
文件: http.c 项目: fankux/webc
inline struct http_pack *http_pack_create() {
    struct http_pack *http;
    http = fmalloc(sizeof(struct http_pack));
    if (http == NULL) return NULL;

    memset(http, 0, sizeof(struct http_pack));
    return http;
}
FeriteAMTArray *ferite_amtarray_create( FeriteScript *script )
{
	FeriteAMTArray *array = fmalloc(sizeof(FeriteAMTArray));
	array->_array = ferite_amt_create( script, FeriteAMT_Low );
	array->_hash = ferite_amt_create( script, FeriteAMT_High );
	array->upperLimit = array->lowerLimit = (INT_MAX / 2);
	return array;
}
示例#21
0
文件: symtab.c 项目: amr-vub/TC
SYM_INFO*
symtab_info_new(char* name,T_INFO* t)
{
	SYM_INFO* i	= fmalloc(sizeof(SYM_INFO));
	i->name	= name;
	i->type	= t;
	return i;
}
示例#22
0
文件: unop.c 项目: 0xaced/SuperCalc
UnOp* UnOp_new(UNTYPE type, Value* a) {
	UnOp* ret = fmalloc(sizeof(*ret));
	
	ret->type = type;
	ret->a = a;
	
	return ret;
}
FeriteAMTArrayEntry *__ferite_amtarray_dup_array_data( FeriteScript *script, FeriteAMTArrayEntry *entry, FeriteScript *_script )
{
	FeriteAMTArrayEntry *newEntry = fmalloc(sizeof(FeriteAMTArrayEntry));
	if( entry->key )
		newEntry->key = fstrdup(entry->key);
	newEntry->variable = ferite_duplicate_variable( script, entry->variable, NULL );
	return newEntry;
}
示例#24
0
文件: symtab.c 项目: amr-vub/TC
SYM_ENTRY*  symtab_entry_new(SYM_INFO* i, short lit)
{
	SYM_ENTRY* e = fmalloc(sizeof(SYM_ENTRY));
	e->literal = lit;
	e->syminf = i;

	return e;
}
示例#25
0
文件: symtab.c 项目: amr-vub/TC
SYM_LIST*
symtab_list_insert(SYM_LIST* l,SYM_ENTRY* e)
{
	SYM_LIST* nl	= fmalloc(sizeof(SYM_LIST));
	nl->enrty	= e;
	nl->next	= l;
	return nl;
}
示例#26
0
文件: set.c 项目: 0xaced/SuperCalc
Set* Set_createConcrete(ConcreteSet* concreteSet) {
	Set* ret = fmalloc(sizeof(*ret));
	
	ret->concrete = true;
	ret->concreteSet = concreteSet;
	
	return ret;
}
示例#27
0
Placeholder* Placeholder_new(PLACETYPE type, unsigned index) {
	Placeholder* ret = fmalloc(sizeof(*ret));
	
	ret->type = type;
	ret->index = index;
	
	return ret;
}
示例#28
0
文件: ccgraph.c 项目: aceskpark/osfeo
/*************************************************************************
* Setup the various arrays for the coarse graph
**************************************************************************/
GraphType *SetUpCoarseGraph(GraphType *graph, int cnvtxs, int dovsize)
{
  GraphType *cgraph;

  cgraph = CreateGraph();
  cgraph->nvtxs = cnvtxs;
  cgraph->ncon = graph->ncon;

  cgraph->finer = graph;
  graph->coarser = cgraph;


  /* Allocate memory for the coarser graph */
  if (graph->ncon == 1) {
    if (dovsize) {
      cgraph->gdata = idxmalloc(5*cnvtxs+1 + 2*graph->nedges, "SetUpCoarseGraph: gdata");
      cgraph->xadj 		= cgraph->gdata;
      cgraph->vwgt 		= cgraph->gdata + cnvtxs+1;
      cgraph->vsize 		= cgraph->gdata + 2*cnvtxs+1;
      cgraph->adjwgtsum 	= cgraph->gdata + 3*cnvtxs+1;
      cgraph->cmap 		= cgraph->gdata + 4*cnvtxs+1;
      cgraph->adjncy 		= cgraph->gdata + 5*cnvtxs+1;
      cgraph->adjwgt 		= cgraph->gdata + 5*cnvtxs+1 + graph->nedges;
    }
    else {
      cgraph->gdata = idxmalloc(4*cnvtxs+1 + 2*graph->nedges, "SetUpCoarseGraph: gdata");
      cgraph->xadj 		= cgraph->gdata;
      cgraph->vwgt 		= cgraph->gdata + cnvtxs+1;
      cgraph->adjwgtsum 	= cgraph->gdata + 2*cnvtxs+1;
      cgraph->cmap 		= cgraph->gdata + 3*cnvtxs+1;
      cgraph->adjncy 		= cgraph->gdata + 4*cnvtxs+1;
      cgraph->adjwgt 		= cgraph->gdata + 4*cnvtxs+1 + graph->nedges;
    }
  }
  else {
    if (dovsize) {
      cgraph->gdata = idxmalloc(4*cnvtxs+1 + 2*graph->nedges, "SetUpCoarseGraph: gdata");
      cgraph->xadj 		= cgraph->gdata;
      cgraph->vsize 		= cgraph->gdata + cnvtxs+1;
      cgraph->adjwgtsum 	= cgraph->gdata + 2*cnvtxs+1;
      cgraph->cmap 		= cgraph->gdata + 3*cnvtxs+1;
      cgraph->adjncy 		= cgraph->gdata + 4*cnvtxs+1;
      cgraph->adjwgt 		= cgraph->gdata + 4*cnvtxs+1 + graph->nedges;
    }
    else {
      cgraph->gdata = idxmalloc(3*cnvtxs+1 + 2*graph->nedges, "SetUpCoarseGraph: gdata");
      cgraph->xadj 		= cgraph->gdata;
      cgraph->adjwgtsum 	= cgraph->gdata + cnvtxs+1;
      cgraph->cmap 		= cgraph->gdata + 2*cnvtxs+1;
      cgraph->adjncy 		= cgraph->gdata + 3*cnvtxs+1;
      cgraph->adjwgt 		= cgraph->gdata + 3*cnvtxs+1 + graph->nedges;
    }

    cgraph->nvwgt 	= fmalloc(graph->ncon*cnvtxs, "SetUpCoarseGraph: nvwgt");
  }

  return cgraph;
}
示例#29
0
文件: grsetup.c 项目: luyukunphy/namd
/*************************************************************************
* This function setsup the CtrlType structure
**************************************************************************/
GraphType *Moc_SetUpGraph(CtrlType *ctrl, int ncon, idxtype *vtxdist, idxtype *xadj,
                          idxtype *vwgt, idxtype *adjncy, idxtype *adjwgt, int *wgtflag)
{
    int i, j;
    GraphType *graph;
    int ltvwgts[MAXNCON];

    graph = CreateGraph();
    graph->level   = 0;
    graph->gnvtxs  = vtxdist[ctrl->npes];
    graph->nvtxs   = vtxdist[ctrl->mype+1]-vtxdist[ctrl->mype];
    graph->ncon    = ncon;
    graph->nedges  = xadj[graph->nvtxs];
    graph->xadj    = xadj;
    graph->vwgt    = vwgt;
    graph->adjncy  = adjncy;
    graph->adjwgt  = adjwgt;
    graph->vtxdist = vtxdist;


    if (((*wgtflag)&2) == 0)
        graph->vwgt = idxsmalloc(graph->nvtxs*ncon, 1, "Par_KMetis: vwgt");

    if (((*wgtflag)&1) == 0)
        graph->adjwgt = idxsmalloc(graph->nedges, 1, "Par_KMetis: adjwgt");

    /* compute tvwgts */
    for (j=0; j<ncon; j++)
        ltvwgts[j] = 0;

    for (i=0; i<graph->nvtxs; i++)
        for (j=0; j<ncon; j++)
            ltvwgts[j] += graph->vwgt[i*ncon+j];

    for (j=0; j<ncon; j++)
        ctrl->tvwgts[j] = GlobalSESum(ctrl, ltvwgts[j]);

    /* check for zero wgt constraints */
    for (i=0; i<ncon; i++) {
        /* ADD: take care of the case in which tvwgts is zero */
        if (ctrl->tvwgts[i] == 0) {
            rprintf(ctrl, "ERROR: sum weight for constraint %d is zero\n", i);
            MPI_Finalize();
            exit(-1);
        }
    }

    /* compute nvwgts */
    graph->nvwgt = fmalloc(graph->nvtxs*ncon, "graph->nvwgt");
    for (i=0; i<graph->nvtxs; i++) {
        for (j=0; j<ncon; j++)
            graph->nvwgt[i*ncon+j] = (floattype)(graph->vwgt[i*ncon+j]) / (floattype)(ctrl->tvwgts[j]);
    }

    srand(ctrl->seed);

    return graph;
}
示例#30
0
文件: io.c 项目: KnoooW/gpgpu-sim
/*************************************************************************
* This function reads the CSR matrix
**************************************************************************/
float *ReadTestCoordinates(GraphType *graph, char *filename, int ndims, MPI_Comm comm)
{
  int i, j, k, npes, mype, penum;
  float *xyz, *txyz;
  FILE *fpin;
  idxtype *vtxdist;
  MPI_Status status;
  char xyzfile[256];

  MPI_Comm_size(comm, &npes);
  MPI_Comm_rank(comm, &mype);

  vtxdist = graph->vtxdist;

  xyz = fmalloc(graph->nvtxs*ndims, "io");

  if (mype == 0) {
    sprintf(xyzfile, "%s.xyz", filename);
    if ((fpin = fopen(xyzfile, "r")) == NULL) 
      errexit("Failed to open file %s\n", xyzfile);
  }

  if (mype == 0) {
    txyz = fmalloc(2*graph->nvtxs*ndims, "io");

    for (penum=0; penum<npes; penum++) {
      for (k=0, i=vtxdist[penum]; i<vtxdist[penum+1]; i++, k++) {
        for (j=0; j<ndims; j++)
          fscanf(fpin, "%e ", txyz+k*ndims+j);
      }

      if (penum == mype) 
        memcpy((void *)xyz, (void *)txyz, sizeof(float)*ndims*k);
      else {
        MPI_Send((void *)txyz, ndims*k, MPI_FLOAT, penum, 1, comm); 
      }
    }
    free(txyz);
    fclose(fpin);
  }
  else 
    MPI_Recv((void *)xyz, ndims*graph->nvtxs, MPI_FLOAT, 0, 1, comm, &status);

  return xyz;
}