/* Compares lists of real and stored metadata and calls pfunc for each */ void mentries_compare(struct metahash *mhashreal, struct metahash *mhashstored, void (*pfunc) (struct metaentry *real, struct metaentry *stored, int cmp), bool do_mtime) { struct metaentry *real, *stored; int key; if (!mhashreal || !mhashstored) { msg(MSG_ERROR, "%s called with empty list\n", __FUNCTION__); return; } for (key = 0; key < HASH_INDEXES; key++) { for (real = mhashreal->bucket[key]; real; real = real->next) { stored = mentry_find(real->path, mhashstored); if (!stored) pfunc(real, NULL, DIFF_ADDED); else pfunc(real, stored, mentry_compare(real, stored, do_mtime)); } for (stored = mhashstored->bucket[key]; stored; stored = stored->next) { real = mentry_find(stored->path, mhashreal); if (!real) pfunc(NULL, stored, DIFF_DELE); } } }
int main() { APPROX int x; x = 5; // Flow violation. int y; y = x; // expected-error {{precision flow violation}} x = x; // OK y = y; // OK // Approximate & precise conditions. if (x) {} // expected-error {{approximate condition}} while (x) {} // expected-error {{approximate condition}} for (int i=2; i<x; ++i) {} // expected-error {{approximate condition}} switch (x) {} // expected-error {{approximate condition}} if (1) {} // OK if (y) {} // OK // Pointers and such. APPROX int* xp; int* yp; xp = &x; // OK yp = &x; // expected-error {{precision flow violation}} xp = &y; // expected-error {{precision flow violation}} yp = &y; // OK if (*yp) {} // OK if (*xp) {} // expected-error {{approximate condition}} APPROX int ax[] = {3, 4, 5}; int ay[] = {3, 4, 5}; if (ax[0]) {} // expected-error {{approximate condition}} if (ay[0]) {} // OK // Pointer types are incompatible. xp = xp; // OK yp = yp; // OK xp = yp; // expected-error {{precision flow violation}} yp = xp; // expected-error {{precision flow violation}} // Function calls. afunc(2); // OK pfunc(2); // OK aafunc(2); // OK afunc(x); // OK aafunc(x); // OK pfunc(x); // expected-error {{precision flow violation}} y = aafunc(x); // expected-error {{precision flow violation}} x = aafunc(x); // OK ppfunc(xp); // expected-error {{precision flow violation}} // Variable initialization. int pinit = x; // expected-error {{precision flow violation}} return 0; }
cudaError_t cudaConfigureCall( dim3 gridDim, dim3 blockDim, size_t sharedMem, cudaStream_t stream) { pfunc(); time_begin(); ptrace("gridDim= %d %d %d\n", gridDim.x, gridDim.y, gridDim.z); ptrace("blockDim= %d %d %d\n", blockDim.x, blockDim.y, blockDim.z); ptrace("sharedMem= %lu\n", sharedMem); ptrace("stream= %p\n", (void*)stream); //ptrace("size= %lu\n", sizeof(cudaStream_t)); cudaKernelConf[0] = gridDim.x; cudaKernelConf[1] = gridDim.y; cudaKernelConf[2] = gridDim.z; cudaKernelConf[3] = blockDim.x; cudaKernelConf[4] = blockDim.y; cudaKernelConf[5] = blockDim.z; cudaKernelConf[6] = sharedMem; cudaKernelConf[7] = (stream==NULL)?(uint64_t)-1:(uint64_t)stream; memset(cudaKernelPara, 0, cudaKernelParaMaxSize); cudaParaSize = sizeof(uint32_t); time_end(t_ConfigCall); return cudaSuccess; }
void JUMP_CHAR_walk_move(int charaPtr){ //再call此jump function之前, 對象已設定完走路之後的座標 //人物重疊事件 if(*(int*)(charaPtr+12) == 1) //1代表玩家, 只有玩家走動會觸發事件 { int i; int objbuf[128]; int objbufindex=0; char tmp[64]; objbufindex = API_CHAR_getSameCoordinateObjects( objbuf, 128, *(int*)(charaPtr + 24), *(int*)(charaPtr + 28), *(int*)(charaPtr + 32), *(int*)(charaPtr + 36)); for(i=0; i<objbufindex; i++) { //定義函數指針 typedef void (*POSTOFUNC)(int,int); POSTOFUNC pfunc=NULL; //獲取object index int objindex= objbuf[i]; int obj_charaIndex = API_OBJECT_getIndex(objindex); //排除自己的object if(API_GetCharaPtrFromCharaIndex(obj_charaIndex) == charaPtr) continue; //開始判斷同位置的物件 switch( API_OBJECT_getType(objindex) ){ case OBJTYPE_CHARA: //包含玩家, NPC, 寵物 pfunc = CHAR_DATA_EXTEND[obj_charaIndex].funcAddr[CHAR_POSTOVERFUNC]; break; default: break; } if( pfunc ) pfunc(API_GetCharaPtrFromCharaIndex(obj_charaIndex), charaPtr); } } }
void transPackage(struct b_pool* pbuf, void (*pfunc)(uint8_t* pBuffer, unsigned int size)) { struct head *htr, *h = (struct head*)pbuf->pbuf; struct b_pool* ptr = alloc_buf(SIZE_LITTLE_BUFFER); unsigned int fullSize = h->size; unsigned int trans =0, fillSize = 0, count = 0; htr = (struct head*)ptr->pbuf; while(fullSize > 0) { memcpy(htr, h, sizeof(struct head)); if(fullSize + sizeof(struct head) <= SIZE_LITTLE_BUFFER) { trans = fullSize; htr->count = LAST; } else { trans = SIZE_LITTLE_BUFFER - sizeof(struct head); htr->count = count++; } htr->size = trans; memcpy(ptr->pbuf + sizeof(struct head), pbuf->pbuf + sizeof(struct head) + fillSize, trans); pfunc((uint8_t*)htr, trans + sizeof(struct head)); fillSize += trans; fullSize -= trans; } free_buf(ptr); return; }
int main(const int argc, const char* argv[]) { if (argc < 2) { fprintf(stderr, "specify the problem number\n"); exit(EXIT_FAILURE); } uint32_t pnum; if (!sscanf(argv[1], "%u", &pnum)) { fprintf(stderr, "could not parse problem number\n"); exit(EXIT_FAILURE); } void (*pfunc)() = get_function(pnum); if (!pfunc) { fprintf(stderr, "problem %d not implemented\n", pnum); exit(EXIT_FAILURE); } clock_t start = clock(); pfunc(); unsigned int runtime_ms = (1000 * (clock() - start)) / CLOCKS_PER_SEC; fprintf(stderr, "Runtime(ms): %u\n", runtime_ms); exit(EXIT_SUCCESS); }
/** *@brief Pythonの関数実行の関数 * @param fname 関数名 */ void PyObj::setFunc(const char *fname) { PyGILState_STATE gilstate; gilstate = PyGILState_Ensure(); bpy::object pfunc = getFunc(fname); try { pfunc(); } catch(const bpy::error_already_set&) { PyErr_Print(); } catch (...) { } PyGILState_Release(gilstate); }
cudaError_t cudaSetupArgument( const void *arg, size_t size, size_t offset) { pfunc(); /* cudaKernelPara: uint32_t uint32_t uint32_t ============================================================================= | number of arg | arg1 size | arg1 data | arg2 size | arg2 data | ..... ============================================================================= */ // set data size memcpy(&cudaKernelPara[cudaParaSize], &size, sizeof(uint32_t)); ptrace("size= %u\n", *(uint32_t*)&cudaKernelPara[cudaParaSize]); cudaParaSize += sizeof(uint32_t); // set data memcpy(&cudaKernelPara[cudaParaSize], arg, size); ptrace("value= %llx\n", *(unsigned long long*)&cudaKernelPara[cudaParaSize]); cudaParaSize += size; (*((uint32_t*)cudaKernelPara))++; time_end(t_SetArg); return cudaSuccess; }
int main() { APPROX int x; x = 5; // Flow violation. int y; y = x; // error x = x; // OK y = y; // OK // Approximate & precise conditions. if (x) {} // error while (x) {} // error for (int i=2; i<x; ++i) {} // error switch (x) {} // error if (1) {} // OK if (y) {} // OK // Pointers and such. APPROX int* xp; int* yp; xp = &x; // OK yp = &x; // error xp = &y; // OK yp = &y; // OK if (*yp) {} // OK if (*xp) {} // error APPROX int ax[] = {3, 4, 5}; int ay[] = {3, 4, 5}; if (ax[0]) {} // error if (ay[0]) {} // OK // Function calls. afunc(2); // OK pfunc(2); // OK aafunc(2); // OK afunc(x); // OK aafunc(x); // OK pfunc(x); // error y = aafunc(x); // error x = aafunc(x); // OK // Variable initialization. int pinit = x; // error return 0; }
void log_printf(void (*pfunc)(const char *), const char* fmt, ...) { va_list ap; va_start(ap, fmt); vsprintf(log_buffer, fmt, ap); va_end(ap); pfunc(log_buffer); }
int main(int argc, const char *argv[]) { int a, b; //定义变量 类型加上变量名 void (*pfunc)(int, int)=NULL; pfunc=test; pfunc(a, b); return 0; }
/*----------------------------------------------------------------------------*/ int nxp_send_file(ASerialPort_t* aPort, ADeviceNXP_t* aDevice) { ALineHEX_t linehex; char hexchk[COUNT_HEXSTR_BUFF]; int linecount, line = 0, error = 0; int count, size = COUNT_HEXSTR_CHAR*sizeof(char); char *buff = malloc(size); FILE *pfile_hex; nxp_hexfunc_t pfunc; /* prepare links! */ linehex.hexstr = hexchk; aDevice->linehex = &linehex; /* get line count and check for error! */ linecount = nxp_check_file(aPort,aDevice); if(linecount<0) return linecount; /* check for verification request */ if(aDevice->do_verify) pfunc = nxp_verify_hex; else pfunc = nxp_device_hex; aDevice->do_verify = 0; /* do the thing! */ pfile_hex = fopen(aDevice->hexfile_name,"rt"); if(!pfile_hex) return HEX_ERROR_FILE; printf("000/%03u\b\b\b\b",linecount); while((count=fget_line(&buff,(int*)&size,pfile_hex))!=-1) { if(size<count) size = count; line++; /* this should be okay! */ nxp_check_hex(buff,&linehex); /* do the requested process */ if((error=pfunc(aPort,aDevice))!=0) break; printf("\b\b\b%03u",line); fflush(stdout); } fclose(pfile_hex); free(buff); printf("\b\b\b \b\b\b\b\b\b\b"); if(error) { printf("Failed @line %d (%d)!\n",line,error); return error; } if(pfunc==nxp_verify_hex) return 0; error = nxp_wait_acknowledge(aPort,aDevice); if(!aDevice->do_acknowledge) { printf("[ACK ERROR] NOT FOUND!\n"); error++; } /* need to get extra ack? */ nxp_wait_acknowledge(aPort,aDevice); return error; }
void open_device() { pfunc(); fd = open(dev_path, O_RDWR); if( fd < 0 ) { error("open device %s faild, %s (%d)\n", dev_path, strerror(errno), errno); exit (EXIT_FAILURE); } //printf("open is ok fd: %d\n", fd); }
int main01() { auto num = 100; auto func = add;//int (*pfunc) = add; int (*pfunc)(int num) = add; std::cout << run(num, add) << std::endl; std::cout << func(1010) << std::endl; std::cout << pfunc(101) << std::endl; return 0; }
static int rtnpw(BW *bw) { W *w = bw->parent; PW *pw = (PW *) bw->object; unsigned char *s; W *win; int *notify; int (*pfunc) (); void *object; long byte; /* Extract entered text from buffer */ p_goto_eol(bw->cursor); byte = bw->cursor->byte; p_goto_bol(bw->cursor); s = brvs(bw->cursor, (int) (byte - bw->cursor->byte)); /* Save text into history buffer */ if (pw->hist) { if (bw->b->changed) { append_history(pw->hist, sv(s)); } else { promote_history(pw->hist, bw->cursor->line); } } /* Do ~ expansion and set new current directory */ if (pw->file_prompt&2) { set_current_dir(s,1); } if (pw->file_prompt) { s = canonical(s); } win = w->win; pfunc = pw->pfunc; object = pw->object; bwrm(bw); joe_free(pw->prompt); joe_free(pw); w->object = NULL; notify = w->notify; w->notify = 0; wabort(w); dostaupd = 1; /* Call callback function */ if (pfunc) { return pfunc(win->object, s, object, notify); } else { return -1; } }
void asm_do_irq(void) { //读的是主中断源的处理函数 pfunc = (void*)VIC0ADDRESS ; pfunc () ; //清除VIC状态 VIC0ADDRESS = 0 ; VIC1ADDRESS = 0 ; VIC2ADDRESS = 0 ; }
void free(void* ptr) { pfunc(); VirtioQCArg arg; ptr(arg.pA, ptr, 0); send_cmd_to_device(VIRTQC_CMD_MMAPRELEASE, &arg); #ifdef USER_KERNEL_COPY if((int)arg.cmd == -1) __libc_free(ptr); #endif }
void __cudaUnregisterFatBinary(void **fatCubinHandle) { pfunc(); time_begin(); ptrace("fatCubinHandle= %p, value= %p\n", fatCubinHandle, *fatCubinHandle); send_cmd_to_device( VIRTQC_cudaUnregisterFatBinary, NULL); free(fatCubinHandle); time_end(t_UnregFatbin); close_device(); }
/* icalbdbset_parse_data -- parses using pfunc to unpack data. */ char *icalbdbset_parse_data(DBT *dbt, char *(*pfunc) (const DBT *dbt)) { char *ret; if (pfunc) { ret = (char *)pfunc(dbt); } else { ret = (char *)dbt->data; } return ret; }
void *malloc(uint64_t size) { pfunc(); #ifdef USER_KERNEL_COPY if( size > QCU_KMALLOC_MAX_SIZE) #endif return __zcmalloc(size); #ifdef USER_KERNEL_COPY else return __libc_malloc(size); #endif }
void __cudaRegisterFunction( void **fatCubinHandle, const char *hostFun, char *deviceFun, const char *deviceName, int thread_limit, uint3 *tid, uint3 *bid, dim3 *bDim, dim3 *gDim, int *wSize ) { VirtioQCArg arg; computeFatBinaryFormat_t fatBinHeader; pfunc(); time_begin(); ptrace("fatCubinHandle= %p, value= %p\n", fatCubinHandle, *fatCubinHandle); ptrace("hostFun= %s (%p)\n", hostFun, hostFun); ptrace("deviceFun= %s (%p)\n", deviceFun, deviceFun); ptrace("deviceName= %s\n", deviceName); ptrace("thread_limit= %d\n", thread_limit); if(tid) ptrace("tid= %u %u %u\n", tid->x, tid->y, tid->z); else ptrace("tid is NULL\n"); if(bid) ptrace("bid= %u %u %u\n", bid->x, bid->y, bid->z); else ptrace("bid is NULL\n"); if(bDim)ptrace("bDim= %u %u %u\n", bDim->x, bDim->y, bDim->z); else ptrace("bDim is NULL\n"); if(gDim)ptrace("gDim= %u %u %u\n", gDim->x, gDim->y, gDim->z); else ptrace("gDim is NULL\n"); if(wSize)ptrace("wSize= %d\n", *wSize); else ptrace("wSize is NULL\n"); memset(&arg, 0, sizeof(VirtioQCArg)); fatBinHeader = (computeFatBinaryFormat_t)(*fatCubinHandle); ptr( arg.pA , fatBinHeader, fatBinHeader->fatSize); ptr( arg.pB , deviceName , strlen(deviceName)+1 ); arg.flag = (uint32_t)(uint64_t)hostFun; ptrace("pA= %p, pASize= %u, pB= %p, pBSize= %u\n", (void*)arg.pA, arg.pASize, (void*)arg.pB, arg.pBSize); send_cmd_to_device( VIRTQC_cudaRegisterFunction, &arg); time_end(t_RegFunc); }
cudaError_t cudaGetLastError(void) { VirtioQCArg arg; pfunc(); time_begin(); memset(&arg, 0, sizeof(VirtioQCArg)); send_cmd_to_device( VIRTQC_cudaGetLastError, &arg); time_end(t_GetLastError); return (cudaError_t)arg.cmd; }
cudaError_t cudaDeviceReset(void) { VirtioQCArg arg; pfunc(); time_begin(); memset(&arg, 0, sizeof(VirtioQCArg)); send_cmd_to_device( VIRTQC_cudaDeviceReset, &arg); time_end(t_DevReset); return (cudaError_t)arg.cmd; }
cudaError_t cudaSetDevice(int device) { VirtioQCArg arg; pfunc(); time_begin(); memset(&arg, 0, sizeof(VirtioQCArg)); ptr( arg.pA, device, 0); send_cmd_to_device( VIRTQC_cudaSetDevice, &arg); time_end(t_SetDev); return (cudaError_t)arg.cmd; }
/*ARGSUSED1*/ static void key(unsigned char key, int x, int y) { switch(key) { case 'h': help(); break; case 'g': gfunc(); break; case 't': tfunc(); break; case 'z': zfunc(); break; case 'x': xfunc(); break; case 'p': pfunc(); break; case '\033': exit(EXIT_SUCCESS); break; default: break; } glutPostRedisplay(); }
cudaError_t cudaEventDestroy(cudaEvent_t event) { VirtioQCArg arg; pfunc(); time_begin(); memset(&arg, 0, sizeof(VirtioQCArg)); ptr( arg.pA, event, 0); send_cmd_to_device( VIRTQC_cudaEventDestroy, &arg); time_end(t_EventDestroy); return (cudaError_t)arg.cmd; }
cudaError_t cudaRuntimeGetVersion(int *runtimeVersion) { VirtioQCArg arg; pfunc(); time_begin(); memset(&arg, 0, sizeof(VirtioQCArg)); send_cmd_to_device( VIRTQC_cudaRuntimeGetVersion, &arg); *runtimeVersion = (uint64_t)arg.pA; time_end(t_RuntimeGetVersion); return (cudaError_t)arg.cmd; }
cudaError_t cudaDriverGetVersion(int *driverVersion) { VirtioQCArg arg; pfunc(); time_begin(); memset(&arg, 0, sizeof(VirtioQCArg)); send_cmd_to_device( VIRTQC_cudaDriverGetVersion, &arg); *driverVersion = (int)arg.pA; time_end(t_DriverGetVersion); return (cudaError_t)arg.cmd; }
cudaError_t cudaGetDeviceCount(int *count) { VirtioQCArg arg; pfunc(); time_begin(); memset(&arg, 0, sizeof(VirtioQCArg)); send_cmd_to_device( VIRTQC_cudaGetDeviceCount, &arg); *count = (int)arg.pA; time_end(t_GetDevCount); return (cudaError_t)arg.cmd; }
cudaError_t cudaEventCreate(cudaEvent_t *event) { VirtioQCArg arg; pfunc(); time_begin(); memset(&arg, 0, sizeof(VirtioQCArg)); send_cmd_to_device( VIRTQC_cudaEventCreate, &arg); *event = (void*)arg.pA; time_end(t_EventCreate); return (cudaError_t)arg.cmd; }