On Thu, Nov 12, 2015 at 2:39 PM, Tom Lane <t...@sss.pgh.pa.us> wrote:
> Either that's a reportable compiler bug, or someplace nearby we've
> casted the pointer to something that would require a 4-byte struct.
> I'm not sure which code you're looking at exactly, but maybe we're
> using "union NumericChoice" prematurely?

I don't see how these structs could ever be used without casting to
NumericChoice to get the scale and weight even when there are no
digits. I think it wouldn't be too hard to just give up on the structs
and unions and use a char * as the underlying type. We could access
the meta information directly using byte accesses and memcpy the
digits to an aligned array of digits when setting up the var. I think
the code would be simpler in the end and make it easy to support
packed varlenas.

It triggers on the line with the NUMERIC_WEIGHT() macro call in

    (((n)->choice.n_short.n_header & NUMERIC_SHORT_WEIGHT_SIGN_MASK ? \
     | ((n)->choice.n_short.n_header & NUMERIC_SHORT_WEIGHT_MASK)) \
    : ((n)->choice.n_long.n_weight))

static void
init_var_from_num(Numeric num, NumericVar *dest)
  dump_numeric("init_var_from_num", num);

  dest->ndigits = NUMERIC_NDIGITS(num);
  dest->weight = NUMERIC_WEIGHT(num);
  dest->sign = NUMERIC_SIGN(num);
  dest->dscale = NUMERIC_DSCALE(num);
  dest->digits = NUMERIC_DIGITS(num);
  dest->buf = NULL; /* digits array is not palloc'd */

I think the


Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:

Reply via email to