本文整理汇总了C++中PUT函数的典型用法代码示例。如果您正苦于以下问题:C++ PUT函数的具体用法?C++ PUT怎么用?C++ PUT使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PUT函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: idt77105_start
static int idt77105_start(struct atm_dev *dev)
{
unsigned long flags;
if (!(dev->dev_data = kmalloc(sizeof(struct idt77105_priv),GFP_KERNEL)))
return -ENOMEM;
PRIV(dev)->dev = dev;
spin_lock_irqsave(&idt77105_priv_lock, flags);
PRIV(dev)->next = idt77105_all;
idt77105_all = PRIV(dev);
spin_unlock_irqrestore(&idt77105_priv_lock, flags);
memset(&PRIV(dev)->stats,0,sizeof(struct idt77105_stats));
/* initialise dev->signal from Good Signal Bit */
atm_dev_signal_change(dev,
GET(ISTAT) & IDT77105_ISTAT_GOODSIG ?
ATM_PHY_SIG_FOUND : ATM_PHY_SIG_LOST);
if (dev->signal == ATM_PHY_SIG_LOST)
#ifdef CONFIG_DEBUG_PRINTK
printk(KERN_WARNING "%s(itf %d): no signal\n",dev->type,
dev->number);
#else
;
#endif
/* initialise loop mode from hardware */
switch ( GET(DIAG) & IDT77105_DIAG_LCMASK ) {
case IDT77105_DIAG_LC_NORMAL:
PRIV(dev)->loop_mode = ATM_LM_NONE;
break;
case IDT77105_DIAG_LC_PHY_LOOPBACK:
PRIV(dev)->loop_mode = ATM_LM_LOC_ATM;
break;
case IDT77105_DIAG_LC_LINE_LOOPBACK:
PRIV(dev)->loop_mode = ATM_LM_RMT_ATM;
break;
}
/* enable interrupts, e.g. on loss of signal */
PRIV(dev)->old_mcr = GET(MCR);
if (dev->signal == ATM_PHY_SIG_FOUND) {
PRIV(dev)->old_mcr |= IDT77105_MCR_EIP;
PUT(PRIV(dev)->old_mcr, MCR);
}
idt77105_stats_timer_func(0); /* clear 77105 counters */
(void) fetch_stats(dev,NULL,1); /* clear kernel counters */
spin_lock_irqsave(&idt77105_priv_lock, flags);
if (start_timer) {
start_timer = 0;
init_timer(&stats_timer);
stats_timer.expires = jiffies+IDT77105_STATS_TIMER_PERIOD;
stats_timer.function = idt77105_stats_timer_func;
add_timer(&stats_timer);
init_timer(&restart_timer);
restart_timer.expires = jiffies+IDT77105_RESTART_TIMER_PERIOD;
restart_timer.function = idt77105_restart_timer_func;
add_timer(&restart_timer);
}
spin_unlock_irqrestore(&idt77105_priv_lock, flags);
return 0;
}
开发者ID:nos1609,项目名称:Chrono_Kernel-1,代码行数:66,代码来源:idt77105.c
示例2: mm_free
void mm_free(void *bp) {
size_t size = GET_SIZE(HDRP(bp));
PUT(HDRP(bp), PACK(size, 0));
PUT(FTRP(bp), PACK(size, 0));
coalesce(bp);
}
开发者ID:gigi13164269,项目名称:blog-1,代码行数:6,代码来源:mm.c
示例3: mm_malloc
/*
* mm_realloc - Implemented simply in terms of mm_malloc and mm_free
* 重新调整之前malloc分配的block的大小
* TODO: 改用next_fid策略后,好像这里就死循环了
*/
void *mm_realloc(void *bp, size_t size)
{
if (bp == NULL)
return mm_malloc(size);
else if (0 == size) {
mm_free(bp);
return NULL;
}
/* check if bp is aliged */
if ((uint32_t)bp % ALIGNMENT != 0)
return NULL;
void *new_bp = NULL;
size_t old_size = GET_SIZE(HDRP(bp));
size_t new_size = ALIGN(size + DSIZE); /* 别忘了header和footer的size! */
size_t frag_size;
if (new_size > old_size) {
/*
* 这个IF中的逻辑感觉多余了,只需要通过malloc()找到一个更大的空闲块就行了.
*
* 2015-9-18
* 通过malloc()重新给找一个更大的block是可以,但是我这implicit的实现,每次
* 都要遍历所有的block寻找free block,效率非常低
* */
/**
* 判断相邻的下一块是否是一个足以容纳(new_size - old_size)的空闲块,
* 如果是,那么就把当前块扩展到下一块就好了
*/
if (!GET_ALLOC(HDRP(NEXT_BLKP(bp))) &&
GET_SIZE(HDRP(NEXT_BLKP(bp))) >= (new_size - old_size)) {
/* next block is large enough, bp not need to change */
frag_size = GET_SIZE(HDRP(NEXT_BLKP(bp))) - (new_size - old_size);
if (frag_size >= MIN_BLK) {
PUT(HDRP(bp), PACK(new_size, 1));
PUT(FTRP(bp), PACK(new_size, 1));
PUT(HDRP(NEXT_BLKP(bp)), PACK(frag_size, 0));
PUT(FTRP(NEXT_BLKP(bp)), PACK(frag_size, 0));
} else {
new_size = old_size + GET_SIZE(HDRP(NEXT_BLKP(bp)));
PUT(HDRP(bp), PACK(new_size, 1));
PUT(FTRP(bp), PACK(new_size, 1));
}
new_bp = bp;
} else {
/* next block isn't large enough, bp need to be pointed to a large region */
if ((new_bp = find_fit(last_found, new_size)) == NULL)
new_bp = extend_heap(MAX(new_size, CHUNKSIZE) / WSIZE);
place(new_bp, new_size);
/* copy payload from old block to new block */
memcpy(new_bp, bp, old_size - DSIZE);
/* free old block */
mm_free(bp);
}
} else if (new_size < old_size) {
/* if new_size < old_size, check if need to split */
if (old_size - new_size >= MIN_BLK) {
PUT(HDRP(bp), PACK(new_size, 1));
PUT(FTRP(bp), PACK(new_size, 1));
/* split a new free block */
PUT(HDRP(NEXT_BLKP(bp)), PACK(old_size - new_size, 0));
PUT(FTRP(NEXT_BLKP(bp)), PACK(old_size - new_size, 0));
}
new_bp = bp;
}
/* mm_check(); */
return new_bp;
}
开发者ID:Jarvishappy,项目名称:malloc_lab,代码行数:83,代码来源:mm.c
示例4: GET
void *place(void *bp,size_t asize)
{
// dbg_printf("place\n");
void *p = GET(FLPB(bp)); //preview free_block
void *n = GET(FLSB(bp)); //next free_block
void *return_bp = bp;
// dbg_printf(" p : %d\tbp : %d\tn : %d\n",p,bp,n);
size_t size = GET_SIZE(HDRP(bp));
PUT(HDRP(bp),PACK(asize,1));
PUT(FTRP(bp),PACK(asize,1));
size -=asize;
bp = NEXT_BLKP(bp); //split block
if ( size == 0 )
{
if ( free_count >=2 )
{
PUT(FLSB(p),n);
if ( n != NULL )
PUT(FLPB(n),p);
// dbg_printf("true\n");
}
else
init = NULL;
free_count--;
}
else
{
PUT(HDRP(bp),PACK(size,0));
PUT(FTRP(bp),PACK(size,0));
// dbg_printf("p : %d\tbp : %d\tn : %d\n",p,bp,n);
if ( p == &init)
{
PUT(FLPB(bp),&init);
PUT(FLSB(bp),n);
init = bp;
}
else
{
PUT(FLSB(bp),n);
PUT(FLPB(bp),p);
PUT(FLSB(p),bp);
}
if ( n != NULL )
PUT(FLPB(n),bp);
}
return return_bp;
}
开发者ID:dudfoKim,项目名称:System-Programming,代码行数:49,代码来源:mm_view.c
示例5: mm_init
/*
* mm_init - initialize the malloc package.
*/
int mm_init(void)
{
int i;
dbg1("[IN ] : mm_init()\n");
/* create the initial empty heap */
// if ((heap_listp = mem_sbrk(18*DSIZE + 4 * WSIZE)) == NULL)
if ((heap_listp = mem_sbrk((MAXCLASS+1)*2*DSIZE + 4 * WSIZE)) == NULL)
return -1;
/* free_list_ptrs points to starting point of free list pointers */
free_list_ptrs = heap_listp;
for (i=0; i<= MAXCLASS; i++) {
PUT8(heap_listp+DSIZE*(i*2), NULL);
PUT8(heap_listp+DSIZE*(i*2+1), NULL);
}
/* heap starting point is set right after the free list pointers */
heap_listp = heap_listp+DSIZE*2*(MAXCLASS+1);
#if 0
/* set up segregated free list pointers */
PUT8(heap_listp, NULL); /* free list 0 head */
PUT8(heap_listp+DSIZE, NULL); /* free list 0 tail */
PUT8(heap_listp+DSIZE*2, NULL); /* free list 1 head */
PUT8(heap_listp+DSIZE*3, NULL); /* free list 1 tail */
PUT8(heap_listp+DSIZE*4, NULL); /* free list 2 head */
PUT8(heap_listp+DSIZE*5, NULL); /* free list 2 tail */
PUT8(heap_listp+DSIZE*6, NULL); /* free list 3 head */
PUT8(heap_listp+DSIZE*7, NULL); /* free list 3 tail */
PUT8(heap_listp+DSIZE*8, NULL); /* free list 4 head */
PUT8(heap_listp+DSIZE*9, NULL); /* free list 4 tail */
PUT8(heap_listp+DSIZE*10, NULL); /* free list 5 head */
PUT8(heap_listp+DSIZE*11, NULL); /* free list 5 tail */
PUT8(heap_listp+DSIZE*12, NULL); /* free list 6 head */
PUT8(heap_listp+DSIZE*13, NULL); /* free list 6 tail */
PUT8(heap_listp+DSIZE*14, NULL); /* free list 7 head */
PUT8(heap_listp+DSIZE*15, NULL); /* free list 7 tail */
PUT8(heap_listp+DSIZE*16, NULL); /* free list 8 head */
PUT8(heap_listp+DSIZE*17, NULL); /* free list 8 tail */
/* free_list_ptrs points to starting point of free list pointers */
free_list_ptrs = heap_listp;
/* heap starting point is set right after the free list pointers */
heap_listp = heap_listp+DSIZE*18;
#endif
PUT(heap_listp, 0); /* alignment padding */
PUT(heap_listp+WSIZE, PACK(OVERHEAD, 3)); /* prologue header */
PUT(heap_listp+2*WSIZE, PACK(OVERHEAD, 3)); /* prologue footer */
PUT(heap_listp+3*WSIZE, PACK(0, 3)); /* epilogue header */
epilogue = (unsigned *)(heap_listp+3*WSIZE); /* update epilogue pointer */
heap_listp += 2*WSIZE;
/* extends heap only on demand */
mm_initialized = 1;
dbg1("[OUT] : mm_init()\n");
return 0;
}
开发者ID:447327642,项目名称:CSAPP2e,代码行数:71,代码来源:mm-seglist.c
示例6: mm_realloc
/*
* mm_realloc : This routine is a kind of a wrapper routine for the already implimented
* mm_malloc and mm_free routines. It also takes care of the reallocation of a new
* pointer or memory space.
*/
void *
mm_realloc(void *ptr, size_t size)
{
size_t oldsize= GET_SIZE(HDRP(ptr)),total_size;// Gets the present size of the allocated block which has to be reallocated
void *newptr;
// If size == 0 It means it's a free block. We return NULL
if (size == 0) {
mm_free(ptr);// frees the block
return (NULL);
}
/* If ptr is NULL, It means we have freshly allocate ablock with the mentioned size*/
if (ptr == NULL)
return (mm_malloc(size));// allaoctes the block of the mentioned size.
if (size <= DSIZE)
total_size = 2 * DSIZE;
else
total_size = DSIZE * ((size + DSIZE + (DSIZE - 1)) / DSIZE);// calcuates the total_size required for the new block to be allocated
if(oldsize == total_size) return ptr;
if (oldsize >= total_size)
{
if((oldsize - total_size) != (DSIZE))
{
if((oldsize - total_size) != 0)
{
PUT(HDRP(ptr), PACK(total_size, 1));//packs the size of the block and the allocation(1) status in the header
PUT(FTRP(ptr), PACK(total_size, 1));//packs the size of the block and the allocation(1) status in the footer
void *bp = NEXT_BLKP(ptr);//Gets the pointer of the next block in the heap
PUT(HDRP(bp), PACK(oldsize - total_size, 0));//packs the size of the block and the allocation(0) status in the header
PUT(FTRP(bp), PACK(oldsize - total_size, 0));//packs the size of the block and the allocation(1) status in the footer
coalesce(bp);// coaleseces the block
}
return ptr;
}
}
size_t next_blkp_size = (size_t)GET_SIZE(HDRP(NEXT_BLKP(ptr)));
if((size_t)GET_ALLOC(HDRP(NEXT_BLKP(ptr)))==0 && next_blkp_size + oldsize - total_size > DSIZE)
{
Delete_Free_Block(NEXT_BLKP(ptr),next_blkp_size);//Deletes the block from the explicictly maintained free list
PUT(HDRP(ptr), PACK(total_size, 1));//packs the size of the block and the allocation(1) status in the header
PUT(FTRP(ptr), PACK(total_size, 1));//packs the size of the block and the allocation(1) status in the footer
void *bp = NEXT_BLKP(ptr);
PUT(HDRP(bp), PACK(next_blkp_size + oldsize - total_size, 0));//packs the size of the block and the allocation(0) status in the header
PUT(FTRP(bp), PACK(next_blkp_size + oldsize - total_size, 0));//packs the size of the block and the allocation(0) status in the footer
Add_Free_Block(bp,next_blkp_size + oldsize - total_size);//Adds the block to the explicictly maintained free list
//checkheap(1);
return ptr;
}
newptr = mm_malloc(size);// allocates the new block at the new pointer
//If realloc() fails the original block is left untouched
if (newptr == NULL)
return (NULL);
// Copy the old data.
oldsize = GET_SIZE(HDRP(ptr));
if (size < oldsize)
oldsize = size;
memcpy(newptr, ptr, oldsize);
// Free the old block.
mm_free(ptr);
return (newptr);
}
开发者ID:saianirudh123,项目名称:Memory-Allocator-Project,代码行数:77,代码来源:mm.c
示例7: Cpp
/*
* Cpp: read C++ file and pickup tag entries.
*/
void
Cpp(const struct parser_param *param)
{
int c, cc;
int savelevel;
int startclass, startthrow, startmacro, startsharp, startequal;
char classname[MAXTOKEN];
char completename[MAXCOMPLETENAME];
int classlevel;
struct {
char *classname;
char *terminate;
int level;
} stack[MAXCLASSSTACK];
const char *interested = "{}=;~";
STRBUF *sb = strbuf_open(0);
*classname = *completename = 0;
stack[0].classname = completename;
stack[0].terminate = completename;
stack[0].level = 0;
level = classlevel = piflevel = namespacelevel = 0;
savelevel = -1;
startclass = startthrow = startmacro = startsharp = startequal = 0;
if (!opentoken(param->file))
die("'%s' cannot open.", param->file);
cmode = 1; /* allow token like '#xxx' */
crflag = 1; /* require '\n' as a token */
cppmode = 1; /* treat '::' as a token */
while ((cc = nexttoken(interested, cpp_reserved_word)) != EOF) {
if (cc == '~' && level == stack[classlevel].level)
continue;
switch (cc) {
case SYMBOL: /* symbol */
if (startclass || startthrow) {
PUT(PARSER_REF_SYM, token, lineno, sp);
} else if (peekc(0) == '('/* ) */) {
if (param->isnotfunction(token)) {
PUT(PARSER_REF_SYM, token, lineno, sp);
} else if (level > stack[classlevel].level || startequal || startmacro) {
PUT(PARSER_REF_SYM, token, lineno, sp);
} else if (level == stack[classlevel].level && !startmacro && !startsharp && !startequal) {
char savetok[MAXTOKEN], *saveline;
int savelineno = lineno;
strlimcpy(savetok, token, sizeof(savetok));
strbuf_reset(sb);
strbuf_puts(sb, sp);
saveline = strbuf_value(sb);
if (function_definition(param)) {
/* ignore constructor */
if (strcmp(stack[classlevel].classname, savetok))
PUT(PARSER_DEF, savetok, savelineno, saveline);
} else {
PUT(PARSER_REF_SYM, savetok, savelineno, saveline);
}
}
} else {
PUT(PARSER_REF_SYM, token, lineno, sp);
}
break;
case CPP_USING:
/*
* using namespace name;
* using ...;
*/
if ((c = nexttoken(interested, cpp_reserved_word)) == CPP_NAMESPACE) {
if ((c = nexttoken(interested, cpp_reserved_word)) == SYMBOL) {
PUT(PARSER_REF_SYM, token, lineno, sp);
} else {
if (param->flags & PARSER_WARNING)
warning("missing namespace name. [+%d %s].", lineno, curfile);
pushbacktoken();
}
} else
pushbacktoken();
break;
case CPP_NAMESPACE:
crflag = 0;
/*
* namespace name = ...;
* namespace [name] { ... }
*/
if ((c = nexttoken(interested, cpp_reserved_word)) == SYMBOL) {
PUT(PARSER_DEF, token, lineno, sp);
if ((c = nexttoken(interested, cpp_reserved_word)) == '=') {
crflag = 1;
break;
}
}
/*
* Namespace block doesn't have any influence on level.
*/
if (c == '{') /* } */ {
namespacelevel++;
//.........这里部分代码省略.........
开发者ID:gsliu,项目名称:emacs_C,代码行数:101,代码来源:Cpp.c
示例8: GET_SIZE
/*
* mm_realloc - naive implementation of mm_realloc. The realloc() function shall change the
* size of the memory object pointed to by ptr to the size specified by size. The contents
* of the object shall remain unchanged up to the lesser of the new and old sizes. If the
* new size of the memory object would require movement of the object, the space for the
* previous instantiation of the object is freed. If the new size is larger, the contents
* of the newly allocated portion of the object are unspecified.
*/
void *mm_realloc(void *ptr, size_t size)
{
void *newp;
void *oldp = ptr;
size_t oldSize = GET_SIZE(HDRP(oldp));
//size_t newSize = ALIGN(size);
size_t asize;
//size_t isPrevFree = GET_ALLOC(FTRP(PREV_BLKP(oldp)));
size_t isNextFree = GET_ALLOC(HDRP(NEXT_BLKP(oldp)));
//size_t prevSize = GET_SIZE(FTRP(PREV_BLKP(oldp)));
size_t nextSize = GET_SIZE(HDRP(NEXT_BLKP(oldp)));
//mm_checkheap(0);
if(ptr == NULL)
return mm_malloc(size);
else if(size == 0){
mm_free(ptr);
return NULL;
}
else if(size == GET_SIZE(HDRP(ptr)))
return ptr;
if (size <= DSIZE)
asize = DSIZE + OVERHEAD;
else
asize = DSIZE * ((size + (OVERHEAD) + (DSIZE-1)) / DSIZE);
if(asize <= oldSize){
//printf("OldSize: %zu , asize: %zu\n", oldSize, asize);
if(oldSize - asize < OVERHEAD){
//printf("FER HINGAÐ\n");
return oldp;
}
PUT(HDRP(oldp), PACK(asize, 1));
PUT(FTRP(oldp), PACK(asize, 1));
//printf("alloc minnkar og nýtir rest í fría blokk\n");
PUT(HDRP(NEXT_BLKP(oldp)), PACK(oldSize - asize, 0));
PUT(FTRP(NEXT_BLKP(oldp)), PACK(oldSize - asize, 0));
insert_block(NEXT_BLKP(oldp));
}
/*else if(!isNextFree && (oldSize + nextSize) >= asize){
if((oldSize + nextSize) - asize < OVERHEAD){
PUT(HDRP(oldp), PACK(oldSize + nextSize, 1));
PUT(FTRP(oldp), PACK(oldSize + nextSize, 1));
}
else{
PUT(HDRP(oldp), PACK(asize, 1));
PUT(FTRP(oldp), PACK(asize, 1));
PUT(HDRP(NEXT_BLKP(oldp)), PACK((oldSize+nextSize)-asize, 0));
PUT(FTRP(NEXT_BLKP(oldp)), PACK((oldSize+nextSize)-asize, 0));
void *freeBlock = NEXT_BLKP(oldp);
insert_block(freeBlock);
return oldp;
}
}*/
// calculate the adjusted size of the request ????
// ef adjustedSize <= oldsize, return ptr
if ((newp = mm_malloc(size)) == NULL) {
printf("ERROR: mm_malloc failed in mm_realloc\n");
exit(1);
}
if (size < oldSize) {
oldSize = size;
}
memcpy(newp, ptr, oldSize);
mm_free(ptr);
return newp;
}
开发者ID:olikari,项目名称:malloclab,代码行数:80,代码来源:mm.c
示例9: GaussBin_Elimination
void GaussBin_Elimination(char * inputname, char * outputname)
{ FILE * in=fopen(inputname,"rb");
long m, n, i, j, k, l, cols, sum, old, rem=0;
fscanf(in,"%ld %ld", &n, &m);
cols=1+(n>>5);
unsigned long ** mas=new unsigned long*[m];
for(i=0; i<m; ++i) mas[i]=new unsigned long[cols];
for(i=0; i<m; ++i) memset(mas[i],0,sizeof(unsigned long)*cols);
// #define GET(i,j) ((mas[i][j>>5]>>(j&31))&1)
// #define PUT(i,j,k) mas[i][j>>5]=(k)?(mas[i][j>>5]|(1<<(j&31))):(mas[i][j>>5]&((1<<(j&31))^-1))
// Read the input matrix m*n
for(i=0; i<n; i++)
for(j=0; j<m; j++)
{ fscanf(in, "%ld", &k);
k%=2;
if(k) PUT(mas, j,i,k);
}
// Gaussian elimination here
long * vert=new long[m], *horz=new long[n], *uncl=new long[n], *solv=new long[n];
memset(vert,0,sizeof(long)*m);
memset(horz,0,sizeof(long)*n);
memset(uncl,0,sizeof(long)*n);
// Here I include removal of columns, which are equal.
for(i=0; i<n; ++i)
for(j=i+1; j<n; ++j)
{ for(k=0; k<m; k++)
if(GET(mas, k,i)!=GET(mas, k,j)) break;
if(k==m) horz[j]=-1, ++rem; // delete the column j in this case
}
printf("Rejected rows: %ld\n", rem);
for(i=0; i<n; ++i)
if(!horz[i])
{ for(j=0; j<m; ++j)
if(vert[j]==0 && GET(mas, j,i)) break;
if(j==m) continue;
vert[j]=1;
horz[i]=j+1; // horizontal references
l=j;
for(j=0; j<m; ++j)
if(GET(mas,j,i) && j!=l)
for(k=0; k<cols; ++k)
mas[j][k]^=mas[l][k];
}
for(i=sum=0; i<n; ++i)
if(--horz[i]==-1) uncl[sum++]=i; // unresolved columns
FILE * out=fopen(outputname,"wb");
// Generate resulting vectors
old=sum;
if(sum>12)
{ printf("The number of solutions is too many (2^%ld) ... trancated to 2^12!\n", sum);
sum=12; // too many solutions!!!
}
fprintf(out,"%d\n", (1<<sum)-1);
for(i=1; i<(1<<sum); ++i)
{ memset(solv,0,sizeof(long)*n);
for(j=sum; j<old; ++j) solv[uncl[j]]=rand()%2;
for(j=0; j<sum; ++j) // fill unknown variables first
solv[uncl[j]]=(i>>j)&1;
// calculate the rest variables here
for(j=0; j<n; ++j)
if(horz[j]>=0)
{ for(l=k=0; l<old; ++l)
if(GET(mas, horz[j], uncl[l])) k^=solv[uncl[l]];
solv[j]=k;
}
// output one solution here
for(j=0; j<n; j++)
fprintf(out,"%ld ", solv[j]);
fprintf(out,"\n");
}
fclose(out);
for(i=0; i<m; ++i) delete []mas[i];
delete []mas;
delete []vert;
delete []horz;
delete []uncl;
fclose(in);
}
开发者ID:HaraldNordgren,项目名称:edin01,代码行数:91,代码来源:GaussBin.cpp
示例10: C_family
/**
* @param[in] param source file
* @param[in] type #TYPE_C, #TYPE_YACC, #TYPE_LEX
*/
static void
C_family(const struct parser_param *param, int type)
{
int c, cc;
int savelevel;
int startmacro, startsharp;
const char *interested = "{}=;";
STRBUF *sb = strbuf_open(0);
/*
* yacc file format is like the following.
*
* declarations
* %%
* rules
* %%
* programs
*
*/
int yaccstatus = (type == TYPE_YACC) ? DECLARATIONS : PROGRAMS;
int inC = (type == TYPE_YACC) ? 0 : 1; /* 1 while C source */
level = piflevel = externclevel = 0;
savelevel = -1;
startmacro = startsharp = 0;
if (!opentoken(param->file))
die("'%s' cannot open.", param->file);
cmode = 1; /* allow token like '#xxx' */
crflag = 1; /* require '\n' as a token */
if (type == TYPE_YACC)
ymode = 1; /* allow token like '%xxx' */
while ((cc = nexttoken(interested, c_reserved_word)) != EOF) {
switch (cc) {
case SYMBOL: /* symbol */
if (inC && peekc(0) == '('/* ) */) {
if (param->isnotfunction(token)) {
PUT(PARSER_REF_SYM, token, lineno, sp);
} else if (level > 0 || startmacro) {
PUT(PARSER_REF_SYM, token, lineno, sp);
} else if (level == 0 && !startmacro && !startsharp) {
char arg1[MAXTOKEN], savetok[MAXTOKEN], *saveline;
int savelineno = lineno;
strlimcpy(savetok, token, sizeof(savetok));
strbuf_reset(sb);
strbuf_puts(sb, sp);
saveline = strbuf_value(sb);
arg1[0] = '\0';
/*
* Guile function entry using guile-snarf is like follows:
*
* SCM_DEFINE (scm_list, "list", 0, 0, 1,
* (SCM objs),
* "Return a list containing OBJS, the arguments to `list'.")
* #define FUNC_NAME s_scm_list
* {
* return objs;
* }
* #undef FUNC_NAME
*
* We should assume the first argument as a function name instead of 'SCM_DEFINE'.
*/
if (function_definition(param, arg1)) {
if (!strcmp(savetok, "SCM_DEFINE") && *arg1)
strlimcpy(savetok, arg1, sizeof(savetok));
PUT(PARSER_DEF, savetok, savelineno, saveline);
} else {
PUT(PARSER_REF_SYM, savetok, savelineno, saveline);
}
}
} else {
PUT(PARSER_REF_SYM, token, lineno, sp);
}
break;
case '{': /* } */
DBG_PRINT(level, "{"); /* } */
if (yaccstatus == RULES && level == 0)
inC = 1;
++level;
if ((param->flags & PARSER_BEGIN_BLOCK) && atfirst) {
if ((param->flags & PARSER_WARNING) && level != 1)
warning("forced level 1 block start by '{' at column 0 [+%d %s].", lineno, curfile); /* } */
level = 1;
}
break;
/* { */
case '}':
if (--level < 0) {
if (externclevel > 0)
externclevel--;
else if (param->flags & PARSER_WARNING)
warning("missing left '{' [+%d %s].", lineno, curfile); /* } */
level = 0;
}
if ((param->flags & PARSER_END_BLOCK) && atfirst) {
//.........这里部分代码省略.........
开发者ID:qbai,项目名称:.emacs.d,代码行数:101,代码来源:C.c
示例11: mm_free
/*
* Requires:
* "ptr" is either the address of an allocated block or NULL.
*
* Effects:
* Reallocates the block "ptr" to a block with at least "size" bytes of
* payload, unless "size" is zero. If "size" is zero, frees the block
* "ptr" and returns NULL. If the block "ptr" is already a block with at
* least "size" bytes of payload, then "ptr" may optionally be returned.
* Otherwise, a new block is allocated and the contents of the old block
* "ptr" are copied to that new block. Returns the address of this new
* block if the allocation was successful and NULL otherwise.
*/
void *mm_realloc(void *ptr, size_t size)
{
size_t oldsize;
void *newptr;
/* If size == 0 then this is just free, and we return NULL. */
if (size == 0) {
mm_free(ptr);
return (NULL);
}
/* If oldptr is NULL, then this is just malloc. */
if (ptr == NULL)
return (mm_malloc(size));
oldsize = GET_SIZE(HDRP(ptr));
size_t asize;
if((size+WSIZE)%DSIZE==0)
asize = size+WSIZE;
else
asize = (((size+WSIZE)/DSIZE+1)*DSIZE);
if(oldsize == asize)
return ptr;
if(oldsize > asize) {
if(oldsize-asize<=MINIMUM)
return ptr;
bool prev_alloc = GET_PREV_ALLOC(HDRP(ptr));
if(!prev_alloc) {
PUT(HDRP(ptr),PACK(asize,1));
} else {
PUT(HDRP(ptr),PACK(asize,3));
}
PUT(HDRP(ptr),PACK(oldsize-asize,2));
PUT(FTRP(ptr),PACK(oldsize-asize,2));
int *next = NEXT_BLKP(ptr);
bool next_alloc = GET_ALLOC(HDRP(next));
size_t size_next = GET_SIZE(HDRP(next));
if(!next_alloc) {
PUT(HDRP(ptr),PACK(size_next,0));
PUT(FTRP(ptr),PACK(size_next,0));
} else {
PUT(HDRP(ptr),PACK(size_next,1));
}
}
int *next = NEXT_BLKP(ptr);
bool next_alloc = GET_ALLOC(HDRP(next));
if(!next_alloc) {
size_t size_next = GET_SIZE(HDRP(next));
if((size_next+oldsize)>=asize) {
oldsize += size_next;
if((oldsize-asize)>=(2*WSIZE)){
bool prev_alloc = GET_PREV_ALLOC(HDRP(ptr));
if(!prev_alloc) {
PUT(HDRP(ptr),PACK(asize,1));
} else {
PUT(HDRP(ptr),PACK(asize,3));
}
int *next = NEXT_BLKP(ptr);
PUT(HDRP(next),PACK(oldsize-asize,2));
PUT(FTRP(next),PACK(oldsize-asize,2));
} else {
bool prev_alloc = GET_PREV_ALLOC(HDRP(ptr));
if(!prev_alloc) {
PUT(HDRP(ptr),PACK(oldsize,1));
} else {
PUT(HDRP(ptr),PACK(oldsize,3));
}
int *next = NEXT_BLKP(ptr);
size_t size_next = GET_SIZE(HDRP(next));
bool next_alloc = GET_ALLOC(HDRP(next));
if(!next_alloc) {
PUT(HDRP(next),PACK(size_next,2));
PUT(FTRP(next),PACK(size_next,2));
} else {
PUT(HDRP(next),PACK(size_next,3));
}
}
return ptr;
}
}
newptr = mm_malloc(size);
/* If realloc() fails the original block is left untouched */
if (newptr == NULL)
return (NULL);
/* Copy the old data. */
if (size < oldsize)
//.........这里部分代码省略.........
开发者ID:Zarana-Parekh,项目名称:Dynamic-Memory-Allocator,代码行数:101,代码来源:mm.c
示例12: function_definition
/**
* function_definition: return if function definition or not.
*
* @param param
* @param[out] arg1 the first argument
* @return target type
*/
static int
function_definition(const struct parser_param *param, char arg1[MAXTOKEN])
{
int c;
int brace_level, isdefine;
int accept_arg1 = 0;
brace_level = isdefine = 0;
while ((c = nexttoken("()", c_reserved_word)) != EOF) {
switch (c) {
case SHARP_IFDEF:
case SHARP_IFNDEF:
case SHARP_IF:
case SHARP_ELIF:
case SHARP_ELSE:
case SHARP_ENDIF:
condition_macro(param, c);
continue;
default:
break;
}
if (c == '('/* ) */)
brace_level++;
else if (c == /* ( */')') {
if (--brace_level == 0)
break;
}
/* pick up symbol */
if (c == SYMBOL) {
if (accept_arg1 == 0) {
accept_arg1 = 1;
strlimcpy(arg1, token, MAXTOKEN);
}
PUT(PARSER_REF_SYM, token, lineno, sp);
}
}
if (c == EOF)
return 0;
brace_level = 0;
while ((c = nexttoken(",;[](){}=", c_reserved_word)) != EOF) {
switch (c) {
case SHARP_IFDEF:
case SHARP_IFNDEF:
case SHARP_IF:
case SHARP_ELIF:
case SHARP_ELSE:
case SHARP_ENDIF:
condition_macro(param, c);
continue;
case C___ATTRIBUTE__:
process_attribute(param);
continue;
default:
break;
}
if (c == '('/* ) */ || c == '[')
brace_level++;
else if (c == /* ( */')' || c == ']')
brace_level--;
else if (brace_level == 0
&& ((c == SYMBOL && strcmp(token, "__THROW")) || IS_RESERVED_WORD(c)))
isdefine = 1;
else if (c == ';' || c == ',') {
if (!isdefine)
break;
} else if (c == '{' /* } */) {
pushbacktoken();
return 1;
} else if (c == /* { */'}')
break;
else if (c == '=')
break;
/* pick up symbol */
if (c == SYMBOL)
PUT(PARSER_REF_SYM, token, lineno, sp);
}
return 0;
}
开发者ID:qbai,项目名称:.emacs.d,代码行数:86,代码来源:C.c
示例13: _icv_iconv
//.........这里部分代码省略.........
is greater than octal \178 ( ie a high bit char) convert it
to an underscore (_), as it has no mapping to 7 bit ASCII.
Otrherwise the char is the same in both cose sets.
*/
/* The following was changed from the switch statement for
64-bit building
*/
if (ic == '\100')
ic = '\247';
else if (ic == '[')
ic = '\304';
else if (ic == ']')
ic = '\334';
else if (ic == '{')
ic = '\344';
else if (ic == '|')
ic = '\366';
else if (ic == '}')
ic = '\374';
else if (ic == '\134')
ic = '\326';
else if (ic == '~')
ic = '\337';
else if (ic > '\177')
ic = '_';
/* switch ( ic )
{
case '\100' :
ic = '\247';
break;
case '[' :
ic = '\304';
break;
case ']' :
ic = '\334';
break;
case '{' :
ic = '\344';
break;
case '|' :
ic = '\366';
break;
case '}' :
ic = '\374';
break;
case '\134' :
ic = '\326';
break;
case '~' :
ic = '\337';
break;
default :
if (ic > '\177')
ic = '_';
break;
} */
PUT(ic);
/*
Put the converted character into the output buffer, and decrement
the count of chars left in both the in and out buffers.
If we have no space left in the out buffer, but we have no reached
the end of the input buffer. We return what we have, and set the
errno (Error) to E2BIG.
*/
if ((oleft < 1) && (ileft > 0))
{
errno = E2BIG;
retval = ERR_RETURN;
goto ret;
}
}
/*
We only get here if the end of the in buffer has been reached, we therefore return the
value 0 to denote that we have sucesfully converted the inbuffer.
*/
retval = ileft;
/* Taken unchanged from @(#)ISO-2022-JP%SJIS. */
ret:
st->_st_cset = cset;
st->_st_stat = stat;
*inbuf = ip;
*inbytesleft = ileft;
ret2:
*outbuf = (char *)op;
*outbytesleft = oleft;
return (retval);
}
开发者ID:alhazred,项目名称:illumos-extra,代码行数:101,代码来源:646de%8859.c
示例14: GET_ALLOC
/**********************************************************
* coalesce
* Covers the 4 cases discussed in the text:
* - both neighbours are allocated
* - the next block is available for coalescing
* - the previous block is available for coalescing
* - both neighbours are available for coalescing
**********************************************************/
void *coalesce(void *bp)
{
size_t prev_alloc = GET_ALLOC(FTRP(PREV_BLKP(bp)));
size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp)));
size_t size = GET_SIZE(HDRP(bp));
// MACRO for PREV_BLKP does not work for this case
if (bp == heap_listp) {
prev_alloc = 1;
}
// printf("Coalesce: size1: %u\n",(unsigned int) size);
void *coalesced_bp = NULL;
if (prev_alloc && next_alloc) { /* Case 1 */
coalesced_bp = bp;
}
else if (prev_alloc && !next_alloc) { /* Case 2 */
//account for size 16 external fragmentation which isn't
//in the free list
if (GET_SIZE(HDRP(NEXT_BLKP(bp))) != DSIZE) {
assert(remove_from_free_list(NEXT_BLKP(bp)));
}
size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
PUT(HDRP(bp), PACK(size, 0));
PUT(FTRP(bp), PACK(size, 0));
coalesced_bp = bp;
}
else if (!prev_alloc && next_alloc){
//account for size 16 external fragmentation which isn't
//in the free list
if (GET_SIZE(HDRP(PREV_BLKP(bp))) != DSIZE) {
void * if_free = remove_from_free_list(PREV_BLKP(bp));
assert(if_free);
}
/* Case 3 */
size += GET_SIZE(HDRP(PREV_BLKP(bp)));
PUT(FTRP(bp), PACK(size, 0));
PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
coalesced_bp = PREV_BLKP(bp);
}
else { /* Case 4 */
//account for size 16 external fragmentation which isn't
//in the free list
int size_prev = GET_SIZE(HDRP(PREV_BLKP(bp)));
int size_next = GET_SIZE(FTRP(NEXT_BLKP(bp)));
if (size_prev != DSIZE)
assert(remove_from_free_list(PREV_BLKP(bp)));
if (size_next != DSIZE)
assert(remove_from_free_list(NEXT_BLKP(bp)));
size += size_prev + size_next;
// printf("Coalesce: size_p: %u\n",(unsigned int) size_prev);
// printf("Coalesce: size_n: %u\n",(unsigned int) size_next);
PUT(HDRP(PREV_BLKP(bp)), PACK(size,0));
PUT(FTRP(NEXT_BLKP(bp)), PACK(size,0));
coalesced_bp = PREV_BLKP(bp);
}
// printf("Coalesced into size: %u, addr: %p\n",(unsigned int) size, (int*)coalesced_bp);
return coalesced_bp;
}
开发者ID:divd,项目名称:ece454,代码行数:72,代码来源:mm.c
示例15: main
void main(int argc, char *argv[])
{
char val[512], *p;
char rbuf[512+1];
char svcname[17];
int timeout;
long revent, rcvlen;
FLDKEY key;
FBUF *transf;
FILE *fp;
int cd, n, fflag=0, i, idx=0;
int ret;
/*
if (argc != 2) {
fprintf(stderr, "Usage:%s input-file\n", argv[0]);
exit(1);
}
*/
if(parseArg(argc, argv)<0){
printf("parseArg error!!\n");
exit(1);
}
if( (fp=fopen(filename, "r")) == (FILE *)0 ){
printf( "file open error [%d:%s]\n", errno, strerror(errno) );
exit( 1 );
}
memset( svcname, 0x00, sizeof(svcname) );
if( get_svcname(fp, svcname) < 0 ){
printf( "get_svcname() failed!! -- (input-file=%s)\n", argv[1] );
exit(1);
}
timeout = 5;
n = tpstart((TPSTART_T *)NULL);
if (n < 0) {
fprintf(stderr, "tpstart fail tperrno = %s\n", tperrno);
exit(1);
}
printf("tpstart ok!\n");
transf = fballoc(100, 100);
if( transf == NULL) {
fprintf(stderr, "fballoc fail: rcvbuf tperrno = %d\n", tperrno);
tpend();
exit(1);
}
Finit(transf, Fsizeof(transf));
while( 1 ){
memset( rbuf, 0x00, sizeof(rbuf) );
if( fgets(rbuf, sizeof(rbuf)-1, fp)==(char *) 0 ){
break;
}
p = strchr(rbuf, '\n');
if( p == (char *)0 && strlen(rbuf) >= sizeof(rbuf)-1 ){
printf( "한 라인의 길이가 너무 길어 무시합니다..\n" );
printf( "=>[%s]\n", rbuf );
continue;
}
*p = 0x00;
memset( val, 0x00, sizeof(val) );
key = 0;
if( line_proc(rbuf, &key, &idx, val)<0 ) continue;
PUT(key, idx, val);
printf( "key=%d, idx=%d, val=%s\n", key, idx, val );
fflag = 1;
}
if( !fflag ){
printf( "not exist send data .....\n" );
fbfree( transf );
tpend();
exit(1);
}
printf( ">>service[%s], send data->\n", svcname );
fbprint( transf );
printf( "\t----------------------------------------------------\n\n\n" );
fflush( stdout );
/* original
cd = tpconnect(svcname, (char *)transf, fbget_fbsize(transf), TPRECVONLY);
*/
if(flag==1){
ret = tx_begin();
printf("tx_begin() [%s] \n", ret==TX_OK ? "success" : "fail");
if(ret!=TX_OK) exit(1);
//.........这里部分代码省略.........
开发者ID:nawhizz,项目名称:KAIT,代码行数:101,代码来源:conv.c
示例16: main
int main()
{
SystemInit();
const Ec1 g1(-1, 1);
const Ec2 g2(
Fp2(Fp(g2c.aa), Fp(g2c.ab)),
Fp2(Fp(g2c.ba), Fp(g2c.bb))
);
// assertBool g2 and g1 on curve
assertBool("g1 is on EC", g1.isValid());
assertBool("g2 is on twist EC", g2.isValid());
puts("order of group");
const Mpz& r = GetParamR();
PUT(r);
{
Ec1 t = g1;
t.mul(r);
assertBool("orgder of g1 == r", t.isZero());
}
{
Ec2 t = g2;
t.mul(r);
assertBool("order of g2 == r", t.isZero());
}
const Mpz a("123456789012345");
const Mpz b("998752342342342342424242421");
// scalar-multiplication sample
{
Mpz c = a;
c.add(b);
Ec1 Pa = g1; Pa.mul(a);
Ec1 Pb = g1; Pb.mul(b);
Ec1 Pc = g1; Pc.mul(c);
Ec1 out = Pa;
out.add(Pb);
assertEqual("check g1 * c = g1 * a + g1 * b", Pc, out);
}
Fp12 e;
// calc e : G2 x G1 -> G3 pairing
e.pairing(g2, g1); // e = e(g2, g1)
PUT(e);
{
Fp12 t = e;
t.power(r);
assertEqual("order of e == r", t, Fp12(1));
}
Ec2 g2a = g2;
g2a.mul(a);
Fp12 ea1;
ea1.pairing(g2a, g1);
Fp12 ea2 = e;
ea2.power(a); // ea2 = e^a
assertEqual("e(g2 * a, g1) = e(g2, g1)^a", ea1, ea2);
Ec1 g1b = g1;
g1b.mul(b);
Fp12 eb1;
eb1.pairing(g2, g1b); // eb1 = e(g2, g1b)
Fp12 eb2 = e;
eb2.power(b); // eb2 = e^b
assertEqual("e(g2a, g1 * b) = e(g2, g1)^b", eb1, eb2);
Ec1 q1 = g1;
q1.mul(12345);
assertBool("q1 is on EC", q1.isValid());
Fp12 e1, e2;
e1.pairing(g2, g1); // e1 = e(g2, g1)
e2.pairing(g2, q1); // e2 = e(g2, q1)
Ec1 q2 = g1;
q2.add(q1);
e.pairing(g2, q2); // e = e(g2, q2)
e1.mul(e2);
assertEqual("e = e1 * e2", e, e1);
/*
reduce one copy as the following
*/
g2a = g2;
g2a.mul(a);
g1b = g1;
g1b.mul(b);
Ec2 g2at = g2; g2at.mul(a);
Ec1 g1bt = g1; g1bt.mul(b);
assertEqual("g2a == g2 * a", g2a, g2at);
assertEqual("g1b == g1 * b", g1b, g1bt);
printf("errNum = %d\n", errNum);
}
开发者ID:herumi,项目名称:ate-pairing,代码行数:89,代码来源:java_api.cpp
示例17: main
//.........这里部分代码省略.........
space = mushspace_init(space_buf, NULL); \
if (!space) { \
tap_not_ok("init returned null"); \
tap_skip_remaining("init failed"); \
free(saved_pos); \
return 1; \
} \
tap_ok("init succeeded"); \
POS_INIT; \
FOREACH_CELL { \
GET_POS(data_cell[i]); \
if (SAVE_POS) \
saved_pos[i] = pos; \
mushspace_put(space, pos, data_cell[i]); \
} \
\
ok = true; \
POS_INIT; \
for (size_t i = 0; i < data_cell_count; ++i) { \
mushcell dc = data_cell[i]; \
GET_POS(dc); \
mushcell gc = mushspace_get(space, pos); \
if (gc == dc) \
continue; \
ok = false; \
tap_not_ok("get doesn't match what was put" S); \
printf(" ---\n" \
" failed index: %zu\n" \
" expected: %" MUSHCELL_PRIx "\n" \
" got: %" MUSHCELL_PRIx "\n", \
i, dc, gc); \
printf(" failed pos relative to min: ("); \
for (uint8_t j = 0; j < MUSHSPACE_DIM; ++j) \
printf(" %" MUSHCELL_PRId, mushcell_sub(pos.v[j], MUSHCELL_MIN)); \
printf(" )\n" \
" ...\n"); \
break; \
} \
if (ok) \
tap_ok("get matches what was put" S);
#define FORWARD for (size_t i = 0; i < data_cell_count; ++i)
#define REVERSE for (size_t i = data_cell_count; i--;)
#define SAVED_POS(_) pos = saved_pos[i];
PUT(FORWARD, " (forward order)", CP_POS, true);
mushspace_free(space);
PUT(REVERSE, " (reverse order)", SAVED_POS, false);
free(saved_pos);
if (!ok) {
tap_skip_remaining("won't copy bad space");
return 1;
}
void *space_buf2 = malloc(mushspace_sizeof);
mushspace *space2 = mushspace_copy(space_buf2, space, NULL);
mushspace_free(space);
free(space_buf);
space = space2;
if (!space) {
tap_not_ok("copy returned null");
tap_skip_remaining("copy failed");
return 1;
}
tap_ok("copy succeeded");
ok = true;
POS_INIT;
for (size_t i = 0; i < DATA_LEN / sizeof *data_cell; ++i) {
mushcell dc = data_cell[i];
CP_POS(dc);
mushcell gc = mushspace_get(space, pos);
if (gc == dc)
continue;
ok = false;
tap_not_ok("get in copy doesn't match data");
printf(" ---\n"
" failed index: %zu\n"
" expected: %" MUSHCELL_PRIx "\n"
" got: %" MUSHCELL_PRIx "\n",
i, dc, gc);
printf(" failed pos relative to min: (");
for (uint8_t j = 0; j < MUSHSPACE_DIM; ++j)
printf(" %" MUSHCELL_PRId, mushcell_sub(pos.v[j], MUSHCELL_MIN)); \
printf(" )\n"
" ...\n");
break;
}
if (ok)
tap_ok("get in copy matched data");
free(data);
mushspace_free(space);
free(space_buf2);
}
开发者ID:Deewiant,项目名称:mushspace,代码行数:101,代码来源:wrap-textual.98.c
|
请发表评论