>>>>> "Tom" == Tom Lane <tgl@sss.pgh.pa.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)