Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f62975b

Browse files
committed
Tighten header pre-inclusions in headerscheck and cpluspluscheck.
We allow our header files to depend on the appropriate one of postgres.h, postgres_fe.h, or c.h having already been included. However, there are a few headers such as libpq-fe.h that are meant to be used by client applications and therefore must compile without any assumptions about previous inclusions. These test scripts failed to consider that, which seems quite hazardous since we might not immediately notice such a problem otherwise. Hence, adjust these scripts to test relevant libpq and ecpg headers with no prior inclusion. While at it, we can also make an effort to actually use the relevant one of postgres.h, postgres_fe.h, or c.h. I added some rules that guess which one to use based on the first-level src subdirectory, e.g. use postgres_fe.h under src/bin/. These rules are hardly water-tight but they seem to work today, and we can always refine them in the future. These changes don't reveal any live problems today, which is good, but they should make these scripts more able to catch future bugs. Discussion: https://postgr.es/m/2488193.1677863247@sss.pgh.pa.us
1 parent ebd551f commit f62975b

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

src/tools/pginclude/cpluspluscheck

+29-3
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,33 @@ do
161161
# OK, create .c file to include this .h file.
162162
{
163163
echo 'extern "C" {'
164-
test "$f" != src/include/postgres_fe.h && echo '#include "postgres.h"'
164+
# Ideally we'd pre-include only the appropriate one of
165+
# postgres.h, postgres_fe.h, or c.h. We don't always have enough
166+
# info to guess which, but in some subdirectories there's a
167+
# reasonable choice to make, and otherwise we use postgres.h.
168+
# Also, those three files should compile with no pre-include, as
169+
# should src/interfaces headers meant to be exposed to clients.
170+
case "$f" in
171+
src/include/postgres.h) ;;
172+
src/include/postgres_fe.h) ;;
173+
src/include/c.h) ;;
174+
src/interfaces/libpq/libpq-fe.h) ;;
175+
src/interfaces/libpq/libpq-events.h) ;;
176+
src/interfaces/ecpg/ecpglib/ecpglib_extern.h)
177+
echo '#include "postgres_fe.h"' ;;
178+
src/interfaces/ecpg/ecpglib/*) ;;
179+
src/interfaces/*)
180+
echo '#include "postgres_fe.h"' ;;
181+
src/bin/*)
182+
echo '#include "postgres_fe.h"' ;;
183+
src/fe_utils/*)
184+
echo '#include "postgres_fe.h"' ;;
185+
src/port/*) ;;
186+
src/common/*)
187+
echo '#include "c.h"' ;;
188+
*)
189+
echo '#include "postgres.h"' ;;
190+
esac
165191
echo "#include \"$f\""
166192
echo '};'
167193
} >$tmp/test.cpp
@@ -174,9 +200,9 @@ do
174200
EXTRAINCLUDES="$python_includespec" ;;
175201
src/interfaces/ecpg/*)
176202
EXTRAINCLUDES="-I $builddir/src/interfaces/ecpg/include -I $srcdir/src/interfaces/ecpg/include" ;;
177-
src/backend/parser/*)
203+
src/backend/parser/*)
178204
EXTRAINCLUDES="-I $builddir/src/backend/parser/" ;;
179-
src/backend/utils/adt/*)
205+
src/backend/utils/adt/*)
180206
EXTRAINCLUDES="-I $builddir/src/backend/utils/adt/" ;;
181207
*)
182208
EXTRAINCLUDES="" ;;

src/tools/pginclude/headerscheck

+27-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,33 @@ do
142142

143143
# OK, create .c file to include this .h file.
144144
{
145-
test "$f" != src/include/postgres_fe.h && echo '#include "postgres.h"'
145+
# Ideally we'd pre-include only the appropriate one of
146+
# postgres.h, postgres_fe.h, or c.h. We don't always have enough
147+
# info to guess which, but in some subdirectories there's a
148+
# reasonable choice to make, and otherwise we use postgres.h.
149+
# Also, those three files should compile with no pre-include, as
150+
# should src/interfaces headers meant to be exposed to clients.
151+
case "$f" in
152+
src/include/postgres.h) ;;
153+
src/include/postgres_fe.h) ;;
154+
src/include/c.h) ;;
155+
src/interfaces/libpq/libpq-fe.h) ;;
156+
src/interfaces/libpq/libpq-events.h) ;;
157+
src/interfaces/ecpg/ecpglib/ecpglib_extern.h)
158+
echo '#include "postgres_fe.h"' ;;
159+
src/interfaces/ecpg/ecpglib/*) ;;
160+
src/interfaces/*)
161+
echo '#include "postgres_fe.h"' ;;
162+
src/bin/*)
163+
echo '#include "postgres_fe.h"' ;;
164+
src/fe_utils/*)
165+
echo '#include "postgres_fe.h"' ;;
166+
src/port/*) ;;
167+
src/common/*)
168+
echo '#include "c.h"' ;;
169+
*)
170+
echo '#include "postgres.h"' ;;
171+
esac
146172
echo "#include \"$f\""
147173
} >$tmp/test.c
148174

0 commit comments

Comments
 (0)