/* 0 on success, nonzero on error */ int check_types(struct lp_block *b) { int c = 0; /* we'll do all of the type checking here so that * the per-mod loaders only have to sanitize values */ for(c = 0; c < b->params_len; c++) { if(b->params[c]) { if(lp_param_name(b->type, b->params[c]->name) == -1) { fprintf(stderr, "*** warning: parameter %s not valid in context %s\n", b->params[c]->name, lp_modules[b->type]->name); } else if(lp_modules[b->type]->modvars[lp_param_name(b->type, b->params[c]->name)].type != PTYPE(b->params[c])) { /* implicitly convert ints to doubles */ if((lp_modules[b->type]->modvars[lp_param_name(b->type, b->params[c]->name)].type == D) && (PTYPE(b->params[c]) == I)) { b->params[c]->v->t = D; DVAL(b->params[c]) = (double) IVAL(b->params[c]); } else { fprintf(stderr, "*** error: type error: %s::\"%s\" cannot take type ", lp_modules[b->type]->name, b->params[c]->name); /* unparse_type(PTYPE(b->params[c]), stderr); */ fprintf(stderr, "\n"); die("check_types() failed"); } } if(PTYPE(b->params[c]) >= BLOCK) { check_types(BVAL(b->params[c])); } else if(PTYPE(b->params[c]) == LIST) { int d; struct lp_list *l = LVAL(b->params[c]); for(d = 0; d < l->values_len; d++) { if(l->values[d]) { if(l->values[d]->t >= BLOCK) { check_types(l->values[d]->v.b); } } } } } } return 0; }
int main(/*@unused@*/ int argc, /*@unused@*/ char **argv) { (void)argc; (void)argv; printf ("#include <sys/types.h>\n" "#include <time.h>\n" "#include <stddef.h>\n\n" "#include \"PCSC/pcsclite.h\"\n" "#include \"pcscd.h\"\n" "#include \"readerfactory.h\"\n" "#include \"eventhandler.h\"\n" "#include \"winscard_msg.h\"\n\n" "#include \"lassert.h\"\n\n" "int pcsc_assert_wire_constants(void);\n" "int pcsc_assert_wire_constants(void)\n" "{\n"); BLANK_LINE (); check_constants (); check_types (); BLANK_LINE (); printf ("return 0;\n"); printf ("}\n"); return 0; }
PRIVATE void project_fun(def d1, def d2, env v, tree cxt) { if (d2 == NULL) return; if (d1 != NULL) check_types(d1->d_type, d2->d_type, d1->d_name, cxt, cxt->x_loc); push_def(d2, v); }
/* instantiate a component with overrides * tname type to instantiate, * cname name of instantiated component * loader is the module loader function for tname */ int *lp_override_inst(struct lp_block *spec, char *cname, lp_modloader_t loader, char **overrides, int overrides_len) { int c, d; struct lp_block *spec_copy; char *p1, *p2; int *result; spec_copy = copy_block(spec); for(c = 0; c < overrides_len; c += 3) { if(range_match(overrides[c], cname)) { /* overrides[c+2] could be an int, a real, a string or a list or * a block. need parser to deal with lists and blocks * reasonably so we aren't going to deal with them here */ if(!dumb_split2(overrides[c+1], &p1, &p2)) { /* descend hierarchy */ for(d = 0; d < spec_copy->params_len; d++) { if(!spec_copy->params[d]) continue; if(!strcmp(p1, spec_copy->params[d]->name)) { if(spec_copy->params[d]->v->t != BLOCK) { fprintf(stderr, "*** error: tried to recurse through non-block parameter.\n"); return 0; } else { param_override(spec_copy->params[d]->v->v.b, p2, overrides[c+2]); } } } } else { param_override(spec_copy, overrides[c+1], overrides[c+2]); } } } if(!check_types(spec_copy)) { result = loader(spec_copy, 0); } // XXX don't leak (segfaults) // destroy_block(spec_copy); return result; }
PRIVATE void and_fun(def d1, def d2, env v, tree cxt) { if (d1 == NULL) push_def(d2, v); else if (d2 == NULL) push_def(d1, v); else { (void) check_types(d1->d_type, d2->d_type, d1->d_name, cxt, cxt->x_loc); push_def(d1, v); } }
PRIVATE void implies_fun(def d1, def d2, env v, tree cxt) { if (d1 == NULL) { d2->d_type = super_expand(d2->d_type, arid); push_def(d2, v); } else { if (d2 != NULL) (void) check_types(d1->d_type, d2->d_type, d1->d_name, cxt, cxt->x_loc); d1->d_type = super_expand(d1->d_type, arid); push_def(d1, v); } }
PRIVATE void or_fun(def d1, def d2, env v, tree cxt) { if (d1 == NULL) { d2->d_type = super_expand(d2->d_type, arid); push_def(d2, v); } else if (d2 == NULL) { d1->d_type = super_expand(d1->d_type, arid); push_def(d1, v); } else { if (check_types(d1->d_type, d2->d_type, d1->d_name, cxt, cxt->x_loc)) d1->d_type = type_union(d1->d_type, arid, d2->d_type, arid); push_def(d1, v); } }
int check_types_nativeptr() { void *ptr = (void *) 0xdead; return check_types(ptr); }
int pg_cmd(db_cmd_t* cmd) { struct pg_cmd* pcmd; pcmd = (struct pg_cmd*)pkg_malloc(sizeof(struct pg_cmd)); if (pcmd == NULL) { ERR("postgres: No memory left\n"); goto error; } memset(pcmd, '\0', sizeof(struct pg_cmd)); if (db_drv_init(&pcmd->gen, pg_cmd_free) < 0) goto error; switch(cmd->type) { case DB_PUT: if (build_insert_sql(&pcmd->sql_cmd, cmd) < 0) goto error; break; case DB_DEL: if (build_delete_sql(&pcmd->sql_cmd, cmd) < 0) goto error; break; case DB_GET: if (build_select_sql(&pcmd->sql_cmd, cmd) < 0) goto error; break; case DB_UPD: if (build_update_sql(&pcmd->sql_cmd, cmd) < 0) goto error; break; case DB_SQL: pcmd->sql_cmd.s = (char*)pkg_malloc(cmd->table.len + 1); if (pcmd->sql_cmd.s == NULL) { ERR("postgres: Out of private memory\n"); goto error; } memcpy(pcmd->sql_cmd.s,cmd->table.s, cmd->table.len); pcmd->sql_cmd.s[cmd->table.len] = '\0'; pcmd->sql_cmd.len = cmd->table.len; break; } DB_SET_PAYLOAD(cmd, pcmd); /* Create parameter arrays for PostgreSQL API functions */ if (create_pg_params(cmd) < 0) goto error; /* Generate a unique name for the command on the server */ if (gen_cmd_name(cmd) != 0) goto error; /* Upload the command to the server */ if (upload_cmd(cmd) != 0) goto error; /* Obtain the description of the uploaded command, this includes * information about result and parameter fields */ if (get_types(cmd) != 0) goto error; /* Update fields based on the information retrieved from the */ if (pg_resolve_param_oids(cmd->vals, cmd->match, cmd->vals_count, cmd->match_count, pcmd->types)) goto error; if (pg_resolve_result_oids(cmd->result, cmd->result_count, pcmd->types)) goto error; if (check_types(cmd)) goto error; return 0; error: if (pcmd) { DB_SET_PAYLOAD(cmd, NULL); free_pg_params(&pcmd->params); if (pcmd->types) PQclear(pcmd->types); if (pcmd->name) pkg_free(pcmd->name); if (pcmd->sql_cmd.s) pkg_free(pcmd->sql_cmd.s); db_drv_free(&pcmd->gen); pkg_free(pcmd); } return -1; }
void init_membed(FILE *fplog, gmx_membed_t *membed, int nfile, const t_filenm fnm[], gmx_mtop_t *mtop, t_inputrec *inputrec, t_state *state, t_commrec *cr,real *cpt) { char *ins; int i,rm_bonded_at,fr_id,fr_i=0,tmp_id,warn=0; int ng,j,max_lip_rm,ins_grp_id,ins_nat,mem_nat,ntype,lip_rm,tpr_version; real prot_area; rvec *r_ins=NULL; t_block *ins_at,*rest_at; pos_ins_t *pos_ins; mem_t *mem_p; rm_t *rm_p; gmx_groups_t *groups; gmx_bool bExcl=FALSE; t_atoms atoms; t_pbc *pbc; char **piecename=NULL; /* input variables */ const char *membed_input; real xy_fac = 0.5; real xy_max = 1.0; real z_fac = 1.0; real z_max = 1.0; int it_xy = 1000; int it_z = 0; real probe_rad = 0.22; int low_up_rm = 0; int maxwarn=0; int pieces=1; gmx_bool bALLOW_ASYMMETRY=FALSE; snew(ins_at,1); snew(pos_ins,1); if(MASTER(cr)) { /* get input data out membed file */ membed_input = opt2fn("-membed",nfile,fnm); get_input(membed_input,&xy_fac,&xy_max,&z_fac,&z_max,&it_xy,&it_z,&probe_rad,&low_up_rm,&maxwarn,&pieces,&bALLOW_ASYMMETRY); tpr_version = get_tpr_version(ftp2fn(efTPX,nfile,fnm)); if (tpr_version<58) gmx_fatal(FARGS,"Version of *.tpr file to old (%d). Rerun grompp with gromacs VERSION 4.0.3 or newer.\n",tpr_version); if( !EI_DYNAMICS(inputrec->eI) ) gmx_input("Change integrator to a dynamics integrator in mdp file (e.g. md or sd)."); if(PAR(cr)) gmx_input("Sorry, parallel g_membed is not yet fully functional."); #ifdef GMX_OPENMM gmx_input("Sorry, g_membed does not work with openmm."); #endif if(*cpt>=0) { fprintf(stderr,"\nSetting -cpt to -1, because embedding cannot be restarted from cpt-files.\n"); *cpt=-1; } groups=&(mtop->groups); atoms=gmx_mtop_global_atoms(mtop); snew(mem_p,1); fprintf(stderr,"\nSelect a group to embed in the membrane:\n"); get_index(&atoms,opt2fn_null("-mn",nfile,fnm),1,&(ins_at->nr),&(ins_at->index),&ins); ins_grp_id = search_string(ins,groups->ngrpname,(groups->grpname)); fprintf(stderr,"\nSelect a group to embed %s into (e.g. the membrane):\n",ins); get_index(&atoms,opt2fn_null("-mn",nfile,fnm),1,&(mem_p->mem_at.nr),&(mem_p->mem_at.index),&(mem_p->name)); pos_ins->pieces=pieces; snew(pos_ins->nidx,pieces); snew(pos_ins->subindex,pieces); snew(piecename,pieces); if (pieces>1) { fprintf(stderr,"\nSelect pieces to embed:\n"); get_index(&atoms,opt2fn_null("-mn",nfile,fnm),pieces,pos_ins->nidx,pos_ins->subindex,piecename); } else { /*use whole embedded group*/ snew(pos_ins->nidx,1); snew(pos_ins->subindex,1); pos_ins->nidx[0]=ins_at->nr; pos_ins->subindex[0]=ins_at->index; } if(probe_rad<0.2199999) { warn++; fprintf(stderr,"\nWarning %d:\nA probe radius (-rad) smaller than 0.2 can result in overlap between waters " "and the group to embed, which will result in Lincs errors etc.\nIf you are sure, you can increase maxwarn.\n\n",warn); } if(xy_fac<0.09999999) { warn++; fprintf(stderr,"\nWarning %d:\nThe initial size of %s is probably too smal.\n" "If you are sure, you can increase maxwarn.\n\n",warn,ins); } if(it_xy<1000) { warn++; fprintf(stderr,"\nWarning %d;\nThe number of steps used to grow the xy-coordinates of %s (%d) is probably too small.\n" "Increase -nxy or, if you are sure, you can increase maxwarn.\n\n",warn,ins,it_xy); } if( (it_z<100) && ( z_fac<0.99999999 || z_fac>1.0000001) ) { warn++; fprintf(stderr,"\nWarning %d;\nThe number of steps used to grow the z-coordinate of %s (%d) is probably too small.\n" "Increase -nz or, if you are sure, you can increase maxwarn.\n\n",warn,ins,it_z); } if(it_xy+it_z>inputrec->nsteps) { warn++; fprintf(stderr,"\nWarning %d:\nThe number of growth steps (-nxy + -nz) is larger than the number of steps in the tpr.\n" "If you are sure, you can increase maxwarn.\n\n",warn); } fr_id=-1; if( inputrec->opts.ngfrz==1) gmx_fatal(FARGS,"You did not specify \"%s\" as a freezegroup.",ins); for(i=0;i<inputrec->opts.ngfrz;i++) { tmp_id = mtop->groups.grps[egcFREEZE].nm_ind[i]; if(ins_grp_id==tmp_id) { fr_id=tmp_id; fr_i=i; } } if (fr_id == -1 ) gmx_fatal(FARGS,"\"%s\" not as freezegroup defined in the mdp-file.",ins); for(i=0;i<DIM;i++) if( inputrec->opts.nFreeze[fr_i][i] != 1) gmx_fatal(FARGS,"freeze dimensions for %s are not Y Y Y\n",ins); ng = groups->grps[egcENER].nr; if (ng == 1) gmx_input("No energy groups defined. This is necessary for energy exclusion in the freeze group"); for(i=0;i<ng;i++) { for(j=0;j<ng;j++) { if (inputrec->opts.egp_flags[ng*i+j] == EGP_EXCL) { bExcl = TRUE; if ( (groups->grps[egcENER].nm_ind[i] != ins_grp_id) || (groups->grps[egcENER].nm_ind[j] != ins_grp_id) ) gmx_fatal(FARGS,"Energy exclusions \"%s\" and \"%s\" do not match the group to embed \"%s\"", *groups->grpname[groups->grps[egcENER].nm_ind[i]], *groups->grpname[groups->grps[egcENER].nm_ind[j]],ins); } } } if (!bExcl) gmx_input("No energy exclusion groups defined. This is necessary for energy exclusion in the freeze group"); /* Guess the area the protein will occupy in the membrane plane Calculate area per lipid*/ snew(rest_at,1); ins_nat = init_ins_at(ins_at,rest_at,state,pos_ins,groups,ins_grp_id,xy_max); /* Check moleculetypes in insertion group */ check_types(ins_at,rest_at,mtop); mem_nat = init_mem_at(mem_p,mtop,state->x,state->box,pos_ins); prot_area = est_prot_area(pos_ins,state->x,ins_at,mem_p); if ( (prot_area>7.5) && ( (state->box[XX][XX]*state->box[YY][YY]-state->box[XX][YY]*state->box[YY][XX])<50) ) { warn++; fprintf(stderr,"\nWarning %d:\nThe xy-area is very small compared to the area of the protein.\n" "This might cause pressure problems during the growth phase. Just try with\n" "current setup (-maxwarn + 1), but if pressure problems occur, lower the\n" "compressibility in the mdp-file or use no pressure coupling at all.\n\n",warn); } if(warn>maxwarn) gmx_fatal(FARGS,"Too many warnings.\n"); printf("The estimated area of the protein in the membrane is %.3f nm^2\n",prot_area); printf("\nThere are %d lipids in the membrane part that overlaps the protein.\nThe area per lipid is %.4f nm^2.\n",mem_p->nmol,mem_p->lip_area); /* Maximum number of lipids to be removed*/ max_lip_rm=(int)(2*prot_area/mem_p->lip_area); printf("Maximum number of lipids that will be removed is %d.\n",max_lip_rm); printf("\nWill resize the protein by a factor of %.3f in the xy plane and %.3f in the z direction.\n" "This resizing will be done with respect to the geometrical center of all protein atoms\n" "that span the membrane region, i.e. z between %.3f and %.3f\n\n",xy_fac,z_fac,mem_p->zmin,mem_p->zmax); /* resize the protein by xy and by z if necessary*/ snew(r_ins,ins_at->nr); init_resize(ins_at,r_ins,pos_ins,mem_p,state->x,bALLOW_ASYMMETRY); membed->fac[0]=membed->fac[1]=xy_fac; membed->fac[2]=z_fac; membed->xy_step =(xy_max-xy_fac)/(double)(it_xy); membed->z_step =(z_max-z_fac)/(double)(it_z-1); resize(r_ins,state->x,pos_ins,membed->fac); /* remove overlapping lipids and water from the membrane box*/ /*mark molecules to be removed*/ snew(pbc,1); set_pbc(pbc,inputrec->ePBC,state->box); snew(rm_p,1); lip_rm = gen_rm_list(rm_p,ins_at,rest_at,pbc,mtop,state->x, r_ins, mem_p,pos_ins,probe_rad,low_up_rm,bALLOW_ASYMMETRY); lip_rm -= low_up_rm; if(fplog) for(i=0;i<rm_p->nr;i++) fprintf(fplog,"rm mol %d\n",rm_p->mol[i]); for(i=0;i<mtop->nmolblock;i++) { ntype=0; for(j=0;j<rm_p->nr;j++) if(rm_p->block[j]==i) ntype++; printf("Will remove %d %s molecules\n",ntype,*(mtop->moltype[mtop->molblock[i].type].name)); } if(lip_rm>max_lip_rm) { warn++; fprintf(stderr,"\nWarning %d:\nTrying to remove a larger lipid area than the estimated protein area\n" "Try making the -xyinit resize factor smaller.\n\n",warn); } /*remove all lipids and waters overlapping and update all important structures*/ rm_group(inputrec,groups,mtop,rm_p,state,ins_at,pos_ins); rm_bonded_at = rm_bonded(ins_at,mtop); if (rm_bonded_at != ins_at->nr) { fprintf(stderr,"Warning: The number of atoms for which the bonded interactions are removed is %d, " "while %d atoms are embedded. Make sure that the atoms to be embedded are not in the same" "molecule type as atoms that are not to be embedded.\n",rm_bonded_at,ins_at->nr); } if(warn>maxwarn) gmx_fatal(FARGS,"Too many warnings.\nIf you are sure these warnings are harmless, you can increase -maxwarn"); if (ftp2bSet(efTOP,nfile,fnm)) top_update(opt2fn("-mp",nfile,fnm),ins,rm_p,mtop); sfree(pbc); sfree(rest_at); if (pieces>1) { sfree(piecename); } membed->it_xy=it_xy; membed->it_z=it_z; membed->pos_ins=pos_ins; membed->r_ins=r_ins; } }
void complete_test(std::vector<T1> data1,std::list<T2> data2){ typedef CGAL::Dispatch_output_iterator< CGAL::cpp11::tuple<T1,T2 >,CGAL::cpp11::tuple< T1*,std::back_insert_iterator<std::vector<T2> > > > Dispatcher; typedef CGAL::Dispatch_or_drop_output_iterator< CGAL::cpp11::tuple<T1,T2 >,CGAL::cpp11::tuple< T1*,std::back_insert_iterator<std::vector<T2> > > > Dropper; assert(data1.size()==4); T1 cont_1[6]; std::vector<T2> cont_2; Dispatcher disp=CGAL::dispatch_output<T1,T2>( cont_1,std::back_inserter(cont_2) ); Dropper drop=CGAL::dispatch_or_drop_output<T1,T2>( cont_1,std::back_inserter(cont_2) ); assert( (CGAL::Is_in_tuple<T1,typename Dispatcher::Value_type_tuple >::value) ); assert( (CGAL::Is_in_tuple<T2,typename Dispatcher::Value_type_tuple >::value) ); assert( (!CGAL::Is_in_tuple<A,typename Dispatcher::Value_type_tuple >::value) ); assert( (CGAL::Is_in_tuple<T1,typename Dropper::Value_type_tuple >::value) ); assert( (CGAL::Is_in_tuple<T2,typename Dropper::Value_type_tuple >::value) ); assert( (!CGAL::Is_in_tuple<A,typename Dropper::Value_type_tuple >::value) ); std::copy(data1.begin(),data1.end(),disp); std::copy(data2.begin(),data2.end(),disp); assert(cont_2.size()==data2.size()); for (int i=0;i<4;++i) assert(data1[i]==cont_1[i]); std::copy(data1.begin(),data1.end(),drop); std::copy(data2.begin(),data2.end(),drop); *drop++=A(); assert(cont_2.size()==2 * data2.size()); for (int i=0;i<4;++i) assert(data1[i]==cont_1[i]); check_types(disp); check_types(drop); disp = disp; drop = drop; std::back_insert_iterator<std::vector<T2> > bck_ins(cont_2); T1* d; CGAL::cpp11::tie(d, bck_ins) = disp; CGAL::cpp11::tie(d, bck_ins) = drop; //testing putting the tuple directly CGAL::cpp11::tuple<T1,T2> tuple = CGAL::cpp11::make_tuple(*data1.begin(), *data2.begin()); *disp++ = tuple; assert(cont_2.size()==2 * data2.size()+1); *drop++ = tuple; assert(cont_2.size()==2 * data2.size()+2); }