Re: jsonapi: scary new warnings with LTO enabled

2025-04-23 Thread Daniel Gustafsson
> On 23 Apr 2025, at 02:01, Jacob Champion > wrote: > On Tue, Apr 22, 2025 at 3:10 AM Daniel Gustafsson wrote: >> The attached >> v3 allocates via the JSON api, no specific error handling should be required >> as >> it's already handled today. > > pgindent shows one whitespace change on my ma

Re: jsonapi: scary new warnings with LTO enabled

2025-04-22 Thread Jacob Champion
On Tue, Apr 22, 2025 at 3:10 AM Daniel Gustafsson wrote: > My preference is that no operation can silently work on a failed object, but > it's not a hill (even more so given where we are in the cycle). Hm, okay. Something to talk about with Andrew and Peter, maybe. > The attached > v3 allocates

Re: jsonapi: scary new warnings with LTO enabled

2025-04-22 Thread Daniel Gustafsson
> On 21 Apr 2025, at 20:58, Jacob Champion > wrote: > Personally, I'm fine with can't-fail APIs, as long as they're > documented as such. (I think the deferred error API was probably > chosen so that src/common JSON clients could be written without a lot > of pain?) My preference is that no ope

Re: jsonapi: scary new warnings with LTO enabled

2025-04-21 Thread Jacob Champion
On Mon, Apr 21, 2025 at 11:46 AM Daniel Gustafsson wrote: > We do, but with the current coding we call setJsonLexContextOwnsTokens > immediately after creation which derefences the pointer without checkinf for > allocation failure. Right. (The flag does nothing on the OOM sentinel.) > This means

Re: jsonapi: scary new warnings with LTO enabled

2025-04-21 Thread Daniel Gustafsson
> On 21 Apr 2025, at 20:28, Jacob Champion > wrote: > > On Mon, Apr 21, 2025 at 11:20 AM Daniel Gustafsson wrote: >> Sure, but I fear we'll get an endless stream of static analysis reports for >> the >> allocation leaking if we don't free it. > > But we do free it, in freeJsonLexContext(). Th

Re: jsonapi: scary new warnings with LTO enabled

2025-04-21 Thread Jacob Champion
On Mon, Apr 21, 2025 at 11:20 AM Daniel Gustafsson wrote: > Sure, but I fear we'll get an endless stream of static analysis reports for > the > allocation leaking if we don't free it. But we do free it, in freeJsonLexContext(). That usage of the API goes back to 2023, with 1c99cde2f344. Or am I

Re: jsonapi: scary new warnings with LTO enabled

2025-04-21 Thread Daniel Gustafsson
> On 21 Apr 2025, at 17:33, Jacob Champion > wrote: > > On Sat, Apr 19, 2025 at 2:15 PM Daniel Gustafsson wrote: >> Since there is no way to determine if the allocation succeeded from outside >> of >> the JSON api it might be better to keep the calloc and explicitly free it? > > I don't think

Re: jsonapi: scary new warnings with LTO enabled

2025-04-21 Thread Jacob Champion
On Sat, Apr 19, 2025 at 2:15 PM Daniel Gustafsson wrote: > Since there is no way to determine if the allocation succeeded from outside of > the JSON api it might be better to keep the calloc and explicitly free it? I don't think so; pg_parse_json() will error out quickly, so I don't see much adva

Re: jsonapi: scary new warnings with LTO enabled

2025-04-19 Thread Daniel Gustafsson
> On 17 Apr 2025, at 17:48, Jacob Champion > wrote: > > On Thu, Apr 17, 2025 at 8:20 AM Tom Lane wrote: >> I confirm this silences those warnings on my Fedora 41 box. > > Instead of doing > >lex = calloc(...); >/* (error out on NULL return) */ >makeJsonLexContextCstringLen(lex, ..

Re: jsonapi: scary new warnings with LTO enabled

2025-04-18 Thread Tom Lane
Jacob Champion writes: > On Wed, Apr 16, 2025 at 4:04 PM Tom Lane wrote: >> Looking through all of the callers of freeJsonLexContext, quite >> a lot of them use local JsonLexContext structs, and probably some >> of them are more performance-critical than these. So that raises >> the question of

Re: jsonapi: scary new warnings with LTO enabled

2025-04-18 Thread Jacob Champion
On Thu, Apr 17, 2025 at 8:20 AM Tom Lane wrote: > I confirm this silences those warnings on my Fedora 41 box. Instead of doing lex = calloc(...); /* (error out on NULL return) */ makeJsonLexContextCstringLen(lex, ...); we need to do lex = makeJsonLexContextCstringLen(NULL, ...)

Re: jsonapi: scary new warnings with LTO enabled

2025-04-17 Thread Tom Lane
Daniel Gustafsson writes: > Agreed, moving to heap allocated structures for these callsites seem much > better. Something like the attached should be enough I think? I confirm this silences those warnings on my Fedora 41 box. I'm content to do it like this, but maybe Jacob wants to investigate a

Re: jsonapi: scary new warnings with LTO enabled

2025-04-17 Thread Daniel Gustafsson
> On 17 Apr 2025, at 01:28, Tom Lane wrote: > > Jacob Champion writes: >> On Wed, Apr 16, 2025 at 4:04 PM Tom Lane wrote: >>> Looking through all of the callers of freeJsonLexContext, quite >>> a lot of them use local JsonLexContext structs, and probably some >>> of them are more performance-cr

Re: jsonapi: scary new warnings with LTO enabled

2025-04-16 Thread Tom Lane
Daniel Gustafsson writes: >> On 16 Apr 2025, at 23:42, Tom Lane wrote: >> I'm not sure >> how other than giving up on stack allocation of JsonLexContexts, >> though, especially if we consider the jsonapi API frozen. But seeing >> that there are only three such call sites and none of them seem in

Re: jsonapi: scary new warnings with LTO enabled

2025-04-16 Thread Tom Lane
Daniel Gustafsson writes: > On 17 Apr 2025, at 00:12, Tom Lane wrote: >> The only alternative I can see that might stop the warning is if we >> can find a way to make it clearer to the optimizer that the FREE() >> isn't reached. But I'm not sure about a trustworthy way to make that >> happen. >

Re: jsonapi: scary new warnings with LTO enabled

2025-04-16 Thread Daniel Gustafsson
> On 16 Apr 2025, at 23:42, Tom Lane wrote: > It seems fairly dangerous to ignore -Wfree-nonheap-object warnings. > I feel like we ought to move to prevent these somehow. Absolutely agree. > I'm not sure > how other than giving up on stack allocation of JsonLexContexts, > though, especially if

Re: jsonapi: scary new warnings with LTO enabled

2025-04-16 Thread Jacob Champion
On Wed, Apr 16, 2025 at 4:04 PM Tom Lane wrote: > Looking through all of the callers of freeJsonLexContext, quite > a lot of them use local JsonLexContext structs, and probably some > of them are more performance-critical than these. So that raises > the question of why are we seeing warnings for

Re: jsonapi: scary new warnings with LTO enabled

2025-04-16 Thread Daniel Gustafsson
> On 17 Apr 2025, at 00:12, Tom Lane wrote: > > Daniel Gustafsson writes: >>> On 16 Apr 2025, at 23:42, Tom Lane wrote: >>> I'm not sure >>> how other than giving up on stack allocation of JsonLexContexts, >>> though, especially if we consider the jsonapi API frozen. But seeing >>> that there

Re: jsonapi: scary new warnings with LTO enabled

2025-04-16 Thread Ranier Vilela
Em qua., 16 de abr. de 2025 às 18:42, Tom Lane escreveu: > I noticed some new warnings from buildfarm member chafer, > which I'm able to reproduce locally on a Fedora 41 box > by building with "meson setup build -Db_lto=true": > > ninja: Entering directory `build' > [1515/2472] Linking target src

jsonapi: scary new warnings with LTO enabled

2025-04-16 Thread Tom Lane
I noticed some new warnings from buildfarm member chafer, which I'm able to reproduce locally on a Fedora 41 box by building with "meson setup build -Db_lto=true": ninja: Entering directory `build' [1515/2472] Linking target src/interfaces/libpq/libpq.so.5.18 In function 'freeJsonLexContext',