diff options
Diffstat (limited to 'src/backend/utils/adt')
| -rw-r--r-- | src/backend/utils/adt/array_selfuncs.c | 48 | ||||
| -rw-r--r-- | src/backend/utils/adt/arrayfuncs.c | 10 | ||||
| -rw-r--r-- | src/backend/utils/adt/formatting.c | 778 | ||||
| -rw-r--r-- | src/backend/utils/adt/json.c | 6 | ||||
| -rw-r--r-- | src/backend/utils/adt/jsonfuncs.c | 28 | ||||
| -rw-r--r-- | src/backend/utils/adt/jsonpath_scan.l | 6 | ||||
| -rw-r--r-- | src/backend/utils/adt/multirangetypes_selfuncs.c | 16 | ||||
| -rw-r--r-- | src/backend/utils/adt/network_selfuncs.c | 20 | ||||
| -rw-r--r-- | src/backend/utils/adt/orderedsetaggs.c | 4 | ||||
| -rw-r--r-- | src/backend/utils/adt/pg_locale_builtin.c | 44 | ||||
| -rw-r--r-- | src/backend/utils/adt/pg_locale_icu.c | 5 | ||||
| -rw-r--r-- | src/backend/utils/adt/pg_locale_libc.c | 3 | ||||
| -rw-r--r-- | src/backend/utils/adt/pgstatfuncs.c | 20 | ||||
| -rw-r--r-- | src/backend/utils/adt/rangetypes_selfuncs.c | 16 | ||||
| -rw-r--r-- | src/backend/utils/adt/selfuncs.c | 7 | ||||
| -rw-r--r-- | src/backend/utils/adt/tid.c | 6 | ||||
| -rw-r--r-- | src/backend/utils/adt/tsvector_op.c | 12 | ||||
| -rw-r--r-- | src/backend/utils/adt/varlena.c | 40 | ||||
| -rw-r--r-- | src/backend/utils/adt/xml.c | 4 | 
19 files changed, 524 insertions, 549 deletions
diff --git a/src/backend/utils/adt/array_selfuncs.c b/src/backend/utils/adt/array_selfuncs.c index cf6fbf8652c..4dab35b0057 100644 --- a/src/backend/utils/adt/array_selfuncs.c +++ b/src/backend/utils/adt/array_selfuncs.c @@ -39,25 +39,25 @@  static Selectivity calc_arraycontsel(VariableStatData *vardata, Datum constval,  									 Oid elemtype, Oid operator); -static Selectivity mcelem_array_selec(ArrayType *array, +static Selectivity mcelem_array_selec(const ArrayType *array,  									  TypeCacheEntry *typentry, -									  Datum *mcelem, int nmcelem, -									  float4 *numbers, int nnumbers, -									  float4 *hist, int nhist, +									  const Datum *mcelem, int nmcelem, +									  const float4 *numbers, int nnumbers, +									  const float4 *hist, int nhist,  									  Oid operator); -static Selectivity mcelem_array_contain_overlap_selec(Datum *mcelem, int nmcelem, -													  float4 *numbers, int nnumbers, -													  Datum *array_data, int nitems, +static Selectivity mcelem_array_contain_overlap_selec(const Datum *mcelem, int nmcelem, +													  const float4 *numbers, int nnumbers, +													  const Datum *array_data, int nitems,  													  Oid operator, TypeCacheEntry *typentry); -static Selectivity mcelem_array_contained_selec(Datum *mcelem, int nmcelem, -												float4 *numbers, int nnumbers, -												Datum *array_data, int nitems, -												float4 *hist, int nhist, +static Selectivity mcelem_array_contained_selec(const Datum *mcelem, int nmcelem, +												const float4 *numbers, int nnumbers, +												const Datum *array_data, int nitems, +												const float4 *hist, int nhist,  												Oid operator, TypeCacheEntry *typentry);  static float *calc_hist(const float4 *hist, int nhist, int n);  static float *calc_distr(const float *p, int n, int m, float rest);  static int	floor_log2(uint32 n); -static bool find_next_mcelem(Datum *mcelem, int nmcelem, Datum value, +static bool find_next_mcelem(const Datum *mcelem, int nmcelem, Datum value,  							 int *index, TypeCacheEntry *typentry);  static int	element_compare(const void *key1, const void *key2, void *arg);  static int	float_compare_desc(const void *key1, const void *key2); @@ -425,10 +425,10 @@ calc_arraycontsel(VariableStatData *vardata, Datum constval,   * mcelem_array_contained_selec depending on the operator.   */  static Selectivity -mcelem_array_selec(ArrayType *array, TypeCacheEntry *typentry, -				   Datum *mcelem, int nmcelem, -				   float4 *numbers, int nnumbers, -				   float4 *hist, int nhist, +mcelem_array_selec(const ArrayType *array, TypeCacheEntry *typentry, +				   const Datum *mcelem, int nmcelem, +				   const float4 *numbers, int nnumbers, +				   const float4 *hist, int nhist,  				   Oid operator)  {  	Selectivity selec; @@ -518,9 +518,9 @@ mcelem_array_selec(ArrayType *array, TypeCacheEntry *typentry,   * fraction of nonempty arrays in the column.   */  static Selectivity -mcelem_array_contain_overlap_selec(Datum *mcelem, int nmcelem, -								   float4 *numbers, int nnumbers, -								   Datum *array_data, int nitems, +mcelem_array_contain_overlap_selec(const Datum *mcelem, int nmcelem, +								   const float4 *numbers, int nnumbers, +								   const Datum *array_data, int nitems,  								   Oid operator, TypeCacheEntry *typentry)  {  	Selectivity selec, @@ -699,10 +699,10 @@ mcelem_array_contain_overlap_selec(Datum *mcelem, int nmcelem,   * ... * fn^on * (1 - fn)^(1 - on), o1, o2, ..., on) | o1 + o2 + .. on = m   */  static Selectivity -mcelem_array_contained_selec(Datum *mcelem, int nmcelem, -							 float4 *numbers, int nnumbers, -							 Datum *array_data, int nitems, -							 float4 *hist, int nhist, +mcelem_array_contained_selec(const Datum *mcelem, int nmcelem, +							 const float4 *numbers, int nnumbers, +							 const Datum *array_data, int nitems, +							 const float4 *hist, int nhist,  							 Oid operator, TypeCacheEntry *typentry)  {  	int			mcelem_index, @@ -1136,7 +1136,7 @@ floor_log2(uint32 n)   * exact match.)   */  static bool -find_next_mcelem(Datum *mcelem, int nmcelem, Datum value, int *index, +find_next_mcelem(const Datum *mcelem, int nmcelem, Datum value, int *index,  				 TypeCacheEntry *typentry)  {  	int			l = *index, diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c index a8951f55b93..a464349ee33 100644 --- a/src/backend/utils/adt/arrayfuncs.c +++ b/src/backend/utils/adt/arrayfuncs.c @@ -960,8 +960,8 @@ ending_error:   */  void  CopyArrayEls(ArrayType *array, -			 Datum *values, -			 bool *nulls, +			 const Datum *values, +			 const bool *nulls,  			 int nitems,  			 int typlen,  			 bool typbyval, @@ -3629,7 +3629,7 @@ construct_empty_expanded_array(Oid element_type,   * to hard-wire values if the element type is hard-wired.   */  void -deconstruct_array(ArrayType *array, +deconstruct_array(const ArrayType *array,  				  Oid elmtype,  				  int elmlen, bool elmbyval, char elmalign,  				  Datum **elemsp, bool **nullsp, int *nelemsp) @@ -3695,7 +3695,7 @@ deconstruct_array(ArrayType *array,   * useful when manipulating arrays from/for system catalogs.   */  void -deconstruct_array_builtin(ArrayType *array, +deconstruct_array_builtin(const ArrayType *array,  						  Oid elmtype,  						  Datum **elemsp, bool **nullsp, int *nelemsp)  { @@ -3765,7 +3765,7 @@ deconstruct_array_builtin(ArrayType *array,   * if the array *might* contain a null.   */  bool -array_contains_nulls(ArrayType *array) +array_contains_nulls(const ArrayType *array)  {  	int			nelems;  	bits8	   *bitmap; diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index 78e19ac39ac..5f7b3114da7 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -1,4 +1,4 @@ -/* ----------------------------------------------------------------------- +/*-------------------------------------------------------------------------   * formatting.c   *   * src/backend/utils/adt/formatting.c @@ -54,7 +54,7 @@   *	  than Oracle :-),   *		to_char('Hello', 'X X X X X') -> 'H e l l o'   * - * ----------------------------------------------------------------------- + *-------------------------------------------------------------------------   */  #ifdef DEBUG_TO_FROM_CHAR @@ -92,44 +92,46 @@  #include "varatt.h" -/* ---------- +/*   * Routines flags - * ----------   */  #define DCH_FLAG		0x1		/* DATE-TIME flag	*/  #define NUM_FLAG		0x2		/* NUMBER flag	*/  #define STD_FLAG		0x4		/* STANDARD flag	*/ -/* ---------- +/*   * KeyWord Index (ascii from position 32 (' ') to 126 (~)) - * ----------   */  #define KeyWord_INDEX_SIZE		('~' - ' ')  #define KeyWord_INDEX_FILTER(_c)	((_c) <= ' ' || (_c) >= '~' ? 0 : 1) -/* ---------- +/*   * Maximal length of one node - * ----------   */  #define DCH_MAX_ITEM_SIZ	   12	/* max localized day name		*/  #define NUM_MAX_ITEM_SIZ		8	/* roman number (RN has 15 chars)	*/ -/* ---------- +/*   * Format parser structs - * ----------   */ + +enum KeySuffixType +{ +	SUFFTYPE_PREFIX = 1, +	SUFFTYPE_POSTFIX = 2, +}; +  typedef struct  {  	const char *name;			/* suffix string		*/ -	int			len,			/* suffix length		*/ -				id,				/* used in node->suffix */ -				type;			/* prefix / postfix		*/ +	size_t		len;			/* suffix length		*/ +	int			id;				/* used in node->suffix */ +	enum KeySuffixType type;	/* prefix / postfix		*/  } KeySuffix; -/* ---------- +/*   * FromCharDateMode - * ----------   *   * This value is used to nominate one of several distinct (and mutually   * exclusive) date conventions that a keyword can belong to. @@ -144,36 +146,33 @@ typedef enum  typedef struct  {  	const char *name; -	int			len; +	size_t		len;  	int			id;  	bool		is_digit;  	FromCharDateMode date_mode;  } KeyWord; +enum FormatNodeType +{ +	NODE_TYPE_END = 1, +	NODE_TYPE_ACTION = 2, +	NODE_TYPE_CHAR = 3, +	NODE_TYPE_SEPARATOR = 4, +	NODE_TYPE_SPACE = 5, +}; +  typedef struct  { -	uint8		type;			/* NODE_TYPE_XXX, see below */ +	enum FormatNodeType type;  	char		character[MAX_MULTIBYTE_CHAR_LEN + 1];	/* if type is CHAR */ -	uint8		suffix;			/* keyword prefix/suffix code, if any */ +	uint8		suffix;			/* keyword prefix/suffix code, if any +								 * (DCH_SUFFIX_*) */  	const KeyWord *key;			/* if type is ACTION */  } FormatNode; -#define NODE_TYPE_END		1 -#define NODE_TYPE_ACTION	2 -#define NODE_TYPE_CHAR		3 -#define NODE_TYPE_SEPARATOR	4 -#define NODE_TYPE_SPACE		5 - -#define SUFFTYPE_PREFIX		1 -#define SUFFTYPE_POSTFIX	2 - -#define CLOCK_24_HOUR		0 -#define CLOCK_12_HOUR		1 - -/* ---------- +/*   * Full months - * ----------   */  static const char *const months_full[] = {  	"January", "February", "March", "April", "May", "June", "July", @@ -184,9 +183,9 @@ static const char *const days_short[] = {  	"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL  }; -/* ---------- +/*   * AD / BC - * ---------- + *   *	There is no 0 AD.  Years go from 1 BC to 1 AD, so we make it   *	positive and map year == -1 to year zero, and shift all negative   *	years up one.  For interval years, we just return the year. @@ -216,9 +215,8 @@ static const char *const days_short[] = {  static const char *const adbc_strings[] = {ad_STR, bc_STR, AD_STR, BC_STR, NULL};  static const char *const adbc_strings_long[] = {a_d_STR, b_c_STR, A_D_STR, B_C_STR, NULL}; -/* ---------- +/*   * AM / PM - * ----------   */  #define A_M_STR		"A.M."  #define a_m_STR		"a.m." @@ -243,11 +241,10 @@ static const char *const adbc_strings_long[] = {a_d_STR, b_c_STR, A_D_STR, B_C_S  static const char *const ampm_strings[] = {am_STR, pm_STR, AM_STR, PM_STR, NULL};  static const char *const ampm_strings_long[] = {a_m_STR, p_m_STR, A_M_STR, P_M_STR, NULL}; -/* ---------- +/*   * Months in roman-numeral   * (Must be in reverse order for seq_search (in FROM_CHAR), because   *	'VIII' must have higher precedence than 'V') - * ----------   */  static const char *const rm_months_upper[] =  {"XII", "XI", "X", "IX", "VIII", "VII", "VI", "V", "IV", "III", "II", "I", NULL}; @@ -255,9 +252,8 @@ static const char *const rm_months_upper[] =  static const char *const rm_months_lower[] =  {"xii", "xi", "x", "ix", "viii", "vii", "vi", "v", "iv", "iii", "ii", "i", NULL}; -/* ---------- +/*   * Roman numerals - * ----------   */  static const char *const rm1[] = {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", NULL};  static const char *const rm10[] = {"X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC", NULL}; @@ -289,40 +285,46 @@ static const char *const rm100[] = {"C", "CC", "CCC", "CD", "D", "DC", "DCC", "D   */  #define MAX_ROMAN_LEN	15 -/* ---------- +/*   * Ordinal postfixes - * ----------   */  static const char *const numTH[] = {"ST", "ND", "RD", "TH", NULL};  static const char *const numth[] = {"st", "nd", "rd", "th", NULL}; -/* ---------- +/*   * Flags & Options: - * ----------   */ -#define TH_UPPER		1 -#define TH_LOWER		2 +enum TH_Case +{ +	TH_UPPER = 1, +	TH_LOWER = 2, +}; -/* ---------- +enum NUMDesc_lsign +{ +	NUM_LSIGN_PRE = -1, +	NUM_LSIGN_POST = 1, +	NUM_LSIGN_NONE = 0, +}; + +/*   * Number description struct - * ----------   */  typedef struct  { -	int			pre,			/* (count) numbers before decimal */ -				post,			/* (count) numbers after decimal  */ -				lsign,			/* want locales sign		  */ -				flag,			/* number parameters		  */ -				pre_lsign_num,	/* tmp value for lsign		  */ -				multi,			/* multiplier for 'V'		  */ -				zero_start,		/* position of first zero	  */ -				zero_end,		/* position of last zero	  */ -				need_locale;	/* needs it locale		  */ +	int			pre;			/* (count) numbers before decimal */ +	int			post;			/* (count) numbers after decimal */ +	enum NUMDesc_lsign lsign;	/* want locales sign */ +	int			flag;			/* number parameters (NUM_F_*) */ +	int			pre_lsign_num;	/* tmp value for lsign */ +	int			multi;			/* multiplier for 'V' */ +	int			zero_start;		/* position of first zero */ +	int			zero_end;		/* position of last zero */ +	bool		need_locale;	/* needs it locale */  } NUMDesc; -/* ---------- +/*   * Flags for NUMBER version - * ----------   */  #define NUM_F_DECIMAL		(1 << 1)  #define NUM_F_LDECIMAL		(1 << 2) @@ -339,13 +341,8 @@ typedef struct  #define NUM_F_MINUS_POST	(1 << 13)  #define NUM_F_EEEE			(1 << 14) -#define NUM_LSIGN_PRE	(-1) -#define NUM_LSIGN_POST	1 -#define NUM_LSIGN_NONE	0 - -/* ---------- +/*   * Tests - * ----------   */  #define IS_DECIMAL(_f)	((_f)->flag & NUM_F_DECIMAL)  #define IS_LDECIMAL(_f) ((_f)->flag & NUM_F_LDECIMAL) @@ -360,7 +357,7 @@ typedef struct  #define IS_MULTI(_f)	((_f)->flag & NUM_F_MULTI)  #define IS_EEEE(_f)		((_f)->flag & NUM_F_EEEE) -/* ---------- +/*   * Format picture cache   *   * We will cache datetime format pictures up to DCH_CACHE_SIZE bytes long; @@ -376,7 +373,6 @@ typedef struct   *   * The max number of entries in each cache is DCH_CACHE_ENTRIES   * resp. NUM_CACHE_ENTRIES. - * ----------   */  #define DCH_CACHE_OVERHEAD \  	MAXALIGN(sizeof(bool) + sizeof(int)) @@ -419,53 +415,49 @@ static NUMCacheEntry *NUMCache[NUM_CACHE_ENTRIES];  static int	n_NUMCache = 0;		/* current number of entries */  static int	NUMCounter = 0;		/* aging-event counter */ -/* ---------- +/*   * For char->date/time conversion - * ----------   */  typedef struct  {  	FromCharDateMode mode; -	int			hh, -				pm, -				mi, -				ss, -				ssss, -				d,				/* stored as 1-7, Sunday = 1, 0 means missing */ -				dd, -				ddd, -				mm, -				ms, -				year, -				bc, -				ww, -				w, -				cc, -				j, -				us, -				yysz,			/* is it YY or YYYY ? */ -				clock,			/* 12 or 24 hour clock? */ -				tzsign,			/* +1, -1, or 0 if no TZH/TZM fields */ -				tzh, -				tzm, -				ff;				/* fractional precision */ +	int			hh; +	int			pm; +	int			mi; +	int			ss; +	int			ssss; +	int			d;				/* stored as 1-7, Sunday = 1, 0 means missing */ +	int			dd; +	int			ddd; +	int			mm; +	int			ms; +	int			year; +	int			bc; +	int			ww; +	int			w; +	int			cc; +	int			j; +	int			us; +	int			yysz;			/* is it YY or YYYY ? */ +	bool		clock_12_hour;	/* 12 or 24 hour clock? */ +	int			tzsign;			/* +1, -1, or 0 if no TZH/TZM fields */ +	int			tzh; +	int			tzm; +	int			ff;				/* fractional precision */  	bool		has_tz;			/* was there a TZ field? */  	int			gmtoffset;		/* GMT offset of fixed-offset zone abbrev */  	pg_tz	   *tzp;			/* pg_tz for dynamic abbrev */ -	char	   *abbrev;			/* dynamic abbrev */ +	const char *abbrev;			/* dynamic abbrev */  } TmFromChar; -#define ZERO_tmfc(_X) memset(_X, 0, sizeof(TmFromChar)) -  struct fmt_tz					/* do_to_timestamp's timezone info output */  {  	bool		has_tz;			/* was there any TZ/TZH/TZM field? */  	int			gmtoffset;		/* GMT offset in seconds */  }; -/* ---------- +/*   * Debug - * ----------   */  #ifdef DEBUG_TO_FROM_CHAR  #define DEBUG_TMFC(_X) \ @@ -473,7 +465,7 @@ struct fmt_tz					/* do_to_timestamp's timezone info output */  			(_X)->mode, (_X)->hh, (_X)->pm, (_X)->mi, (_X)->ss, (_X)->ssss, \  			(_X)->d, (_X)->dd, (_X)->ddd, (_X)->mm, (_X)->ms, (_X)->year, \  			(_X)->bc, (_X)->ww, (_X)->w, (_X)->cc, (_X)->j, (_X)->us, \ -			(_X)->yysz, (_X)->clock) +			(_X)->yysz, (_X)->clock_12_hour)  #define DEBUG_TM(_X) \  		elog(DEBUG_elog_output, "TM:\nsec %d\nyear %d\nmin %d\nwday %d\nhour %d\nyday %d\nmday %d\nnisdst %d\nmon %d\n",\  			(_X)->tm_sec, (_X)->tm_year,\ @@ -484,13 +476,12 @@ struct fmt_tz					/* do_to_timestamp's timezone info output */  #define DEBUG_TM(_X)  #endif -/* ---------- +/*   * Datetime to char conversion   *   * To support intervals as well as timestamps, we use a custom "tm" struct   * that is almost like struct pg_tm, but has a 64-bit tm_hour field.   * We omit the tm_isdst and tm_zone fields, which are not used here. - * ----------   */  struct fmt_tm  { @@ -561,50 +552,74 @@ do { \   *			KeyWord definitions   *****************************************************************************/ -/* ---------- +/*   * Suffixes (FormatNode.suffix is an OR of these codes) - * ----------   */ -#define DCH_S_FM	0x01 -#define DCH_S_TH	0x02 -#define DCH_S_th	0x04 -#define DCH_S_SP	0x08 -#define DCH_S_TM	0x10 +#define DCH_SUFFIX_FM	0x01 +#define DCH_SUFFIX_TH	0x02 +#define DCH_SUFFIX_th	0x04 +#define DCH_SUFFIX_SP	0x08 +#define DCH_SUFFIX_TM	0x10 -/* ---------- +/*   * Suffix tests - * ----------   */ -#define S_THth(_s)	((((_s) & DCH_S_TH) || ((_s) & DCH_S_th)) ? 1 : 0) -#define S_TH(_s)	(((_s) & DCH_S_TH) ? 1 : 0) -#define S_th(_s)	(((_s) & DCH_S_th) ? 1 : 0) -#define S_TH_TYPE(_s)	(((_s) & DCH_S_TH) ? TH_UPPER : TH_LOWER) +static inline bool +IS_SUFFIX_TH(uint8 _s) +{ +	return (_s & DCH_SUFFIX_TH); +} + +static inline bool +IS_SUFFIX_th(uint8 _s) +{ +	return (_s & DCH_SUFFIX_th); +} + +static inline bool +IS_SUFFIX_THth(uint8 _s) +{ +	return IS_SUFFIX_TH(_s) || IS_SUFFIX_th(_s); +} + +static inline enum TH_Case +SUFFIX_TH_TYPE(uint8 _s) +{ +	return _s & DCH_SUFFIX_TH ? TH_UPPER : TH_LOWER; +}  /* Oracle toggles FM behavior, we don't; see docs. */ -#define S_FM(_s)	(((_s) & DCH_S_FM) ? 1 : 0) -#define S_SP(_s)	(((_s) & DCH_S_SP) ? 1 : 0) -#define S_TM(_s)	(((_s) & DCH_S_TM) ? 1 : 0) +static inline bool +IS_SUFFIX_FM(uint8 _s) +{ +	return (_s & DCH_SUFFIX_FM); +} + +static inline bool +IS_SUFFIX_TM(uint8 _s) +{ +	return (_s & DCH_SUFFIX_TM); +} -/* ---------- +/*   * Suffixes definition for DATE-TIME TO/FROM CHAR - * ----------   */  #define TM_SUFFIX_LEN	2  static const KeySuffix DCH_suff[] = { -	{"FM", 2, DCH_S_FM, SUFFTYPE_PREFIX}, -	{"fm", 2, DCH_S_FM, SUFFTYPE_PREFIX}, -	{"TM", TM_SUFFIX_LEN, DCH_S_TM, SUFFTYPE_PREFIX}, -	{"tm", 2, DCH_S_TM, SUFFTYPE_PREFIX}, -	{"TH", 2, DCH_S_TH, SUFFTYPE_POSTFIX}, -	{"th", 2, DCH_S_th, SUFFTYPE_POSTFIX}, -	{"SP", 2, DCH_S_SP, SUFFTYPE_POSTFIX}, +	{"FM", 2, DCH_SUFFIX_FM, SUFFTYPE_PREFIX}, +	{"fm", 2, DCH_SUFFIX_FM, SUFFTYPE_PREFIX}, +	{"TM", TM_SUFFIX_LEN, DCH_SUFFIX_TM, SUFFTYPE_PREFIX}, +	{"tm", 2, DCH_SUFFIX_TM, SUFFTYPE_PREFIX}, +	{"TH", 2, DCH_SUFFIX_TH, SUFFTYPE_POSTFIX}, +	{"th", 2, DCH_SUFFIX_th, SUFFTYPE_POSTFIX}, +	{"SP", 2, DCH_SUFFIX_SP, SUFFTYPE_POSTFIX},  	/* last */  	{NULL, 0, 0, 0}  }; -/* ---------- +/*   * Format-pictures (KeyWord).   *   * The KeyWord field; alphabetic sorted, *BUT* strings alike is sorted @@ -628,8 +643,6 @@ static const KeySuffix DCH_suff[] = {   *	1)	see in index to index['M' - 32],   *	2)	take keywords position (enum DCH_MI) from index   *	3)	run sequential search in keywords[] from this position - * - * ----------   */  typedef enum @@ -794,9 +807,8 @@ typedef enum  	_NUM_last_  }			NUM_poz; -/* ---------- +/*   * KeyWords for DATE-TIME version - * ----------   */  static const KeyWord DCH_keywords[] = {  /*	name, len, id, is_digit, date_mode */ @@ -917,11 +929,10 @@ static const KeyWord DCH_keywords[] = {  	{NULL, 0, 0, 0, 0}  }; -/* ---------- +/*   * KeyWords for NUMBER version   *   * The is_digit and date_mode fields are not relevant here. - * ----------   */  static const KeyWord NUM_keywords[] = {  /*	name, len, id			is in Index */ @@ -967,9 +978,8 @@ static const KeyWord NUM_keywords[] = {  }; -/* ---------- +/*   * KeyWords index for DATE-TIME version - * ----------   */  static const int DCH_index[KeyWord_INDEX_SIZE] = {  /* @@ -991,9 +1001,8 @@ static const int DCH_index[KeyWord_INDEX_SIZE] = {  	/*---- chars over 126 are skipped ----*/  }; -/* ---------- +/*   * KeyWords index for NUMBER version - * ----------   */  static const int NUM_index[KeyWord_INDEX_SIZE] = {  /* @@ -1015,9 +1024,8 @@ static const int NUM_index[KeyWord_INDEX_SIZE] = {  	/*---- chars over 126 are skipped ----*/  }; -/* ---------- +/*   * Number processor struct - * ----------   */  typedef struct NUMProc  { @@ -1062,13 +1070,12 @@ typedef struct NUMProc  #define AMOUNT_TEST(s)	(Np->inout_p <= Np->inout + (input_len - (s))) -/* ---------- +/*   * Functions - * ----------   */  static const KeyWord *index_seq_search(const char *str, const KeyWord *kw,  									   const int *index); -static const KeySuffix *suff_search(const char *str, const KeySuffix *suf, int type); +static const KeySuffix *suff_search(const char *str, const KeySuffix *suf, enum KeySuffixType type);  static bool is_separator_char(const char *str);  static void NUMDesc_prepare(NUMDesc *num, FormatNode *n);  static void parse_format(FormatNode *node, const char *str, const KeyWord *kw, @@ -1084,38 +1091,38 @@ static void dump_index(const KeyWord *k, const int *index);  static void dump_node(FormatNode *node, int max);  #endif -static const char *get_th(char *num, int type); -static char *str_numth(char *dest, char *num, int type); +static const char *get_th(const char *num, enum TH_Case type); +static char *str_numth(char *dest, const char *num, enum TH_Case type);  static int	adjust_partial_year_to_2020(int year); -static int	strspace_len(const char *str); +static size_t strspace_len(const char *str);  static bool from_char_set_mode(TmFromChar *tmfc, const FromCharDateMode mode,  							   Node *escontext);  static bool from_char_set_int(int *dest, const int value, const FormatNode *node,  							  Node *escontext); -static int	from_char_parse_int_len(int *dest, const char **src, const int len, +static int	from_char_parse_int_len(int *dest, const char **src, const size_t len,  									FormatNode *node, Node *escontext);  static int	from_char_parse_int(int *dest, const char **src, FormatNode *node,  								Node *escontext); -static int	seq_search_ascii(const char *name, const char *const *array, int *len); -static int	seq_search_localized(const char *name, char **array, int *len, +static int	seq_search_ascii(const char *name, const char *const *array, size_t *len); +static int	seq_search_localized(const char *name, char **array, size_t *len,  								 Oid collid);  static bool from_char_seq_search(int *dest, const char **src,  								 const char *const *array,  								 char **localized_array, Oid collid,  								 FormatNode *node, Node *escontext); -static bool do_to_timestamp(text *date_txt, text *fmt, Oid collid, bool std, +static bool do_to_timestamp(const text *date_txt, const text *fmt, Oid collid, bool std,  							struct pg_tm *tm, fsec_t *fsec, struct fmt_tz *tz,  							int *fprec, uint32 *flags, Node *escontext); -static char *fill_str(char *str, int c, int max); -static FormatNode *NUM_cache(int len, NUMDesc *Num, text *pars_str, bool *shouldFree); +static void fill_str(char *str, int c, int max); +static FormatNode *NUM_cache(int len, NUMDesc *Num, const text *pars_str, bool *shouldFree);  static char *int_to_roman(int number); -static int	roman_to_int(NUMProc *Np, int input_len); +static int	roman_to_int(NUMProc *Np, size_t input_len);  static void NUM_prepare_locale(NUMProc *Np); -static char *get_last_relevant_decnum(char *num); -static void NUM_numpart_from_char(NUMProc *Np, int id, int input_len); +static char *get_last_relevant_decnum(const char *num); +static void NUM_numpart_from_char(NUMProc *Np, int id, size_t input_len);  static void NUM_numpart_to_char(NUMProc *Np, int id);  static char *NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, -						   char *number, int input_len, int to_char_out_pre_spaces, +						   char *number, size_t input_len, int to_char_out_pre_spaces,  						   int sign, bool is_to_char, Oid collid);  static DCHCacheEntry *DCH_cache_getnew(const char *str, bool std);  static DCHCacheEntry *DCH_cache_search(const char *str, bool std); @@ -1125,11 +1132,10 @@ static NUMCacheEntry *NUM_cache_search(const char *str);  static NUMCacheEntry *NUM_cache_fetch(const char *str); -/* ---------- +/*   * Fast sequential search, use index for data selection which   * go to seq. cycle (it is very fast for unwanted strings)   * (can't be used binary search in format parsing) - * ----------   */  static const KeyWord *  index_seq_search(const char *str, const KeyWord *kw, const int *index) @@ -1139,7 +1145,7 @@ index_seq_search(const char *str, const KeyWord *kw, const int *index)  	if (!KeyWord_INDEX_FILTER(*str))  		return NULL; -	if ((poz = *(index + (*str - ' '))) > -1) +	if ((poz = index[*str - ' ']) > -1)  	{  		const KeyWord *k = kw + poz; @@ -1156,11 +1162,9 @@ index_seq_search(const char *str, const KeyWord *kw, const int *index)  }  static const KeySuffix * -suff_search(const char *str, const KeySuffix *suf, int type) +suff_search(const char *str, const KeySuffix *suf, enum KeySuffixType type)  { -	const KeySuffix *s; - -	for (s = suf; s->name != NULL; s++) +	for (const KeySuffix *s = suf; s->name != NULL; s++)  	{  		if (s->type != type)  			continue; @@ -1181,9 +1185,8 @@ is_separator_char(const char *str)  			!(*str >= '0' && *str <= '9'));  } -/* ---------- +/*   * Prepare NUMDesc (number description struct) via FormatNode struct - * ----------   */  static void  NUMDesc_prepare(NUMDesc *num, FormatNode *n) @@ -1233,7 +1236,7 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)  			break;  		case NUM_B: -			if (num->pre == 0 && num->post == 0 && (!IS_ZERO(num))) +			if (num->pre == 0 && num->post == 0 && !IS_ZERO(num))  				num->flag |= NUM_F_BLANK;  			break; @@ -1364,12 +1367,11 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)  				 errdetail("\"RN\" may only be used together with \"FM\".")));  } -/* ---------- +/*   * Format parser, search small keywords and keyword's suffixes, and make   * format-node tree.   *   * for DATE-TIME & NUMBER version - * ----------   */  static void  parse_format(FormatNode *node, const char *str, const KeyWord *kw, @@ -1514,14 +1516,13 @@ parse_format(FormatNode *node, const char *str, const KeyWord *kw,  	n->suffix = 0;  } -/* ---------- +/*   * DEBUG: Dump the FormatNode Tree (debug) - * ----------   */  #ifdef DEBUG_TO_FROM_CHAR -#define DUMP_THth(_suf) (S_TH(_suf) ? "TH" : (S_th(_suf) ? "th" : " ")) -#define DUMP_FM(_suf)	(S_FM(_suf) ? "FM" : " ") +#define DUMP_THth(_suf) (IS_SUFFIX_TH(_suf) ? "TH" : (IS_SUFFIX_th(_suf) ? "th" : " ")) +#define DUMP_FM(_suf)	(IS_SUFFIX_FM(_suf) ? "FM" : " ")  static void  dump_node(FormatNode *node, int max) @@ -1554,20 +1555,18 @@ dump_node(FormatNode *node, int max)   *			Private utils   *****************************************************************************/ -/* ---------- +/*   * Return ST/ND/RD/TH for simple (1..9) numbers - * type --> 0 upper, 1 lower - * ----------   */  static const char * -get_th(char *num, int type) +get_th(const char *num, enum TH_Case type)  { -	int			len = strlen(num), -				last; +	size_t		len = strlen(num); +	char		last;  	Assert(len > 0); -	last = *(num + (len - 1)); +	last = num[len - 1];  	if (!isdigit((unsigned char) last))  		ereport(ERROR,  				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), @@ -1577,7 +1576,7 @@ get_th(char *num, int type)  	 * All "teens" (<x>1[0-9]) get 'TH/th', while <x>[02-9][123] still get  	 * 'ST/st', 'ND/nd', 'RD/rd', respectively  	 */ -	if ((len > 1) && (num[len - 2] == '1')) +	if (len > 1 && num[len - 2] == '1')  		last = 0;  	switch (last) @@ -1601,13 +1600,11 @@ get_th(char *num, int type)  	}  } -/* ---------- +/*   * Convert string-number to ordinal string-number - * type --> 0 upper, 1 lower - * ----------   */  static char * -str_numth(char *dest, char *num, int type) +str_numth(char *dest, const char *num, enum TH_Case type)  {  	if (dest != num)  		strcpy(dest, num); @@ -1900,14 +1897,13 @@ char *  asc_tolower(const char *buff, size_t nbytes)  {  	char	   *result; -	char	   *p;  	if (!buff)  		return NULL;  	result = pnstrdup(buff, nbytes); -	for (p = result; *p; p++) +	for (char *p = result; *p; p++)  		*p = pg_ascii_tolower((unsigned char) *p);  	return result; @@ -1923,14 +1919,13 @@ char *  asc_toupper(const char *buff, size_t nbytes)  {  	char	   *result; -	char	   *p;  	if (!buff)  		return NULL;  	result = pnstrdup(buff, nbytes); -	for (p = result; *p; p++) +	for (char *p = result; *p; p++)  		*p = pg_ascii_toupper((unsigned char) *p);  	return result; @@ -1946,7 +1941,6 @@ char *  asc_initcap(const char *buff, size_t nbytes)  {  	char	   *result; -	char	   *p;  	int			wasalnum = false;  	if (!buff) @@ -1954,7 +1948,7 @@ asc_initcap(const char *buff, size_t nbytes)  	result = pnstrdup(buff, nbytes); -	for (p = result; *p; p++) +	for (char *p = result; *p; p++)  	{  		char		c; @@ -2006,15 +2000,14 @@ asc_toupper_z(const char *buff)  /* asc_initcap_z is not currently needed */ -/* ---------- +/*   * Skip TM / th in FROM_CHAR   * - * If S_THth is on, skip two chars, assuming there are two available - * ---------- + * If IS_SUFFIX_THth is on, skip two chars, assuming there are two available   */  #define SKIP_THth(ptr, _suf) \  	do { \ -		if (S_THth(_suf)) \ +		if (IS_SUFFIX_THth(_suf)) \  		{ \  			if (*(ptr)) (ptr) += pg_mblen(ptr); \  			if (*(ptr)) (ptr) += pg_mblen(ptr); \ @@ -2023,21 +2016,19 @@ asc_toupper_z(const char *buff)  #ifdef DEBUG_TO_FROM_CHAR -/* ----------- +/*   * DEBUG: Call for debug and for index checking; (Show ASCII char   * and defined keyword for each used position - * ----------   */  static void  dump_index(const KeyWord *k, const int *index)  { -	int			i, -				count = 0, +	int			count = 0,  				free_i = 0;  	elog(DEBUG_elog_output, "TO-FROM_CHAR: Dump KeyWord Index:"); -	for (i = 0; i < KeyWord_INDEX_SIZE; i++) +	for (int i = 0; i < KeyWord_INDEX_SIZE; i++)  	{  		if (index[i] != -1)  		{ @@ -2055,9 +2046,8 @@ dump_index(const KeyWord *k, const int *index)  }  #endif							/* DEBUG */ -/* ---------- +/*   * Return true if next format picture is not digit value - * ----------   */  static bool  is_next_separator(FormatNode *n) @@ -2065,7 +2055,7 @@ is_next_separator(FormatNode *n)  	if (n->type == NODE_TYPE_END)  		return false; -	if (n->type == NODE_TYPE_ACTION && S_THth(n->suffix)) +	if (n->type == NODE_TYPE_ACTION && IS_SUFFIX_THth(n->suffix))  		return true;  	/* @@ -2116,10 +2106,10 @@ adjust_partial_year_to_2020(int year)  } -static int +static size_t  strspace_len(const char *str)  { -	int			len = 0; +	size_t		len = 0;  	while (*str && isspace((unsigned char) *str))  	{ @@ -2150,8 +2140,7 @@ from_char_set_mode(TmFromChar *tmfc, const FromCharDateMode mode,  			ereturn(escontext, false,  					(errcode(ERRCODE_INVALID_DATETIME_FORMAT),  					 errmsg("invalid combination of date conventions"), -					 errhint("Do not mix Gregorian and ISO week date " -							 "conventions in a formatting template."))); +					 errhint("Do not mix Gregorian and ISO week date conventions in a formatting template.")));  	}  	return true;  } @@ -2174,8 +2163,7 @@ from_char_set_int(int *dest, const int value, const FormatNode *node,  				(errcode(ERRCODE_INVALID_DATETIME_FORMAT),  				 errmsg("conflicting values for \"%s\" field in formatting string",  						node->key->name), -				 errdetail("This value contradicts a previous setting " -						   "for the same field type."))); +				 errdetail("This value contradicts a previous setting for the same field type.")));  	*dest = value;  	return true;  } @@ -2202,13 +2190,13 @@ from_char_set_int(int *dest, const int value, const FormatNode *node,   * with DD and MI).   */  static int -from_char_parse_int_len(int *dest, const char **src, const int len, FormatNode *node, +from_char_parse_int_len(int *dest, const char **src, const size_t len, FormatNode *node,  						Node *escontext)  {  	long		result;  	char		copy[DCH_MAX_ITEM_SIZ + 1];  	const char *init = *src; -	int			used; +	size_t		used;  	/*  	 * Skip any whitespace before parsing the integer. @@ -2216,9 +2204,9 @@ from_char_parse_int_len(int *dest, const char **src, const int len, FormatNode *  	*src += strspace_len(*src);  	Assert(len <= DCH_MAX_ITEM_SIZ); -	used = (int) strlcpy(copy, *src, len + 1); +	used = strlcpy(copy, *src, len + 1); -	if (S_FM(node->suffix) || is_next_separator(node)) +	if (IS_SUFFIX_FM(node->suffix) || is_next_separator(node))  	{  		/*  		 * This node is in Fill Mode, or the next node is known to be a @@ -2243,10 +2231,9 @@ from_char_parse_int_len(int *dest, const char **src, const int len, FormatNode *  					(errcode(ERRCODE_INVALID_DATETIME_FORMAT),  					 errmsg("source string too short for \"%s\" formatting field",  							node->key->name), -					 errdetail("Field requires %d characters, but only %d remain.", +					 errdetail("Field requires %zu characters, but only %zu remain.",  							   len, used), -					 errhint("If your source string is not fixed-width, " -							 "try using the \"FM\" modifier."))); +					 errhint("If your source string is not fixed-width, try using the \"FM\" modifier.")));  		errno = 0;  		result = strtol(copy, &last, 10); @@ -2257,10 +2244,9 @@ from_char_parse_int_len(int *dest, const char **src, const int len, FormatNode *  					(errcode(ERRCODE_INVALID_DATETIME_FORMAT),  					 errmsg("invalid value \"%s\" for \"%s\"",  							copy, node->key->name), -					 errdetail("Field requires %d characters, but only %d could be parsed.", +					 errdetail("Field requires %zu characters, but only %zu could be parsed.",  							   len, used), -					 errhint("If your source string is not fixed-width, " -							 "try using the \"FM\" modifier."))); +					 errhint("If your source string is not fixed-width, try using the \"FM\" modifier.")));  		*src += used;  	} @@ -2317,10 +2303,9 @@ from_char_parse_int(int *dest, const char **src, FormatNode *node,   * suitable for comparisons to ASCII strings.   */  static int -seq_search_ascii(const char *name, const char *const *array, int *len) +seq_search_ascii(const char *name, const char *const *array, size_t *len)  {  	unsigned char firstc; -	const char *const *a;  	*len = 0; @@ -2331,17 +2316,14 @@ seq_search_ascii(const char *name, const char *const *array, int *len)  	/* we handle first char specially to gain some speed */  	firstc = pg_ascii_tolower((unsigned char) *name); -	for (a = array; *a != NULL; a++) +	for (const char *const *a = array; *a != NULL; a++)  	{ -		const char *p; -		const char *n; -  		/* compare first chars */  		if (pg_ascii_tolower((unsigned char) **a) != firstc)  			continue;  		/* compare rest of string */ -		for (p = *a + 1, n = name + 1;; p++, n++) +		for (const char *p = *a + 1, *n = name + 1;; p++, n++)  		{  			/* return success if we matched whole array entry */  			if (*p == '\0') @@ -2374,9 +2356,8 @@ seq_search_ascii(const char *name, const char *const *array, int *len)   * the arrays exported by pg_locale.c aren't const.   */  static int -seq_search_localized(const char *name, char **array, int *len, Oid collid) +seq_search_localized(const char *name, char **array, size_t *len, Oid collid)  { -	char	  **a;  	char	   *upper_name;  	char	   *lower_name; @@ -2390,9 +2371,9 @@ seq_search_localized(const char *name, char **array, int *len, Oid collid)  	 * The case-folding processing done below is fairly expensive, so before  	 * doing that, make a quick pass to see if there is an exact match.  	 */ -	for (a = array; *a != NULL; a++) +	for (char **a = array; *a != NULL; a++)  	{ -		int			element_len = strlen(*a); +		size_t		element_len = strlen(*a);  		if (strncmp(name, *a, element_len) == 0)  		{ @@ -2409,11 +2390,11 @@ seq_search_localized(const char *name, char **array, int *len, Oid collid)  	lower_name = str_tolower(upper_name, strlen(upper_name), collid);  	pfree(upper_name); -	for (a = array; *a != NULL; a++) +	for (char **a = array; *a != NULL; a++)  	{  		char	   *upper_element;  		char	   *lower_element; -		int			element_len; +		size_t		element_len;  		/* Likewise upper/lower-case array element */  		upper_element = str_toupper(*a, strlen(*a), collid); @@ -2462,7 +2443,7 @@ from_char_seq_search(int *dest, const char **src, const char *const *array,  					 char **localized_array, Oid collid,  					 FormatNode *node, Node *escontext)  { -	int			len; +	size_t		len;  	if (localized_array == NULL)  		*dest = seq_search_ascii(*src, array, &len); @@ -2476,9 +2457,8 @@ from_char_seq_search(int *dest, const char **src, const char *const *array,  		 * any) to avoid including irrelevant data.  		 */  		char	   *copy = pstrdup(*src); -		char	   *c; -		for (c = copy; *c; c++) +		for (char *c = copy; *c; c++)  		{  			if (scanner_isspace(*c))  			{ @@ -2491,22 +2471,19 @@ from_char_seq_search(int *dest, const char **src, const char *const *array,  				(errcode(ERRCODE_INVALID_DATETIME_FORMAT),  				 errmsg("invalid value \"%s\" for \"%s\"",  						copy, node->key->name), -				 errdetail("The given value did not match any of " -						   "the allowed values for this field."))); +				 errdetail("The given value did not match any of the allowed values for this field.")));  	}  	*src += len;  	return true;  } -/* ---------- +/*   * Process a TmToChar struct as denoted by a list of FormatNodes.   * The formatted data is written to the string pointed to by 'out'. - * ----------   */  static void  DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid collid)  { -	FormatNode *n;  	char	   *s;  	struct fmt_tm *tm = &in->tm;  	int			i; @@ -2515,7 +2492,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  	cache_locale_time();  	s = out; -	for (n = node; n->type != NODE_TYPE_END; n++) +	for (FormatNode *n = node; n->type != NODE_TYPE_END; n++)  	{  		if (n->type != NODE_TYPE_ACTION)  		{ @@ -2557,40 +2534,40 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  				 * display time as shown on a 12-hour clock, even for  				 * intervals  				 */ -				sprintf(s, "%0*lld", S_FM(n->suffix) ? 0 : (tm->tm_hour >= 0) ? 2 : 3, +				sprintf(s, "%0*lld", IS_SUFFIX_FM(n->suffix) ? 0 : (tm->tm_hour >= 0) ? 2 : 3,  						tm->tm_hour % (HOURS_PER_DAY / 2) == 0 ?  						(long long) (HOURS_PER_DAY / 2) :  						(long long) (tm->tm_hour % (HOURS_PER_DAY / 2))); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  			case DCH_HH24: -				sprintf(s, "%0*lld", S_FM(n->suffix) ? 0 : (tm->tm_hour >= 0) ? 2 : 3, +				sprintf(s, "%0*lld", IS_SUFFIX_FM(n->suffix) ? 0 : (tm->tm_hour >= 0) ? 2 : 3,  						(long long) tm->tm_hour); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  			case DCH_MI: -				sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : (tm->tm_min >= 0) ? 2 : 3, +				sprintf(s, "%0*d", IS_SUFFIX_FM(n->suffix) ? 0 : (tm->tm_min >= 0) ? 2 : 3,  						tm->tm_min); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  			case DCH_SS: -				sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : (tm->tm_sec >= 0) ? 2 : 3, +				sprintf(s, "%0*d", IS_SUFFIX_FM(n->suffix) ? 0 : (tm->tm_sec >= 0) ? 2 : 3,  						tm->tm_sec); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  #define DCH_to_char_fsec(frac_fmt, frac_val) \  				sprintf(s, frac_fmt, (int) (frac_val)); \ -				if (S_THth(n->suffix)) \ -					str_numth(s, s, S_TH_TYPE(n->suffix)); \ +				if (IS_SUFFIX_THth(n->suffix)) \ +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix)); \  				s += strlen(s)  			case DCH_FF1:		/* tenth of second */ @@ -2619,8 +2596,8 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  						(long long) (tm->tm_hour * SECS_PER_HOUR +  									 tm->tm_min * SECS_PER_MINUTE +  									 tm->tm_sec)); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  			case DCH_tz: @@ -2660,7 +2637,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  				INVALID_FOR_INTERVAL;  				sprintf(s, "%c%0*d",  						(tm->tm_gmtoff >= 0) ? '+' : '-', -						S_FM(n->suffix) ? 0 : 2, +						IS_SUFFIX_FM(n->suffix) ? 0 : 2,  						abs((int) tm->tm_gmtoff) / SECS_PER_HOUR);  				s += strlen(s);  				if (abs((int) tm->tm_gmtoff) % SECS_PER_HOUR != 0) @@ -2698,7 +2675,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  				INVALID_FOR_INTERVAL;  				if (!tm->tm_mon)  					break; -				if (S_TM(n->suffix)) +				if (IS_SUFFIX_TM(n->suffix))  				{  					char	   *str = str_toupper_z(localized_full_months[tm->tm_mon - 1], collid); @@ -2710,7 +2687,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  								 errmsg("localized string format value too long")));  				}  				else -					sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -9, +					sprintf(s, "%*s", IS_SUFFIX_FM(n->suffix) ? 0 : -9,  							asc_toupper_z(months_full[tm->tm_mon - 1]));  				s += strlen(s);  				break; @@ -2718,7 +2695,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  				INVALID_FOR_INTERVAL;  				if (!tm->tm_mon)  					break; -				if (S_TM(n->suffix)) +				if (IS_SUFFIX_TM(n->suffix))  				{  					char	   *str = str_initcap_z(localized_full_months[tm->tm_mon - 1], collid); @@ -2730,7 +2707,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  								 errmsg("localized string format value too long")));  				}  				else -					sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -9, +					sprintf(s, "%*s", IS_SUFFIX_FM(n->suffix) ? 0 : -9,  							months_full[tm->tm_mon - 1]);  				s += strlen(s);  				break; @@ -2738,7 +2715,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  				INVALID_FOR_INTERVAL;  				if (!tm->tm_mon)  					break; -				if (S_TM(n->suffix)) +				if (IS_SUFFIX_TM(n->suffix))  				{  					char	   *str = str_tolower_z(localized_full_months[tm->tm_mon - 1], collid); @@ -2750,7 +2727,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  								 errmsg("localized string format value too long")));  				}  				else -					sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -9, +					sprintf(s, "%*s", IS_SUFFIX_FM(n->suffix) ? 0 : -9,  							asc_tolower_z(months_full[tm->tm_mon - 1]));  				s += strlen(s);  				break; @@ -2758,7 +2735,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  				INVALID_FOR_INTERVAL;  				if (!tm->tm_mon)  					break; -				if (S_TM(n->suffix)) +				if (IS_SUFFIX_TM(n->suffix))  				{  					char	   *str = str_toupper_z(localized_abbrev_months[tm->tm_mon - 1], collid); @@ -2777,7 +2754,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  				INVALID_FOR_INTERVAL;  				if (!tm->tm_mon)  					break; -				if (S_TM(n->suffix)) +				if (IS_SUFFIX_TM(n->suffix))  				{  					char	   *str = str_initcap_z(localized_abbrev_months[tm->tm_mon - 1], collid); @@ -2796,7 +2773,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  				INVALID_FOR_INTERVAL;  				if (!tm->tm_mon)  					break; -				if (S_TM(n->suffix)) +				if (IS_SUFFIX_TM(n->suffix))  				{  					char	   *str = str_tolower_z(localized_abbrev_months[tm->tm_mon - 1], collid); @@ -2812,15 +2789,15 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  				s += strlen(s);  				break;  			case DCH_MM: -				sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : (tm->tm_mon >= 0) ? 2 : 3, +				sprintf(s, "%0*d", IS_SUFFIX_FM(n->suffix) ? 0 : (tm->tm_mon >= 0) ? 2 : 3,  						tm->tm_mon); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  			case DCH_DAY:  				INVALID_FOR_INTERVAL; -				if (S_TM(n->suffix)) +				if (IS_SUFFIX_TM(n->suffix))  				{  					char	   *str = str_toupper_z(localized_full_days[tm->tm_wday], collid); @@ -2832,13 +2809,13 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  								 errmsg("localized string format value too long")));  				}  				else -					sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -9, +					sprintf(s, "%*s", IS_SUFFIX_FM(n->suffix) ? 0 : -9,  							asc_toupper_z(days[tm->tm_wday]));  				s += strlen(s);  				break;  			case DCH_Day:  				INVALID_FOR_INTERVAL; -				if (S_TM(n->suffix)) +				if (IS_SUFFIX_TM(n->suffix))  				{  					char	   *str = str_initcap_z(localized_full_days[tm->tm_wday], collid); @@ -2850,13 +2827,13 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  								 errmsg("localized string format value too long")));  				}  				else -					sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -9, +					sprintf(s, "%*s", IS_SUFFIX_FM(n->suffix) ? 0 : -9,  							days[tm->tm_wday]);  				s += strlen(s);  				break;  			case DCH_day:  				INVALID_FOR_INTERVAL; -				if (S_TM(n->suffix)) +				if (IS_SUFFIX_TM(n->suffix))  				{  					char	   *str = str_tolower_z(localized_full_days[tm->tm_wday], collid); @@ -2868,13 +2845,13 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  								 errmsg("localized string format value too long")));  				}  				else -					sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -9, +					sprintf(s, "%*s", IS_SUFFIX_FM(n->suffix) ? 0 : -9,  							asc_tolower_z(days[tm->tm_wday]));  				s += strlen(s);  				break;  			case DCH_DY:  				INVALID_FOR_INTERVAL; -				if (S_TM(n->suffix)) +				if (IS_SUFFIX_TM(n->suffix))  				{  					char	   *str = str_toupper_z(localized_abbrev_days[tm->tm_wday], collid); @@ -2891,7 +2868,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  				break;  			case DCH_Dy:  				INVALID_FOR_INTERVAL; -				if (S_TM(n->suffix)) +				if (IS_SUFFIX_TM(n->suffix))  				{  					char	   *str = str_initcap_z(localized_abbrev_days[tm->tm_wday], collid); @@ -2908,7 +2885,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  				break;  			case DCH_dy:  				INVALID_FOR_INTERVAL; -				if (S_TM(n->suffix)) +				if (IS_SUFFIX_TM(n->suffix))  				{  					char	   *str = str_tolower_z(localized_abbrev_days[tm->tm_wday], collid); @@ -2925,54 +2902,54 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  				break;  			case DCH_DDD:  			case DCH_IDDD: -				sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : 3, +				sprintf(s, "%0*d", IS_SUFFIX_FM(n->suffix) ? 0 : 3,  						(n->key->id == DCH_DDD) ?  						tm->tm_yday :  						date2isoyearday(tm->tm_year, tm->tm_mon, tm->tm_mday)); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  			case DCH_DD: -				sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : 2, tm->tm_mday); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				sprintf(s, "%0*d", IS_SUFFIX_FM(n->suffix) ? 0 : 2, tm->tm_mday); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  			case DCH_D:  				INVALID_FOR_INTERVAL;  				sprintf(s, "%d", tm->tm_wday + 1); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  			case DCH_ID:  				INVALID_FOR_INTERVAL;  				sprintf(s, "%d", (tm->tm_wday == 0) ? 7 : tm->tm_wday); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  			case DCH_WW: -				sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : 2, +				sprintf(s, "%0*d", IS_SUFFIX_FM(n->suffix) ? 0 : 2,  						(tm->tm_yday - 1) / 7 + 1); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  			case DCH_IW: -				sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : 2, +				sprintf(s, "%0*d", IS_SUFFIX_FM(n->suffix) ? 0 : 2,  						date2isoweek(tm->tm_year, tm->tm_mon, tm->tm_mday)); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  			case DCH_Q:  				if (!tm->tm_mon)  					break;  				sprintf(s, "%d", (tm->tm_mon - 1) / 3 + 1); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  			case DCH_CC: @@ -2988,25 +2965,25 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  						i = tm->tm_year / 100 - 1;  				}  				if (i <= 99 && i >= -99) -					sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : (i >= 0) ? 2 : 3, i); +					sprintf(s, "%0*d", IS_SUFFIX_FM(n->suffix) ? 0 : (i >= 0) ? 2 : 3, i);  				else  					sprintf(s, "%d", i); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  			case DCH_Y_YYY:  				i = ADJUST_YEAR(tm->tm_year, is_interval) / 1000;  				sprintf(s, "%d,%03d", i,  						ADJUST_YEAR(tm->tm_year, is_interval) - (i * 1000)); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  			case DCH_YYYY:  			case DCH_IYYY:  				sprintf(s, "%0*d", -						S_FM(n->suffix) ? 0 : +						IS_SUFFIX_FM(n->suffix) ? 0 :  						(ADJUST_YEAR(tm->tm_year, is_interval) >= 0) ? 4 : 5,  						(n->key->id == DCH_YYYY ?  						 ADJUST_YEAR(tm->tm_year, is_interval) : @@ -3014,14 +2991,14 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  												  tm->tm_mon,  												  tm->tm_mday),  									 is_interval))); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  			case DCH_YYY:  			case DCH_IYY:  				sprintf(s, "%0*d", -						S_FM(n->suffix) ? 0 : +						IS_SUFFIX_FM(n->suffix) ? 0 :  						(ADJUST_YEAR(tm->tm_year, is_interval) >= 0) ? 3 : 4,  						(n->key->id == DCH_YYY ?  						 ADJUST_YEAR(tm->tm_year, is_interval) : @@ -3029,14 +3006,14 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  												  tm->tm_mon,  												  tm->tm_mday),  									 is_interval)) % 1000); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  			case DCH_YY:  			case DCH_IY:  				sprintf(s, "%0*d", -						S_FM(n->suffix) ? 0 : +						IS_SUFFIX_FM(n->suffix) ? 0 :  						(ADJUST_YEAR(tm->tm_year, is_interval) >= 0) ? 2 : 3,  						(n->key->id == DCH_YY ?  						 ADJUST_YEAR(tm->tm_year, is_interval) : @@ -3044,8 +3021,8 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  												  tm->tm_mon,  												  tm->tm_mday),  									 is_interval)) % 100); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  			case DCH_Y: @@ -3057,8 +3034,8 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  												  tm->tm_mon,  												  tm->tm_mday),  									 is_interval)) % 10); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  			case DCH_RM: @@ -3113,21 +3090,21 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col  						mon = MONTHS_PER_YEAR - tm->tm_mon;  					} -					sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -4, +					sprintf(s, "%*s", IS_SUFFIX_FM(n->suffix) ? 0 : -4,  							months[mon]);  					s += strlen(s);  				}  				break;  			case DCH_W:  				sprintf(s, "%d", (tm->tm_mday - 1) / 7 + 1); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  			case DCH_J:  				sprintf(s, "%d", date2j(tm->tm_year, tm->tm_mon, tm->tm_mday)); -				if (S_THth(n->suffix)) -					str_numth(s, s, S_TH_TYPE(n->suffix)); +				if (IS_SUFFIX_THth(n->suffix)) +					str_numth(s, s, SUFFIX_TH_TYPE(n->suffix));  				s += strlen(s);  				break;  		} @@ -3284,7 +3261,7 @@ DCH_from_char(FormatNode *node, const char *in, TmFromChar *out,  					return;  				if (!from_char_set_int(&out->pm, value % 2, n, escontext))  					return; -				out->clock = CLOCK_12_HOUR; +				out->clock_12_hour = true;  				break;  			case DCH_AM:  			case DCH_PM: @@ -3296,13 +3273,13 @@ DCH_from_char(FormatNode *node, const char *in, TmFromChar *out,  					return;  				if (!from_char_set_int(&out->pm, value % 2, n, escontext))  					return; -				out->clock = CLOCK_12_HOUR; +				out->clock_12_hour = true;  				break;  			case DCH_HH:  			case DCH_HH12:  				if (from_char_parse_int_len(&out->hh, &s, 2, n, escontext) < 0)  					return; -				out->clock = CLOCK_12_HOUR; +				out->clock_12_hour = true;  				SKIP_THth(s, n->suffix);  				break;  			case DCH_HH24: @@ -3389,8 +3366,7 @@ DCH_from_char(FormatNode *node, const char *in, TmFromChar *out,  						 */  						ereturn(escontext,,  								(errcode(ERRCODE_INVALID_DATETIME_FORMAT), -								 errmsg("invalid value \"%s\" for \"%s\"", -										s, n->key->name), +								 errmsg("invalid value \"%s\" for \"%s\"", s, n->key->name),  								 errdetail("Time zone abbreviation is not recognized.")));  					}  					/* otherwise parse it like OF */ @@ -3479,7 +3455,7 @@ DCH_from_char(FormatNode *node, const char *in, TmFromChar *out,  			case DCH_Month:  			case DCH_month:  				if (!from_char_seq_search(&value, &s, months_full, -										  S_TM(n->suffix) ? localized_full_months : NULL, +										  IS_SUFFIX_TM(n->suffix) ? localized_full_months : NULL,  										  collid,  										  n, escontext))  					return; @@ -3490,7 +3466,7 @@ DCH_from_char(FormatNode *node, const char *in, TmFromChar *out,  			case DCH_Mon:  			case DCH_mon:  				if (!from_char_seq_search(&value, &s, months, -										  S_TM(n->suffix) ? localized_abbrev_months : NULL, +										  IS_SUFFIX_TM(n->suffix) ? localized_abbrev_months : NULL,  										  collid,  										  n, escontext))  					return; @@ -3506,7 +3482,7 @@ DCH_from_char(FormatNode *node, const char *in, TmFromChar *out,  			case DCH_Day:  			case DCH_day:  				if (!from_char_seq_search(&value, &s, days, -										  S_TM(n->suffix) ? localized_full_days : NULL, +										  IS_SUFFIX_TM(n->suffix) ? localized_full_days : NULL,  										  collid,  										  n, escontext))  					return; @@ -3518,7 +3494,7 @@ DCH_from_char(FormatNode *node, const char *in, TmFromChar *out,  			case DCH_Dy:  			case DCH_dy:  				if (!from_char_seq_search(&value, &s, days_short, -										  S_TM(n->suffix) ? localized_abbrev_days : NULL, +										  IS_SUFFIX_TM(n->suffix) ? localized_abbrev_days : NULL,  										  collid,  										  n, escontext))  					return; @@ -3592,8 +3568,7 @@ DCH_from_char(FormatNode *node, const char *in, TmFromChar *out,  					if (matched < 2)  						ereturn(escontext,,  								(errcode(ERRCODE_INVALID_DATETIME_FORMAT), -								 errmsg("invalid value \"%s\" for \"%s\"", -										s, "Y,YYY"))); +								 errmsg("invalid value \"%s\" for \"%s\"", s, "Y,YYY")));  					/* years += (millennia * 1000); */  					if (pg_mul_s32_overflow(millennia, 1000, &millennia) || @@ -3725,10 +3700,9 @@ DCH_prevent_counter_overflow(void)  static int  DCH_datetime_type(FormatNode *node)  { -	FormatNode *n;  	int			flags = 0; -	for (n = node; n->type != NODE_TYPE_END; n++) +	for (FormatNode *n = node; n->type != NODE_TYPE_END; n++)  	{  		if (n->type != NODE_TYPE_ACTION)  			continue; @@ -3928,13 +3902,13 @@ DCH_cache_fetch(const char *str, bool std)   * for formatting.   */  static text * -datetime_to_char_body(TmToChar *tmtc, text *fmt, bool is_interval, Oid collid) +datetime_to_char_body(TmToChar *tmtc, const text *fmt, bool is_interval, Oid collid)  {  	FormatNode *format;  	char	   *fmt_str,  			   *result;  	bool		incache; -	int			fmt_len; +	size_t		fmt_len;  	text	   *res;  	/* @@ -3992,9 +3966,8 @@ datetime_to_char_body(TmToChar *tmtc, text *fmt, bool is_interval, Oid collid)   *				Public routines   ***************************************************************************/ -/* ------------------- +/*   * TIMESTAMP to_char() - * -------------------   */  Datum  timestamp_to_char(PG_FUNCTION_ARGS) @@ -4068,9 +4041,8 @@ timestamptz_to_char(PG_FUNCTION_ARGS)  } -/* ------------------- +/*   * INTERVAL to_char() - * -------------------   */  Datum  interval_to_char(PG_FUNCTION_ARGS) @@ -4107,12 +4079,11 @@ interval_to_char(PG_FUNCTION_ARGS)  	PG_RETURN_TEXT_P(res);  } -/* --------------------- +/*   * TO_TIMESTAMP()   *   * Make Timestamp from date_str which is formatted at argument 'fmt'   * ( to_timestamp is reverse to_char() ) - * ---------------------   */  Datum  to_timestamp(PG_FUNCTION_ARGS) @@ -4148,10 +4119,9 @@ to_timestamp(PG_FUNCTION_ARGS)  	PG_RETURN_TIMESTAMP(result);  } -/* ---------- +/*   * TO_DATE   *	Make Date from date_str which is formatted at argument 'fmt' - * ----------   */  Datum  to_date(PG_FUNCTION_ARGS) @@ -4171,8 +4141,7 @@ to_date(PG_FUNCTION_ARGS)  	if (!IS_VALID_JULIAN(tm.tm_year, tm.tm_mon, tm.tm_mday))  		ereport(ERROR,  				(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), -				 errmsg("date out of range: \"%s\"", -						text_to_cstring(date_txt)))); +				 errmsg("date out of range: \"%s\"", text_to_cstring(date_txt))));  	result = date2j(tm.tm_year, tm.tm_mon, tm.tm_mday) - POSTGRES_EPOCH_JDATE; @@ -4180,8 +4149,7 @@ to_date(PG_FUNCTION_ARGS)  	if (!IS_VALID_DATE(result))  		ereport(ERROR,  				(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), -				 errmsg("date out of range: \"%s\"", -						text_to_cstring(date_txt)))); +				 errmsg("date out of range: \"%s\"", text_to_cstring(date_txt))));  	PG_RETURN_DATEADT(result);  } @@ -4285,8 +4253,7 @@ parse_datetime(text *date_txt, text *fmt, Oid collid, bool strict,  				if (!IS_VALID_JULIAN(tm.tm_year, tm.tm_mon, tm.tm_mday))  					ereturn(escontext, (Datum) 0,  							(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), -							 errmsg("date out of range: \"%s\"", -									text_to_cstring(date_txt)))); +							 errmsg("date out of range: \"%s\"", text_to_cstring(date_txt))));  				result = date2j(tm.tm_year, tm.tm_mon, tm.tm_mday) -  					POSTGRES_EPOCH_JDATE; @@ -4295,8 +4262,7 @@ parse_datetime(text *date_txt, text *fmt, Oid collid, bool strict,  				if (!IS_VALID_DATE(result))  					ereturn(escontext, (Datum) 0,  							(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), -							 errmsg("date out of range: \"%s\"", -									text_to_cstring(date_txt)))); +							 errmsg("date out of range: \"%s\"", text_to_cstring(date_txt))));  				*typid = DATEOID;  				return DateADTGetDatum(result); @@ -4368,7 +4334,7 @@ bool  datetime_format_has_tz(const char *fmt_str)  {  	bool		incache; -	int			fmt_len = strlen(fmt_str); +	size_t		fmt_len = strlen(fmt_str);  	int			result;  	FormatNode *format; @@ -4428,12 +4394,12 @@ datetime_format_has_tz(const char *fmt_str)   * struct 'tm', 'fsec', struct 'tz', and 'fprec'.   */  static bool -do_to_timestamp(text *date_txt, text *fmt, Oid collid, bool std, +do_to_timestamp(const text *date_txt, const text *fmt, Oid collid, bool std,  				struct pg_tm *tm, fsec_t *fsec, struct fmt_tz *tz,  				int *fprec, uint32 *flags, Node *escontext)  {  	FormatNode *format = NULL; -	TmFromChar	tmfc; +	TmFromChar	tmfc = {0};  	int			fmt_len;  	char	   *date_str;  	int			fmask; @@ -4444,7 +4410,6 @@ do_to_timestamp(text *date_txt, text *fmt, Oid collid, bool std,  	date_str = text_to_cstring(date_txt); -	ZERO_tmfc(&tmfc);  	ZERO_tm(tm);  	*fsec = 0;  	tz->has_tz = false; @@ -4527,14 +4492,13 @@ do_to_timestamp(text *date_txt, text *fmt, Oid collid, bool std,  	if (tmfc.hh)  		tm->tm_hour = tmfc.hh; -	if (tmfc.clock == CLOCK_12_HOUR) +	if (tmfc.clock_12_hour)  	{  		if (tm->tm_hour < 1 || tm->tm_hour > HOURS_PER_DAY / 2)  		{  			errsave(escontext,  					(errcode(ERRCODE_INVALID_DATETIME_FORMAT), -					 errmsg("hour \"%d\" is invalid for the 12-hour clock", -							tm->tm_hour), +					 errmsg("hour \"%d\" is invalid for the 12-hour clock", tm->tm_hour),  					 errhint("Use the 24-hour clock, or give an hour between 1 and 12.")));  			goto fail;  		} @@ -4860,27 +4824,17 @@ fail:   *********************************************************************/ -static char * +/* + * Fill str with character c max times, and add terminating \0.  (So max+1 + * bytes are written altogether!) + */ +static void  fill_str(char *str, int c, int max)  {  	memset(str, c, max); -	*(str + max) = '\0'; -	return str; +	str[max] = '\0';  } -#define zeroize_NUM(_n) \ -do { \ -	(_n)->flag		= 0;	\ -	(_n)->lsign		= 0;	\ -	(_n)->pre		= 0;	\ -	(_n)->post		= 0;	\ -	(_n)->pre_lsign_num = 0;	\ -	(_n)->need_locale	= 0;	\ -	(_n)->multi		= 0;	\ -	(_n)->zero_start	= 0;	\ -	(_n)->zero_end		= 0;	\ -} while(0) -  /* This works the same as DCH_prevent_counter_overflow */  static inline void  NUM_prevent_counter_overflow(void) @@ -4988,7 +4942,7 @@ NUM_cache_fetch(const char *str)  		 */  		ent = NUM_cache_getnew(str); -		zeroize_NUM(&ent->Num); +		memset(&ent->Num, 0, sizeof ent->Num);  		parse_format(ent->format, str, NUM_keywords,  					 NULL, NUM_index, NUM_FLAG, &ent->Num); @@ -4998,12 +4952,11 @@ NUM_cache_fetch(const char *str)  	return ent;  } -/* ---------- +/*   * Cache routine for NUM to_char version - * ----------   */  static FormatNode * -NUM_cache(int len, NUMDesc *Num, text *pars_str, bool *shouldFree) +NUM_cache(int len, NUMDesc *Num, const text *pars_str, bool *shouldFree)  {  	FormatNode *format = NULL;  	char	   *str; @@ -5020,7 +4973,7 @@ NUM_cache(int len, NUMDesc *Num, text *pars_str, bool *shouldFree)  		*shouldFree = true; -		zeroize_NUM(Num); +		memset(Num, 0, sizeof *Num);  		parse_format(format, str, NUM_keywords,  					 NULL, NUM_index, NUM_FLAG, Num); @@ -5070,8 +5023,7 @@ int_to_roman(int number)  {  	int			len,  				num; -	char	   *p, -			   *result, +	char	   *result,  				numstr[12];  	result = (char *) palloc(MAX_ROMAN_LEN + 1); @@ -5092,7 +5044,7 @@ int_to_roman(int number)  	len = snprintf(numstr, sizeof(numstr), "%d", number);  	Assert(len > 0 && len <= 4); -	for (p = numstr; *p != '\0'; p++, --len) +	for (char *p = numstr; *p != '\0'; p++, --len)  	{  		num = *p - ('0' + 1);  		if (num < 0) @@ -5126,10 +5078,10 @@ int_to_roman(int number)   * If input is invalid, return -1.   */  static int -roman_to_int(NUMProc *Np, int input_len) +roman_to_int(NUMProc *Np, size_t input_len)  {  	int			result = 0; -	int			len; +	size_t		len;  	char		romanChars[MAX_ROMAN_LEN];  	int			romanValues[MAX_ROMAN_LEN];  	int			repeatCount = 1; @@ -5168,7 +5120,7 @@ roman_to_int(NUMProc *Np, int input_len)  		return -1;				/* No valid roman numerals. */  	/* Check for valid combinations and compute the represented value. */ -	for (int i = 0; i < len; i++) +	for (size_t i = 0; i < len; i++)  	{  		char		currChar = romanChars[i];  		int			currValue = romanValues[i]; @@ -5271,9 +5223,8 @@ roman_to_int(NUMProc *Np, int input_len)  } -/* ---------- +/*   * Locale - * ----------   */  static void  NUM_prepare_locale(NUMProc *Np) @@ -5349,16 +5300,15 @@ NUM_prepare_locale(NUMProc *Np)  	}  } -/* ---------- +/*   * Return pointer of last relevant number after decimal point   *	12.0500 --> last relevant is '5'   *	12.0000 --> last relevant is '.'   * If there is no decimal point, return NULL (which will result in same   * behavior as if FM hadn't been specified). - * ----------   */  static char * -get_last_relevant_decnum(char *num) +get_last_relevant_decnum(const char *num)  {  	char	   *result,  			   *p = strchr(num, '.'); @@ -5381,12 +5331,11 @@ get_last_relevant_decnum(char *num)  	return result;  } -/* ---------- +/*   * Number extraction for TO_NUMBER() - * ----------   */  static void -NUM_numpart_from_char(NUMProc *Np, int id, int input_len) +NUM_numpart_from_char(NUMProc *Np, int id, size_t input_len)  {  	bool		isread = false; @@ -5420,7 +5369,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int input_len)  		 */  		if (IS_LSIGN(Np->Num) && Np->Num->lsign == NUM_LSIGN_PRE)  		{ -			int			x = 0; +			size_t		x = 0;  #ifdef DEBUG_TO_FROM_CHAR  			elog(DEBUG_elog_output, "Try read locale pre-sign (%c)", *Np->inout_p); @@ -5499,7 +5448,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int input_len)  		 * Np->decimal is always just "." if we don't have a D format token.  		 * So we just unconditionally match to Np->decimal.  		 */ -		int			x = strlen(Np->decimal); +		size_t		x = strlen(Np->decimal);  #ifdef DEBUG_TO_FROM_CHAR  		elog(DEBUG_elog_output, "Try read decimal point (%c)", @@ -5538,7 +5487,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int input_len)  			(Np->inout_p + 1) < Np->inout + input_len &&  			!isdigit((unsigned char) *(Np->inout_p + 1)))  		{ -			int			x; +			size_t		x;  			char	   *tmp = Np->inout_p++;  #ifdef DEBUG_TO_FROM_CHAR @@ -5596,9 +5545,8 @@ NUM_numpart_from_char(NUMProc *Np, int id, int input_len)  		 *(_n)->number == '0' && \  				 (_n)->Num->post != 0) -/* ---------- +/*   * Add digit or sign to number-string - * ----------   */  static void  NUM_numpart_to_char(NUMProc *Np, int id) @@ -5791,7 +5739,7 @@ NUM_numpart_to_char(NUMProc *Np, int id)   * Skip over "n" input characters, but only if they aren't numeric data   */  static void -NUM_eat_non_data_chars(NUMProc *Np, int n, int input_len) +NUM_eat_non_data_chars(NUMProc *Np, int n, size_t input_len)  {  	while (n-- > 0)  	{ @@ -5805,14 +5753,14 @@ NUM_eat_non_data_chars(NUMProc *Np, int n, int input_len)  static char *  NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, -			  char *number, int input_len, int to_char_out_pre_spaces, +			  char *number, size_t input_len, int to_char_out_pre_spaces,  			  int sign, bool is_to_char, Oid collid)  {  	FormatNode *n;  	NUMProc		_Np,  			   *Np = &_Np;  	const char *pattern; -	int			pattern_len; +	size_t		pattern_len;  	MemSet(Np, 0, sizeof(NUMProc)); @@ -5893,7 +5841,7 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout,  			 */  			if (Np->last_relevant && Np->Num->zero_end > Np->out_pre_spaces)  			{ -				int			last_zero_pos; +				size_t		last_zero_pos;  				char	   *last_zero;  				/* note that Np->number cannot be zero-length here */ @@ -6267,10 +6215,9 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout,  	}  } -/* ---------- +/*   * MACRO: Start part of NUM - for all NUM's to_char variants   *	(sorry, but I hate copy same code - macro is better..) - * ----------   */  #define NUM_TOCHAR_prepare \  do { \ @@ -6281,13 +6228,12 @@ do { \  	format	= NUM_cache(len, &Num, fmt, &shouldFree);		\  } while (0) -/* ---------- +/*   * MACRO: Finish part of NUM - * ----------   */  #define NUM_TOCHAR_finish \  do { \ -	int		len; \ +	size_t	len; \  									\  	NUM_processor(format, &Num, VARDATA(result), numstr, 0, out_pre_spaces, sign, true, PG_GET_COLLATION()); \  									\ @@ -6303,9 +6249,8 @@ do { \  	SET_VARSIZE(result, len + VARHDRSZ); \  } while (0) -/* ------------------- +/*   * NUMERIC to_number() (convert string to numeric) - * -------------------   */  Datum  numeric_to_number(PG_FUNCTION_ARGS) @@ -6362,9 +6307,8 @@ numeric_to_number(PG_FUNCTION_ARGS)  	return result;  } -/* ------------------ +/*   * NUMERIC to_char() - * ------------------   */  Datum  numeric_to_char(PG_FUNCTION_ARGS) @@ -6434,7 +6378,7 @@ numeric_to_char(PG_FUNCTION_ARGS)  	}  	else  	{ -		int			numstr_pre_len; +		size_t		numstr_pre_len;  		Numeric		val = value;  		Numeric		x; @@ -6490,9 +6434,8 @@ numeric_to_char(PG_FUNCTION_ARGS)  	PG_RETURN_TEXT_P(result);  } -/* --------------- +/*   * INT4 to_char() - * ---------------   */  Datum  int4_to_char(PG_FUNCTION_ARGS) @@ -6532,7 +6475,7 @@ int4_to_char(PG_FUNCTION_ARGS)  	}  	else  	{ -		int			numstr_pre_len; +		size_t		numstr_pre_len;  		if (IS_MULTI(&Num))  		{ @@ -6584,9 +6527,8 @@ int4_to_char(PG_FUNCTION_ARGS)  	PG_RETURN_TEXT_P(result);  } -/* --------------- +/*   * INT8 to_char() - * ---------------   */  Datum  int8_to_char(PG_FUNCTION_ARGS) @@ -6642,7 +6584,7 @@ int8_to_char(PG_FUNCTION_ARGS)  	}  	else  	{ -		int			numstr_pre_len; +		size_t		numstr_pre_len;  		if (IS_MULTI(&Num))  		{ @@ -6696,9 +6638,8 @@ int8_to_char(PG_FUNCTION_ARGS)  	PG_RETURN_TEXT_P(result);  } -/* ----------------- +/*   * FLOAT4 to_char() - * -----------------   */  Datum  float4_to_char(PG_FUNCTION_ARGS) @@ -6757,7 +6698,7 @@ float4_to_char(PG_FUNCTION_ARGS)  	{  		float4		val = value;  		char	   *orgnum; -		int			numstr_pre_len; +		size_t		numstr_pre_len;  		if (IS_MULTI(&Num))  		{ @@ -6809,9 +6750,8 @@ float4_to_char(PG_FUNCTION_ARGS)  	PG_RETURN_TEXT_P(result);  } -/* ----------------- +/*   * FLOAT8 to_char() - * -----------------   */  Datum  float8_to_char(PG_FUNCTION_ARGS) @@ -6870,7 +6810,7 @@ float8_to_char(PG_FUNCTION_ARGS)  	{  		float8		val = value;  		char	   *orgnum; -		int			numstr_pre_len; +		size_t		numstr_pre_len;  		if (IS_MULTI(&Num))  		{ diff --git a/src/backend/utils/adt/json.c b/src/backend/utils/adt/json.c index 14f5cb498fc..88a612b041d 100644 --- a/src/backend/utils/adt/json.c +++ b/src/backend/utils/adt/json.c @@ -89,7 +89,7 @@ typedef struct JsonAggState  static void composite_to_json(Datum composite, StringInfo result,  							  bool use_line_feeds);  static void array_dim_to_json(StringInfo result, int dim, int ndims, int *dims, -							  Datum *vals, bool *nulls, int *valcount, +							  const Datum *vals, const bool *nulls, int *valcount,  							  JsonTypeCategory tcategory, Oid outfuncoid,  							  bool use_line_feeds);  static void array_to_json_internal(Datum array, StringInfo result, @@ -429,8 +429,8 @@ JsonEncodeDateTime(char *buf, Datum value, Oid typid, const int *tzp)   * ourselves recursively to process the next dimension.   */  static void -array_dim_to_json(StringInfo result, int dim, int ndims, int *dims, Datum *vals, -				  bool *nulls, int *valcount, JsonTypeCategory tcategory, +array_dim_to_json(StringInfo result, int dim, int ndims, int *dims, const Datum *vals, +				  const bool *nulls, int *valcount, JsonTypeCategory tcategory,  				  Oid outfuncoid, bool use_line_feeds)  {  	int			i; diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c index c5e1a027956..41862872e8a 100644 --- a/src/backend/utils/adt/jsonfuncs.c +++ b/src/backend/utils/adt/jsonfuncs.c @@ -477,16 +477,16 @@ static Datum populate_domain(DomainIOData *io, Oid typid, const char *colname,  /* functions supporting jsonb_delete, jsonb_set and jsonb_concat */  static JsonbValue *IteratorConcat(JsonbIterator **it1, JsonbIterator **it2,  								  JsonbParseState **state); -static JsonbValue *setPath(JsonbIterator **it, Datum *path_elems, -						   bool *path_nulls, int path_len, +static JsonbValue *setPath(JsonbIterator **it, const Datum *path_elems, +						   const bool *path_nulls, int path_len,  						   JsonbParseState **st, int level, JsonbValue *newval,  						   int op_type); -static void setPathObject(JsonbIterator **it, Datum *path_elems, -						  bool *path_nulls, int path_len, JsonbParseState **st, +static void setPathObject(JsonbIterator **it, const Datum *path_elems, +						  const bool *path_nulls, int path_len, JsonbParseState **st,  						  int level,  						  JsonbValue *newval, uint32 npairs, int op_type); -static void setPathArray(JsonbIterator **it, Datum *path_elems, -						 bool *path_nulls, int path_len, JsonbParseState **st, +static void setPathArray(JsonbIterator **it, const Datum *path_elems, +						 const bool *path_nulls, int path_len, JsonbParseState **st,  						 int level,  						 JsonbValue *newval, uint32 nelems, int op_type); @@ -1528,7 +1528,7 @@ get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text)  }  Datum -jsonb_get_element(Jsonb *jb, Datum *path, int npath, bool *isnull, bool as_text) +jsonb_get_element(Jsonb *jb, const Datum *path, int npath, bool *isnull, bool as_text)  {  	JsonbContainer *container = &jb->root;  	JsonbValue *jbvp = NULL; @@ -1676,7 +1676,7 @@ jsonb_get_element(Jsonb *jb, Datum *path, int npath, bool *isnull, bool as_text)  }  Datum -jsonb_set_element(Jsonb *jb, Datum *path, int path_len, +jsonb_set_element(Jsonb *jb, const Datum *path, int path_len,  				  JsonbValue *newval)  {  	JsonbValue *res; @@ -1718,8 +1718,8 @@ push_null_elements(JsonbParseState **ps, int num)   * Caller is responsible to make sure such path does not exist yet.   */  static void -push_path(JsonbParseState **st, int level, Datum *path_elems, -		  bool *path_nulls, int path_len, JsonbValue *newval) +push_path(JsonbParseState **st, int level, const Datum *path_elems, +		  const bool *path_nulls, int path_len, JsonbValue *newval)  {  	/*  	 * tpath contains expected type of an empty jsonb created at each level @@ -5201,8 +5201,8 @@ IteratorConcat(JsonbIterator **it1, JsonbIterator **it2,   * whatever bits in op_type are set, or nothing is done.   */  static JsonbValue * -setPath(JsonbIterator **it, Datum *path_elems, -		bool *path_nulls, int path_len, +setPath(JsonbIterator **it, const Datum *path_elems, +		const bool *path_nulls, int path_len,  		JsonbParseState **st, int level, JsonbValue *newval, int op_type)  {  	JsonbValue	v; @@ -5283,7 +5283,7 @@ setPath(JsonbIterator **it, Datum *path_elems,   * Object walker for setPath   */  static void -setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls, +setPathObject(JsonbIterator **it, const Datum *path_elems, const bool *path_nulls,  			  int path_len, JsonbParseState **st, int level,  			  JsonbValue *newval, uint32 npairs, int op_type)  { @@ -5422,7 +5422,7 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,   * Array walker for setPath   */  static void -setPathArray(JsonbIterator **it, Datum *path_elems, bool *path_nulls, +setPathArray(JsonbIterator **it, const Datum *path_elems, const bool *path_nulls,  			 int path_len, JsonbParseState **st, int level,  			 JsonbValue *newval, uint32 nelems, int op_type)  { diff --git a/src/backend/utils/adt/jsonpath_scan.l b/src/backend/utils/adt/jsonpath_scan.l index c7aab83eeb4..8c3a0a9c642 100644 --- a/src/backend/utils/adt/jsonpath_scan.l +++ b/src/backend/utils/adt/jsonpath_scan.l @@ -574,7 +574,7 @@ hexval(char c, int *result, struct Node *escontext, yyscan_t yyscanner)  /* Add given unicode character to scanstring */  static bool -addUnicodeChar(int ch, struct Node *escontext, yyscan_t yyscanner) +addUnicodeChar(char32_t ch, struct Node *escontext, yyscan_t yyscanner)  {  	if (ch == 0)  	{ @@ -607,7 +607,7 @@ addUnicodeChar(int ch, struct Node *escontext, yyscan_t yyscanner)  /* Add unicode character, processing any surrogate pairs */  static bool -addUnicode(int ch, int *hi_surrogate, struct Node *escontext, yyscan_t yyscanner) +addUnicode(char32_t ch, int *hi_surrogate, struct Node *escontext, yyscan_t yyscanner)  {  	if (is_utf16_surrogate_first(ch))  	{ @@ -655,7 +655,7 @@ parseUnicode(char *s, int l, struct Node *escontext, yyscan_t yyscanner)  	for (i = 2; i < l; i += 2)	/* skip '\u' */  	{ -		int			ch = 0; +		char32_t		ch = 0;  		int			j,  					si; diff --git a/src/backend/utils/adt/multirangetypes_selfuncs.c b/src/backend/utils/adt/multirangetypes_selfuncs.c index b87bcf3ea30..21f0205d803 100644 --- a/src/backend/utils/adt/multirangetypes_selfuncs.c +++ b/src/backend/utils/adt/multirangetypes_selfuncs.c @@ -49,10 +49,10 @@ static float8 get_position(TypeCacheEntry *typcache, const RangeBound *value,  static float8 get_len_position(double value, double hist1, double hist2);  static float8 get_distance(TypeCacheEntry *typcache, const RangeBound *bound1,  						   const RangeBound *bound2); -static int	length_hist_bsearch(Datum *length_hist_values, +static int	length_hist_bsearch(const Datum *length_hist_values,  								int length_hist_nvalues, double value,  								bool equal); -static double calc_length_hist_frac(Datum *length_hist_values, +static double calc_length_hist_frac(const Datum *length_hist_values,  									int length_hist_nvalues, double length1,  									double length2, bool equal);  static double calc_hist_selectivity_contained(TypeCacheEntry *typcache, @@ -60,14 +60,14 @@ static double calc_hist_selectivity_contained(TypeCacheEntry *typcache,  											  RangeBound *upper,  											  const RangeBound *hist_lower,  											  int hist_nvalues, -											  Datum *length_hist_values, +											  const Datum *length_hist_values,  											  int length_hist_nvalues);  static double calc_hist_selectivity_contains(TypeCacheEntry *typcache,  											 const RangeBound *lower,  											 const RangeBound *upper,  											 const RangeBound *hist_lower,  											 int hist_nvalues, -											 Datum *length_hist_values, +											 const Datum *length_hist_values,  											 int length_hist_nvalues);  /* @@ -765,7 +765,7 @@ rbound_bsearch(TypeCacheEntry *typcache, const RangeBound *value, const RangeBou   * given length, returns -1.   */  static int -length_hist_bsearch(Datum *length_hist_values, int length_hist_nvalues, +length_hist_bsearch(const Datum *length_hist_values, int length_hist_nvalues,  					double value, bool equal)  {  	int			lower = -1, @@ -963,7 +963,7 @@ get_distance(TypeCacheEntry *typcache, const RangeBound *bound1, const RangeBoun   * 'equal' is true).   */  static double -calc_length_hist_frac(Datum *length_hist_values, int length_hist_nvalues, +calc_length_hist_frac(const Datum *length_hist_values, int length_hist_nvalues,  					  double length1, double length2, bool equal)  {  	double		frac; @@ -1131,7 +1131,7 @@ static double  calc_hist_selectivity_contained(TypeCacheEntry *typcache,  								const RangeBound *lower, RangeBound *upper,  								const RangeBound *hist_lower, int hist_nvalues, -								Datum *length_hist_values, int length_hist_nvalues) +								const Datum *length_hist_values, int length_hist_nvalues)  {  	int			i,  				upper_index; @@ -1252,7 +1252,7 @@ static double  calc_hist_selectivity_contains(TypeCacheEntry *typcache,  							   const RangeBound *lower, const RangeBound *upper,  							   const RangeBound *hist_lower, int hist_nvalues, -							   Datum *length_hist_values, int length_hist_nvalues) +							   const Datum *length_hist_values, int length_hist_nvalues)  {  	int			i,  				lower_index; diff --git a/src/backend/utils/adt/network_selfuncs.c b/src/backend/utils/adt/network_selfuncs.c index 940cdafa546..d08f40e0332 100644 --- a/src/backend/utils/adt/network_selfuncs.c +++ b/src/backend/utils/adt/network_selfuncs.c @@ -48,17 +48,17 @@ static Selectivity networkjoinsel_inner(Oid operator,  static Selectivity networkjoinsel_semi(Oid operator,  									   VariableStatData *vardata1, VariableStatData *vardata2);  static Selectivity mcv_population(float4 *mcv_numbers, int mcv_nvalues); -static Selectivity inet_hist_value_sel(Datum *values, int nvalues, +static Selectivity inet_hist_value_sel(const Datum *values, int nvalues,  									   Datum constvalue, int opr_codenum);  static Selectivity inet_mcv_join_sel(Datum *mcv1_values,  									 float4 *mcv1_numbers, int mcv1_nvalues, Datum *mcv2_values,  									 float4 *mcv2_numbers, int mcv2_nvalues, Oid operator); -static Selectivity inet_mcv_hist_sel(Datum *mcv_values, float4 *mcv_numbers, -									 int mcv_nvalues, Datum *hist_values, int hist_nvalues, +static Selectivity inet_mcv_hist_sel(const Datum *mcv_values, float4 *mcv_numbers, +									 int mcv_nvalues, const Datum *hist_values, int hist_nvalues,  									 int opr_codenum); -static Selectivity inet_hist_inclusion_join_sel(Datum *hist1_values, +static Selectivity inet_hist_inclusion_join_sel(const Datum *hist1_values,  												int hist1_nvalues, -												Datum *hist2_values, int hist2_nvalues, +												const Datum *hist2_values, int hist2_nvalues,  												int opr_codenum);  static Selectivity inet_semi_join_sel(Datum lhs_value,  									  bool mcv_exists, Datum *mcv_values, int mcv_nvalues, @@ -601,7 +601,7 @@ mcv_population(float4 *mcv_numbers, int mcv_nvalues)   * better option than not considering these buckets at all.   */  static Selectivity -inet_hist_value_sel(Datum *values, int nvalues, Datum constvalue, +inet_hist_value_sel(const Datum *values, int nvalues, Datum constvalue,  					int opr_codenum)  {  	Selectivity match = 0.0; @@ -702,8 +702,8 @@ inet_mcv_join_sel(Datum *mcv1_values, float4 *mcv1_numbers, int mcv1_nvalues,   * the histogram.   */  static Selectivity -inet_mcv_hist_sel(Datum *mcv_values, float4 *mcv_numbers, int mcv_nvalues, -				  Datum *hist_values, int hist_nvalues, +inet_mcv_hist_sel(const Datum *mcv_values, float4 *mcv_numbers, int mcv_nvalues, +				  const Datum *hist_values, int hist_nvalues,  				  int opr_codenum)  {  	Selectivity selec = 0.0; @@ -739,8 +739,8 @@ inet_mcv_hist_sel(Datum *mcv_values, float4 *mcv_numbers, int mcv_nvalues,   * average?  That would at least avoid non-commutative estimation results.   */  static Selectivity -inet_hist_inclusion_join_sel(Datum *hist1_values, int hist1_nvalues, -							 Datum *hist2_values, int hist2_nvalues, +inet_hist_inclusion_join_sel(const Datum *hist1_values, int hist1_nvalues, +							 const Datum *hist2_values, int hist2_nvalues,  							 int opr_codenum)  {  	double		match = 0.0; diff --git a/src/backend/utils/adt/orderedsetaggs.c b/src/backend/utils/adt/orderedsetaggs.c index c41b191be62..2121cc05f28 100644 --- a/src/backend/utils/adt/orderedsetaggs.c +++ b/src/backend/utils/adt/orderedsetaggs.c @@ -660,8 +660,8 @@ pct_info_cmp(const void *pa, const void *pb)   */  static struct pct_info *  setup_pct_info(int num_percentiles, -			   Datum *percentiles_datum, -			   bool *percentiles_null, +			   const Datum *percentiles_datum, +			   const bool *percentiles_null,  			   int64 rowcount,  			   bool continuous)  { diff --git a/src/backend/utils/adt/pg_locale_builtin.c b/src/backend/utils/adt/pg_locale_builtin.c index 3dc611b50e1..1021e0d129b 100644 --- a/src/backend/utils/adt/pg_locale_builtin.c +++ b/src/backend/utils/adt/pg_locale_builtin.c @@ -15,7 +15,6 @@  #include "catalog/pg_collation.h"  #include "common/unicode_case.h"  #include "common/unicode_category.h" -#include "mb/pg_wchar.h"  #include "miscadmin.h"  #include "utils/builtins.h"  #include "utils/pg_locale.h" @@ -36,6 +35,23 @@ struct WordBoundaryState  };  /* + * In UTF-8, pg_wchar is guaranteed to be the code point value. + */ +static inline char32_t +to_char32(pg_wchar wc) +{ +	Assert(GetDatabaseEncoding() == PG_UTF8); +	return (char32_t) wc; +} + +static inline pg_wchar +to_pg_wchar(char32_t c32) +{ +	Assert(GetDatabaseEncoding() == PG_UTF8); +	return (pg_wchar) c32; +} + +/*   * Simple word boundary iterator that draws boundaries each time the result of   * pg_u_isalnum() changes.   */ @@ -47,7 +63,7 @@ initcap_wbnext(void *state)  	while (wbstate->offset < wbstate->len &&  		   wbstate->str[wbstate->offset] != '\0')  	{ -		pg_wchar	u = utf8_to_unicode((unsigned char *) wbstate->str + +		char32_t	u = utf8_to_unicode((unsigned char *) wbstate->str +  										wbstate->offset);  		bool		curr_alnum = pg_u_isalnum(u, wbstate->posix); @@ -112,61 +128,61 @@ strfold_builtin(char *dest, size_t destsize, const char *src, ssize_t srclen,  static bool  wc_isdigit_builtin(pg_wchar wc, pg_locale_t locale)  { -	return pg_u_isdigit(wc, !locale->builtin.casemap_full); +	return pg_u_isdigit(to_char32(wc), !locale->builtin.casemap_full);  }  static bool  wc_isalpha_builtin(pg_wchar wc, pg_locale_t locale)  { -	return pg_u_isalpha(wc); +	return pg_u_isalpha(to_char32(wc));  }  static bool  wc_isalnum_builtin(pg_wchar wc, pg_locale_t locale)  { -	return pg_u_isalnum(wc, !locale->builtin.casemap_full); +	return pg_u_isalnum(to_char32(wc), !locale->builtin.casemap_full);  }  static bool  wc_isupper_builtin(pg_wchar wc, pg_locale_t locale)  { -	return pg_u_isupper(wc); +	return pg_u_isupper(to_char32(wc));  }  static bool  wc_islower_builtin(pg_wchar wc, pg_locale_t locale)  { -	return pg_u_islower(wc); +	return pg_u_islower(to_char32(wc));  }  static bool  wc_isgraph_builtin(pg_wchar wc, pg_locale_t locale)  { -	return pg_u_isgraph(wc); +	return pg_u_isgraph(to_char32(wc));  }  static bool  wc_isprint_builtin(pg_wchar wc, pg_locale_t locale)  { -	return pg_u_isprint(wc); +	return pg_u_isprint(to_char32(wc));  }  static bool  wc_ispunct_builtin(pg_wchar wc, pg_locale_t locale)  { -	return pg_u_ispunct(wc, !locale->builtin.casemap_full); +	return pg_u_ispunct(to_char32(wc), !locale->builtin.casemap_full);  }  static bool  wc_isspace_builtin(pg_wchar wc, pg_locale_t locale)  { -	return pg_u_isspace(wc); +	return pg_u_isspace(to_char32(wc));  }  static bool  wc_isxdigit_builtin(pg_wchar wc, pg_locale_t locale)  { -	return pg_u_isxdigit(wc, !locale->builtin.casemap_full); +	return pg_u_isxdigit(to_char32(wc), !locale->builtin.casemap_full);  }  static bool @@ -179,13 +195,13 @@ char_is_cased_builtin(char ch, pg_locale_t locale)  static pg_wchar  wc_toupper_builtin(pg_wchar wc, pg_locale_t locale)  { -	return unicode_uppercase_simple(wc); +	return to_pg_wchar(unicode_uppercase_simple(to_char32(wc)));  }  static pg_wchar  wc_tolower_builtin(pg_wchar wc, pg_locale_t locale)  { -	return unicode_lowercase_simple(wc); +	return to_pg_wchar(unicode_lowercase_simple(to_char32(wc)));  }  static const struct ctype_methods ctype_methods_builtin = { diff --git a/src/backend/utils/adt/pg_locale_icu.c b/src/backend/utils/adt/pg_locale_icu.c index 05bad202669..f5a0cc8fe41 100644 --- a/src/backend/utils/adt/pg_locale_icu.c +++ b/src/backend/utils/adt/pg_locale_icu.c @@ -128,6 +128,11 @@ char_is_cased_icu(char ch, pg_locale_t locale)  		(ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z');  } +/* + * XXX: many of the functions below rely on casts directly from pg_wchar to + * UChar32, which is correct for the UTF-8 encoding, but not in general. + */ +  static pg_wchar  toupper_icu(pg_wchar wc, pg_locale_t locale)  { diff --git a/src/backend/utils/adt/pg_locale_libc.c b/src/backend/utils/adt/pg_locale_libc.c index 7ae778dc296..9c7fcd1fc7a 100644 --- a/src/backend/utils/adt/pg_locale_libc.c +++ b/src/backend/utils/adt/pg_locale_libc.c @@ -45,8 +45,7 @@   *   * 2. When working in UTF8 encoding, we use the <wctype.h> functions.   * This assumes that every platform uses Unicode codepoints directly - * as the wchar_t representation of Unicode.  (XXX: ICU makes this assumption - * even for non-UTF8 encodings, which may be a problem.)  On some platforms + * as the wchar_t representation of Unicode.  On some platforms   * wchar_t is only 16 bits wide, so we have to punt for codepoints > 0xFFFF.   *   * 3. In all other encodings, we use the <ctype.h> functions for pg_wchar diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index 1fe33df2756..a710508979e 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -1637,7 +1637,7 @@ static Datum  pg_stat_wal_build_tuple(PgStat_WalCounters wal_counters,  						TimestampTz stat_reset_timestamp)  { -#define PG_STAT_WAL_COLS	5 +#define PG_STAT_WAL_COLS	6  	TupleDesc	tupdesc;  	Datum		values[PG_STAT_WAL_COLS] = {0};  	bool		nulls[PG_STAT_WAL_COLS] = {0}; @@ -1651,9 +1651,11 @@ pg_stat_wal_build_tuple(PgStat_WalCounters wal_counters,  					   INT8OID, -1, 0);  	TupleDescInitEntry(tupdesc, (AttrNumber) 3, "wal_bytes",  					   NUMERICOID, -1, 0); -	TupleDescInitEntry(tupdesc, (AttrNumber) 4, "wal_buffers_full", +	TupleDescInitEntry(tupdesc, (AttrNumber) 4, "wal_fpi_bytes", +					   NUMERICOID, -1, 0); +	TupleDescInitEntry(tupdesc, (AttrNumber) 5, "wal_buffers_full",  					   INT8OID, -1, 0); -	TupleDescInitEntry(tupdesc, (AttrNumber) 5, "stats_reset", +	TupleDescInitEntry(tupdesc, (AttrNumber) 6, "stats_reset",  					   TIMESTAMPTZOID, -1, 0);  	BlessTupleDesc(tupdesc); @@ -1669,12 +1671,18 @@ pg_stat_wal_build_tuple(PgStat_WalCounters wal_counters,  									ObjectIdGetDatum(0),  									Int32GetDatum(-1)); -	values[3] = Int64GetDatum(wal_counters.wal_buffers_full); +	snprintf(buf, sizeof buf, UINT64_FORMAT, wal_counters.wal_fpi_bytes); +	values[3] = DirectFunctionCall3(numeric_in, +									CStringGetDatum(buf), +									ObjectIdGetDatum(0), +									Int32GetDatum(-1)); + +	values[4] = Int64GetDatum(wal_counters.wal_buffers_full);  	if (stat_reset_timestamp != 0) -		values[4] = TimestampTzGetDatum(stat_reset_timestamp); +		values[5] = TimestampTzGetDatum(stat_reset_timestamp);  	else -		nulls[4] = true; +		nulls[5] = true;  	/* Returns the record as Datum */  	PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls))); diff --git a/src/backend/utils/adt/rangetypes_selfuncs.c b/src/backend/utils/adt/rangetypes_selfuncs.c index d126abc5a82..d85252cafb2 100644 --- a/src/backend/utils/adt/rangetypes_selfuncs.c +++ b/src/backend/utils/adt/rangetypes_selfuncs.c @@ -46,18 +46,18 @@ static float8 get_position(TypeCacheEntry *typcache, const RangeBound *value,  static float8 get_len_position(double value, double hist1, double hist2);  static float8 get_distance(TypeCacheEntry *typcache, const RangeBound *bound1,  						   const RangeBound *bound2); -static int	length_hist_bsearch(Datum *length_hist_values, +static int	length_hist_bsearch(const Datum *length_hist_values,  								int length_hist_nvalues, double value, bool equal); -static double calc_length_hist_frac(Datum *length_hist_values, +static double calc_length_hist_frac(const Datum *length_hist_values,  									int length_hist_nvalues, double length1, double length2, bool equal);  static double calc_hist_selectivity_contained(TypeCacheEntry *typcache,  											  const RangeBound *lower, RangeBound *upper,  											  const RangeBound *hist_lower, int hist_nvalues, -											  Datum *length_hist_values, int length_hist_nvalues); +											  const Datum *length_hist_values, int length_hist_nvalues);  static double calc_hist_selectivity_contains(TypeCacheEntry *typcache,  											 const RangeBound *lower, const RangeBound *upper,  											 const RangeBound *hist_lower, int hist_nvalues, -											 Datum *length_hist_values, int length_hist_nvalues); +											 const Datum *length_hist_values, int length_hist_nvalues);  /*   * Returns a default selectivity estimate for given operator, when we don't @@ -654,7 +654,7 @@ rbound_bsearch(TypeCacheEntry *typcache, const RangeBound *value, const RangeBou   * given length, returns -1.   */  static int -length_hist_bsearch(Datum *length_hist_values, int length_hist_nvalues, +length_hist_bsearch(const Datum *length_hist_values, int length_hist_nvalues,  					double value, bool equal)  {  	int			lower = -1, @@ -852,7 +852,7 @@ get_distance(TypeCacheEntry *typcache, const RangeBound *bound1, const RangeBoun   * 'equal' is true).   */  static double -calc_length_hist_frac(Datum *length_hist_values, int length_hist_nvalues, +calc_length_hist_frac(const Datum *length_hist_values, int length_hist_nvalues,  					  double length1, double length2, bool equal)  {  	double		frac; @@ -1018,7 +1018,7 @@ static double  calc_hist_selectivity_contained(TypeCacheEntry *typcache,  								const RangeBound *lower, RangeBound *upper,  								const RangeBound *hist_lower, int hist_nvalues, -								Datum *length_hist_values, int length_hist_nvalues) +								const Datum *length_hist_values, int length_hist_nvalues)  {  	int			i,  				upper_index; @@ -1139,7 +1139,7 @@ static double  calc_hist_selectivity_contains(TypeCacheEntry *typcache,  							   const RangeBound *lower, const RangeBound *upper,  							   const RangeBound *hist_lower, int hist_nvalues, -							   Datum *length_hist_values, int length_hist_nvalues) +							   const Datum *length_hist_values, int length_hist_nvalues)  {  	int			i,  				lower_index; diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index e5e066a5537..cb23ad52782 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -6575,6 +6575,13 @@ get_actual_variable_range(PlannerInfo *root, VariableStatData *vardata,  			continue;  		/* +		 * get_actual_variable_endpoint uses the index-only-scan machinery, so +		 * ignore indexes that can't use it on their first column. +		 */ +		if (!index->canreturn[0]) +			continue; + +		/*  		 * The first index column must match the desired variable, sortop, and  		 * collation --- but we can use a descending-order index.  		 */ diff --git a/src/backend/utils/adt/tid.c b/src/backend/utils/adt/tid.c index 39dab3e42df..0cfb0bd3735 100644 --- a/src/backend/utils/adt/tid.c +++ b/src/backend/utils/adt/tid.c @@ -42,7 +42,7 @@  #define DELIM			','  #define NTIDARGS		2 -static ItemPointer currtid_for_view(Relation viewrel, ItemPointer tid); +static ItemPointer currtid_for_view(Relation viewrel, const ItemPointerData *tid);  /* ----------------------------------------------------------------   *		tidin @@ -293,7 +293,7 @@ hashtidextended(PG_FUNCTION_ARGS)   *		relation "rel".   */  static ItemPointer -currtid_internal(Relation rel, ItemPointer tid) +currtid_internal(Relation rel, const ItemPointerData *tid)  {  	ItemPointer result;  	AclResult	aclresult; @@ -335,7 +335,7 @@ currtid_internal(Relation rel, ItemPointer tid)   *		correspond to the CTID of a base relation.   */  static ItemPointer -currtid_for_view(Relation viewrel, ItemPointer tid) +currtid_for_view(Relation viewrel, const ItemPointerData *tid)  {  	TupleDesc	att = RelationGetDescr(viewrel);  	RuleLock   *rulelock; diff --git a/src/backend/utils/adt/tsvector_op.c b/src/backend/utils/adt/tsvector_op.c index 0625da9532f..c752cbe5463 100644 --- a/src/backend/utils/adt/tsvector_op.c +++ b/src/backend/utils/adt/tsvector_op.c @@ -75,7 +75,7 @@ static bool TS_execute_locations_recurse(QueryItem *curitem,  										 void *arg,  										 TSExecuteCallback chkcond,  										 List **locations); -static int	tsvector_bsearch(const TSVector tsv, char *lexeme, int lexeme_len); +static int	tsvector_bsearch(const TSVectorData *tsv, char *lexeme, int lexeme_len);  static Datum tsvector_update_trigger(PG_FUNCTION_ARGS, bool config_column); @@ -83,7 +83,7 @@ static Datum tsvector_update_trigger(PG_FUNCTION_ARGS, bool config_column);   * Order: haspos, len, word, for all positions (pos, weight)   */  static int -silly_cmp_tsvector(const TSVector a, const TSVector b) +silly_cmp_tsvector(const TSVectorData *a, const TSVectorData *b)  {  	if (VARSIZE(a) < VARSIZE(b))  		return -1; @@ -95,8 +95,8 @@ silly_cmp_tsvector(const TSVector a, const TSVector b)  		return 1;  	else  	{ -		WordEntry  *aptr = ARRPTR(a); -		WordEntry  *bptr = ARRPTR(b); +		const WordEntry *aptr = ARRPTR(a); +		const WordEntry *bptr = ARRPTR(b);  		int			i = 0;  		int			res; @@ -397,9 +397,9 @@ add_pos(TSVector src, WordEntry *srcptr,   * found.   */  static int -tsvector_bsearch(const TSVector tsv, char *lexeme, int lexeme_len) +tsvector_bsearch(const TSVectorData *tsv, char *lexeme, int lexeme_len)  { -	WordEntry  *arrin = ARRPTR(tsv); +	const WordEntry *arrin = ARRPTR(tsv);  	int			StopLow = 0,  				StopHigh = tsv->size,  				StopMiddle, diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index 2c398cd9e5c..8d735786e51 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -5419,12 +5419,12 @@ unicode_assigned(PG_FUNCTION_ARGS)  		ereport(ERROR,  				(errmsg("Unicode categorization can only be performed if server encoding is UTF8"))); -	/* convert to pg_wchar */ +	/* convert to char32_t */  	size = pg_mbstrlen_with_len(VARDATA_ANY(input), VARSIZE_ANY_EXHDR(input));  	p = (unsigned char *) VARDATA_ANY(input);  	for (int i = 0; i < size; i++)  	{ -		pg_wchar	uchar = utf8_to_unicode(p); +		char32_t	uchar = utf8_to_unicode(p);  		int			category = unicode_category(uchar);  		if (category == PG_U_UNASSIGNED) @@ -5443,24 +5443,24 @@ unicode_normalize_func(PG_FUNCTION_ARGS)  	char	   *formstr = text_to_cstring(PG_GETARG_TEXT_PP(1));  	UnicodeNormalizationForm form;  	int			size; -	pg_wchar   *input_chars; -	pg_wchar   *output_chars; +	char32_t   *input_chars; +	char32_t   *output_chars;  	unsigned char *p;  	text	   *result;  	int			i;  	form = unicode_norm_form_from_string(formstr); -	/* convert to pg_wchar */ +	/* convert to char32_t */  	size = pg_mbstrlen_with_len(VARDATA_ANY(input), VARSIZE_ANY_EXHDR(input)); -	input_chars = palloc((size + 1) * sizeof(pg_wchar)); +	input_chars = palloc((size + 1) * sizeof(char32_t));  	p = (unsigned char *) VARDATA_ANY(input);  	for (i = 0; i < size; i++)  	{  		input_chars[i] = utf8_to_unicode(p);  		p += pg_utf_mblen(p);  	} -	input_chars[i] = (pg_wchar) '\0'; +	input_chars[i] = (char32_t) '\0';  	Assert((char *) p == VARDATA_ANY(input) + VARSIZE_ANY_EXHDR(input));  	/* action */ @@ -5468,7 +5468,7 @@ unicode_normalize_func(PG_FUNCTION_ARGS)  	/* convert back to UTF-8 string */  	size = 0; -	for (pg_wchar *wp = output_chars; *wp; wp++) +	for (char32_t *wp = output_chars; *wp; wp++)  	{  		unsigned char buf[4]; @@ -5480,7 +5480,7 @@ unicode_normalize_func(PG_FUNCTION_ARGS)  	SET_VARSIZE(result, size + VARHDRSZ);  	p = (unsigned char *) VARDATA_ANY(result); -	for (pg_wchar *wp = output_chars; *wp; wp++) +	for (char32_t *wp = output_chars; *wp; wp++)  	{  		unicode_to_utf8(*wp, p);  		p += pg_utf_mblen(p); @@ -5509,8 +5509,8 @@ unicode_is_normalized(PG_FUNCTION_ARGS)  	char	   *formstr = text_to_cstring(PG_GETARG_TEXT_PP(1));  	UnicodeNormalizationForm form;  	int			size; -	pg_wchar   *input_chars; -	pg_wchar   *output_chars; +	char32_t   *input_chars; +	char32_t   *output_chars;  	unsigned char *p;  	int			i;  	UnicodeNormalizationQC quickcheck; @@ -5519,16 +5519,16 @@ unicode_is_normalized(PG_FUNCTION_ARGS)  	form = unicode_norm_form_from_string(formstr); -	/* convert to pg_wchar */ +	/* convert to char32_t */  	size = pg_mbstrlen_with_len(VARDATA_ANY(input), VARSIZE_ANY_EXHDR(input)); -	input_chars = palloc((size + 1) * sizeof(pg_wchar)); +	input_chars = palloc((size + 1) * sizeof(char32_t));  	p = (unsigned char *) VARDATA_ANY(input);  	for (i = 0; i < size; i++)  	{  		input_chars[i] = utf8_to_unicode(p);  		p += pg_utf_mblen(p);  	} -	input_chars[i] = (pg_wchar) '\0'; +	input_chars[i] = (char32_t) '\0';  	Assert((char *) p == VARDATA_ANY(input) + VARSIZE_ANY_EXHDR(input));  	/* quick check (see UAX #15) */ @@ -5542,11 +5542,11 @@ unicode_is_normalized(PG_FUNCTION_ARGS)  	output_chars = unicode_normalize(form, input_chars);  	output_size = 0; -	for (pg_wchar *wp = output_chars; *wp; wp++) +	for (char32_t *wp = output_chars; *wp; wp++)  		output_size++;  	result = (size == output_size) && -		(memcmp(input_chars, output_chars, size * sizeof(pg_wchar)) == 0); +		(memcmp(input_chars, output_chars, size * sizeof(char32_t)) == 0);  	PG_RETURN_BOOL(result);  } @@ -5602,7 +5602,7 @@ unistr(PG_FUNCTION_ARGS)  	int			len;  	StringInfoData str;  	text	   *result; -	pg_wchar	pair_first = 0; +	char16_t	pair_first = 0;  	char		cbuf[MAX_UNICODE_EQUIVALENT_STRING + 1];  	instr = VARDATA_ANY(input_text); @@ -5626,7 +5626,7 @@ unistr(PG_FUNCTION_ARGS)  			else if ((len >= 5 && isxdigits_n(instr + 1, 4)) ||  					 (len >= 6 && instr[1] == 'u' && isxdigits_n(instr + 2, 4)))  			{ -				pg_wchar	unicode; +				char32_t	unicode;  				int			offset = instr[1] == 'u' ? 2 : 1;  				unicode = hexval_n(instr + offset, 4); @@ -5662,7 +5662,7 @@ unistr(PG_FUNCTION_ARGS)  			}  			else if (len >= 8 && instr[1] == '+' && isxdigits_n(instr + 2, 6))  			{ -				pg_wchar	unicode; +				char32_t	unicode;  				unicode = hexval_n(instr + 2, 6); @@ -5697,7 +5697,7 @@ unistr(PG_FUNCTION_ARGS)  			}  			else if (len >= 10 && instr[1] == 'U' && isxdigits_n(instr + 2, 8))  			{ -				pg_wchar	unicode; +				char32_t	unicode;  				unicode = hexval_n(instr + 2, 8); diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index 66b44183695..35c915573a1 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -891,8 +891,8 @@ xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent)  xmltype *  xmlelement(XmlExpr *xexpr, -		   Datum *named_argvalue, bool *named_argnull, -		   Datum *argvalue, bool *argnull) +		   const Datum *named_argvalue, const bool *named_argnull, +		   const Datum *argvalue, const bool *argnull)  {  #ifdef USE_LIBXML  	xmltype    *result;  | 
