Re: PG_FREE_IF_COPY extraneous in numeric_cmp?

2023-02-25 Thread CK Tan
Thanks! On Fri, Feb 24, 2023 at 2:16 PM Tom Lane wrote: > > CK Tan writes: > > Isn't it true that pfree() will never be called by PG_FREE_IF_COPY? > > No. You're forgetting the possibility that PG_GETARG_NUMERIC will > have to de-toast a toasted input. Granted, numerics are seldom > going to

Re: PG_FREE_IF_COPY extraneous in numeric_cmp?

2023-02-24 Thread Tom Lane
CK Tan writes: > Isn't it true that pfree() will never be called by PG_FREE_IF_COPY? No. You're forgetting the possibility that PG_GETARG_NUMERIC will have to de-toast a toasted input. Granted, numerics are seldom going to be long enough to get compressed or pushed out-of-line; but that's

PG_FREE_IF_COPY extraneous in numeric_cmp?

2023-02-24 Thread CK Tan
Hi hackers, I have a question on the code below: Datum numeric_cmp(PG_FUNCTION_ARGS) { Numeric num1 = PG_GETARG_NUMERIC(0); Numeric num2 = PG_GETARG_NUMERIC(1); int result; result = cmp_numerics(num1, num2); PG_FREE_IF_COPY(num1, 0); PG_FREE_IF_COPY(num2, 1);