563 lines
18 KiB
C
563 lines
18 KiB
C
typedef struct fupg_send fupg_send;
|
|
typedef struct fupg_recv fupg_recv;
|
|
|
|
/* Send function, takes a Perl value and should write the binary encoded
|
|
* format into the given fustr. */
|
|
typedef void (*fupg_send_fn)(pTHX_ const fupg_send *, SV *, fustr *);
|
|
|
|
/* Receive function, takes a binary string and should return a Perl value.
|
|
* libpq guarantees that the given buffer is aligned to MAXIMUM_ALIGNOF.
|
|
*/
|
|
typedef SV *(*fupg_recv_fn)(pTHX_ const fupg_recv *, const char *, int);
|
|
|
|
struct fupg_send {
|
|
Oid oid;
|
|
const char *name;
|
|
fupg_send_fn fn;
|
|
union {
|
|
fupg_send *arrayelem;
|
|
};
|
|
};
|
|
|
|
struct fupg_recv {
|
|
Oid oid;
|
|
const char *name;
|
|
fupg_recv_fn fn;
|
|
union {
|
|
fupg_recv *arrayelem;
|
|
};
|
|
};
|
|
|
|
typedef struct {
|
|
Oid oid;
|
|
Oid elemoid; /* For arrays */
|
|
char name[64];
|
|
fupg_send_fn send;
|
|
fupg_recv_fn recv;
|
|
} fupg_type;
|
|
|
|
|
|
|
|
#define RECVFN(name) static SV *fupg_recv_##name(pTHX_ const fupg_recv *ctx __attribute__((unused)), const char *buf, int len)
|
|
#define SENDFN(name) static void fupg_send_##name(pTHX_ const fupg_send *ctx __attribute__((unused)), SV *val, fustr *out)
|
|
#define RLEN(l) if (l != len) fu_confess("Invalid length for type '%s' (oid %u), expected %d but got %d", ctx->name, ctx->oid, l, len)
|
|
|
|
/* Perl likes to play loose with SV-to-integer conversions, but that's not
|
|
* very fun when trying to store values in a database. Text-based bind
|
|
* parameters get stricter validation by Postgres, so let's emulate some of
|
|
* that for binary parameters as well. */
|
|
#define SIV(min, max) IV iv;\
|
|
if (SvIOK(val)) iv = SvIV(val); \
|
|
else if (SvNOK(val)) { \
|
|
NV nv = SvNV(val); \
|
|
if (nv < IV_MIN || nv > IV_MAX || fabs(nv - floor(nv)) > 0.0000000001) \
|
|
fu_confess("Type '%s' (oid %u) expects an integer but got a floating point", ctx->name, ctx->oid); \
|
|
iv = SvIV(val); \
|
|
} else if (SvPOK(val)) {\
|
|
STRLEN sl; \
|
|
UV uv; \
|
|
char *s = SvPV(val, sl); \
|
|
if (*s == '-' && grok_atoUV(s+1, &uv, NULL) && uv <= ((UV)IV_MAX)+1) iv = SvIV(val);\
|
|
else if (grok_atoUV(s, &uv, NULL) && uv <= IV_MAX) iv = SvIV(val);\
|
|
else fu_confess("Type '%s' (oid %u) expects an integer", ctx->name, ctx->oid); \
|
|
} else fu_confess("Type '%s' (oid %u) expects an integer", ctx->name, ctx->oid);\
|
|
if (iv < min || iv > max) fu_confess("Integer %"IVdf" out of range for type '%s' (oid %u)", iv, ctx->name, ctx->oid)
|
|
|
|
|
|
RECVFN(bool) {
|
|
RLEN(1);
|
|
return *buf ? &PL_sv_yes : &PL_sv_no;
|
|
}
|
|
|
|
SENDFN(bool) {
|
|
fustr_write_ch(out, SvTRUE(val) ? 1 : 0);
|
|
}
|
|
|
|
RECVFN(int2) {
|
|
RLEN(2);
|
|
return newSViv((I16)__builtin_bswap16(*((U16 *)buf)));
|
|
}
|
|
|
|
SENDFN(int2) {
|
|
SIV(-32768, 32767);
|
|
U16 v = __builtin_bswap16((U16)iv);
|
|
fustr_write(out, (const char *)&v, 2);
|
|
}
|
|
|
|
RECVFN(int4) {
|
|
RLEN(4);
|
|
return newSViv((I32)__builtin_bswap32(*((U32 *)buf)));
|
|
}
|
|
|
|
SENDFN(int4) {
|
|
SIV(-2147483648, 2147483647);
|
|
U32 v = __builtin_bswap32((U32)iv);
|
|
fustr_write(out, (const char *)&v, 4);
|
|
}
|
|
|
|
RECVFN(int8) {
|
|
RLEN(8);
|
|
return newSViv((I64)__builtin_bswap64(*((U64 *)buf)));
|
|
}
|
|
|
|
SENDFN(int8) {
|
|
SIV(IV_MIN, IV_MAX);
|
|
U64 v = __builtin_bswap64((U64)SvIV(val));
|
|
fustr_write(out, (const char *)&v, 8);
|
|
}
|
|
|
|
RECVFN(uint4) {
|
|
RLEN(4);
|
|
return newSViv(__builtin_bswap32(*((U32 *)buf)));
|
|
}
|
|
|
|
SENDFN(uint4) {
|
|
SIV(0, UINT32_MAX);
|
|
U32 v = __builtin_bswap32((U32)iv);
|
|
fustr_write(out, (const char *)&v, 4);
|
|
}
|
|
|
|
RECVFN(bytea) {
|
|
return newSVpvn(buf, len);
|
|
}
|
|
|
|
SENDFN(bytea) {
|
|
STRLEN len;
|
|
const char *buf = SvPVbyte(val, len);
|
|
fustr_write(out, buf, len);
|
|
}
|
|
|
|
RECVFN(char) {
|
|
RLEN(1);
|
|
return newSVpvn(buf, len);
|
|
}
|
|
|
|
SENDFN(char) {
|
|
STRLEN len;
|
|
const char *buf = SvPVbyte(val, len);
|
|
if (len != 1) fu_confess("Type '%s' (oid %u) expects a 1-byte string", ctx->name, ctx->oid);
|
|
fustr_write(out, buf, len);
|
|
}
|
|
|
|
/* Works for many text-based column types, including receiving any value in the text format */
|
|
RECVFN(text) {
|
|
if (!is_c9strict_utf8_string((const U8*)buf, len))
|
|
fu_confess("Received invalid UTF-8 for type '%s' (oid %u)", ctx->name, ctx->oid);
|
|
return newSVpvn_utf8(buf, len, 1);
|
|
}
|
|
|
|
SENDFN(text) {
|
|
STRLEN len;
|
|
const char *buf = SvPVutf8(val, len);
|
|
fustr_write(out, buf, len);
|
|
}
|
|
|
|
RECVFN(float4) {
|
|
RLEN(4);
|
|
U32 uv = __builtin_bswap32(*((U32 *)buf));
|
|
float r;
|
|
memcpy(&r, &uv, 4);
|
|
return newSVnv(r);
|
|
}
|
|
|
|
SENDFN(float4) {
|
|
if (!looks_like_number(val)) fu_confess("Type '%s' (oid %u) expects a number", ctx->name, ctx->oid);
|
|
float r = SvNV(val);
|
|
U32 uv;
|
|
memcpy(&uv, &r, 4);
|
|
uv = __builtin_bswap32(uv);
|
|
fustr_write(out, (const char *)&uv, 4);
|
|
}
|
|
|
|
RECVFN(float8) {
|
|
RLEN(8);
|
|
U64 uv = __builtin_bswap64(*((U64 *)buf));
|
|
double r;
|
|
memcpy(&r, &uv, 8);
|
|
return newSVnv(r);
|
|
}
|
|
|
|
SENDFN(float8) {
|
|
if (!looks_like_number(val)) fu_confess("Type '%s' (oid %u) expects a number", ctx->name, ctx->oid);
|
|
double r = SvNV(val);
|
|
U64 uv;
|
|
memcpy(&uv, &r, 8);
|
|
uv = __builtin_bswap64(uv);
|
|
fustr_write(out, (const char *)&uv, 8);
|
|
}
|
|
|
|
RECVFN(json) {
|
|
fujson_parse_ctx json = {
|
|
.buf = (const unsigned char *)buf,
|
|
.end = (const unsigned char *)buf + len,
|
|
.depth = 512
|
|
};
|
|
SV *sv = fujson_parse(aTHX_ &json);
|
|
if (sv == NULL) fu_confess("Received invalid JSON for type '%s' (oid %u)", ctx->name, ctx->oid);
|
|
if (json.buf != json.end) fu_confess("Received invalid JSON for type '%s' (oid %u)", ctx->name, ctx->oid);
|
|
return sv;
|
|
}
|
|
|
|
SENDFN(json) {
|
|
fujson_fmt_ctx json = { .out = out, .depth = 512, .canon = 1, .pretty = 0 };
|
|
fujson_fmt(aTHX_ &json, val);
|
|
}
|
|
|
|
RECVFN(jsonb) {
|
|
if (len <= 1 || *buf != 1) fu_confess("Unexpected format for type '%s' (oid %u)", ctx->name, ctx->oid);
|
|
return fupg_recv_json(aTHX_ ctx, buf+1, len-1);
|
|
}
|
|
|
|
SENDFN(jsonb) {
|
|
fustr_write_ch(out, 1);
|
|
fupg_send_json(aTHX_ ctx, val, out);
|
|
}
|
|
|
|
RECVFN(jsonpath) {
|
|
if (len <= 1 || *buf != 1) fu_confess("Unexpected format for type '%s' (oid %u)", ctx->name, ctx->oid);
|
|
return fupg_recv_text(aTHX_ ctx, buf+1, len-1);
|
|
}
|
|
|
|
SENDFN(jsonpath) {
|
|
fustr_write_ch(out, 1);
|
|
fupg_send_text(aTHX_ ctx, val, out);
|
|
}
|
|
|
|
|
|
#define ARRAY_MAXDIM 100
|
|
|
|
static SV *fupg_recv_array_elem(pTHX_ const fupg_recv *elem, U32 *header, U32 dim, U32 ndim, const char **buf, int *buflen) {
|
|
SV *r;
|
|
if (dim == ndim) {
|
|
if (*buflen < 4) fu_confess("Invalid array format");
|
|
U32 len;
|
|
memcpy(&len, *buf, 4); /* Buffer is not necessarily aligned at this point */
|
|
len = __builtin_bswap32(len);
|
|
*buf += 4;
|
|
*buflen -= 4;
|
|
|
|
r = &PL_sv_undef;
|
|
if (len != (U32)-1) {
|
|
if ((U32)*buflen < len) fu_confess("Invalid array format");
|
|
r = elem->fn(aTHX_ elem, *buf, len);
|
|
*buf += len;
|
|
*buflen -= len;
|
|
}
|
|
|
|
} else {
|
|
U32 n = __builtin_bswap32(header[dim*2]);
|
|
AV *av = newAV_alloc_x(n);
|
|
r = sv_2mortal(newRV_noinc((SV *)av));
|
|
U32 i;
|
|
for (i=0; i<n; i++)
|
|
av_push_simple(av, fupg_recv_array_elem(aTHX_ elem, header, dim+1, ndim, buf, buflen));
|
|
SvREFCNT_inc(r); /* We're done here, make sure it survives the mortal stack cleanup */
|
|
}
|
|
return r;
|
|
}
|
|
|
|
RECVFN(array) {
|
|
if (len < 12) fu_confess("Invalid array format for type '%s' (oid %u)", ctx->name, ctx->oid);
|
|
U32 *header = (U32 *)buf;
|
|
U32 ndim = __builtin_bswap32(header[0]);
|
|
// header[1] is hasnull, can safely ignore
|
|
Oid elemtype = __builtin_bswap32(header[2]);
|
|
if (elemtype != ctx->arrayelem->oid)
|
|
fu_confess("Array type '%s' (oid %u) expected elements of type %u but got %u", ctx->name, ctx->oid, ctx->arrayelem->oid, elemtype);
|
|
|
|
if (ndim == 0) return newRV_noinc((SV *)newAV());
|
|
if (ndim > ARRAY_MAXDIM) fu_confess("Array value of type '%s' (oid %u) has too many dimensions (%d)", ctx->name, ctx->oid, ndim);
|
|
if ((U32)len < 12 + ndim*8) fu_confess("Invalid array format for type '%s' (oid %u)", ctx->name, ctx->oid);
|
|
|
|
buf += 12 + ndim * 8;
|
|
len -= 12 + ndim * 8;
|
|
header = header + 3;
|
|
|
|
/* Arrays need to be created as temporaries so that they are cleaned up
|
|
* when the elem recv function croaks. Their refcnt is increased on
|
|
* successful return. */
|
|
ENTER;
|
|
SAVETMPS;
|
|
SV *r = fupg_recv_array_elem(aTHX_ ctx->arrayelem, header, 0, ndim, &buf, &len);
|
|
FREETMPS;
|
|
LEAVE;
|
|
return r;
|
|
}
|
|
|
|
void fupg_send_array_elem(aTHX_ const fupg_send *elem, const U32 *dims, U32 dim, U32 ndim, SV *v, fustr *out, int *hasnull) {
|
|
SvGETMAGIC(v);
|
|
if (dim == ndim) {
|
|
if (!SvOK(v)) {
|
|
fustr_write(out, "\xff\xff\xff\xff", 4);
|
|
*hasnull = 1;
|
|
return;
|
|
}
|
|
size_t lenoff = fustr_len(out);
|
|
fustr_write(out, "\0\0\0\0", 4);
|
|
elem->fn(elem, v, out);
|
|
U32 len = __builtin_bswap32(fustr_len(out) - lenoff - 4);
|
|
memcpy(fustr_start(out)+lenoff, &len, 4);
|
|
return;
|
|
}
|
|
|
|
if (!SvROK(v)) fu_confess("Invalid array structure in bind parameter");
|
|
v = SvRV(v);
|
|
SvGETMAGIC(v);
|
|
if (SvTYPE(v) != SVt_PVAV) fu_confess("Invalid array structure in bind parameter");
|
|
AV *av = (AV*)v;
|
|
if (av_count(av) != dims[dim]) fu_confess("Invalid array structure in bind parameter");
|
|
U32 i;
|
|
for (i=0; i<dims[dim]; i++) {
|
|
SV **sv = av_fetch(av, i, 0);
|
|
if (!sv || !*sv) fu_confess("Invalid array structure in bind parameter");
|
|
fupg_send_array_elem(aTHX_ elem, dims, dim+1, ndim, *sv, out, hasnull);
|
|
}
|
|
}
|
|
|
|
SENDFN(array) {
|
|
U32 ndim = 0;
|
|
U32 dims[ARRAY_MAXDIM];
|
|
|
|
/* First figure out ndim and length-per-dim. The has-null flag and
|
|
* verification that each array-per-dimension has the same length is done
|
|
* while writing the elements.
|
|
* This is prone to errors if the elem type also accepts arrays as input,
|
|
* not quite sure how to deal with that case. */
|
|
SV *v = val;
|
|
while (true) {
|
|
SvGETMAGIC(v);
|
|
if (!SvROK(v)) break;
|
|
v = SvRV(v);
|
|
SvGETMAGIC(v);
|
|
if (SvTYPE(v) != SVt_PVAV) break;
|
|
if (ndim >= ARRAY_MAXDIM) fu_confess("Maximum depth exceeded while attempting to send array of type '%s' (oid %u)", ctx->name, ctx->oid);
|
|
dims[ndim] = av_count((AV*)v);
|
|
if (ndim > 0 && dims[ndim] == 0) fu_confess("Empty dimension while attempting to send array of type '%s' (oid %u)", ctx->name, ctx->oid);
|
|
ndim++;
|
|
SV **sv = av_fetch((AV*)v, 0, 0);
|
|
if (!sv || !*sv) break;
|
|
v = *sv;
|
|
}
|
|
if (ndim == 0) fu_confess("Type '%s' (oid %u) expects an array", ctx->name, ctx->oid);
|
|
if (dims[0] == 0) ndim = 0;
|
|
|
|
/* Write header */
|
|
U32 tmp = __builtin_bswap32(ndim);
|
|
fustr_write(out, (const char *)&tmp, 4);
|
|
fustr_write(out, "\0\0\0\0", 4); /* Placeholder for isnull */
|
|
size_t hasnull_off = fustr_len(out) - 1;
|
|
tmp = __builtin_bswap32(ctx->arrayelem->oid);
|
|
fustr_write(out, (const char *)&tmp, 4);
|
|
U32 i;
|
|
for (i=0; i<ndim; i++) {
|
|
tmp = __builtin_bswap32(dims[i]);
|
|
fustr_write(out, (const char *)&tmp, 4);
|
|
/* int2vector and oidvector expect 0-based indexing,
|
|
* everything else defaults to 1-based indexing. */
|
|
if (ctx->oid == 22 || ctx->oid == 30) fustr_write(out, "\0\0\0\0", 4);
|
|
else fustr_write(out, "\0\0\0\1", 4);
|
|
}
|
|
if (ndim == 0) return;
|
|
|
|
/* write the elements */
|
|
int hasnull = 0;
|
|
fupg_send_array_elem(aTHX_ ctx->arrayelem, dims, 0, ndim, val, out, &hasnull);
|
|
if (hasnull) fustr_start(out)[hasnull_off] = 1;
|
|
}
|
|
|
|
#undef ARRAY_MAXDIM
|
|
|
|
#undef SIV
|
|
#undef RLEN
|
|
#undef RECVFN
|
|
#undef SENDFN
|
|
|
|
|
|
|
|
|
|
/* List of types we handle directly in this module.
|
|
Ideally, this includes everything returned by:
|
|
|
|
SELECT oid, typname, typelem, typreceive
|
|
FROM pg_type t
|
|
WHERE typtype = 'b'
|
|
AND typnamespace = 'pg_catalog'::regnamespace
|
|
AND (typelem = 0 OR EXISTS(SELECT 1 FROM pg_type e WHERE e.oid = t.typelem AND e.typtype = 'b'))
|
|
ORDER by oid
|
|
|
|
(i.e. all base types and arrays of base types)
|
|
Plus hopefully a bunch of common extension types.
|
|
|
|
The "reg#" types are a bit funny: the Postgres devs obviously realized that
|
|
writing JOINs is cumbersome, so they hacked together a numeric identifier
|
|
type that automatically resolves to a string when formatted as text, or
|
|
performs a lookup in the database when parsing text. In the text format, you
|
|
don't get to see the numeric identifier, but sadly that conversion is not
|
|
performed in the byte format so we're dealing with numbers instead. Oh well.
|
|
Not worth writing custom lookup code for, users will have to adapt.
|
|
|
|
Ordered by oid to support binary search.
|
|
(name is only used when formatting error messages, for now) */
|
|
#define BUILTINS \
|
|
B( 16, "bool", bool )\
|
|
B( 17, "bytea", bytea )\
|
|
B( 18, "char", char )\
|
|
B( 19, "name", text )\
|
|
B( 20, "int8", int8 )\
|
|
B( 21, "int2", int2 )\
|
|
A( 22, "int2vector", 21 )\
|
|
B( 23, "int4", int4 )\
|
|
B( 24, "regproc", uint4 )\
|
|
B( 25, "text", text )\
|
|
B( 26, "oid", uint4 )\
|
|
/* 27 tid: u32 block, u16 offset; represent as hash? */ \
|
|
B( 28, "xid", uint4 )\
|
|
B( 29, "cid", uint4 )\
|
|
A( 30, "oidvector", 26 )\
|
|
B( 114, "json", json )\
|
|
B( 142, "xml", text )\
|
|
A( 143, "_xml", 142 )\
|
|
B( 194, "pg_node_tree", text ) /* can't be used as a bind param */\
|
|
A( 199, "_json", 114 )\
|
|
A( 271, "_xid8", 5069 )\
|
|
/* 600 point */\
|
|
/* 601 lseg */\
|
|
/* 602 path */\
|
|
/* 603 box */\
|
|
/* 604 polygon */\
|
|
/* 628 line */\
|
|
/* 650 cidr */\
|
|
A( 629, "_line", 628 )\
|
|
A( 651, "_cidr", 650 )\
|
|
B( 700, "float4", float4)\
|
|
B( 701, "float8", float8)\
|
|
/* 718 circle */\
|
|
A( 719, "_circle", 718 )\
|
|
/* 774 macaddr8 */\
|
|
A( 775, "_macaddr8", 774 )\
|
|
/* 790 money */\
|
|
A( 791, "_money", 790 )\
|
|
/* 829 macaddr */\
|
|
/* 869 inet */\
|
|
A( 1000, "_bool", 16 )\
|
|
A( 1001, "_bytea", 17 )\
|
|
A( 1002, "_char", 18 )\
|
|
A( 1003, "_name", 19 )\
|
|
A( 1005, "_int2", 21 )\
|
|
A( 1006, "_int2vector", 22 )\
|
|
A( 1007, "_int4", 23 )\
|
|
A( 1008, "_regproc", 24 )\
|
|
A( 1009, "_text", 25 )\
|
|
A( 1010, "_tid", 27 )\
|
|
A( 1011, "_xid", 28 )\
|
|
A( 1012, "_cid", 29 )\
|
|
A( 1013, "_oidvector", 30 )\
|
|
A( 1014, "_bpchar", 1042 )\
|
|
A( 1015, "_varchar", 1043 )\
|
|
A( 1016, "_int8", 20 )\
|
|
A( 1017, "_point", 600 )\
|
|
A( 1018, "_lseg", 601 )\
|
|
A( 1019, "_path", 602 )\
|
|
A( 1020, "_box", 603 )\
|
|
A( 1021, "_float4", 700 )\
|
|
A( 1022, "_float8", 701 )\
|
|
A( 1027, "_polygon", 604 )\
|
|
A( 1028, "_oid", 26 )\
|
|
/* 1033 aclitem, does not support send/recv */\
|
|
/* A( 1034, "_aclitem", 1033 ) */\
|
|
A( 1040, "_macaddr", 829 )\
|
|
A( 1041, "_inet", 869 )\
|
|
B( 1042, "bpchar", text )\
|
|
B( 1043, "varchar", text )\
|
|
/* 1082 date */\
|
|
/* 1083 time */\
|
|
A( 1115, "_timestamp", 1114 )\
|
|
/* 1114 timestamp */\
|
|
A( 1182, "_date", 1082 )\
|
|
A( 1183, "_time", 1083 )\
|
|
/* 1184 timestamptz */\
|
|
A( 1185, "_timestamptz", 1184 )\
|
|
/* 1186 interval */\
|
|
A( 1187, "_interval", 1186 )\
|
|
A( 1231, "_numeric", 1700 )\
|
|
/* 1266 timetz */\
|
|
A( 1270, "_timetz", 1266 )\
|
|
/* 1560 bit */\
|
|
A( 1561, "_bit", 1560 )\
|
|
/* 1562 varbit */\
|
|
A( 1563, "_varbit", 1562 )\
|
|
/* 1700 numeric */\
|
|
B( 1790, "refcursor", text )\
|
|
A( 2201, "_refcursor", 1790 )\
|
|
B( 2202, "regprocedure", uint4 )\
|
|
B( 2203, "regoper", uint4 )\
|
|
B( 2204, "regoperator", uint4 )\
|
|
B( 2205, "regclass", uint4 )\
|
|
B( 2206, "regtype", uint4 )\
|
|
A( 2207, "_regprocedure", 2202 )\
|
|
A( 2208, "_regoper", 2203 )\
|
|
A( 2209, "_regoperator", 2204 )\
|
|
A( 2210, "_regclass", 2205 )\
|
|
A( 2211, "_regtype", 2206 )\
|
|
A( 2949, "_txid_snapshot", 2970 )\
|
|
/* 2950 uuid */\
|
|
A( 2951, "_uuid", 2950 )\
|
|
/* 2970 txid_snapshot */\
|
|
/* 3220 pg_lsn */\
|
|
A( 3221, "_pg_lsn", 3220 )\
|
|
/* 3361 pg_ndistinct */\
|
|
/* 3402 pg_dependencies */\
|
|
/* 3614 tsvector */\
|
|
/* 3615 tsquery */\
|
|
/* 3642 gtsvector, does not support send/recv */\
|
|
A( 3643, "_tsvector", 3614 )\
|
|
/*A( 3644, "_gtsvector", 3642 )*/\
|
|
A( 3645, "_tsquery", 3615 )\
|
|
B( 3734, "regconfig", uint4 )\
|
|
A( 3735, "_regconfig", 3734 )\
|
|
B( 3769, "regdictionary", uint4 )\
|
|
A( 3770, "_regdictionary", 3769 )\
|
|
B( 3802, "jsonb", jsonb )\
|
|
A( 3807, "_jsonb", 3802 )\
|
|
B( 4072, "jsonpath", jsonpath)\
|
|
A( 4073, "_jsonpath", 4072 )\
|
|
B( 4089, "regnamespace", uint4 )\
|
|
A( 4090, "_regnamespace", 4089 )\
|
|
B( 4096, "regrole", uint4 )\
|
|
A( 4097, "_regrole", 4096 )\
|
|
B( 4191, "regcollation", uint4 )\
|
|
A( 4192, "_regcollation", 4191 )\
|
|
/* 4600 pg_brin_bloom_summary */\
|
|
/* 4601 pg_brin_minmax_multi_summary */\
|
|
/* 5017 pg_mcv_list */\
|
|
/* 5038 pg_snapshot */\
|
|
A( 5039, "_pg_snapshot", 5038 )\
|
|
/* 5069 xid8 */
|
|
|
|
static const fupg_type fupg_builtin[] = {
|
|
#define B(oid, name, fun) { oid, 0, name"\0", fupg_send_##fun, fupg_recv_##fun },
|
|
#define A(oid, name, eoid) { oid, eoid, name"\0", fupg_send_array, fupg_recv_array },
|
|
BUILTINS
|
|
#undef B
|
|
#undef A
|
|
};
|
|
|
|
#undef BUILTINS
|
|
|
|
#define FUPG_BUILTIN (sizeof(fupg_builtin) / sizeof(fupg_type))
|
|
|
|
|
|
static const fupg_type *fupg_type_byoid(const fupg_type *list, int len, Oid oid) {
|
|
int i, b = 0, e = len-1;
|
|
while (b <= e) {
|
|
i = b + (e - b)/2;
|
|
if (list[i].oid == oid) return list+i;
|
|
if (list[i].oid < oid) b = i+1;
|
|
else e = i-1;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
static const fupg_type *fupg_builtin_byoid(Oid oid) {
|
|
return fupg_type_byoid(fupg_builtin, FUPG_BUILTIN, oid);
|
|
}
|