Re: AllocSetContextCreate changes breake extensions
Andrew Gierth <andrew@tao11.riddles.org.uk>
From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Andres Freund <andres@anarazel.de>, pgsql-hackers@postgresql.org,
Christoph Berg <cb@df7cb.de>
Date: 2018-12-03T03:10:38Z
Lists: pgsql-hackers
>>>>> "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)
Commits
-
Back-patch addition of the ALLOCSET_FOO_SIZES macros.
- ec185747a46e 9.4.20 landed
- 1245561df490 9.5.15 landed
- 01187f32cd61 9.3.25 landed
-
Simplify use of AllocSetContextCreate() wrapper macro.
- 3d059655be7d 11.0 landed
- 13cd7209f794 12.0 landed
-
Rethink MemoryContext creation to improve performance.
- 9fa6f00b1308 11.0 cited