CAMLprim value PQexecPrepared_stub( value v_conn, value v_stm_name, value v_params, value v_binary_params) { CAMLparam1(v_conn); PGconn *conn = get_conn(v_conn); np_callback *np_cb = get_conn_cb(v_conn); PGresult *res; size_t len = caml_string_length(v_stm_name) + 1; char *stm_name = caml_stat_alloc(len); size_t nparams = Wosize_val(v_params); const char * const *params = copy_params(v_params, nparams); int *formats, *lengths; copy_binary_params(v_params, v_binary_params, nparams, &formats, &lengths); memcpy(stm_name, String_val(v_stm_name), len); caml_enter_blocking_section(); res = PQexecPrepared(conn, stm_name, nparams, params, lengths, formats, 0); free(stm_name); free_binary_params(formats, lengths); free_params(params, nparams); caml_leave_blocking_section(); CAMLreturn(alloc_result(res, np_cb)); #else CAMLprim value PQexecPrepared_stub( value __unused v_conn, value __unused v_stm_name, value __unused v_params, value __unused v_binary_params) { caml_failwith("Postgresql.exec_prepared: not supported"); return Val_unit; #endif }
CAMLprim value PQexecParams_stub( value v_conn, value v_query, value v_params, value v_binary_params) { CAMLparam1(v_conn); PGconn *conn = get_conn(v_conn); np_callback *np_cb = get_conn_cb(v_conn); PGresult *res; size_t len = caml_string_length(v_query) + 1; char *query = caml_stat_alloc(len); size_t nparams = Wosize_val(v_params); const char * const *params = copy_params(v_params, nparams); int *formats, *lengths; copy_binary_params(v_params, v_binary_params, nparams, &formats, &lengths); memcpy(query, String_val(v_query), len); caml_enter_blocking_section(); res = (nparams == 0) ? PQexec(conn, query) : PQexecParams(conn, query, nparams, NULL, params, lengths, formats, 0); free_binary_params(formats, lengths); free_params(params, nparams); free(query); caml_leave_blocking_section(); CAMLreturn(alloc_result(res, np_cb)); }
void ast_translation::mk_sort(sort * s, frame & fr) { sort_info * si = s->get_info(); sort * new_s; if (si == 0) { // TODO: investigate: this branch is probably unreachable. // It became unreachable after we started using mk_uninterpreted_sort for creating uninterpreted sorts, // and mk_uninterpreted_sort actually creates a user_sort. new_s = m_to_manager.mk_uninterpreted_sort(s->get_name()); SASSERT(m_result_stack.size() == fr.m_rpos); } else { buffer<parameter> ps; copy_params(s, fr.m_rpos, ps); new_s = m_to_manager.mk_sort(s->get_name(), sort_info(si->get_family_id(), si->get_decl_kind(), si->get_num_elements(), si->get_num_parameters(), ps.c_ptr(), s->private_parameters())); } m_result_stack.shrink(fr.m_rpos); m_result_stack.push_back(new_s); m_extra_children_stack.shrink(fr.m_cpos); cache(s, new_s); m_frame_stack.pop_back(); }
symbol_t * copy_symbol (symbol_t *symbol) { symbol_t *sym = new_symbol (symbol->name); sym->type = symbol->type; sym->params = copy_params (symbol->params); sym->sy_type = symbol->sy_type; sym->s = symbol->s; return sym; }
sequence_t copy_sequence(sequence_t other){ if(other == NULL){ return NULL; } sequence_t r = new_sequence(other->size); int i = 0; for(;i < other->size; i++){ r->vars[i].index = other->vars[i].index; if(other->vars[i].name){ r->vars[i].name = strdup(other->vars[i].name); } r->vars[i].params = copy_params(other->vars[i].params); } return r; }
struct param *copy_params(struct param *first,struct param *p) { if(p) { struct param *q=malloc(sizeof(struct param)); q->name=p->name; q->inst=p->inst; q->expr=p->expr; if(!first) first=q; q->context=first; q->next=copy_params(first,p->next); return q; } else return 0; }
struct inst *elaborate(struct param *context,char *inst_name,struct param *defparams,struct param *pdp,struct module *m,struct expr *connections,struct inst *mom) { struct inst *i=malloc(sizeof(struct inst)); struct inst *j; struct inst *last=0; i->next=0; i->name=strdup(inst_name); i->module=strdup(m->name); i->mod=m; i->insts=0; i->connections=connections; i->decls=0; i->mom=mom; // Copy parameters from module (list of params is its own context). i->params=copy_params(NULL,m->params); // Apply defparams apply_defparams(i->params,inst_name,context,defparams); // Apply positional defparams apply_positional(i->params,context,pdp); // Evaluate parameters simp_params(i->params); // Copy and simplify declarations i->decls=copy_decls(i->params,m->decls); // Recurse for(j=i->mod->insts;j;j=j->next) if(j->mod) { struct inst *q=elaborate(i->params,j->name,m->defparams,j->pos_defparams,j->mod,j->connections,i); if(i->insts) { last->next=q; last=q; } else last=i->insts=q; } return i; }
void ast_translation::mk_func_decl(func_decl * f, frame & fr) { func_decl_info * fi = f->get_info(); SASSERT(fr.m_cpos <= m_extra_children_stack.size()); unsigned num_extra = m_extra_children_stack.size() - fr.m_cpos; sort ** new_domain = reinterpret_cast<sort**>(m_result_stack.c_ptr() + fr.m_rpos + num_extra); sort * new_range = static_cast<sort*>(m_result_stack.back()); func_decl * new_f; if (fi == 0) { new_f = m_to_manager.mk_func_decl(f->get_name(), f->get_arity(), new_domain, new_range); } else { buffer<parameter> ps; copy_params(f, fr.m_rpos, ps); func_decl_info new_fi(fi->get_family_id(), fi->get_decl_kind(), fi->get_num_parameters(), ps.c_ptr()); new_fi.set_left_associative(fi->is_left_associative()); new_fi.set_right_associative(fi->is_right_associative()); new_fi.set_flat_associative(fi->is_flat_associative()); new_fi.set_commutative(fi->is_commutative()); new_fi.set_chainable(fi->is_chainable()); new_fi.set_pairwise(fi->is_pairwise()); new_fi.set_injective(fi->is_injective()); new_fi.set_skolem(fi->is_skolem()); new_fi.set_idempotent(fi->is_idempotent()); new_f = m_to_manager.mk_func_decl(f->get_name(), f->get_arity(), new_domain, new_range, new_fi); } TRACE("ast_translation", tout << f->get_name() << " "; if (fi) tout << *fi; tout << "\n"; tout << "---->\n"; tout << new_f->get_name() << " "; if (new_f->get_info()) tout << *(new_f->get_info()); tout << "\n";);