From a859e640035680db31531ccd19a67292dd726baf Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Fri, 19 Aug 2016 13:31:10 -0400
Subject: [PATCH] Clean up another pre-ANSI-C-ism in regex code: get rid of
 pcolor typedef.

pcolor was used to represent function arguments that are nominally of
type color, but when using a pre-ANSI C compiler would be passed as the
promoted integer type.  We really don't need that anymore.
---
 src/backend/regex/regc_color.c | 10 +++++-----
 src/backend/regex/regc_nfa.c   |  8 ++++----
 src/backend/regex/regcomp.c    | 14 +++++++-------
 src/backend/regex/rege_dfa.c   |  6 +++---
 src/backend/regex/regexec.c    |  4 ++--
 src/include/regex/regguts.h    |  1 -
 6 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/src/backend/regex/regc_color.c b/src/backend/regex/regc_color.c
index c495cee3003..8ffc8fb797d 100644
--- a/src/backend/regex/regc_color.c
+++ b/src/backend/regex/regc_color.c
@@ -148,7 +148,7 @@ cmtreefree(struct colormap * cm,
 static color					/* previous color */
 setcolor(struct colormap * cm,
 		 chr c,
-		 pcolor co)
+		 color co)
 {
 	uchr		uc = c;
 	int			shift;
@@ -199,7 +199,7 @@ setcolor(struct colormap * cm,
 
 	b = uc & BYTMASK;
 	prev = t->tcolor[b];
-	t->tcolor[b] = (color) co;
+	t->tcolor[b] = co;
 	return prev;
 }
 
@@ -293,7 +293,7 @@ newcolor(struct colormap * cm)
  */
 static void
 freecolor(struct colormap * cm,
-		  pcolor co)
+		  color co)
 {
 	struct colordesc *cd = &cm->cd[co];
 	color		pco,
@@ -393,7 +393,7 @@ subcolor(struct colormap * cm, chr c)
  */
 static color
 newsub(struct colormap * cm,
-	   pcolor co)
+	   color co)
 {
 	color		sco;			/* new subcolor */
 
@@ -658,7 +658,7 @@ static void
 rainbow(struct nfa * nfa,
 		struct colormap * cm,
 		int type,
-		pcolor but,				/* COLORLESS if no exceptions */
+		color but,				/* COLORLESS if no exceptions */
 		struct state * from,
 		struct state * to)
 {
diff --git a/src/backend/regex/regc_nfa.c b/src/backend/regex/regc_nfa.c
index cd9a3239bd3..90dca5d9dea 100644
--- a/src/backend/regex/regc_nfa.c
+++ b/src/backend/regex/regc_nfa.c
@@ -275,7 +275,7 @@ destroystate(struct nfa * nfa,
 static void
 newarc(struct nfa * nfa,
 	   int t,
-	   pcolor co,
+	   color co,
 	   struct state * from,
 	   struct state * to)
 {
@@ -321,7 +321,7 @@ newarc(struct nfa * nfa,
 static void
 createarc(struct nfa * nfa,
 		  int t,
-		  pcolor co,
+		  color co,
 		  struct state * from,
 		  struct state * to)
 {
@@ -334,7 +334,7 @@ createarc(struct nfa * nfa,
 	assert(a != NULL);
 
 	a->type = t;
-	a->co = (color) co;
+	a->co = co;
 	a->to = to;
 	a->from = from;
 
@@ -553,7 +553,7 @@ hasnonemptyout(struct state * s)
 static struct arc *
 findarc(struct state * s,
 		int type,
-		pcolor co)
+		color co)
 {
 	struct arc *a;
 
diff --git a/src/backend/regex/regcomp.c b/src/backend/regex/regcomp.c
index 48d63da11de..b211cc0a189 100644
--- a/src/backend/regex/regcomp.c
+++ b/src/backend/regex/regcomp.c
@@ -97,19 +97,19 @@ static chr	chrnamed(struct vars *, const chr *, const chr *, chr);
 static void initcm(struct vars *, struct colormap *);
 static void freecm(struct colormap *);
 static void cmtreefree(struct colormap *, union tree *, int);
-static color setcolor(struct colormap *, chr, pcolor);
+static color setcolor(struct colormap *, chr, color);
 static color maxcolor(struct colormap *);
 static color newcolor(struct colormap *);
-static void freecolor(struct colormap *, pcolor);
+static void freecolor(struct colormap *, color);
 static color pseudocolor(struct colormap *);
 static color subcolor(struct colormap *, chr c);
-static color newsub(struct colormap *, pcolor);
+static color newsub(struct colormap *, color);
 static void subrange(struct vars *, chr, chr, struct state *, struct state *);
 static void subblock(struct vars *, chr, struct state *, struct state *);
 static void okcolors(struct nfa *, struct colormap *);
 static void colorchain(struct colormap *, struct arc *);
 static void uncolorchain(struct colormap *, struct arc *);
-static void rainbow(struct nfa *, struct colormap *, int, pcolor, struct state *, struct state *);
+static void rainbow(struct nfa *, struct colormap *, int, color, struct state *, struct state *);
 static void colorcomplement(struct nfa *, struct colormap *, int, struct state *, struct state *, struct state *);
 
 #ifdef REG_DEBUG
@@ -125,13 +125,13 @@ static struct state *newfstate(struct nfa *, int flag);
 static void dropstate(struct nfa *, struct state *);
 static void freestate(struct nfa *, struct state *);
 static void destroystate(struct nfa *, struct state *);
-static void newarc(struct nfa *, int, pcolor, struct state *, struct state *);
-static void createarc(struct nfa *, int, pcolor, struct state *, struct state *);
+static void newarc(struct nfa *, int, color, struct state *, struct state *);
+static void createarc(struct nfa *, int, color, struct state *, struct state *);
 static struct arc *allocarc(struct nfa *, struct state *);
 static void freearc(struct nfa *, struct arc *);
 static void changearctarget(struct arc *, struct state *);
 static int	hasnonemptyout(struct state *);
-static struct arc *findarc(struct state *, int, pcolor);
+static struct arc *findarc(struct state *, int, color);
 static void cparc(struct nfa *, struct arc *, struct state *, struct state *);
 static void sortins(struct nfa *, struct state *);
 static int	sortins_cmp(const void *, const void *);
diff --git a/src/backend/regex/rege_dfa.c b/src/backend/regex/rege_dfa.c
index 7d90242acef..b98c9d39021 100644
--- a/src/backend/regex/rege_dfa.c
+++ b/src/backend/regex/rege_dfa.c
@@ -603,7 +603,7 @@ static struct sset *
 miss(struct vars * v,
 	 struct dfa * d,
 	 struct sset * css,
-	 pcolor co,
+	 color co,
 	 chr *cp,					/* next chr */
 	 chr *start)				/* where the attempt got started */
 {
@@ -731,7 +731,7 @@ miss(struct vars * v,
 		css->outs[co] = p;
 		css->inchain[co] = p->ins;
 		p->ins.ss = css;
-		p->ins.co = (color) co;
+		p->ins.co = co;
 	}
 	return p;
 }
@@ -743,7 +743,7 @@ static int						/* predicate:  constraint satisfied? */
 lacon(struct vars * v,
 	  struct cnfa * pcnfa,		/* parent cnfa */
 	  chr *cp,
-	  pcolor co)				/* "color" of the lookaround constraint */
+	  color co)					/* "color" of the lookaround constraint */
 {
 	int			n;
 	struct subre *sub;
diff --git a/src/backend/regex/regexec.c b/src/backend/regex/regexec.c
index 82659a0f2f4..5cbfd9b151b 100644
--- a/src/backend/regex/regexec.c
+++ b/src/backend/regex/regexec.c
@@ -159,8 +159,8 @@ static struct dfa *newdfa(struct vars *, struct cnfa *, struct colormap *, struc
 static void freedfa(struct dfa *);
 static unsigned hash(unsigned *, int);
 static struct sset *initialize(struct vars *, struct dfa *, chr *);
-static struct sset *miss(struct vars *, struct dfa *, struct sset *, pcolor, chr *, chr *);
-static int	lacon(struct vars *, struct cnfa *, chr *, pcolor);
+static struct sset *miss(struct vars *, struct dfa *, struct sset *, color, chr *, chr *);
+static int	lacon(struct vars *, struct cnfa *, chr *, color);
 static struct sset *getvacant(struct vars *, struct dfa *, chr *, chr *);
 static struct sset *pickss(struct vars *, struct dfa *, chr *, chr *);
 
diff --git a/src/include/regex/regguts.h b/src/include/regex/regguts.h
index 2ceffa6563b..b0aa641cc4f 100644
--- a/src/include/regex/regguts.h
+++ b/src/include/regex/regguts.h
@@ -149,7 +149,6 @@
  * which are of much more manageable number.
  */
 typedef short color;			/* colors of characters */
-typedef int pcolor;				/* what color promotes to */
 
 #define MAX_COLOR	32767		/* max color (must fit in 'color' datatype) */
 #define COLORLESS	(-1)		/* impossible color */
-- 
GitLab