Re: AllocSetContextCreate changes breake extensions

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andres Freund <andres(at)anarazel(dot)de>, pgsql-hackers(at)postgresql(dot)org, Christoph Berg <cb(at)df7cb(dot)de>
Subject: Re: AllocSetContextCreate changes breake extensions
Date: 2018-12-03 03:10:38
Message-ID: 87ftvf4bzx.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>>>>> "Tom" == Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:

>> except there IS such a reason: if you need (as I do in pl/lua) to
>> wrap the call in a catch block, inside a function which takes the
>> name and so on as a parameter, then you have no option but to do so
>> (since using the macro errors out on the non-const parameter).

Tom> I'm kind of unimpressed by your example, because you're
Tom> deliberately breaking the safety check the macro sets out to
Tom> provide.

Yes, because in this case the names really _are_ constant strings, but
that fact can't be exposed to AllocSetContextCreate without duplicating
code all over the place.

Tom> With code structure like this, it's impossible to be sure that
Tom> what was passed to the wrapper function is actually a constant
Tom> string.

It's impossible for AllocSetContextCreate to be sure of that, it's not
impossible for _me_ to be sure of that. (I could add my own macro with a
__builtin_constant_p check if I felt the need.)

Tom> You'd be better off using the workaround the comment suggests,
Tom> which is to just pass "" to AllocSetContextCreate and then use
Tom> MemoryContextSetIdentifier to copy the passed string.

Copying the string would be overkill since it really is a constant. (And
I can't copy the string into the context it identifies, because that
would block use of MemoryContextReset. I'd have to copy it somewhere
else - and then freeing it becomes much more tricky.)

--
Andrew (irc:RhodiumToad)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tatsuo Ishii 2018-12-03 04:03:45 Re: idle-in-transaction timeout error does not give a hint
Previous Message Andrew Gierth 2018-12-03 01:47:11 Re: [proposal] Add an option for returning SQLSTATE in psql error message