CAMLprim value PQconndefaults_stub(value __unused v_unit) { CAMLparam0(); CAMLlocal2(v_res, v_el); PQconninfoOption *cios = PQconndefaults(), *p = cios; int i, j, n; while (p->keyword != NULL) p++; n = p - cios; p = cios; v_res = caml_alloc_tuple(n); for (i = 0; i < n; i++, p++) { value v_field; v_el = caml_alloc_small(7, 0); for (j = 0; j < 7; j++) Field(v_el, j) = v_None; Store_field(v_res, i, v_el); v_field = caml_copy_string(p->keyword); Field(v_el, 0) = v_field; if (p->envvar) { v_field = make_some(caml_copy_string(p->envvar)); caml_modify(&Field(v_el, 1), v_field); } if (p->compiled) { v_field = make_some(caml_copy_string(p->compiled)); caml_modify(&Field(v_el, 2), v_field); }; if (p->val) { v_field = make_some(caml_copy_string(p->val)); caml_modify(&Field(v_el, 3), v_field); }; v_field = caml_copy_string(p->label); caml_modify(&Field(v_el, 4), v_field); v_field = caml_copy_string(p->dispchar); caml_modify(&Field(v_el, 5), v_field); caml_modify(&Field(v_el, 6), Val_int(p->dispsize)); }; PQconninfoFree(cios); CAMLreturn(v_res); }
CAMLprim value PQCancel_stub(value v_conn) { CAMLparam1(v_conn); PGconn *conn = get_conn(v_conn); if (conn == NULL) CAMLreturn(v_None); else { PGcancel *cancel = get_cancel_obj(v_conn); char errbuf[256]; int res; caml_enter_blocking_section(); res = PQcancel(cancel, errbuf, 256); caml_leave_blocking_section(); if (res == 0) CAMLreturn(v_None); else CAMLreturn(make_some(caml_copy_string(errbuf))); } }
CAMLprim value PQnotifies_stub(value v_conn) { CAMLparam1(v_conn); CAMLlocal1(v_str); PGnotify *noti = PQnotifies(get_conn(v_conn)); if (noti) { value v_pair; v_str = make_string(noti->relname); v_pair = caml_alloc_small(2, 0); Field(v_pair, 0) = v_str; Field(v_pair, 1) = Val_int(noti->be_pid); PQfreemem(noti); CAMLreturn(make_some(v_pair)); } else CAMLreturn(v_None); }
auto make_some( const F & f, const M & m, const R & r, const REST & ... rest ) { return make_some( f, make_some( m, r, rest ... ) ); }