diff --git a/contrib/intarray/_int.h b/contrib/intarray/_int.h
index 6218cbcd20dbe33c7a44d16df13ef1ff2693c422..f40dc06a92c150a7cd9c08da55a985efd3c3c5e1 100644
--- a/contrib/intarray/_int.h
+++ b/contrib/intarray/_int.h
@@ -1,3 +1,6 @@
+#ifndef ___INT_H__
+#define ___INT_H__
+
 #include "postgres.h"
 
 #include <float.h>
@@ -171,3 +174,5 @@ int			compDESC(const void *a, const void *b);
 if (ARRNELEMS(a) > 1)											\
 		qsort((void*)ARRPTR(a), ARRNELEMS(a),sizeof(int4),		\
 				(direction) ? compASC : compDESC )
+
+#endif
diff --git a/contrib/pgcrypto/pgcrypto.h b/contrib/pgcrypto/pgcrypto.h
index 34bf65320ab43f5f88c6d755872d359cccc72cca..6db7efc407af1c8a1fc85cdd31b1fe7673b80e12 100644
--- a/contrib/pgcrypto/pgcrypto.h
+++ b/contrib/pgcrypto/pgcrypto.h
@@ -26,12 +26,14 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgcrypto.h,v 1.8 2003/11/29 22:39:28 pgsql Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgcrypto.h,v 1.9 2006/07/10 22:06:11 momjian Exp $
  */
 
 #ifndef _PG_CRYPTO_H
 #define _PG_CRYPTO_H
 
+#include "fmgr.h"
+
 /* exported functions */
 Datum		pg_digest(PG_FUNCTION_ARGS);
 Datum		pg_digest_exists(PG_FUNCTION_ARGS);
diff --git a/contrib/tablefunc/tablefunc.h b/contrib/tablefunc/tablefunc.h
index 3c4ed03c2f222415cc713426d0d75a9be1d46b8d..f425b42fc102c118993b9b86ef760bb7de2a27f8 100644
--- a/contrib/tablefunc/tablefunc.h
+++ b/contrib/tablefunc/tablefunc.h
@@ -31,6 +31,8 @@
 #ifndef TABLEFUNC_H
 #define TABLEFUNC_H
 
+#include "fmgr.h"
+
 /*
  * External declarations
  */
diff --git a/contrib/tsearch2/common.h b/contrib/tsearch2/common.h
index d2f4cd66a1908b196af8a80f9fc6f0110895a2d1..c33507e9ac74e89fb35abef8cea3a89f1400dd3c 100644
--- a/contrib/tsearch2/common.h
+++ b/contrib/tsearch2/common.h
@@ -1,11 +1,9 @@
 #ifndef __TS_COMMON_H__
 #define __TS_COMMON_H__
+
 #include "postgres.h"
 #include "fmgr.h"
-
-#ifndef PG_NARGS
-#define PG_NARGS() (fcinfo->nargs)
-#endif
+#include "utils/array.h"
 
 text	   *char2text(char *in);
 text	   *charl2text(char *in, int len);
diff --git a/contrib/tsearch2/query.h b/contrib/tsearch2/query.h
index b4d586a684b085c043c0eb611a269a73a0edf97d..bf1fe18c33a315838d1c85b690b08e92cefa7249 100644
--- a/contrib/tsearch2/query.h
+++ b/contrib/tsearch2/query.h
@@ -48,7 +48,7 @@ typedef struct
 #define CLOSE			5
 #define VALSTOP			6		/* for stop words */
 
-bool TS_execute(ITEM * curitem, void *checkval,
-		   bool calcnot, bool (*chkcond) (void *checkval, ITEM * val));
+bool TS_execute(ITEM *curitem, void *checkval,
+		   bool calcnot, bool (*chkcond) (void *checkval, ITEM *val));
 
 #endif
diff --git a/contrib/tsearch2/query_cleanup.h b/contrib/tsearch2/query_cleanup.h
index d47788a332562a28e867c443158ea6c8876585b7..f6ce893609c248e7d6bd2cec8bca1431820e5e05 100644
--- a/contrib/tsearch2/query_cleanup.h
+++ b/contrib/tsearch2/query_cleanup.h
@@ -1,7 +1,9 @@
 #ifndef __REWRITE_H__
 #define __REWRITE_H__
 
-ITEM	   *clean_NOT_v2(ITEM * ptr, int4 *len);
-ITEM	   *clean_fakeval_v2(ITEM * ptr, int4 *len);
+#include "query.h"
+
+ITEM	   *clean_NOT_v2(ITEM *ptr, int4 *len);
+ITEM	   *clean_fakeval_v2(ITEM *ptr, int4 *len);
 
 #endif
diff --git a/contrib/tsearch2/query_util.h b/contrib/tsearch2/query_util.h
index 484c7f383ca2dfc1156430a9f63515b1b147ba63..5ed98e628ddfc44eb5174b7625e6f56de1be394a 100644
--- a/contrib/tsearch2/query_util.h
+++ b/contrib/tsearch2/query_util.h
@@ -5,6 +5,7 @@
 #include "utils/memutils.h"
 
 #include "query.h"
+#include "executor/spi.h"
 
 typedef struct QTNode
 {
diff --git a/contrib/tsearch2/snowball/header.h b/contrib/tsearch2/snowball/header.h
index 7939fbb8faddd703845d95b008ad6d33c38f93ec..610f99886428c140b01030ba2710da0b08809e2e 100644
--- a/contrib/tsearch2/snowball/header.h
+++ b/contrib/tsearch2/snowball/header.h
@@ -1,10 +1,10 @@
-/* $PostgreSQL: pgsql/contrib/tsearch2/snowball/header.h,v 1.7 2006/03/11 04:38:30 momjian Exp $ */
+/* $PostgreSQL: pgsql/contrib/tsearch2/snowball/header.h,v 1.8 2006/07/10 22:06:11 momjian Exp $ */
 
 #include <limits.h>
 
 #include "api.h"
 
-#define HEAD 2*sizeof(int)
+#define HEAD (2 * sizeof(int))
 
 #define SIZE(p)		   ((int *)(p))[-1]
 #define SET_SIZE(p, n) ((int *)(p))[-1] = n
diff --git a/contrib/tsearch2/ts_stat.h b/contrib/tsearch2/ts_stat.h
index 7d163360451c3a0efc9eef5413c18985ec431776..358b68c808de010be3b819205e80141ea1e6fe57 100644
--- a/contrib/tsearch2/ts_stat.h
+++ b/contrib/tsearch2/ts_stat.h
@@ -7,6 +7,7 @@
 #include "access/itup.h"
 #include "utils/builtins.h"
 #include "storage/bufpage.h"
+#include "tsvector.h"
 
 typedef struct
 {
diff --git a/contrib/userlock/user_locks.h b/contrib/userlock/user_locks.h
index e00735d693dd801a5bb68843081d8df99fda75fe..f7cdc89a099ef6d3f2d8637a4929bceeba41e70f 100644
--- a/contrib/userlock/user_locks.h
+++ b/contrib/userlock/user_locks.h
@@ -1,6 +1,8 @@
 #ifndef USER_LOCKS_H
 #define USER_LOCKS_H
 
+#include "storage/lock.h"
+
 extern int	user_lock(uint32 id1, uint32 id2, LOCKMODE lockmode);
 extern int	user_unlock(uint32 id1, uint32 id2, LOCKMODE lockmode);
 extern int	user_write_lock(uint32 id1, uint32 id2);