Pg: Support custom type overrides with callbacks
This commit is contained in:
parent
327fd9ea50
commit
4686097d00
6 changed files with 227 additions and 85 deletions
49
c/pgtypes.c
49
c/pgtypes.c
|
|
@ -32,6 +32,7 @@ struct fupg_tio {
|
|||
const fupg_record *info;
|
||||
fupg_tio *tio;
|
||||
} record;
|
||||
SV *cb;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -416,6 +417,52 @@ SENDFN(record) {
|
|||
}
|
||||
|
||||
|
||||
RECVFN(perlcb) {
|
||||
dSP;
|
||||
|
||||
ENTER;
|
||||
SAVETMPS;
|
||||
|
||||
PUSHMARK(SP);
|
||||
mXPUSHs(newSVpvn(buf, len));
|
||||
PUTBACK;
|
||||
call_sv(ctx->cb, G_SCALAR);
|
||||
SPAGAIN;
|
||||
|
||||
SV *ret = newSV(0);
|
||||
sv_setsv(ret, POPs);
|
||||
PUTBACK;
|
||||
|
||||
FREETMPS;
|
||||
LEAVE;
|
||||
return ret;
|
||||
}
|
||||
|
||||
SENDFN(perlcb) {
|
||||
dSP;
|
||||
|
||||
ENTER;
|
||||
SAVETMPS;
|
||||
|
||||
PUSHMARK(SP);
|
||||
XPUSHs(val);
|
||||
|
||||
PUTBACK;
|
||||
call_sv(ctx->cb, G_SCALAR);
|
||||
SPAGAIN;
|
||||
|
||||
SV *ret = POPs;
|
||||
PUTBACK;
|
||||
|
||||
STRLEN len;
|
||||
const char *buf = SvPV(ret, len);
|
||||
fustr_write(out, buf, len);
|
||||
|
||||
FREETMPS;
|
||||
LEAVE;
|
||||
}
|
||||
|
||||
|
||||
RECVFN(inet) { /* Also works for cidr */
|
||||
char tmp[128];
|
||||
if (len < 8) RERR("input data too short");
|
||||
|
|
@ -726,6 +773,8 @@ static const fupg_type fupg_builtin[] = {
|
|||
|
||||
#define FUPG_BUILTIN (sizeof(fupg_builtin) / sizeof(fupg_type))
|
||||
|
||||
static const fupg_type fupg_type_perlcb = { 0, 0, {"$perl_cb"}, fupg_send_perlcb, fupg_recv_perlcb };
|
||||
|
||||
|
||||
static const fupg_type *fupg_type_byoid(const fupg_type *list, int len, Oid oid) {
|
||||
int i, b = 0, e = len-1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue