RE: Proposal: Add more compile-time asserts to exposeinconsistencies. - Mailing list pgsql-hackers

From Smith, Peter
Subject RE: Proposal: Add more compile-time asserts to exposeinconsistencies.
Date
Msg-id 201DD0641B056142AC8C6645EC1B5F62014B8EBDBB@SYD1217
Whole thread Raw
In response to Re: Proposal: Add more compile-time asserts to exposeinconsistencies.  (Michael Paquier <michael@paquier.xyz>)
Responses Re: Proposal: Add more compile-time asserts to exposeinconsistencies.
List pgsql-hackers
-----Original Message-----
From: Michael Paquier <michael@paquier.xyz> Sent: Thursday, 19 September 2019 11:08 AM

>On Wed, Sep 18, 2019 at 04:46:30PM +0100, Dagfinn Ilmari Mannsåker wrote:
>> Postgres doesn't seem to have it, but it would be possible to define a
>> StaticAssertDecl macro that can be used at the file level, outside any
>> function.  See for example Perl's STATIC_ASSERT_DECL:
>>
>> https://github.com/Perl/perl5/blob/v5.30.0/perl.h#L3455-L3488
>
>That sounds like a cleaner alternative.  Thanks for the pointer.

In the attached patch example I have defined a new macro StaticAssertDecl. A typical usage of it is shown in the
relpath.cfile. 

The goal was to leave all existing Postgres static assert macros unchanged, but to allow static asserts to be added in
thecode at file scope without the need for the explicit ct_asserts function. 

Notice, in reality the StaticAssertDecl macro still uses a static function as a wrapper for the StaticAssertStmt,  but
nowthe function is not visible in the source. 

If this strategy is acceptable I will update my original patch to remove all those ct_asserts functions, and instead
puteach StaticAssertDecl nearby the array that it is asserting (e.g. just like relpath.c) 

Kind Regards,
Peter Smith
---
Fujitsu Australia

Attachment

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Allow CLUSTER, VACUUM FULL and REINDEX to change tablespace onthe fly
Next
From: Fabien COELHO
Date:
Subject: Re: pgbench - allow to create partitioned tables