pgsql: Generate fmgr prototypes automatically

Started by Peter Eisentrautabout 9 years ago13 messageshackers
Jump to latest
#1Peter Eisentraut
peter_e@gmx.net

Generate fmgr prototypes automatically

Gen_fmgrtab.pl creates a new file fmgrprotos.h, which contains
prototypes for all functions registered in pg_proc.h. This avoids
having to manually maintain these prototypes across a random variety of
header files. It also automatically enforces a correct function
signature, and since there are warnings about missing prototypes, it
will detect functions that are defined but not registered in
pg_proc.h (or otherwise used).

Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com>

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/352a24a1f9d6f7d4abb1175bfd22acc358f43140

Modified Files
--------------
contrib/btree_gist/btree_bit.c | 1 +
contrib/btree_gist/btree_bytea.c | 1 +
contrib/btree_gist/btree_date.c | 1 +
contrib/btree_gist/btree_interval.c | 1 +
contrib/btree_gist/btree_time.c | 1 +
contrib/intarray/_int_selfuncs.c | 1 +
contrib/lo/lo.c | 2 +-
contrib/spi/moddatetime.c | 2 +-
src/backend/Makefile | 15 +-
src/backend/access/brin/brin.c | 1 +
src/backend/access/brin/brin_inclusion.c | 5 +-
src/backend/access/brin/brin_minmax.c | 5 +-
src/backend/access/gin/ginfast.c | 1 +
src/backend/access/gist/gist.c | 1 +
src/backend/access/hash/hash.c | 1 +
src/backend/access/hash/hashfunc.c | 10 +
src/backend/access/index/amapi.c | 1 +
src/backend/access/nbtree/nbtree.c | 1 +
src/backend/access/spgist/spgutils.c | 1 +
src/backend/access/transam/xlogfuncs.c | 1 -
src/backend/catalog/namespace.c | 16 -
src/backend/catalog/pg_proc.c | 4 -
src/backend/commands/define.c | 2 +-
src/backend/executor/nodeSamplescan.c | 1 +
src/backend/foreign/foreign.c | 4 -
src/backend/storage/smgr/smgrtype.c | 1 +
src/backend/tsearch/dict_ispell.c | 1 +
src/backend/tsearch/dict_simple.c | 1 +
src/backend/tsearch/dict_synonym.c | 1 +
src/backend/tsearch/ts_selfuncs.c | 1 +
src/backend/utils/.gitignore | 1 +
src/backend/utils/Gen_fmgrtab.pl | 35 +-
src/backend/utils/Makefile | 12 +-
src/backend/utils/adt/array_selfuncs.c | 1 +
src/backend/utils/adt/array_typanalyze.c | 1 +
src/backend/utils/adt/ascii.c | 1 +
src/backend/utils/adt/geo_selfuncs.c | 1 +
src/backend/utils/adt/jsonb_op.c | 1 +
src/backend/utils/adt/network_gist.c | 1 +
src/backend/utils/adt/network_selfuncs.c | 1 +
src/backend/utils/adt/network_spgist.c | 1 +
src/backend/utils/adt/numeric.c | 6 +-
src/backend/utils/adt/pg_upgrade_support.c | 12 -
src/backend/utils/adt/pgstatfuncs.c | 100 ---
src/backend/utils/adt/rangetypes_spgist.c | 7 -
src/backend/utils/adt/tsgistidx.c | 1 +
src/backend/utils/adt/tsquery_gist.c | 1 +
src/backend/utils/adt/tsquery_op.c | 1 +
src/backend/utils/adt/tsrank.c | 1 +
src/backend/utils/adt/tsvector.c | 1 +
src/backend/utils/adt/varbit.c | 1 +
src/include/Makefile | 3 +-
src/include/access/amapi.h | 2 -
src/include/access/brin.h | 6 -
src/include/access/gin_private.h | 4 -
src/include/access/gist_private.h | 1 -
src/include/access/hash.h | 22 -
src/include/access/nbtree.h | 1 -
src/include/access/spgist.h | 1 -
src/include/access/xlog_fn.h | 37 -
src/include/catalog/pg_proc.h | 1 +
src/include/commands/async.h | 5 -
src/include/commands/sequence.h | 8 -
src/include/commands/trigger.h | 2 -
src/include/libpq/be-fsstubs.h | 31 -
src/include/replication/logicalfuncs.h | 7 -
src/include/replication/origin.h | 14 -
src/include/replication/slot.h | 6 -
src/include/replication/walreceiver.h | 1 -
src/include/replication/walsender.h | 2 -
src/include/storage/smgr.h | 6 -
src/include/tsearch/ts_type.h | 89 ---
src/include/tsearch/ts_utils.h | 117 ---
src/include/utils/.gitignore | 1 +
src/include/utils/acl.h | 14 -
src/include/utils/array.h | 50 --
src/include/utils/ascii.h | 6 -
src/include/utils/builtins.h | 1186 +---------------------------
src/include/utils/bytea.h | 25 -
src/include/utils/cash.h | 48 --
src/include/utils/date.h | 113 ---
src/include/utils/datetime.h | 3 -
src/include/utils/formatting.h | 12 -
src/include/utils/geo_decls.h | 262 +-----
src/include/utils/inet.h | 27 -
src/include/utils/int8.h | 104 ---
src/include/utils/json.h | 64 --
src/include/utils/jsonb.h | 67 --
src/include/utils/nabstime.h | 63 --
src/include/utils/pg_lsn.h | 16 -
src/include/utils/rangetypes.h | 80 --
src/include/utils/selfuncs.h | 28 -
src/include/utils/snapmgr.h | 1 -
src/include/utils/timestamp.h | 125 ---
src/include/utils/varbit.h | 46 --
src/include/utils/xml.h | 33 -
src/tools/msvc/Solution.pm | 10 +-
src/tools/msvc/clean.bat | 2 +
98 files changed, 125 insertions(+), 2899 deletions(-)

--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#1)
Re: pgsql: Generate fmgr prototypes automatically

Peter Eisentraut <peter_e@gmx.net> writes:

Generate fmgr prototypes automatically

Buildfarm's quite unhappy with this. Did you check parallel make?

regards, tom lane

--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#1)
Re: pgsql: Generate fmgr prototypes automatically

Peter Eisentraut <peter_e@gmx.net> writes:

Generate fmgr prototypes automatically

BTW, now that I've looked through this patch ... why does it add

+#include "nodes/nodes.h"
+#include "nodes/pg_list.h"

to utils/builtins.h? AFAICS that shouldn't be necessary, since
there are no declarations in builtins.h that weren't there before.
And seeing that this results in builtins.h being included in even more
places than before, surely we want to minimize that file's inclusion
footprint.

regards, tom lane

--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers

#4Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#3)
Re: pgsql: Generate fmgr prototypes automatically

On 1/17/17 2:35 PM, Tom Lane wrote:

Peter Eisentraut <peter_e@gmx.net> writes:

Generate fmgr prototypes automatically

BTW, now that I've looked through this patch ... why does it add

+#include "nodes/nodes.h"
+#include "nodes/pg_list.h"

to utils/builtins.h? AFAICS that shouldn't be necessary, since
there are no declarations in builtins.h that weren't there before.
And seeing that this results in builtins.h being included in even more
places than before, surely we want to minimize that file's inclusion
footprint.

There are things in builtins.h that technically need those declarations.
It seems to work without it now, but at some point during the
refactoring they were necessary. I can remove them again.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#4)
Re: pgsql: Generate fmgr prototypes automatically

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

On 1/17/17 2:35 PM, Tom Lane wrote:

BTW, now that I've looked through this patch ... why does it add

+#include "nodes/nodes.h"
+#include "nodes/pg_list.h"

to utils/builtins.h?

There are things in builtins.h that technically need those declarations.
It seems to work without it now, but at some point during the
refactoring they were necessary. I can remove them again.

[ looks around ... ] Hm, it looks like the reason it works without
them is that utils/sortsupport.h pulls in relcache.h, which pulls in a
veritable buttload of stuff; those two and a whole lot more beside.

That seems like a pretty bad idea. It's surely not the fault of this
patch that the sortsupport patch didn't give a damn about inclusion
footprints; but I still think we'd be well advised to minimize
builtins.h's footprint now that it's going to need to be included very
far and wide.

It looks like we could get rid of the need for sortsupport.h in
builtins.h via the good old "struct foo" forward reference trick,
that is

struct SortSupportData;

extern void varstr_sortsupport(struct SortSupportData *ssup, Oid collid, bool bpchar);

but I wonder if that's going far enough. We'd still be propagating
pg_list.h into a lot of places that don't necessarily need it.

Alternatively ... is there a specific reason why you chose to make
builtins.h the key inclusion file for this change, rather than having
callers include fmgrprotos.h directly? It seems like the stuff remaining
in builtins.h is just a laundry list of random utility functions.
Maybe dispersing those to other headers is the thing to do.

regards, tom lane

--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers

#6Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Tom Lane (#5)
Re: [COMMITTERS] pgsql: Generate fmgr prototypes automatically

Tom Lane wrote:

Alternatively ... is there a specific reason why you chose to make
builtins.h the key inclusion file for this change, rather than having
callers include fmgrprotos.h directly? It seems like the stuff remaining
in builtins.h is just a laundry list of random utility functions.
Maybe dispersing those to other headers is the thing to do.

It is possible to replace many occurrences of builtins.h with
fmgrprotos.h. I just tried this
git grep -l 'include.*utils/builtins.h' -- *.c | xargs perl -pi -e 's{utils/builtins.h}{utils/fmgrprotos.h}'
There's a large number of changes that the oneliner produces that must
be reverted for the compile to be silent, but a large portion can
remain. (I only tried src/backend/access).

Anyway I support the idea of creating other header files for specific
purposes, such as ruleutils.h, varlena.h, etc. (I am against creating a
header file that contains commonly used macros such as
CStringGetTextDatum together with varstr_sortsupport. I think the
latter should have its own place).

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#7Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Alvaro Herrera (#6)
Re: [COMMITTERS] pgsql: Generate fmgr prototypes automatically

Alvaro Herrera wrote:

It is possible to replace many occurrences of builtins.h with
fmgrprotos.h. I just tried this
git grep -l 'include.*utils/builtins.h' -- *.c | xargs perl -pi -e 's{utils/builtins.h}{utils/fmgrprotos.h}'
There's a large number of changes that the oneliner produces that must
be reverted for the compile to be silent, but a large portion can
remain. (I only tried src/backend/access).

92 files are changed, 241 files still require builtins.h.

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

include-only-fmgrprotos.patchtext/plain; charset=us-asciiDownload+89-89
#8Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#7)
Re: [COMMITTERS] pgsql: Generate fmgr prototypes automatically

Alvaro Herrera <alvherre@2ndquadrant.com> writes:

Alvaro Herrera wrote:

It is possible to replace many occurrences of builtins.h with
fmgrprotos.h. I just tried this
git grep -l 'include.*utils/builtins.h' -- *.c | xargs perl -pi -e 's{utils/builtins.h}{utils/fmgrprotos.h}'
There's a large number of changes that the oneliner produces that must
be reverted for the compile to be silent, but a large portion can
remain. (I only tried src/backend/access).

92 files are changed, 241 files still require builtins.h.

Let's hold off on that till we decide on the bigger-picture plan here.
If we're going to try to move those functions out of builtins.h,
this result will change considerably.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#9Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#1)
Re: [COMMITTERS] pgsql: Generate fmgr prototypes automatically

Peter Eisentraut <peter_e@gmx.net> writes:

Generate fmgr prototypes automatically

BTW, I notice some suspicious-looking behavior with -j:

$ make -j8 -s
Writing fmgroids.h
Writing fmgroids.h
Writing postgres.bki
Writing fmgrprotos.h
Writing fmgrtab.c
Writing schemapg.h
Writing postgres.description
Writing postgres.shdescription
Writing fmgrprotos.h
Writing fmgrtab.c
...

Why do fmgroids.h, fmgrprotos.h, and fmgrtab.c now get mentioned
twice? I suspect there is something broken about the parallelization.
If indeed multiple instances of gmake are writing these files
concurrently, that's likely to result in irreproducible build failures.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#10Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#5)
Re: [COMMITTERS] pgsql: Generate fmgr prototypes automatically

On 1/17/17 3:07 PM, Tom Lane wrote:

Alternatively ... is there a specific reason why you chose to make
builtins.h the key inclusion file for this change, rather than having
callers include fmgrprotos.h directly? It seems like the stuff remaining
in builtins.h is just a laundry list of random utility functions.
Maybe dispersing those to other headers is the thing to do.

Here is a patch that moves two blocks from builtins.h into separate
header files. That avoids having to include nodes/pg_list.h and
utils/sortsupport.h.

The remaining inclusion of nodes/nodes.h is for the oidparse() function.
I think that could be moved out of oid.c and put somewhere near parser/
or objectaddress.c. But the practical savings from avoiding nodes.h is
probably near zero, so I haven't done anything about that here.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

0001-Move-some-things-from-builtins.h-to-new-header-files.patchtext/x-patch; name=0001-Move-some-things-from-builtins.h-to-new-header-files.patchDownload+117-33
#11Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#10)
Re: [COMMITTERS] pgsql: Generate fmgr prototypes automatically

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

Here is a patch that moves two blocks from builtins.h into separate
header files. That avoids having to include nodes/pg_list.h and
utils/sortsupport.h.

Seems like a reasonable solution.

The remaining inclusion of nodes/nodes.h is for the oidparse() function.
I think that could be moved out of oid.c and put somewhere near parser/
or objectaddress.c. But the practical savings from avoiding nodes.h is
probably near zero, so I haven't done anything about that here.

Agreed, not much value in that.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#12Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#9)
Re: [COMMITTERS] pgsql: Generate fmgr prototypes automatically

On 1/18/17 7:38 AM, Tom Lane wrote:

Why do fmgroids.h, fmgrprotos.h, and fmgrtab.c now get mentioned
twice? I suspect there is something broken about the parallelization.
If indeed multiple instances of gmake are writing these files
concurrently, that's likely to result in irreproducible build failures.

I've pushed a fix for this.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#13Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#12)
Re: [COMMITTERS] pgsql: Generate fmgr prototypes automatically

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

On 1/18/17 7:38 AM, Tom Lane wrote:

Why do fmgroids.h, fmgrprotos.h, and fmgrtab.c now get mentioned
twice? I suspect there is something broken about the parallelization.

I've pushed a fix for this.

Seems to fix the problem for me --- thanks!

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers