Re: [PATCH] Make various variables read-only (const)
От | Wim Lewis |
---|---|
Тема | Re: [PATCH] Make various variables read-only (const) |
Дата | |
Msg-id | 52C612B1.5080706@omnigroup.com обсуждение исходный текст |
Ответ на | [PATCH] Make various variables read-only (const) (Oskari Saarenmaa <os@ohmu.fi>) |
Список | pgsql-hackers |
By an odd coincidence, I also decided to try to const-ify libpq recently, and noticed this thread as I was cleaning up my patch for submission. For what it's worth, I've attached my patch to this message. It doesn't move as much data into the text segment as Oskari Saarenmaa's patch does, but it is less intrusive (simply adding const modifiers here and there). I just went after the low-hanging fruit in libpq. As an aside, it might make sense to make pg_encname_tbl and pg_encname_tbl_sz static, since as far as I can tell those symbols are never used outside of encnames.c nor are they likely to be. I didn't make that change in this patch though. On Mon, Dec 23, 2013, Robert Haas <robertmhaas@gmail.com> wrote: > And how much does this really affect data sharing? Doesn't copy-on-write do the same thing for writable data? It can have a surprisingly large effect if read-only data gets intermixed on pages with actual read-write data and can get COWd unnecessarily. My motivation, though, was more about code correctness than memory sharing, though sharing is a nice benefit--- I was examining unexpected symbols in .data/.bss in case they represented a thread-safety problem for my program linked against libpq. (They didn't, FWIW, except for the known and documented issue with PQoidStatus(). Not that I really expected to find a problem in libpq, but marking those structures const makes it nice and clear that they're not mutable.)
Вложения
В списке pgsql-hackers по дате отправления: