From 74e07d330aae3c4b68c792f4d82c2a77fb4d80a8 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Wed, 11 Jan 2017 12:00:00 -0500
Subject: [PATCH 2/2] Collect duplicate copies of oid_cmp()

---
 src/backend/catalog/pg_enum.c     | 15 ---------------
 src/backend/catalog/pg_inherits.c | 18 +-----------------
 src/backend/utils/adt/acl.c       | 20 +-------------------
 src/backend/utils/adt/oid.c       | 14 ++++++++++++++
 src/include/utils/builtins.h      |  1 +
 5 files changed, 17 insertions(+), 51 deletions(-)

diff --git a/src/backend/catalog/pg_enum.c b/src/backend/catalog/pg_enum.c
index 77cf608bb1..8175f6a0a7 100644
--- a/src/backend/catalog/pg_enum.c
+++ b/src/backend/catalog/pg_enum.c
@@ -35,7 +35,6 @@
 Oid			binary_upgrade_next_pg_enum_oid = InvalidOid;
 
 static void RenumberEnumType(Relation pg_enum, HeapTuple *existing, int nelems);
-static int	oid_cmp(const void *p1, const void *p2);
 static int	sort_order_cmp(const void *p1, const void *p2);
 
 
@@ -609,20 +608,6 @@ RenumberEnumType(Relation pg_enum, HeapTuple *existing, int nelems)
 }
 
 
-/* qsort comparison function for oids */
-static int
-oid_cmp(const void *p1, const void *p2)
-{
-	Oid			v1 = *((const Oid *) p1);
-	Oid			v2 = *((const Oid *) p2);
-
-	if (v1 < v2)
-		return -1;
-	if (v1 > v2)
-		return 1;
-	return 0;
-}
-
 /* qsort comparison function for tuples by sort order */
 static int
 sort_order_cmp(const void *p1, const void *p2)
diff --git a/src/backend/catalog/pg_inherits.c b/src/backend/catalog/pg_inherits.c
index 82662a1f7e..9bd2cd16f6 100644
--- a/src/backend/catalog/pg_inherits.c
+++ b/src/backend/catalog/pg_inherits.c
@@ -27,12 +27,11 @@
 #include "catalog/pg_inherits_fn.h"
 #include "parser/parse_type.h"
 #include "storage/lmgr.h"
+#include "utils/builtins.h"
 #include "utils/fmgroids.h"
 #include "utils/syscache.h"
 #include "utils/tqual.h"
 
-static int	oid_cmp(const void *p1, const void *p2);
-
 
 /*
  * find_inheritance_children
@@ -357,18 +356,3 @@ typeInheritsFrom(Oid subclassTypeId, Oid superclassTypeId)
 
 	return result;
 }
-
-
-/* qsort comparison function */
-static int
-oid_cmp(const void *p1, const void *p2)
-{
-	Oid			v1 = *((const Oid *) p1);
-	Oid			v2 = *((const Oid *) p2);
-
-	if (v1 < v2)
-		return -1;
-	if (v1 > v2)
-		return 1;
-	return 0;
-}
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c
index 56a69764c4..f9ba429107 100644
--- a/src/backend/utils/adt/acl.c
+++ b/src/backend/utils/adt/acl.c
@@ -87,7 +87,6 @@ static void check_circularity(const Acl *old_acl, const AclItem *mod_aip,
 				  Oid ownerId);
 static Acl *recursive_revoke(Acl *acl, Oid grantee, AclMode revoke_privs,
 				 Oid ownerId, DropBehavior behavior);
-static int	oidComparator(const void *arg1, const void *arg2);
 
 static AclMode convert_priv_string(text *priv_type_text);
 static AclMode convert_any_priv_string(text *priv_type_text,
@@ -1489,7 +1488,7 @@ aclmembers(const Acl *acl, Oid **roleids)
 	}
 
 	/* Sort the array */
-	qsort(list, j, sizeof(Oid), oidComparator);
+	qsort(list, j, sizeof(Oid), oid_cmp);
 
 	/* Remove duplicates from the array */
 	k = 0;
@@ -1508,23 +1507,6 @@ aclmembers(const Acl *acl, Oid **roleids)
 	return k + 1;
 }
 
-/*
- * oidComparator
- *		qsort comparison function for Oids
- */
-static int
-oidComparator(const void *arg1, const void *arg2)
-{
-	Oid			oid1 = *(const Oid *) arg1;
-	Oid			oid2 = *(const Oid *) arg2;
-
-	if (oid1 > oid2)
-		return 1;
-	if (oid1 < oid2)
-		return -1;
-	return 0;
-}
-
 
 /*
  * aclinsert (exported function)
diff --git a/src/backend/utils/adt/oid.c b/src/backend/utils/adt/oid.c
index fd123827dd..6ec6edd9fb 100644
--- a/src/backend/utils/adt/oid.c
+++ b/src/backend/utils/adt/oid.c
@@ -328,6 +328,20 @@ oidparse(Node *node)
 	return InvalidOid;			/* keep compiler quiet */
 }
 
+/* qsort comparison function for oids */
+int
+oid_cmp(const void *p1, const void *p2)
+{
+	Oid			v1 = *((const Oid *) p1);
+	Oid			v2 = *((const Oid *) p2);
+
+	if (v1 < v2)
+		return -1;
+	if (v1 > v2)
+		return 1;
+	return 0;
+}
+
 
 /*****************************************************************************
  *	 PUBLIC ROUTINES														 *
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index e1bb344e4f..1541d6fb74 100644
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -548,6 +548,7 @@ extern Datum oidvectorge(PG_FUNCTION_ARGS);
 extern Datum oidvectorgt(PG_FUNCTION_ARGS);
 extern oidvector *buildoidvector(const Oid *oids, int n);
 extern Oid	oidparse(Node *node);
+extern int	oid_cmp(const void *p1, const void *p2);
 
 /* orderedsetaggs.c */
 extern Datum ordered_set_transition(PG_FUNCTION_ARGS);
-- 
2.11.0

