Document intentional violations of header inclusion policy.
authorTom Lane <[email protected]>
Wed, 8 Mar 2017 22:01:13 +0000 (17:01 -0500)
committerTom Lane <[email protected]>
Wed, 8 Mar 2017 22:01:13 +0000 (17:01 -0500)
Although there are good reasons for our policy of including postgres.h
as the first #include in every .c file, never from .h files, there are
two places where it seems expedient to violate the policy because the
alternative is to modify externally-supplied .c files.  (In the case
of the regexp library, the idea that it's externally-supplied is kind
of at odds with reality, but I haven't entirely given up hope that it
will become a standalone project some day.)  Add some comments to make
it explicit that this is a policy violation and provide the reasoning.

In passing, move #include "miscadmin.h" out of regcomp.c and into
regcustom.h, which is where it should be if we're taking this reasoning
seriously at all.

Discussion: https://postgr.es/m/CAEepm=2zCoeq3QxVwhS5DFeUh=yU6z81pbWMgfOB8OzyiBwxzw@mail.gmail.com
Discussion: https://postgr.es/m/11634.1488932128@sss.pgh.pa.us

src/backend/regex/regcomp.c
src/include/regex/regcustom.h
src/include/snowball/header.h

index ed95474b3f073fc10670bbc1646697714f91cfb8..0834ae6e064a89dde094bc6306493f9d357ae256 100644 (file)
@@ -34,8 +34,6 @@
 
 #include "regex/regguts.h"
 
-#include "miscadmin.h"         /* needed by rcancelrequested/rstacktoodeep */
-
 /*
  * forward declarations, up here so forward datatypes etc. are defined early
  */
index 04a1893c806ff38556a6f1e490936128ec355fed..82c9e2fad81502ca006c6ebb6f14d5e3e23f0ef7 100644 (file)
  */
 
 /* headers if any */
+
+/*
+ * It's against Postgres coding conventions to include postgres.h in a
+ * header file, but we allow the violation here because the regexp library
+ * files specifically intend this file to supply application-dependent
+ * headers, and are careful to include this file before anything else.
+ */
 #include "postgres.h"
 
 #include <ctype.h>
@@ -47,6 +54,8 @@
 
 #include "mb/pg_wchar.h"
 
+#include "miscadmin.h"         /* needed by rcancelrequested/rstacktoodeep */
+
 
 /* overrides for regguts.h definitions, if any */
 #define FUNCPTR(name, args) (*name) args
index 9501f77ac14ae7afbb352e88407e98f2c47f9d3c..d8be02ee609e5ae548c20db0e6c8b64b76677e8d 100644 (file)
 #ifndef SNOWBALL_HEADR_H
 #define SNOWBALL_HEADR_H
 
+/*
+ * It's against Postgres coding conventions to include postgres.h in a
+ * header file, but we allow the violation here because the alternative is
+ * to modify the machine-generated .c files provided by the Snowball project.
+ */
 #include "postgres.h"
 
 /* Some platforms define MAXINT and/or MININT, causing conflicts */