Assert there is no duplicated exit callbacks
Attached is a patch to assert there is no duplicated exit callbacks.
Along the way, I downgrade the runtime "enough room" check to an
assertion: the callbacks are registered in pretty fixed initialization
code path, thus assertion is good enough to prevent overlook there. If
we don't agree with this, then the duplication check shall also bump
to runtime checks.
Regards,
Qingqing
Attachments:
ipc.difftext/plain; charset=UTF-16LE; name=ipc.diffDownload
diff --git a/src/backend/storage/ipc/ipc.c b/src/backend/storage/ipc/ipc.c
index 6bc0b06..bfc7764 100644
--- a/src/backend/storage/ipc/ipc.c
+++ b/src/backend/storage/ipc/ipc.c
@@ -291,10 +291,12 @@ atexit_callback(void)
void
on_proc_exit(pg_on_exit_callback function, Datum arg)
{
- if (on_proc_exit_index >= MAX_ON_EXITS)
- ereport(FATAL,
- (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
- errmsg_internal("out of on_proc_exit slots")));
+ int i;
+
+ /* check no duplicates and there are rooms */
+ for (i = 0; i < on_proc_exit_index; i++)
+ Assert (on_proc_exit_list[i] != function);
+ Assert (on_proc_exit_index < MAX_ON_EXITS);
on_proc_exit_list[on_proc_exit_index].function = function;
on_proc_exit_list[on_proc_exit_index].arg = arg;
@@ -319,10 +321,12 @@ on_proc_exit(pg_on_exit_callback function, Datum arg)
void
before_shmem_exit(pg_on_exit_callback function, Datum arg)
{
- if (before_shmem_exit_index >= MAX_ON_EXITS)
- ereport(FATAL,
- (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
- errmsg_internal("out of before_shmem_exit slots")));
+ int i;
+
+ /* check no duplicated callbacks and there are rooms */
+ for (i = 0; i < before_shmem_exit_index; i++)
+ Assert (before_shmem_exit_list[i] != function);
+ Assert (before_shmem_exit_index < MAX_ON_EXITS);
before_shmem_exit_list[before_shmem_exit_index].function = function;
before_shmem_exit_list[before_shmem_exit_index].arg = arg;
@@ -347,10 +351,12 @@ before_shmem_exit(pg_on_exit_callback function, Datum arg)
void
on_shmem_exit(pg_on_exit_callback function, Datum arg)
{
- if (on_shmem_exit_index >= MAX_ON_EXITS)
- ereport(FATAL,
- (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
- errmsg_internal("out of on_shmem_exit slots")));
+ int i;
+
+ /* check no duplicates and there are rooms */
+ for (i = 0; i < on_shmem_exit_index; i++)
+ Assert (on_shmem_exit_list[i] != function);
+ Assert (on_shmem_exit_index < MAX_ON_EXITS);
on_shmem_exit_list[on_shmem_exit_index].function = function;
on_shmem_exit_list[on_shmem_exit_index].arg = arg;
湏〠⼴㔱㈯‵㜰㔺′䵐楑杮楱杮娠潨⁵牷瑯㩥㸊䄠瑴捡敨獩愠瀠瑡档琠獡敳瑲琠敨敲椠潮搠灵楬慣整硥瑩挠污扬捡獫ਮ䤊搠湯琧爠浥浥敢桴瑡攠敶敢湥愠瀠潲汢浥ਮ㸊䄠潬杮琠敨眠祡⁉潤湷牧摡桴畲瑮浩攢潮杵潲浯•档捥潴愠੮‾獡敳瑲潩㩮琠敨挠污扬捡獫愠敲爠来獩整敲湩瀠敲瑴⁹楦數湩瑩慩楬慺楴湯㸊挠摯慰桴桴獵愠獳牥楴湯椠潧摯攠潮杵潴瀠敲敶瑮漠敶汲潯桴牥䤠੦‾敷搠湯琧愠牧敥眠瑩桴獩桴湥琠敨搠灵楬慣楴湯挠敨正猠慨汬愠獬畢灭㸊琠畲瑮浩档捥獫ਮ䤊搠湯琧琠楨歮愠祮漠桴獩椠敮摥摥ਮⴊ䠠楥歫੩ਊⴊ匊湥⁴楶杰煳慨正牥慭汩湩楬瑳⠠杰煳慨正牥䁳潰瑳牧獥汱漮杲潔洠歡档湡敧潴礠畯畳獢牣灩楴湯瑨灴⼺眯睷瀮獯杴敲煳牯⽧慭汩牰晥瀯獧汱栭捡敫獲ਊ
Hmm, the email text seems corrupted?
Regards,
Qingqing
On Wed, Apr 15, 2015 at 10:03 AM, Heikki Linnakangas <hlinnaka@iki.fi> wrote:
湏〠⼴㔱㈯‵㜰㔺′䵐楑杮楱杮娠潨⁵牷瑯㩥‾瑁慴档摥椠慰捴潴愠獳牥⁴
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Wed, Apr 15, 2015 at 11:14:43AM -0700, Qingqing Zhou wrote:
Hmm, the email text seems corrupted?
I think it was an encoding issue. Here's what I got when I piped it
through less.
Cheers,
David.
On 04/15/2015 07:52 PM, Qingqing Zhou wrote:
Attached is a patch to assert there is no duplicated exit callbacks.
I don't remember that ever been a problem.
Along the way, I downgrade the runtime "enough room" check to an
assertion: the callbacks are registered in pretty fixed initialization
code path, thus assertion is good enough to prevent overlook there. If
we don't agree with this, then the duplication check shall also bump
to runtime checks.
I don't think any of this is needed.
- Heikki
--
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david.fetter@gmail.com
Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers