Rationalizing the API for array_ref, array_set, and friends

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)postgreSQL(dot)org
Subject: Rationalizing the API for array_ref, array_set, and friends
Date: 2015-02-16 01:39:18
Message-ID: 26511.1424050758@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

The four functions array_ref, array_set, array_get_slice, array_set_slice
have traditionally declared their array inputs and results as being of
type "ArrayType *". This is a lie, and has been since Berkeley days,
because they actually also support "fixed-length array" types such as
"name" and "point". If anyone tried to reference such arguments/results
as an ArrayType struct they'd be in for a surprise. We made it worse
when we invented toasting, because the arguments (though not the results,
at the moment) might also be toast pointers or short-header varlenas.

Aside from being confusing, ISTM this notational abuse runs some risk of
bad code generation, because a compiler might think the declaration of
these arguments entitles it to assume the pointers are 4-byte-aligned.
I'm not aware that we've had any actual bug reports like that, but as
the compiler boys get ever tenser, who knows what will happen?

Anyway, I'd been quietly averting my eyes from this issue for some time,
but preserving this mess is helping to make a mess of my expanded-array
patch, so I think it's time to do something about it. Does anyone have
an objection to my pushing the attached cleanup patch? It simply fixes
the function declarations and adds/subtracts DatumGet/GetDatum calls
as necessary.

regards, tom lane

Attachment Content-Type Size
fix-array-ref-set-API-1.patch text/x-diff 33.5 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message David Steele 2015-02-16 02:23:16 Re: Issue installing doc tools on OSX
Previous Message Tomas Vondra 2015-02-16 01:16:34 Re: Really bad blowups with hash outer join and nulls