From 6f30dc0b653b5b19f9d3ae29788fc922848b52e5 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 1/2] Move atooid() definition to a central place

---
 contrib/lo/lo.c                       | 2 --
 contrib/vacuumlo/vacuumlo.c           | 2 --
 src/backend/bootstrap/bootparse.y     | 2 --
 src/backend/libpq/hba.c               | 3 ---
 src/backend/nodes/readfuncs.c         | 2 --
 src/backend/utils/adt/misc.c          | 2 --
 src/bin/pg_basebackup/pg_basebackup.c | 2 --
 src/bin/pg_upgrade/pg_upgrade.h       | 2 --
 src/bin/psql/common.h                 | 2 --
 src/bin/scripts/droplang.c            | 2 --
 src/include/fe_utils/string_utils.h   | 2 --
 src/include/postgres_ext.h            | 4 ++++
 12 files changed, 4 insertions(+), 23 deletions(-)

diff --git a/contrib/lo/lo.c b/contrib/lo/lo.c
index 953659305f..805514d97a 100644
--- a/contrib/lo/lo.c
+++ b/contrib/lo/lo.c
@@ -14,8 +14,6 @@
 
 PG_MODULE_MAGIC;
 
-#define atooid(x)  ((Oid) strtoul((x), NULL, 10))
-
 
 /*
  * This is the trigger that protects us from orphaned large objects
diff --git a/contrib/vacuumlo/vacuumlo.c b/contrib/vacuumlo/vacuumlo.c
index d9dee2f7a0..06f469067b 100644
--- a/contrib/vacuumlo/vacuumlo.c
+++ b/contrib/vacuumlo/vacuumlo.c
@@ -24,8 +24,6 @@
 #include "libpq-fe.h"
 #include "pg_getopt.h"
 
-#define atooid(x)  ((Oid) strtoul((x), NULL, 10))
-
 #define BUFSIZE			1024
 
 enum trivalue
diff --git a/src/backend/bootstrap/bootparse.y b/src/backend/bootstrap/bootparse.y
index d28af23c94..23bdb5c759 100644
--- a/src/backend/bootstrap/bootparse.y
+++ b/src/backend/bootstrap/bootparse.y
@@ -51,8 +51,6 @@
 #include "tcop/dest.h"
 #include "utils/rel.h"
 
-#define atooid(x)	((Oid) strtoul((x), NULL, 10))
-
 
 /*
  * Bison doesn't allocate anything that needs to live across parser calls,
diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c
index 07f046fd8b..91c5a49de5 100644
--- a/src/backend/libpq/hba.c
+++ b/src/backend/libpq/hba.c
@@ -47,9 +47,6 @@
 #endif
 
 
-#define atooid(x)  ((Oid) strtoul((x), NULL, 10))
-#define atoxid(x)  ((TransactionId) strtoul((x), NULL, 10))
-
 #define MAX_TOKEN	256
 #define MAX_LINE	8192
 
diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c
index dc40d0181e..52b6cc9ffc 100644
--- a/src/backend/nodes/readfuncs.c
+++ b/src/backend/nodes/readfuncs.c
@@ -164,8 +164,6 @@
  */
 #define atoui(x)  ((unsigned int) strtoul((x), NULL, 10))
 
-#define atooid(x)  ((Oid) strtoul((x), NULL, 10))
-
 #define strtobool(x)  ((*(x) == 't') ? true : false)
 
 #define nullable_string(token,length)  \
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c
index 66d09bcb0c..42221da128 100644
--- a/src/backend/utils/adt/misc.c
+++ b/src/backend/utils/adt/misc.c
@@ -44,8 +44,6 @@
 #include "utils/builtins.h"
 #include "utils/timestamp.h"
 
-#define atooid(x)  ((Oid) strtoul((x), NULL, 10))
-
 
 /*
  * Common subroutine for num_nulls() and num_nonnulls().
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 8ebf24e771..f8f1133a1e 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -40,8 +40,6 @@
 #include "streamutil.h"
 
 
-#define atooid(x)  ((Oid) strtoul((x), NULL, 10))
-
 typedef struct TablespaceListCell
 {
 	struct TablespaceListCell *next;
diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h
index 42e7aebb01..524709a118 100644
--- a/src/bin/pg_upgrade/pg_upgrade.h
+++ b/src/bin/pg_upgrade/pg_upgrade.h
@@ -97,8 +97,6 @@ extern char *output_files[];
 #define CLUSTER_NAME(cluster)	((cluster) == &old_cluster ? "old" : \
 								 (cluster) == &new_cluster ? "new" : "none")
 
-#define atooid(x)  ((Oid) strtoul((x), NULL, 10))
-
 /* OID system catalog preservation added during PG 9.0 development */
 #define TABLE_SPACE_SUBDIRS_CAT_VER 201001111
 /* postmaster/postgres -b (binary_upgrade) flag added during PG 9.1 development */
diff --git a/src/bin/psql/common.h b/src/bin/psql/common.h
index dad0eb822a..a83bc69ab7 100644
--- a/src/bin/psql/common.h
+++ b/src/bin/psql/common.h
@@ -13,8 +13,6 @@
 #include "libpq-fe.h"
 #include "fe_utils/print.h"
 
-#define atooid(x)  ((Oid) strtoul((x), NULL, 10))
-
 extern bool openQueryOutputFile(const char *fname, FILE **fout, bool *is_pipe);
 extern bool setQFout(const char *fname);
 
diff --git a/src/bin/scripts/droplang.c b/src/bin/scripts/droplang.c
index ab0215d495..97d1de43ae 100644
--- a/src/bin/scripts/droplang.c
+++ b/src/bin/scripts/droplang.c
@@ -14,8 +14,6 @@
 #include "common.h"
 #include "fe_utils/print.h"
 
-#define atooid(x)  ((Oid) strtoul((x), NULL, 10))
-
 
 static void help(const char *progname);
 
diff --git a/src/include/fe_utils/string_utils.h b/src/include/fe_utils/string_utils.h
index 8f96a0b991..6fb7f5e30e 100644
--- a/src/include/fe_utils/string_utils.h
+++ b/src/include/fe_utils/string_utils.h
@@ -19,8 +19,6 @@
 #include "libpq-fe.h"
 #include "pqexpbuffer.h"
 
-#define atooid(x)  ((Oid) strtoul((x), NULL, 10))
-
 /* Global variables controlling behavior of fmtId() and fmtQualifiedId() */
 extern int	quote_all_identifiers;
 extern PQExpBuffer (*getLocalPQExpBuffer) (void);
diff --git a/src/include/postgres_ext.h b/src/include/postgres_ext.h
index ae2f087798..452eae9935 100644
--- a/src/include/postgres_ext.h
+++ b/src/include/postgres_ext.h
@@ -39,6 +39,10 @@ typedef unsigned int Oid;
 #define OID_MAX  UINT_MAX
 /* you will need to include <limits.h> to use the above #define */
 
+#define atooid(x) ((Oid) strtoul((x), NULL, 10))
+/* the above needs <stdlib.h> */
+
+
 /* Define a signed 64-bit integer type for use in client API declarations. */
 typedef PG_INT64_TYPE pg_int64;
 
-- 
2.11.0

