Abstract and cleanup ugly byte swapping code

These macros don't assume alignment and may be somewhat inefficient with
all that copying. I'm hoping GCC is able to optimize that crap somewhat.

Also the pg type receive functions can not, in fact, assume that their
input buffers are properly aligned. That won't necessarily be the case
for array elements.
This commit is contained in:
Yorhel 2025-02-10 07:34:08 +01:00
parent 7d71e446d0
commit d5f593387a
4 changed files with 55 additions and 77 deletions

View file

@ -284,10 +284,10 @@ static void fupg_refresh_types(pTHX_ fupg_conn *c) {
int i;
for (i=0; i<c->ntypes; i++) {
fupg_type *t = c->types + i;
t->oid = __builtin_bswap32(*((Oid *)PQgetvalue(r, i, 0)));
t->oid = fu_frombeU(32, PQgetvalue(r, i, 0));
snprintf(t->name, sizeof(t->name), "%s", PQgetvalue(r, i, 1));
char typ = *PQgetvalue(r, i, 2);
t->elemoid = __builtin_bswap32(*((Oid *)PQgetvalue(r, i, 3)));
t->elemoid = fu_frombeU(32, PQgetvalue(r, i, 3));
if (t->elemoid) {
/* array */
@ -298,7 +298,7 @@ static void fupg_refresh_types(pTHX_ fupg_conn *c) {
t->send = fupg_send_text;
t->recv = fupg_recv_text;
} else {
/* TODO: records, (multi)ranges, custom overrides, by-name lookup for dynamic-oid types */
/* TODO: records, domain types, (multi)ranges, custom overrides, by-name lookup for dynamic-oid types */
const fupg_type *builtin = fupg_builtin_byoid(t->oid);
if (builtin) {
t->send = builtin->send;