void xrLC_GlobalData ::gl_mesh_clear () { vec_clear( _g_vertices, _destruct_vertex_not_uregister ); vec_clear( _g_faces, _destruct_face_not_uregister ); _VertexPool.clear(); _FacePool.clear(); }
void xrLC_GlobalData::clear_mu_models () { clLog( "mem usage before mu_clear %d", Memory.mem_usage() ); vec_clear(_mu_models);// not clear ogf vec_clear(_mu_refs); mu_mesh_clear(); Memory.mem_compact(); clLog( "mem usage after mu_clear: %d", Memory.mem_usage() ); }
static obj_ptr _vec_clear(obj_ptr arg, obj_ptr env) { if (NVECP(arg)) return MKERROR(MKSTRING("Expected a vector in vec-clear"), arg); vec_clear(&VEC(arg)); return NIL; }
void dyad_close(dyad_Stream *stream) { dyad_Event e; if (stream->state == DYAD_STATE_CLOSED) return; stream->state = DYAD_STATE_CLOSED; /* Close socket */ if (stream->sockfd != INVALID_SOCKET) { close(stream->sockfd); stream->sockfd = INVALID_SOCKET; } /* Emit event */ e = createEvent(DYAD_EVENT_CLOSE); e.msg = "stream closed"; stream_emitEvent(stream, &e); /* Clear buffers */ vec_clear(&stream->lineBuffer); vec_clear(&stream->writeBuffer); }
void map_clear(hashmap_t* map) { for(size_t i = 0; i < map->active_buckets.length; ++i) { unsigned long pos = *(unsigned long*)vec_get(&map->active_buckets, i); hashmap_node_t* node = map->buckets[pos]; free_bucket(node); map->buckets[pos] = NULL; } vec_clear(&map->active_buckets); }
void dyad_removeAllListeners(dyad_Stream *stream, int event) { if (event == DYAD_EVENT_NULL) { vec_clear(&stream->listeners); } else { int i = stream->listeners.length; while (i--) { if (stream->listeners.data[i].event == event) { vec_splice(&stream->listeners, i, 1); } } } }
void xrLC_GlobalData:: clear () { vec_spetial_clear(_cl_globs._textures ); _cl_globs._materials.clear(); _cl_globs._shaders.Unload(); // CMemoryWriter _err_invalid; // b_params _g_params; close_models_read(); close_models_write(); vec_clear(_g_lightmaps); vec_clear(_mu_models);//mem leak vec_clear(_mu_refs); mu_mesh_clear(); gl_mesh_clear(); //VertexPool; //FacePool; // vecVertex _g_vertices; // vecFace _g_faces; gl_mesh_clear (); vec_clear (_g_deflectors); //base_lighting _L_static; xr_delete(_cl_globs._RCAST_Model); xr_delete( write_lightmaps ); xr_delete( ::write_vertices ); //xr_delete( write_faces ); xr_delete( write_deflectors ); xr_delete( read_lightmaps ); xr_delete( ::read_vertices ); //xr_delete( read_faces ); xr_delete( read_deflectors ); // bool _b_nosun; // bool _gl_linear; }
static int stream_flushWriteBuffer(dyad_Stream *stream) { stream->flags &= ~DYAD_FLAG_WRITTEN; if (stream->writeBuffer.length > 0) { /* Send data */ int size = send(stream->sockfd, stream->writeBuffer.data, stream->writeBuffer.length, 0); if (size <= 0) { if (errno == EWOULDBLOCK) { /* No more data can be written */ return 0; } else { /* Handle disconnect */ dyad_close(stream); return 0; } } if (size == stream->writeBuffer.length) { vec_clear(&stream->writeBuffer); } else { vec_splice(&stream->writeBuffer, 0, size); } /* Update status */ stream->bytesSent += size; stream->lastActivity = dyad_getTime(); } if (stream->writeBuffer.length == 0) { dyad_Event e; /* If this is a 'closing' stream we can properly close it now */ if (stream->state == DYAD_STATE_CLOSING) { dyad_close(stream); return 0; } /* Set ready flag and emit 'ready for data' event */ stream->flags |= DYAD_FLAG_READY; e = createEvent(DYAD_EVENT_READY); e.msg = "stream is ready for more data"; stream_emitEvent(stream, &e); } /* Return 1 to indicate that more data can immediately be written to the * stream's socket */ return 1; }
void set_destination(double *v) { int i; double dif[MAX_DIM]; vec_copy(origin, position); vec_copy(destination, v); tim = 0.0; delta_t = feedrate_begin; dist = vec_dist(position, v); if(dist == 0.0) { vec_clear(incvec); for(i = 0; i < MAX_DIM; i++) amp[i] = amplitude_dc; return; } vec_diff(dif, v, origin); for(i = 0; i < MAX_DIM; i++) incvec[i] = dif[i] / dist; calc_amplitude(); }
static void symhash_add(D_SymHash *sh, D_Sym *s) { uint i, h = s->hash % sh->syms.n, n; D_Sym **v = sh->syms.v, *x; Vec(D_Sym*) vv, tv; sh->index++; s->next = v[h]; v[h] = s; if (sh->index > sh->grow) { vv.v = sh->syms.v; vv.n = sh->syms.n; sh->syms.n = sh->grow; sh->grow = sh->grow * 2 + 1; sh->syms.v = MALLOC(sh->syms.n * sizeof(void *)); memset(sh->syms.v, 0, sh->syms.n * sizeof(void *)); v = sh->syms.v; n = sh->syms.n; vec_clear(&tv); for (i = 0; i < vv.n; i++) /* use temporary to preserve order */ while (vv.v[i]) { x = vv.v[i]; vv.v[i] = x->next; vec_add(&tv, x); } while (tv.v[i]) { x = tv.v[i]; tv.v[i] = x->next; h = x->hash % n; x->next = v[h]; v[h] = x; } FREE(vv.v); } }
void comsubs() { register block *bl,*blc,*bln; register int n; /* # of blocks to treat as one */ //static int xx; //printf("comsubs() %d\n", ++xx); //debugx = (xx == 37); #ifdef DEBUG if (debugx) dbg_printf("comsubs(%p)\n",startblock); #endif // No longer do we just compute Bcount. We now eliminate unreachable // blocks. block_compbcount(); // eliminate unreachable blocks #if SCPP if (errcnt) return; #endif if (!csvec) { csvec = vec_calloc(CSVECDIM); } for (bl = startblock; bl; bl = bln) { bln = bl->Bnext; if (!bl->Belem) continue; /* if no expression or no parents */ // Count up n, the number of blocks in this extended basic block (EBB) n = 1; // always at least one block in EBB blc = bl; while (bln && list_nitems(bln->Bpred) == 1 && ((blc->BC == BCiftrue && list_block(list_next(blc->Bsucc)) == bln) || (blc->BC == BCgoto && list_block(blc->Bsucc) == bln) ) && bln->BC != BCasm // no CSE's extending across ASM blocks ) { n++; // add block to EBB blc = bln; bln = blc->Bnext; } vec_clear(csvec); hcstop = 0; touchstari = 0; touchfunci[0] = 0; touchfunci[1] = 0; bln = bl; while (n--) // while more blocks in EBB { #ifdef DEBUG if (debugx) dbg_printf("cses for block %p\n",bln); #endif if (bln->Belem) ecom(&bln->Belem); // do the tree bln = bln->Bnext; } } #ifdef DEBUG if (debugx) dbg_printf("done with comsubs()\n"); #endif }
static void stream_handleReceivedData(dyad_Stream *stream) { for (;;) { /* Receive data */ dyad_Event e; char data[8192]; int size = recv(stream->sockfd, data, sizeof(data) - 1, 0); if (size <= 0) { if (size == 0 || errno != EWOULDBLOCK) { /* Handle disconnect */ dyad_close(stream); return; } else { /* No more data */ return; } } data[size] = 0; /* Update status */ stream->bytesReceived += size; stream->lastActivity = dyad_getTime(); /* Emit data event */ e = createEvent(DYAD_EVENT_DATA); e.msg = "received data"; e.data = data; e.size = size; stream_emitEvent(stream, &e); /* Check stream state in case it was closed during one of the data event * handlers. */ if (stream->state != DYAD_STATE_CONNECTED) { return; } /* Handle line event */ if (stream_hasListenerForEvent(stream, DYAD_EVENT_LINE)) { int i, start; char *buf; for (i = 0; i < size; i++) { vec_push(&stream->lineBuffer, data[i]); } start = 0; buf = stream->lineBuffer.data; for (i = 0; i < stream->lineBuffer.length; i++) { if (buf[i] == '\n') { dyad_Event e; buf[i] = '\0'; e = createEvent(DYAD_EVENT_LINE); e.msg = "received line"; e.data = &buf[start]; e.size = i - start; /* Check and strip carriage return */ if (e.size > 0 && e.data[e.size - 1] == '\r') { e.data[--e.size] = '\0'; } stream_emitEvent(stream, &e); start = i + 1; /* Check stream state in case it was closed during one of the line * event handlers. */ if (stream->state != DYAD_STATE_CONNECTED) { return; } } } if (start == stream->lineBuffer.length) { vec_clear(&stream->lineBuffer); } else { vec_splice(&stream->lineBuffer, 0, start); } } } }
clock_t alu3(_fhe_int *into,_fhe_int *opcode,fhe_int_t carry, _fhe_int *op1, _fhe_int *op2,fhe_pk_t pk,fhe_sk_t sk) { clock_t _clock; _fhe_int *or; _fhe_int *xor; _fhe_int *and; _fhe_int *add; _fhe_int *nopcode; fhe_int_t temp; fhe_int_t sel_or; fhe_int_t sel_xor; fhe_int_t sel_and; fhe_int_t sel_add; _clock=clock(); nopcode=vec_init(2); for(int i=0;i<2;i++) { fhe_int_not(&nopcode[i],&opcode[i],pk); } or=vec_init(DATA_BITS); xor=vec_init(DATA_BITS); and=vec_init(DATA_BITS); add=vec_init(DATA_BITS+1); fhe_int_init(temp); fhe_int_init(sel_or); fhe_int_init(sel_xor); fhe_int_init(sel_and); fhe_int_init(sel_add); for(int i=0;i<DATA_BITS;i++) fhe_int_encrypt(&into[i],pk,0); fhe_int_and(sel_or,&nopcode[0],&nopcode[1],pk); fhe_int_and(sel_xor,&opcode[0],&nopcode[1],pk); fhe_int_and(sel_and,&nopcode[0],&opcode[1],pk); fhe_int_and(sel_add,&opcode[0],&opcode[1],pk); for(int i=0;i<DATA_BITS;i++) { fhe_int_xor(&xor[i],&op1[i],&op2[i],pk); //xor fhe_int_and(&and[i],&op1[i],&op2[i],pk); //and fhe_int_xor(&or[i],&xor[i],&and[i],pk); //or fhe_int_xor(&add[i],&xor[i],carry,pk); //rc-add fhe_int_and(temp,&xor[i],carry,pk); fhe_int_or(carry,temp,&and[i],pk); fhe_int_and(temp,&or[i],sel_or,pk); //select output fhe_int_xor(&into[i],&into[i],temp,pk); fhe_int_and(temp,&xor[i],sel_xor,pk); fhe_int_xor(&into[i],&into[i],temp,pk); fhe_int_and(temp,&and[i],sel_and,pk); fhe_int_xor(&into[i],&into[i],temp,pk); fhe_int_and(temp,&add[i],sel_add,pk); fhe_int_xor(&into[i],&into[i],temp,pk); } vec_clear(or,DATA_BITS); vec_clear(xor,DATA_BITS); vec_clear(and,DATA_BITS); vec_clear(add,DATA_BITS); fhe_int_clear(temp); fhe_int_clear(sel_or); fhe_int_clear(sel_xor); fhe_int_clear(sel_and); fhe_int_clear(sel_add); return clock()-_clock; }
TagValueFunction* tnfa_match(TNFA* tnfa, char* input, int anchorStart, int anchorEnd){ Vector* reach, *reachNext, *tmp; TagValueFunction** reachTVFs, **reachNextTVFs, **tmpTVFs; int i; int leftmostMatchFound = 0; TagValueFunction* finalTVF = NULL; void** vd; TNFAMatcher m; /* Construct the matcher Object */ m.tnfa = tnfa; m.pos = 0; m.counts = ecalloc(tnfa->laststate+1,sizeof(int)); m.queue = ibqueue_create(tnfa->laststate+1); m.priorities = ecalloc(tnfa->laststate+1,sizeof(PriorityList*)); m.tmp = tvf_create(tnfa->tagcount); m.tvfpool = opool_createWithExt((void*(*)(void*))tvf_create,shared_free,NULL,NULL,(void*)tnfa->tagcount,10); m.plistpool = opool_createWithExt((void*(*)(void*))plist_create,shared_free,NULL,NULL,(void*)tnfa->maxpath,10); reach = vec_createDefault(); reachTVFs = ecalloc(tnfa->laststate+1,sizeof(TagValueFunction*)); reachNext = vec_createDefault(); reachNextTVFs = ecalloc(tnfa->laststate+1,sizeof(TagValueFunction*)); /* Initialize reach to consistentClosure({<s,v0>}); */ vec_add(reach,(void*)tnfa->start); reachTVFs[tnfa->start] = (TagValueFunction*)opool_grab(m.tvfpool); reach = tnfa_close(m,reach,reachTVFs); /* If this regex matches the empty string then we may already have a possible match :P */ if(reachTVFs[tnfa->finish]!=NULL && (!anchorEnd || (anchorEnd && !*input)) ){ leftmostMatchFound = 1; finalTVF = (TagValueFunction*)opool_grab(m.tvfpool); tvf_copyInto(finalTVF,reachTVFs[tnfa->finish],m.tnfa->tagcount); } /*{int i; printf("{"); for(i=0;i<vec_size(reach);i++) printf("%d,",vec_get(reach,i)); printf("}"); printf("{"); for(i=0;i<m.tnfa->laststate+1;i++){ int j;int found=0; if(reachTVFs[i] != NULL){ for(j=0;j<vec_size(reach);j++) if(vec_get(reach,j) == i) found =1; if(found) printf("*,"); else printf("?"); } else { printf("_,"); } } printf("}\n"); } */ //printf("\nclosure(s%d) = %s",tnfa->start,match_toString(reach,tnfa)); /* while pos < |input| */ while(*input && vec_size(reach) > 0){ /* fetch the next input symbol */ char c = *input; input ++; m.pos++; vec_clear(reachNext); memset(reachNextTVFs,'\0',(tnfa->laststate+1) * sizeof(TagValueFunction*)); /* For each item <q,v> in reach */ for(i=vec_size(reach)-1,vd=vec_data(reach);i>=0;i--){ TFATrans* t; TagValueFunction* v; int q = (int)vd[i]; v = reachTVFs[q]; /* For each transition on c out of q do */ t = tnfa->cStates[q]; while(t != NULL){ /* add <t->to,v> to reachNext */ if(t->c == c){ /* WARNING: ... dangerous : I believe that with NFAs constructed with the thompson construction there is a 1to1 mapping between 'from' states and 'to' states on a non-epsilon transition. If that were not the case then there might be two different ways to get to the same state from reach on c and I would need to add those seperately to reachNext prohibiting the use of a hash */ reachNextTVFs[t->to] = (TagValueFunction*)opool_grab(m.tvfpool); tvf_copyInto(reachNextTVFs[t->to],v,m.tnfa->tagcount); vec_add(reachNext,(void*)t->to); } t = t->next; } } /* Free reach */ for(i=vec_size(reach)-1,vd=vec_data(reach);i>=0;i--) opool_release(m.tvfpool,reachTVFs[(int)vd[i]]); if(!anchorStart && (!leftmostMatchFound || anchorEnd)){ if(reachNextTVFs[tnfa->start] == NULL){ reachNextTVFs[tnfa->start] = (TagValueFunction*)opool_grab(m.tvfpool); tvf_initialize(reachNextTVFs[tnfa->start],tnfa->tagcount); vec_add(reachNext,(void*)tnfa->start); } } reachNext = tnfa_close(m,reachNext,reachNextTVFs); if(reachNextTVFs[tnfa->finish] != NULL){ leftmostMatchFound = 1; if( (!anchorEnd && (finalTVF == NULL || reachNextTVFs[tnfa->finish][0] <= finalTVF[0])) || (anchorEnd && !*input) ){ if(finalTVF!=NULL) opool_release(m.tvfpool,finalTVF); finalTVF = (TagValueFunction*)opool_grab(m.tvfpool); tvf_copyInto(finalTVF,reachNextTVFs[tnfa->finish],m.tnfa->tagcount); // printf("\tFound potential match: %s\n",match_toString(reachNext,tnfa)); } } //printf("\nclosure = %s",match_toString(reachNext,tnfa)); // Swap reach and reachNext tmp = reach; tmpTVFs = reachTVFs; reach = reachNext; reachTVFs = reachNextTVFs; reachNext = tmp; reachNextTVFs = tmpTVFs; } /* Free reach */ for(i=vec_size(reach)-1,vd=vec_data(reach);i>=0;i--) opool_release(m.tvfpool,reachTVFs[(int)vd[i]]); vec_free(reach); free(reachTVFs); vec_free(reachNext); free(reachNextTVFs); free(m.tmp); free(m.counts); free(m.priorities); ibqueue_free(m.queue); if(finalTVF){ TagValueFunction* tmp = finalTVF; finalTVF = tvf_copyInto(tvf_create(tnfa->tagcount),finalTVF,tnfa->tagcount); opool_release(m.tvfpool,tmp); } else { finalTVF = tvf_create(tnfa->tagcount); } if(anchorEnd && *input) { TagValueFunction* tmp = finalTVF; finalTVF = tvf_create(tnfa->tagcount); free(tmp); } opool_free(m.tvfpool); opool_free(m.plistpool); return finalTVF; }
int audiostep_open(const char *devname, int channels, unsigned int rate) { int err; snd_pcm_hw_params_t *hw_params; int dir = 0; int i; snd_pcm_uframes_t periods = PERIODSIZE; snd_pcm_uframes_t bufsize = PERIODSIZE * 8; dim = channels; if ((err = snd_pcm_open (&playback_handle, devname, SND_PCM_STREAM_PLAYBACK, 0)) < 0) { fprintf(stderr, "cannot open audio device %s (%s)\n", devname, snd_strerror(err)); return err; } if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) { fprintf(stderr, "cannot allocate hardware parameter structure (%s)\n", snd_strerror (err)); return err; } if ((err = snd_pcm_hw_params_any (playback_handle, hw_params)) < 0) { fprintf(stderr, "cannot initialize hardware parameter structure (%s)\n", snd_strerror (err)); goto out_free; } if ((err = snd_pcm_hw_params_set_access (playback_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) { fprintf(stderr, "cannot set access type (%s)\n", snd_strerror (err)); goto out_free; } if ((err = snd_pcm_hw_params_set_format (playback_handle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) { fprintf(stderr, "cannot set sample format (%s)\n", snd_strerror (err)); goto out_free; } if ((err = snd_pcm_hw_params_set_rate_near (playback_handle, hw_params, &rate, &dir)) < 0) { fprintf(stderr, "cannot set sample rate (%s)\n", snd_strerror (err)); goto out_free; } if ((err = snd_pcm_hw_params_set_channels (playback_handle, hw_params, 2 * channels)) < 0) { fprintf(stderr, "cannot set channel count (%s)\n", snd_strerror (err)); goto out_free; } if ((err = snd_pcm_hw_params_set_buffer_size_near(playback_handle, hw_params, &bufsize)) < 0) { fprintf(stderr, "cannot set buffer size (%s)\n", snd_strerror (err)); goto out_free; } if ((err = snd_pcm_hw_params_set_period_size_near(playback_handle, hw_params, &periods, &dir)) < 0) { fprintf(stderr, "cannot set period size (%s)\n", snd_strerror (err)); goto out_free; } if ((err = snd_pcm_hw_params (playback_handle, hw_params)) < 0) { fprintf(stderr, "cannot set parameters (%s)\n", snd_strerror (err)); goto out_free; } if ((err = snd_pcm_prepare (playback_handle)) < 0) { fprintf(stderr, "cannot prepare audio interface for use (%s)\n", snd_strerror (err)); goto out_free; } vec_clear(position); vec_clear(speed); vec_clear(destination); vec_clear(origin); vec_clear(amp); for (i = 0; i < MAX_DIM * 2; i ++) { currents[i] = 0.0; } for(i = 0; i < STEP_PERIOD_SIZE; i ++) { sintab[i] = CURR_OFFSET + CURR_AMPLITUDE * sin((i * 2 * M_PI) / (double)STEP_PERIOD_SIZE); costab[i] = CURR_OFFSET + CURR_AMPLITUDE * cos((i * 2 * M_PI) / (double)STEP_PERIOD_SIZE); } out_free: snd_pcm_hw_params_free(hw_params); return err; }
void moto_clearEnv(MotoEnv *env) { Enumeration *e; int size; //hset_free(env->ptrs); //mpool_free(env->mpool); /* Clear out the globals */ e = stab_getKeys(env->globals); while (enum_hasNext(e)) { char* n = (char*)enum_next(e); MotoVar* var = stab_get(env->globals,n); if(env->mode != COMPILER_MODE) { moto_freeVal(env,var->vs); } else { opool_release(env->valpool,var->vs); } free(var); } enum_free(e); stab_clear(env->globals); /* Clear out the frames */ size = vec_size(env->frames); while (--size >= 0) { MotoFrame *frame = (MotoFrame *)vec_get(env->frames, size); stack_free(frame->opstack); stab_free(frame->symtab); buf_free(frame->out); free(frame); } vec_clear(env->frames); e = stack_elements(env->scope); while (enum_hasNext(e)) { free(enum_next(e)); } enum_free(e); stack_clear(env->scope); buf_clear(env->out); buf_clear(env->err); // stab_free(env->types); // ftab_free(env->ftable); // stab_free(env->rxcache); // stack_clear(env->callstack); sset_clear(env->errs); // sset_clear(env->uses); if (env->mode == COMPILER_MODE) { sset_free(env->includes); htab_free(env->fdefs); htab_free(env->adefs); buf_free(env->constantPool); buf_free(env->fcodebuffer); istack_free(env->scopeIDStack); } env->frameindex = -1; /* error stuff */ env->meta.filename = env->filename; env->meta.caller = NULL; env->meta.macroname = NULL; env->meta.lineno = 1; env->errflag = 0; //free(env); }
void stack_clear(Stack *p) { vec_clear(p); }