diff options
Diffstat (limited to 'src/backend/utils')
78 files changed, 2081 insertions, 1996 deletions
diff --git a/src/backend/utils/adt/arrayutils.c b/src/backend/utils/adt/arrayutils.c index cd59ffb62d..7b4f7754f1 100644 --- a/src/backend/utils/adt/arrayutils.c +++ b/src/backend/utils/adt/arrayutils.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/arrayutils.c,v 1.24 2007/06/15 20:56:50 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/arrayutils.c,v 1.25 2007/11/15 21:14:38 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -193,7 +193,7 @@ mda_next_tuple(int n, int *curr, const int *span) /* * ArrayGetIntegerTypmods: verify that argument is a 1-D cstring array, - * and get the contents converted to integers. Returns a palloc'd array + * and get the contents converted to integers. Returns a palloc'd array * and places the length at *n. */ int32 * diff --git a/src/backend/utils/adt/bool.c b/src/backend/utils/adt/bool.c index 1e44bc1cb5..deed08dcc4 100644 --- a/src/backend/utils/adt/bool.c +++ b/src/backend/utils/adt/bool.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/bool.c,v 1.40 2007/06/05 21:31:06 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/bool.c,v 1.41 2007/11/15 21:14:38 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -35,9 +35,9 @@ Datum boolin(PG_FUNCTION_ARGS) { - const char *in_str = PG_GETARG_CSTRING(0); - const char *str; - size_t len; + const char *in_str = PG_GETARG_CSTRING(0); + const char *str; + size_t len; /* * Skip leading and trailing whitespace @@ -92,7 +92,7 @@ boolin(PG_FUNCTION_ARGS) ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), - errmsg("invalid input syntax for type boolean: \"%s\"", in_str))); + errmsg("invalid input syntax for type boolean: \"%s\"", in_str))); /* not reached */ PG_RETURN_BOOL(false); @@ -143,7 +143,7 @@ boolsend(PG_FUNCTION_ARGS) } /* - * booltext - cast function for bool => text + * booltext - cast function for bool => text * * We need this because it's different from the behavior of boolout(); * this function follows the SQL-spec result (except for producing lower case) @@ -151,8 +151,8 @@ boolsend(PG_FUNCTION_ARGS) Datum booltext(PG_FUNCTION_ARGS) { - bool arg1 = PG_GETARG_BOOL(0); - char *str; + bool arg1 = PG_GETARG_BOOL(0); + char *str; if (arg1) str = "true"; diff --git a/src/backend/utils/adt/cash.c b/src/backend/utils/adt/cash.c index 74127d05cb..de0db349fc 100644 --- a/src/backend/utils/adt/cash.c +++ b/src/backend/utils/adt/cash.c @@ -13,7 +13,7 @@ * this version handles 64 bit numbers and so can hold values up to * $92,233,720,368,547,758.07. * - * $PostgreSQL: pgsql/src/backend/utils/adt/cash.c,v 1.73 2007/08/21 03:56:07 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/cash.c,v 1.74 2007/11/15 21:14:38 momjian Exp $ */ #include "postgres.h" @@ -783,7 +783,7 @@ Datum cash_words(PG_FUNCTION_ARGS) { Cash value = PG_GETARG_CASH(0); - uint64 val; + uint64 val; char buf[256]; char *p = buf; Cash m0; @@ -808,13 +808,13 @@ cash_words(PG_FUNCTION_ARGS) /* Now treat as unsigned, to avoid trouble at INT_MIN */ val = (uint64) value; - m0 = val % 100ll; /* cents */ + m0 = val % 100ll; /* cents */ m1 = (val / 100ll) % 1000; /* hundreds */ - m2 = (val / 100000ll) % 1000; /* thousands */ - m3 = val / 100000000ll % 1000; /* millions */ + m2 = (val / 100000ll) % 1000; /* thousands */ + m3 = val / 100000000ll % 1000; /* millions */ m4 = val / 100000000000ll % 1000; /* billions */ - m5 = val / 100000000000000ll % 1000; /* trillions */ - m6 = val / 100000000000000000ll % 1000; /* quadrillions */ + m5 = val / 100000000000000ll % 1000; /* trillions */ + m6 = val / 100000000000000000ll % 1000; /* quadrillions */ if (m6) { diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c index be37584190..0f2b44b356 100644 --- a/src/backend/utils/adt/date.c +++ b/src/backend/utils/adt/date.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.136 2007/09/26 01:10:42 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.137 2007/11/15 21:14:38 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -49,9 +49,9 @@ static void AdjustTimeForTypmod(TimeADT *time, int32 typmod); static int32 anytime_typmodin(bool istz, ArrayType *ta) { - int32 typmod; - int32 *tl; - int n; + int32 typmod; + int32 *tl; + int n; tl = ArrayGetIntegerTypmods(ta, &n); @@ -74,10 +74,11 @@ anytime_typmodin(bool istz, ArrayType *ta) ereport(WARNING, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("TIME(%d)%s precision reduced to maximum allowed, %d", - *tl, (istz ? " WITH TIME ZONE" : "" ), + *tl, (istz ? " WITH TIME ZONE" : ""), MAX_TIME_PRECISION))); typmod = MAX_TIME_PRECISION; - } else + } + else typmod = *tl; return typmod; @@ -87,7 +88,7 @@ anytime_typmodin(bool istz, ArrayType *ta) static char * anytime_typmodout(bool istz, int32 typmod) { - char *res = (char *) palloc(64); + char *res = (char *) palloc(64); const char *tz = istz ? " with time zone" : " without time zone"; if (typmod >= 0) @@ -339,7 +340,7 @@ date_mii(PG_FUNCTION_ARGS) static Timestamp date2timestamp(DateADT dateVal) { - Timestamp result; + Timestamp result; #ifdef HAVE_INT64_TIMESTAMP /* date is days since 2000, timestamp is microseconds since same... */ @@ -1045,7 +1046,7 @@ time_send(PG_FUNCTION_ARGS) Datum timetypmodin(PG_FUNCTION_ARGS) { - ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); + ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); PG_RETURN_INT32(anytime_typmodin(false, ta)); } @@ -1053,7 +1054,7 @@ timetypmodin(PG_FUNCTION_ARGS) Datum timetypmodout(PG_FUNCTION_ARGS) { - int32 typmod = PG_GETARG_INT32(0); + int32 typmod = PG_GETARG_INT32(0); PG_RETURN_CSTRING(anytime_typmodout(false, typmod)); } @@ -1815,7 +1816,7 @@ timetz_send(PG_FUNCTION_ARGS) Datum timetztypmodin(PG_FUNCTION_ARGS) { - ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); + ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); PG_RETURN_INT32(anytime_typmodin(true, ta)); } @@ -1823,7 +1824,7 @@ timetztypmodin(PG_FUNCTION_ARGS) Datum timetztypmodout(PG_FUNCTION_ARGS) { - int32 typmod = PG_GETARG_INT32(0); + int32 typmod = PG_GETARG_INT32(0); PG_RETURN_CSTRING(anytime_typmodout(true, typmod)); } @@ -1994,17 +1995,17 @@ timetz_hash(PG_FUNCTION_ARGS) uint32 thash; /* - * To avoid any problems with padding bytes in the struct, - * we figure the field hashes separately and XOR them. This also - * provides a convenient framework for dealing with the fact that - * the time field might be either double or int64. + * To avoid any problems with padding bytes in the struct, we figure the + * field hashes separately and XOR them. This also provides a convenient + * framework for dealing with the fact that the time field might be either + * double or int64. */ #ifdef HAVE_INT64_TIMESTAMP thash = DatumGetUInt32(DirectFunctionCall1(hashint8, Int64GetDatumFast(key->time))); #else thash = DatumGetUInt32(DirectFunctionCall1(hashfloat8, - Float8GetDatumFast(key->time))); + Float8GetDatumFast(key->time))); #endif thash ^= DatumGetUInt32(hash_uint32(key->zone)); PG_RETURN_UINT32(thash); diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index 742a328b28..30aea83c93 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.182 2007/08/04 01:26:53 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.183 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -546,7 +546,7 @@ ParseDateTime(const char *timestr, char *workbuf, size_t buflen, */ else if (isalpha((unsigned char) *cp)) { - bool is_date; + bool is_date; ftype[nf] = DTK_STRING; APPEND_CHAR(bufp, bufend, pg_tolower((unsigned char) *cp++)); @@ -555,12 +555,11 @@ ParseDateTime(const char *timestr, char *workbuf, size_t buflen, /* * Dates can have embedded '-', '/', or '.' separators. It could - * also be a timezone name containing embedded '/', '+', '-', - * '_', or ':' (but '_' or ':' can't be the first punctuation). - * If the next character is a digit or '+', we need to check - * whether what we have so far is a recognized non-timezone - * keyword --- if so, don't believe that this is the start of - * a timezone. + * also be a timezone name containing embedded '/', '+', '-', '_', + * or ':' (but '_' or ':' can't be the first punctuation). If the + * next character is a digit or '+', we need to check whether what + * we have so far is a recognized non-timezone keyword --- if so, + * don't believe that this is the start of a timezone. */ is_date = false; if (*cp == '-' || *cp == '/' || *cp == '.') @@ -790,8 +789,8 @@ DecodeDateTime(char **field, int *ftype, int nf, { /* * We should return an error code instead of - * ereport'ing directly, but then there is no - * way to report the bad time zone name. + * ereport'ing directly, but then there is no way + * to report the bad time zone name. */ ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), @@ -1209,6 +1208,7 @@ DecodeDateTime(char **field, int *ftype, int nf, break; case UNKNOWN_FIELD: + /* * Before giving up and declaring error, check to see * if it is an all-alpha timezone name. @@ -1303,8 +1303,8 @@ DecodeDateTime(char **field, int *ftype, int nf, return DTERR_FIELD_OVERFLOW; /* - * If we had a full timezone spec, compute the offset (we could not - * do it before, because we need the date to resolve DST status). + * If we had a full timezone spec, compute the offset (we could not do + * it before, because we need the date to resolve DST status). */ if (namedTz != NULL) { @@ -1566,8 +1566,8 @@ DecodeTimeOnly(char **field, int *ftype, int nf, { /* * We should return an error code instead of - * ereport'ing directly, but then there is no - * way to report the bad time zone name. + * ereport'ing directly, but then there is no way + * to report the bad time zone name. */ ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), @@ -1934,6 +1934,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf, break; case UNKNOWN_FIELD: + /* * Before giving up and declaring error, check to see * if it is an all-alpha timezone name. @@ -1968,7 +1969,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf, if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 || tm->tm_sec < 0 || tm->tm_sec > 60 || tm->tm_hour > 24 || - /* test for > 24:00:00 */ + /* test for > 24:00:00 */ #ifdef HAVE_INT64_TIMESTAMP (tm->tm_hour == 24 && (tm->tm_min > 0 || tm->tm_sec > 0 || *fsec > INT64CONST(0))) || @@ -1985,8 +1986,8 @@ DecodeTimeOnly(char **field, int *ftype, int nf, return DTERR_BAD_FORMAT; /* - * If we had a full timezone spec, compute the offset (we could not - * do it before, because we may need the date to resolve DST status). + * If we had a full timezone spec, compute the offset (we could not do it + * before, because we may need the date to resolve DST status). */ if (namedTz != NULL) { @@ -2470,7 +2471,7 @@ DecodeNumber(int flen, char *str, bool haveTextMonth, int fmask, */ static int DecodeNumberField(int len, char *str, int fmask, - int *tmask, struct pg_tm * tm, fsec_t *fsec, bool *is2digits) + int *tmask, struct pg_tm * tm, fsec_t *fsec, bool *is2digits) { char *cp; @@ -2832,10 +2833,10 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm, #else *fsec += fval; #endif + /* - * If any subseconds were specified, consider - * this microsecond and millisecond input as - * well. + * If any subseconds were specified, consider this + * microsecond and millisecond input as well. */ if (fval == 0) tmask = DTK_M(SECOND); @@ -3322,12 +3323,12 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, if (style == USE_ISO_DATES) sprintf(str, "%04d-%02d-%02d %02d:%02d", - (tm->tm_year > 0) ? tm->tm_year : -(tm->tm_year - 1), - tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min); + (tm->tm_year > 0) ? tm->tm_year : -(tm->tm_year - 1), + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min); else sprintf(str, "%04d-%02d-%02dT%02d:%02d", - (tm->tm_year > 0) ? tm->tm_year : -(tm->tm_year - 1), - tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min); + (tm->tm_year > 0) ? tm->tm_year : -(tm->tm_year - 1), + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min); /* diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c index 3848e8111f..12d1d9d364 100644 --- a/src/backend/utils/adt/dbsize.c +++ b/src/backend/utils/adt/dbsize.c @@ -5,7 +5,7 @@ * Copyright (c) 2002-2007, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/dbsize.c,v 1.14 2007/08/29 17:24:29 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/dbsize.c,v 1.15 2007/11/15 21:14:39 momjian Exp $ * */ @@ -162,8 +162,9 @@ calculate_tablespace_size(Oid tblspcOid) AclResult aclresult; /* - * User must have CREATE privilege for target tablespace, either explicitly - * granted or implicitly because it is default for current database. + * User must have CREATE privilege for target tablespace, either + * explicitly granted or implicitly because it is default for current + * database. */ if (tblspcOid != MyDatabaseTableSpace) { diff --git a/src/backend/utils/adt/enum.c b/src/backend/utils/adt/enum.c index d5187f06a7..5d8bf3175c 100644 --- a/src/backend/utils/adt/enum.c +++ b/src/backend/utils/adt/enum.c @@ -1,13 +1,13 @@ /*------------------------------------------------------------------------- * * enum.c - * I/O functions, operators, aggregates etc for enum types + * I/O functions, operators, aggregates etc for enum types * * Copyright (c) 2006-2007, PostgreSQL Global Development Group * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/enum.c,v 1.4 2007/09/04 16:41:42 adunstan Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/enum.c,v 1.5 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -32,10 +32,10 @@ static int enum_elem_cmp(const void *left, const void *right); Datum enum_in(PG_FUNCTION_ARGS) { - char *name = PG_GETARG_CSTRING(0); - Oid enumtypoid = PG_GETARG_OID(1); - Oid enumoid; - HeapTuple tup; + char *name = PG_GETARG_CSTRING(0); + Oid enumtypoid = PG_GETARG_OID(1); + Oid enumoid; + HeapTuple tup; /* must check length to prevent Assert failure within SearchSysCache */ if (strlen(name) >= NAMEDATALEN) @@ -66,9 +66,9 @@ enum_in(PG_FUNCTION_ARGS) Datum enum_out(PG_FUNCTION_ARGS) { - Oid enumval = PG_GETARG_OID(0); - char *result; - HeapTuple tup; + Oid enumval = PG_GETARG_OID(0); + char *result; + HeapTuple tup; Form_pg_enum en; tup = SearchSysCache(ENUMOID, @@ -92,12 +92,12 @@ enum_out(PG_FUNCTION_ARGS) Datum enum_recv(PG_FUNCTION_ARGS) { - StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); - Oid enumtypoid = PG_GETARG_OID(1); - Oid enumoid; - HeapTuple tup; - char *name; - int nbytes; + StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); + Oid enumtypoid = PG_GETARG_OID(1); + Oid enumoid; + HeapTuple tup; + char *name; + int nbytes; name = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes); @@ -132,9 +132,9 @@ enum_recv(PG_FUNCTION_ARGS) Datum enum_send(PG_FUNCTION_ARGS) { - Oid enumval = PG_GETARG_OID(0); + Oid enumval = PG_GETARG_OID(0); StringInfoData buf; - HeapTuple tup; + HeapTuple tup; Form_pg_enum en; tup = SearchSysCache(ENUMOID, @@ -160,8 +160,8 @@ enum_send(PG_FUNCTION_ARGS) Datum enum_lt(PG_FUNCTION_ARGS) { - Oid a = PG_GETARG_OID(0); - Oid b = PG_GETARG_OID(1); + Oid a = PG_GETARG_OID(0); + Oid b = PG_GETARG_OID(1); PG_RETURN_BOOL(a < b); } @@ -169,8 +169,8 @@ enum_lt(PG_FUNCTION_ARGS) Datum enum_le(PG_FUNCTION_ARGS) { - Oid a = PG_GETARG_OID(0); - Oid b = PG_GETARG_OID(1); + Oid a = PG_GETARG_OID(0); + Oid b = PG_GETARG_OID(1); PG_RETURN_BOOL(a <= b); } @@ -178,8 +178,8 @@ enum_le(PG_FUNCTION_ARGS) Datum enum_eq(PG_FUNCTION_ARGS) { - Oid a = PG_GETARG_OID(0); - Oid b = PG_GETARG_OID(1); + Oid a = PG_GETARG_OID(0); + Oid b = PG_GETARG_OID(1); PG_RETURN_BOOL(a == b); } @@ -187,8 +187,8 @@ enum_eq(PG_FUNCTION_ARGS) Datum enum_ne(PG_FUNCTION_ARGS) { - Oid a = PG_GETARG_OID(0); - Oid b = PG_GETARG_OID(1); + Oid a = PG_GETARG_OID(0); + Oid b = PG_GETARG_OID(1); PG_RETURN_BOOL(a != b); } @@ -196,8 +196,8 @@ enum_ne(PG_FUNCTION_ARGS) Datum enum_ge(PG_FUNCTION_ARGS) { - Oid a = PG_GETARG_OID(0); - Oid b = PG_GETARG_OID(1); + Oid a = PG_GETARG_OID(0); + Oid b = PG_GETARG_OID(1); PG_RETURN_BOOL(a >= b); } @@ -205,8 +205,8 @@ enum_ge(PG_FUNCTION_ARGS) Datum enum_gt(PG_FUNCTION_ARGS) { - Oid a = PG_GETARG_OID(0); - Oid b = PG_GETARG_OID(1); + Oid a = PG_GETARG_OID(0); + Oid b = PG_GETARG_OID(1); PG_RETURN_BOOL(a > b); } @@ -214,8 +214,8 @@ enum_gt(PG_FUNCTION_ARGS) Datum enum_smaller(PG_FUNCTION_ARGS) { - Oid a = PG_GETARG_OID(0); - Oid b = PG_GETARG_OID(1); + Oid a = PG_GETARG_OID(0); + Oid b = PG_GETARG_OID(1); PG_RETURN_OID(a <= b ? a : b); } @@ -223,8 +223,8 @@ enum_smaller(PG_FUNCTION_ARGS) Datum enum_larger(PG_FUNCTION_ARGS) { - Oid a = PG_GETARG_OID(0); - Oid b = PG_GETARG_OID(1); + Oid a = PG_GETARG_OID(0); + Oid b = PG_GETARG_OID(1); PG_RETURN_OID(a >= b ? a : b); } @@ -232,8 +232,8 @@ enum_larger(PG_FUNCTION_ARGS) Datum enum_cmp(PG_FUNCTION_ARGS) { - Oid a = PG_GETARG_OID(0); - Oid b = PG_GETARG_OID(1); + Oid a = PG_GETARG_OID(0); + Oid b = PG_GETARG_OID(1); if (a > b) PG_RETURN_INT32(1); @@ -248,10 +248,11 @@ enum_cmp(PG_FUNCTION_ARGS) Datum enum_first(PG_FUNCTION_ARGS) { - Oid enumtypoid; - Oid min = InvalidOid; - CatCList *list; - int num, i; + Oid enumtypoid; + Oid min = InvalidOid; + CatCList *list; + int num, + i; /* * We rely on being able to get the specific enum type from the calling @@ -270,7 +271,8 @@ enum_first(PG_FUNCTION_ARGS) num = list->n_members; for (i = 0; i < num; i++) { - Oid valoid = HeapTupleHeaderGetOid(list->members[i]->tuple.t_data); + Oid valoid = HeapTupleHeaderGetOid(list->members[i]->tuple.t_data); + if (!OidIsValid(min) || valoid < min) min = valoid; } @@ -287,10 +289,11 @@ enum_first(PG_FUNCTION_ARGS) Datum enum_last(PG_FUNCTION_ARGS) { - Oid enumtypoid; - Oid max = InvalidOid; - CatCList *list; - int num, i; + Oid enumtypoid; + Oid max = InvalidOid; + CatCList *list; + int num, + i; /* * We rely on being able to get the specific enum type from the calling @@ -309,7 +312,8 @@ enum_last(PG_FUNCTION_ARGS) num = list->n_members; for (i = 0; i < num; i++) { - Oid valoid = HeapTupleHeaderGetOid(list->members[i]->tuple.t_data); + Oid valoid = HeapTupleHeaderGetOid(list->members[i]->tuple.t_data); + if (!OidIsValid(max) || valoid > max) max = valoid; } @@ -327,9 +331,9 @@ enum_last(PG_FUNCTION_ARGS) Datum enum_range_bounds(PG_FUNCTION_ARGS) { - Oid lower; - Oid upper; - Oid enumtypoid; + Oid lower; + Oid upper; + Oid enumtypoid; if (PG_ARGISNULL(0)) lower = InvalidOid; @@ -358,7 +362,7 @@ enum_range_bounds(PG_FUNCTION_ARGS) Datum enum_range_all(PG_FUNCTION_ARGS) { - Oid enumtypoid; + Oid enumtypoid; /* * We rely on being able to get the specific enum type from the calling @@ -378,10 +382,12 @@ enum_range_all(PG_FUNCTION_ARGS) static ArrayType * enum_range_internal(Oid enumtypoid, Oid lower, Oid upper) { - ArrayType *result; - CatCList *list; - int total, i, j; - Datum *elems; + ArrayType *result; + CatCList *list; + int total, + i, + j; + Datum *elems; list = SearchSysCacheList(ENUMTYPOIDNAME, 1, ObjectIdGetDatum(enumtypoid), @@ -393,7 +399,7 @@ enum_range_internal(Oid enumtypoid, Oid lower, Oid upper) j = 0; for (i = 0; i < total; i++) { - Oid val = HeapTupleGetOid(&(list->members[i]->tuple)); + Oid val = HeapTupleGetOid(&(list->members[i]->tuple)); if ((!OidIsValid(lower) || lower <= val) && (!OidIsValid(upper) || val <= upper)) @@ -418,8 +424,8 @@ enum_range_internal(Oid enumtypoid, Oid lower, Oid upper) static int enum_elem_cmp(const void *left, const void *right) { - Oid l = DatumGetObjectId(*((const Datum *) left)); - Oid r = DatumGetObjectId(*((const Datum *) right)); + Oid l = DatumGetObjectId(*((const Datum *) left)); + Oid r = DatumGetObjectId(*((const Datum *) right)); if (l < r) return -1; diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c index 53bfd321d7..23e8947eec 100644 --- a/src/backend/utils/adt/float.c +++ b/src/backend/utils/adt/float.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.151 2007/09/19 22:31:48 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.152 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -251,10 +251,11 @@ float4in(PG_FUNCTION_ARGS) #endif /* HAVE_BUGGY_SOLARIS_STRTOD */ #ifdef HAVE_BUGGY_IRIX_STRTOD + /* - * In some IRIX versions, strtod() recognizes only "inf", so if the - * input is "infinity" we have to skip over "inity". Also, it may - * return positive infinity for "-inf". + * In some IRIX versions, strtod() recognizes only "inf", so if the input + * is "infinity" we have to skip over "inity". Also, it may return + * positive infinity for "-inf". */ if (isinf(val)) { @@ -274,7 +275,7 @@ float4in(PG_FUNCTION_ARGS) endptr = num + 4; } } -#endif /* HAVE_BUGGY_IRIX_STRTOD */ +#endif /* HAVE_BUGGY_IRIX_STRTOD */ /* skip trailing whitespace */ while (*endptr != '\0' && isspace((unsigned char) *endptr)) @@ -443,10 +444,11 @@ float8in(PG_FUNCTION_ARGS) #endif /* HAVE_BUGGY_SOLARIS_STRTOD */ #ifdef HAVE_BUGGY_IRIX_STRTOD + /* - * In some IRIX versions, strtod() recognizes only "inf", so if the - * input is "infinity" we have to skip over "inity". Also, it may - * return positive infinity for "-inf". + * In some IRIX versions, strtod() recognizes only "inf", so if the input + * is "infinity" we have to skip over "inity". Also, it may return + * positive infinity for "-inf". */ if (isinf(val)) { @@ -466,7 +468,7 @@ float8in(PG_FUNCTION_ARGS) endptr = num + 4; } } -#endif /* HAVE_BUGGY_IRIX_STRTOD */ +#endif /* HAVE_BUGGY_IRIX_STRTOD */ /* skip trailing whitespace */ while (*endptr != '\0' && isspace((unsigned char) *endptr)) @@ -706,12 +708,13 @@ float4pl(PG_FUNCTION_ARGS) float4 result; result = arg1 + arg2; + /* - * There isn't any way to check for underflow of addition/subtraction - * because numbers near the underflow value have been already been - * to the point where we can't detect the that the two values - * were originally different, e.g. on x86, '1e-45'::float4 == - * '2e-45'::float4 == 1.4013e-45. + * There isn't any way to check for underflow of addition/subtraction + * because numbers near the underflow value have been already been to the + * point where we can't detect the that the two values were originally + * different, e.g. on x86, '1e-45'::float4 == '2e-45'::float4 == + * 1.4013e-45. */ CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), true); PG_RETURN_FLOAT4(result); @@ -738,7 +741,7 @@ float4mul(PG_FUNCTION_ARGS) result = arg1 * arg2; CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), - arg1 == 0 || arg2 == 0); + arg1 == 0 || arg2 == 0); PG_RETURN_FLOAT4(result); } @@ -803,7 +806,7 @@ float8mul(PG_FUNCTION_ARGS) result = arg1 * arg2; CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), - arg1 == 0 || arg2 == 0); + arg1 == 0 || arg2 == 0); PG_RETURN_FLOAT8(result); } @@ -1338,12 +1341,12 @@ dpow(PG_FUNCTION_ARGS) /* * pow() sets errno only on some platforms, depending on whether it - * follows _IEEE_, _POSIX_, _XOPEN_, or _SVID_, so we try to avoid - * using errno. However, some platform/CPU combinations return - * errno == EDOM and result == Nan for negative arg1 and very large arg2 - * (they must be using something different from our floor() test to - * decide it's invalid). Other platforms (HPPA) return errno == ERANGE - * and a large (HUGE_VAL) but finite result to signal overflow. + * follows _IEEE_, _POSIX_, _XOPEN_, or _SVID_, so we try to avoid using + * errno. However, some platform/CPU combinations return errno == EDOM + * and result == Nan for negative arg1 and very large arg2 (they must be + * using something different from our floor() test to decide it's + * invalid). Other platforms (HPPA) return errno == ERANGE and a large + * (HUGE_VAL) but finite result to signal overflow. */ errno = 0; result = pow(arg1, arg2); @@ -1359,7 +1362,7 @@ dpow(PG_FUNCTION_ARGS) } else if (errno == ERANGE && result != 0 && !isinf(result)) result = get_float8_infinity(); - + CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), arg1 == 0); PG_RETURN_FLOAT8(result); } @@ -1453,8 +1456,8 @@ dacos(PG_FUNCTION_ARGS) float8 result; /* - * We use errno here because the trigonometric functions are cyclic - * and hard to check for underflow. + * We use errno here because the trigonometric functions are cyclic and + * hard to check for underflow. */ errno = 0; result = acos(arg1); @@ -1570,7 +1573,7 @@ dcot(PG_FUNCTION_ARGS) errmsg("input is out of range"))); result = 1.0 / result; - CHECKFLOATVAL(result, true /* cotan(pi/2) == inf */, true); + CHECKFLOATVAL(result, true /* cotan(pi/2) == inf */ , true); PG_RETURN_FLOAT8(result); } @@ -1612,7 +1615,7 @@ dtan(PG_FUNCTION_ARGS) (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("input is out of range"))); - CHECKFLOATVAL(result, true /* tan(pi/2) == Inf */, true); + CHECKFLOATVAL(result, true /* tan(pi/2) == Inf */ , true); PG_RETURN_FLOAT8(result); } @@ -1748,7 +1751,7 @@ float8_accum(PG_FUNCTION_ARGS) CHECKFLOATVAL(sumX, isinf(transvalues[1]) || isinf(newval), true); sumX2 += newval * newval; CHECKFLOATVAL(sumX2, isinf(transvalues[2]) || isinf(newval), true); - + /* * If we're invoked by nodeAgg, we can cheat and modify our first * parameter in-place to reduce palloc overhead. Otherwise we construct a @@ -1783,6 +1786,7 @@ Datum float4_accum(PG_FUNCTION_ARGS) { ArrayType *transarray = PG_GETARG_ARRAYTYPE_P(0); + /* do computations as float8 */ float8 newval = PG_GETARG_FLOAT4(1); float8 *transvalues; @@ -1800,7 +1804,7 @@ float4_accum(PG_FUNCTION_ARGS) CHECKFLOATVAL(sumX, isinf(transvalues[1]) || isinf(newval), true); sumX2 += newval * newval; CHECKFLOATVAL(sumX2, isinf(transvalues[2]) || isinf(newval), true); - + /* * If we're invoked by nodeAgg, we can cheat and modify our first * parameter in-place to reduce palloc overhead. Otherwise we construct a @@ -2016,8 +2020,8 @@ float8_regr_accum(PG_FUNCTION_ARGS) CHECKFLOATVAL(sumY2, isinf(transvalues[4]) || isinf(newvalY), true); sumXY += newvalX * newvalY; CHECKFLOATVAL(sumXY, isinf(transvalues[5]) || isinf(newvalX) || - isinf(newvalY), true); - + isinf(newvalY), true); + /* * If we're invoked by nodeAgg, we can cheat and modify our first * parameter in-place to reduce palloc overhead. Otherwise we construct a @@ -2136,7 +2140,7 @@ float8_regr_sxy(PG_FUNCTION_ARGS) numerator = N * sumXY - sumX * sumY; CHECKFLOATVAL(numerator, isinf(sumXY) || isinf(sumX) || - isinf(sumY), true); + isinf(sumY), true); /* A negative result is valid here */ @@ -2204,7 +2208,7 @@ float8_covar_pop(PG_FUNCTION_ARGS) numerator = N * sumXY - sumX * sumY; CHECKFLOATVAL(numerator, isinf(sumXY) || isinf(sumX) || - isinf(sumY), true); + isinf(sumY), true); PG_RETURN_FLOAT8(numerator / (N * N)); } @@ -2232,7 +2236,7 @@ float8_covar_samp(PG_FUNCTION_ARGS) numerator = N * sumXY - sumX * sumY; CHECKFLOATVAL(numerator, isinf(sumXY) || isinf(sumX) || - isinf(sumY), true); + isinf(sumY), true); PG_RETURN_FLOAT8(numerator / (N * (N - 1.0))); } @@ -2270,7 +2274,7 @@ float8_corr(PG_FUNCTION_ARGS) CHECKFLOATVAL(numeratorY, isinf(sumY2) || isinf(sumY), true); numeratorXY = N * sumXY - sumX * sumY; CHECKFLOATVAL(numeratorXY, isinf(sumXY) || isinf(sumX) || - isinf(sumY), true); + isinf(sumY), true); if (numeratorX <= 0 || numeratorY <= 0) PG_RETURN_NULL(); @@ -2310,7 +2314,7 @@ float8_regr_r2(PG_FUNCTION_ARGS) CHECKFLOATVAL(numeratorY, isinf(sumY2) || isinf(sumY), true); numeratorXY = N * sumXY - sumX * sumY; CHECKFLOATVAL(numeratorXY, isinf(sumXY) || isinf(sumX) || - isinf(sumY), true); + isinf(sumY), true); if (numeratorX <= 0) PG_RETURN_NULL(); /* per spec, horizontal line produces 1.0 */ @@ -2349,7 +2353,7 @@ float8_regr_slope(PG_FUNCTION_ARGS) CHECKFLOATVAL(numeratorX, isinf(sumX2) || isinf(sumX), true); numeratorXY = N * sumXY - sumX * sumY; CHECKFLOATVAL(numeratorXY, isinf(sumXY) || isinf(sumX) || - isinf(sumY), true); + isinf(sumY), true); if (numeratorX <= 0) PG_RETURN_NULL(); @@ -2384,7 +2388,7 @@ float8_regr_intercept(PG_FUNCTION_ARGS) CHECKFLOATVAL(numeratorX, isinf(sumX2) || isinf(sumX), true); numeratorXXY = sumY * sumX2 - sumX * sumXY; CHECKFLOATVAL(numeratorXXY, isinf(sumY) || isinf(sumX2) || - isinf(sumX) || isinf(sumXY), true); + isinf(sumX) || isinf(sumXY), true); if (numeratorX <= 0) PG_RETURN_NULL(); @@ -2437,7 +2441,7 @@ float48mul(PG_FUNCTION_ARGS) result = arg1 * arg2; CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), - arg1 == 0 || arg2 == 0); + arg1 == 0 || arg2 == 0); PG_RETURN_FLOAT8(result); } @@ -2500,7 +2504,7 @@ float84mul(PG_FUNCTION_ARGS) result = arg1 * arg2; CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), - arg1 == 0 || arg2 == 0); + arg1 == 0 || arg2 == 0); PG_RETURN_FLOAT8(result); } @@ -2659,11 +2663,11 @@ float84ge(PG_FUNCTION_ARGS) Datum width_bucket_float8(PG_FUNCTION_ARGS) { - float8 operand = PG_GETARG_FLOAT8(0); - float8 bound1 = PG_GETARG_FLOAT8(1); - float8 bound2 = PG_GETARG_FLOAT8(2); - int32 count = PG_GETARG_INT32(3); - int32 result; + float8 operand = PG_GETARG_FLOAT8(0); + float8 bound1 = PG_GETARG_FLOAT8(1); + float8 bound2 = PG_GETARG_FLOAT8(2); + int32 count = PG_GETARG_INT32(3); + int32 result; if (count <= 0.0) ereport(ERROR, @@ -2673,7 +2677,7 @@ width_bucket_float8(PG_FUNCTION_ARGS) if (isnan(operand) || isnan(bound1) || isnan(bound2)) ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION), - errmsg("operand, lower bound and upper bound cannot be NaN"))); + errmsg("operand, lower bound and upper bound cannot be NaN"))); /* Note that we allow "operand" to be infinite */ if (is_infinite(bound1) || is_infinite(bound2)) @@ -2718,7 +2722,7 @@ width_bucket_float8(PG_FUNCTION_ARGS) ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION), errmsg("lower bound cannot equal upper bound"))); - result = 0; /* keep the compiler quiet */ + result = 0; /* keep the compiler quiet */ } PG_RETURN_INT32(result); diff --git a/src/backend/utils/adt/format_type.c b/src/backend/utils/adt/format_type.c index f7879bafc5..9e54217f4f 100644 --- a/src/backend/utils/adt/format_type.c +++ b/src/backend/utils/adt/format_type.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/format_type.c,v 1.47 2007/04/02 03:49:39 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/format_type.c,v 1.48 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -334,7 +334,7 @@ format_type_internal(Oid type_oid, int32 typemod, static char * printTypmod(const char *typname, int32 typmod, Oid typmodout) { - char *res; + char *res; /* Shouldn't be called if typmod is -1 */ Assert(typmod >= 0); @@ -348,7 +348,7 @@ printTypmod(const char *typname, int32 typmod, Oid typmodout) else { /* Use the type-specific typmodout procedure */ - char *tmstr; + char *tmstr; tmstr = DatumGetCString(OidFunctionCall1(typmodout, Int32GetDatum(typmod))); diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index f9ccd461d8..d0e8ac2bc6 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------- * formatting.c * - * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.131 2007/08/04 01:26:53 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.132 2007/11/15 21:14:39 momjian Exp $ * * * Portions Copyright (c) 1999-2007, PostgreSQL Global Development Group @@ -703,7 +703,7 @@ static const KeyWord DCH_keywords[] = { {"HH24", 4, dch_time, DCH_HH24, TRUE}, /* H */ {"HH12", 4, dch_time, DCH_HH12, TRUE}, {"HH", 2, dch_time, DCH_HH, TRUE}, - {"IDDD", 4, dch_date, DCH_IDDD, TRUE}, /* I */ + {"IDDD", 4, dch_date, DCH_IDDD, TRUE}, /* I */ {"ID", 2, dch_date, DCH_ID, TRUE}, {"IW", 2, dch_date, DCH_IW, TRUE}, {"IYYY", 4, dch_date, DCH_IYYY, TRUE}, @@ -749,7 +749,7 @@ static const KeyWord DCH_keywords[] = { {"hh24", 4, dch_time, DCH_HH24, TRUE}, /* h */ {"hh12", 4, dch_time, DCH_HH12, TRUE}, {"hh", 2, dch_time, DCH_HH, TRUE}, - {"iddd", 4, dch_date, DCH_IDDD, TRUE}, /* i */ + {"iddd", 4, dch_date, DCH_IDDD, TRUE}, /* i */ {"id", 2, dch_date, DCH_ID, TRUE}, {"iw", 2, dch_date, DCH_IW, TRUE}, {"iyyy", 4, dch_date, DCH_IYYY, TRUE}, @@ -1605,7 +1605,7 @@ localized_str_tolower(char *buff) return buff; } -#endif /* USE_WIDE_UPPER_LOWER */ +#endif /* USE_WIDE_UPPER_LOWER */ /* ---------- * Sequential search with to upper/lower conversion @@ -2383,7 +2383,7 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval, case DCH_Day: INVALID_FOR_INTERVAL; if (S_TM(suf)) - sprintf(inout, "%*s", 0, localize_day_full(tm->tm_wday)); + sprintf(inout, "%*s", 0, localize_day_full(tm->tm_wday)); else sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, days[tm->tm_wday]); return strlen(p_inout); @@ -2393,7 +2393,7 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval, if (S_TM(suf)) { strcpy(workbuff, localize_day_full(tm->tm_wday)); - sprintf(inout, "%*s", 0, localized_str_tolower(workbuff)); + sprintf(inout, "%*s", 0, localized_str_tolower(workbuff)); } else { @@ -2414,7 +2414,7 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval, strcpy(inout, days_short[tm->tm_wday]); str_toupper(inout); } - + return strlen(p_inout); case DCH_Dy: @@ -2443,10 +2443,10 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval, case DCH_IDDD: if (is_to_char) { - sprintf(inout, "%0*d", S_FM(suf) ? 0 : 3, - (arg == DCH_DDD) ? - tm->tm_yday : - date2isoyearday(tm->tm_year, tm->tm_mon, tm->tm_mday)); + sprintf(inout, "%0*d", S_FM(suf) ? 0 : 3, + (arg == DCH_DDD) ? + tm->tm_yday : + date2isoyearday(tm->tm_year, tm->tm_mon, tm->tm_mday)); if (S_THth(suf)) str_numth(p_inout, inout, S_TH_TYPE(suf)); return strlen(p_inout); @@ -2573,9 +2573,9 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval, case DCH_CC: if (is_to_char) { - if (is_interval) /* straight calculation */ + if (is_interval) /* straight calculation */ i = tm->tm_year / 100; - else /* century 21 starts in 2001 */ + else /* century 21 starts in 2001 */ i = (tm->tm_year - 1) / 100 + 1; if (i <= 99 && i >= -99) sprintf(inout, "%0*d", S_FM(suf) ? 0 : 2, i); @@ -2645,7 +2645,8 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval, } else { - int *field; + int *field; + field = (arg == DCH_YYYY) ? &tmfc->year : &tmfc->iyear; if (S_FM(suf) || is_next_separator(node)) @@ -2680,7 +2681,8 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval, } else { - int *field; + int *field; + field = (arg == DCH_YYY) ? &tmfc->year : &tmfc->iyear; sscanf(inout, "%03d", field); @@ -2715,7 +2717,8 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval, } else { - int *field; + int *field; + field = (arg == DCH_YY) ? &tmfc->year : &tmfc->iyear; sscanf(inout, "%02d", field); @@ -2750,7 +2753,8 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval, } else { - int *field; + int *field; + field = (arg == DCH_Y) ? &tmfc->year : &tmfc->iyear; sscanf(inout, "%1d", field); @@ -3064,7 +3068,7 @@ localize_month(int index) m = _("Apr"); break; case 4: - /*------ + /*------ translator: Translate this as the abbreviation of "May". In English, it is both the full month name and the abbreviation, so this hack is needed to distinguish @@ -3481,17 +3485,17 @@ do_to_timestamp(text *date_txt, text *fmt, } /* - * Only one year value is used. If iyear (the ISO year) is defined, it takes precedence. - * Otherwise year (the Gregorian year) is used. + * Only one year value is used. If iyear (the ISO year) is defined, it + * takes precedence. Otherwise year (the Gregorian year) is used. */ year = (tmfc.iyear) ? tmfc.iyear : tmfc.year; if (year) { /* - * If CC and YY (or Y) are provided, use YY as 2 low-order digits - * for the year in the given century. Keep in mind that the 21st - * century runs from 2001-2100, not 2000-2099. + * If CC and YY (or Y) are provided, use YY as 2 low-order digits for + * the year in the given century. Keep in mind that the 21st century + * runs from 2001-2100, not 2000-2099. * * If a 4-digit year is provided, we use that and ignore CC. */ @@ -3525,15 +3529,16 @@ do_to_timestamp(text *date_txt, text *fmt, if (tmfc.iw) { - /* - * Since the user has employed the IW field, it is assumed that the value in tmfc.d - * is in ISO day-of-week form (1 = Monday), as set by the ID field. Mixing IW and D - * will yield weird results. + /* + * Since the user has employed the IW field, it is assumed that the + * value in tmfc.d is in ISO day-of-week form (1 = Monday), as set by + * the ID field. Mixing IW and D will yield weird results. * - * tmfc.iyear must have been set (e.g., with IYYY) for this to work properly (an ISO week - * without an ISO year is meaningless). + * tmfc.iyear must have been set (e.g., with IYYY) for this to work + * properly (an ISO week without an ISO year is meaningless). * - * If tmfc.d is not set, then the date is left at the beginning of the ISO week (Monday). + * If tmfc.d is not set, then the date is left at the beginning of the + * ISO week (Monday). */ if (tmfc.d) { @@ -3556,14 +3561,15 @@ do_to_timestamp(text *date_txt, text *fmt, if (tmfc.ddd && (tm->tm_mon <= 1 || tm->tm_mday <= 1)) { /* - * If the iyear field is set, the value of ddd is taken to be an ISO day-of-year. - * Otherwise, it is a Gregorian day-of-year. - * Either way, since the month and day fields have not been set by some other means, - * the value of ddd will be used to compute them. + * If the iyear field is set, the value of ddd is taken to be an ISO + * day-of-year. Otherwise, it is a Gregorian day-of-year. Either way, + * since the month and day fields have not been set by some other + * means, the value of ddd will be used to compute them. */ if (tmfc.iyear) { - int j0; /* zeroth day of the ISO year, in Julian */ + int j0; /* zeroth day of the ISO year, in Julian */ + j0 = isoweek2j(tmfc.iyear, 1) - 1; j2date(j0 + tmfc.ddd, &tm->tm_year, &tm->tm_mon, &tm->tm_mday); @@ -3580,7 +3586,7 @@ do_to_timestamp(text *date_txt, text *fmt, if (!tm->tm_year) ereport(ERROR, (errcode(ERRCODE_INVALID_DATETIME_FORMAT), - errmsg("cannot calculate day of year without year information"))); + errmsg("cannot calculate day of year without year information"))); y = ysum[isleap(tm->tm_year)]; @@ -3909,6 +3915,7 @@ NUM_prepare_locale(NUMProc *Np) */ if (lconv->decimal_point && *lconv->decimal_point) Np->decimal = lconv->decimal_point; + else Np->decimal = "."; @@ -3917,10 +3924,10 @@ NUM_prepare_locale(NUMProc *Np) /* * Number thousands separator - * - * Some locales (e.g. broken glibc pt_BR), have a comma for - * decimal, but "" for thousands_sep, so we might make the - * thousands_sep comma too. 2007-02-12 + * + * Some locales (e.g. broken glibc pt_BR), have a comma for decimal, + * but "" for thousands_sep, so we might make the thousands_sep comma + * too. 2007-02-12 */ if (lconv->thousands_sep && *lconv->thousands_sep) Np->L_thousands_sep = lconv->thousands_sep; @@ -3943,6 +3950,7 @@ NUM_prepare_locale(NUMProc *Np) Np->L_negative_sign = "-"; Np->L_positive_sign = "+"; Np->decimal = "."; + Np->L_thousands_sep = ","; Np->L_currency_symbol = " "; } @@ -4809,7 +4817,7 @@ do { \ */ #define NUM_TOCHAR_finish \ do { \ - NUM_processor(format, &Num, VARDATA(result), numstr, plen, sign, true); \ + NUM_processor(format, &Num, VARDATA(result), numstr, plen, sign, true); \ \ if (shouldFree) \ pfree(format); \ @@ -4843,7 +4851,7 @@ numeric_to_number(PG_FUNCTION_ARGS) len = VARSIZE(fmt) - VARHDRSZ; - if (len <= 0 || len >= INT_MAX/NUM_MAX_ITEM_SIZ) + if (len <= 0 || len >= INT_MAX / NUM_MAX_ITEM_SIZ) PG_RETURN_NULL(); format = NUM_cache(len, &Num, VARDATA(fmt), &shouldFree); diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c index 33a781bb30..b2e603a46a 100644 --- a/src/backend/utils/adt/geo_ops.c +++ b/src/backend/utils/adt/geo_ops.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/geo_ops.c,v 1.96 2007/03/05 23:29:14 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/geo_ops.c,v 1.97 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -5085,7 +5085,8 @@ point_inside(Point *p, int npts, Point *plist) int i = 0; double x, y; - int cross, total_cross = 0; + int cross, + total_cross = 0; if (npts <= 0) return 0; @@ -5107,7 +5108,7 @@ point_inside(Point *p, int npts, Point *plist) if ((cross = lseg_crossing(x, y, prev_x, prev_y)) == POINT_ON_POLYGON) return 2; total_cross += cross; - + prev_x = x; prev_y = y; } @@ -5139,18 +5140,18 @@ lseg_crossing(double x, double y, double prev_x, double prev_y) int y_sign; if (FPzero(y)) - { /* y == 0, on X axis */ - if (FPzero(x)) /* (x,y) is (0,0)? */ + { /* y == 0, on X axis */ + if (FPzero(x)) /* (x,y) is (0,0)? */ return POINT_ON_POLYGON; else if (FPgt(x, 0)) - { /* x > 0 */ - if (FPzero(prev_y)) /* y and prev_y are zero */ + { /* x > 0 */ + if (FPzero(prev_y)) /* y and prev_y are zero */ /* prev_x > 0? */ return FPgt(prev_x, 0) ? 0 : POINT_ON_POLYGON; return FPlt(prev_y, 0) ? 1 : -1; } else - { /* x < 0, x not on positive X axis */ + { /* x < 0, x not on positive X axis */ if (FPzero(prev_y)) /* prev_x < 0? */ return FPlt(prev_x, 0) ? 0 : POINT_ON_POLYGON; @@ -5158,7 +5159,7 @@ lseg_crossing(double x, double y, double prev_x, double prev_y) } } else - { /* y != 0 */ + { /* y != 0 */ /* compute y crossing direction from previous point */ y_sign = FPgt(y, 0) ? 1 : -1; @@ -5167,9 +5168,9 @@ lseg_crossing(double x, double y, double prev_x, double prev_y) return FPlt(prev_x, 0) ? 0 : y_sign; else if (FPgt(y_sign * prev_y, 0)) /* both above or below X axis */ - return 0; /* same sign */ + return 0; /* same sign */ else - { /* y and prev_y cross X-axis */ + { /* y and prev_y cross X-axis */ if (FPge(x, 0) && FPgt(prev_x, 0)) /* both non-negative so cross positive X-axis */ return 2 * y_sign; diff --git a/src/backend/utils/adt/like.c b/src/backend/utils/adt/like.c index 4c4ca2c193..edac82d698 100644 --- a/src/backend/utils/adt/like.c +++ b/src/backend/utils/adt/like.c @@ -11,7 +11,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/like.c,v 1.71 2007/09/22 03:58:34 adunstan Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/like.c,v 1.72 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -38,7 +38,7 @@ static int UTF8_MatchText(char *t, int tlen, char *p, int plen); static int SB_IMatchText(char *t, int tlen, char *p, int plen); -static int GenericMatchText(char *s, int slen, char* p, int plen); +static int GenericMatchText(char *s, int slen, char *p, int plen); static int Generic_Text_IC_like(text *str, text *pat); /*-------------------- @@ -116,13 +116,13 @@ wchareq(char *p1, char *p2) /* setup to compile like_match.c for UTF8 encoding, using fast NextChar */ #define NextChar(p, plen) \ - do { (p)++; (plen)--; } while ((plen) > 0 && (*(p) & 0xC0) == 0x80 ) + do { (p)++; (plen)--; } while ((plen) > 0 && (*(p) & 0xC0) == 0x80 ) #define MatchText UTF8_MatchText #include "like_match.c" static inline int -GenericMatchText(char *s, int slen, char* p, int plen) +GenericMatchText(char *s, int slen, char *p, int plen) { if (pg_database_encoding_max_length() == 1) return SB_MatchText(s, slen, p, plen); @@ -140,9 +140,10 @@ Generic_Text_IC_like(text *str, text *pat) int slen, plen; - /* For efficiency reasons, in the single byte case we don't call - * lower() on the pattern and text, but instead call to_lower on each - * character. In the multi-byte case we don't have much choice :-( + /* + * For efficiency reasons, in the single byte case we don't call lower() + * on the pattern and text, but instead call to_lower on each character. + * In the multi-byte case we don't have much choice :-( */ if (pg_database_encoding_max_length() > 1) @@ -312,7 +313,7 @@ nameiclike(PG_FUNCTION_ARGS) text *strtext; strtext = DatumGetTextP(DirectFunctionCall1(name_text, - NameGetDatum(str))); + NameGetDatum(str))); result = (Generic_Text_IC_like(strtext, pat) == LIKE_TRUE); PG_RETURN_BOOL(result); @@ -327,7 +328,7 @@ nameicnlike(PG_FUNCTION_ARGS) text *strtext; strtext = DatumGetTextP(DirectFunctionCall1(name_text, - NameGetDatum(str))); + NameGetDatum(str))); result = (Generic_Text_IC_like(strtext, pat) != LIKE_TRUE); PG_RETURN_BOOL(result); @@ -385,8 +386,7 @@ like_escape_bytea(PG_FUNCTION_ARGS) { bytea *pat = PG_GETARG_BYTEA_PP(0); bytea *esc = PG_GETARG_BYTEA_PP(1); - bytea *result = SB_do_like_escape((text *)pat, (text *)esc); + bytea *result = SB_do_like_escape((text *) pat, (text *) esc); - PG_RETURN_BYTEA_P((bytea *)result); + PG_RETURN_BYTEA_P((bytea *) result); } - diff --git a/src/backend/utils/adt/like_match.c b/src/backend/utils/adt/like_match.c index f2ee0bae0e..eadb80a750 100644 --- a/src/backend/utils/adt/like_match.c +++ b/src/backend/utils/adt/like_match.c @@ -11,7 +11,7 @@ * * Before the inclusion, we need to define following macros: * - * NextChar + * NextChar * MatchText - to name of function wanted * do_like_escape - name of function if wanted - needs CHAREQ and CopyAdvChar * MATCH_LOWER - define iff using to_lower on text chars @@ -19,7 +19,7 @@ * Copyright (c) 1996-2007, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.18 2007/09/22 03:58:34 adunstan Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.19 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -84,11 +84,11 @@ MatchText(char *t, int tlen, char *p, int plen) return LIKE_TRUE; /* - * In this loop, we advance by char when matching wildcards (and thus - * on recursive entry to this function we are properly char-synced). On - * other occasions it is safe to advance by byte, as the text and pattern - * will be in lockstep. This allows us to perform all comparisons between - * the text and pattern on a byte by byte basis, even for multi-byte + * In this loop, we advance by char when matching wildcards (and thus on + * recursive entry to this function we are properly char-synced). On other + * occasions it is safe to advance by byte, as the text and pattern will + * be in lockstep. This allows us to perform all comparisons between the + * text and pattern on a byte by byte basis, even for multi-byte * encodings. */ @@ -98,15 +98,15 @@ MatchText(char *t, int tlen, char *p, int plen) { /* Next byte must match literally, whatever it is */ NextByte(p, plen); - if ((plen <= 0) || *p != *t ) + if ((plen <= 0) || *p != *t) return LIKE_FALSE; } else if (*p == '%') { /* - * % processing is essentially a search for a match for what - * follows the %, plus a recursive match of the remainder. - * We succeed if and only if both conditions are met. + * % processing is essentially a search for a match for what + * follows the %, plus a recursive match of the remainder. We + * succeed if and only if both conditions are met. */ /* %% is the same as % according to the SQL standard */ @@ -141,9 +141,9 @@ MatchText(char *t, int tlen, char *p, int plen) while (tlen > 0) { int matched = MatchText(t, tlen, p, plen); - + if (matched != LIKE_FALSE) - return matched; /* TRUE or ABORT */ + return matched; /* TRUE or ABORT */ NextChar(t, tlen); } @@ -151,7 +151,7 @@ MatchText(char *t, int tlen, char *p, int plen) else { - char firstpat = TCHAR(*p) ; + char firstpat = TCHAR(*p); if (*p == '\\') { @@ -169,9 +169,9 @@ MatchText(char *t, int tlen, char *p, int plen) if (TCHAR(*t) == firstpat) { int matched = MatchText(t, tlen, p, plen); - + if (matched != LIKE_FALSE) - return matched; /* TRUE or ABORT */ + return matched; /* TRUE or ABORT */ } NextChar(t, tlen); @@ -199,17 +199,16 @@ MatchText(char *t, int tlen, char *p, int plen) */ return LIKE_FALSE; } + /* * It is safe to use NextByte instead of NextChar here, even for - * multi-byte character sets, because we are not following - * immediately after a wildcard character. - * If we are in the middle of a multibyte character, we must - * already have matched at least one byte of the character from - * both text and pattern; so we cannot get out-of-sync - * on character boundaries. And we know that no backend-legal - * encoding allows ASCII characters such as '%' to appear as - * non-first bytes of characters, so we won't mistakenly detect - * a new wildcard. + * multi-byte character sets, because we are not following immediately + * after a wildcard character. If we are in the middle of a multibyte + * character, we must already have matched at least one byte of the + * character from both text and pattern; so we cannot get out-of-sync + * on character boundaries. And we know that no backend-legal + * encoding allows ASCII characters such as '%' to appear as non-first + * bytes of characters, so we won't mistakenly detect a new wildcard. */ NextByte(t, tlen); NextByte(p, plen); @@ -332,7 +331,7 @@ do_like_escape(text *pat, text *esc) return result; } -#endif /* do_like_escape */ +#endif /* do_like_escape */ #ifdef CHAREQ #undef CHAREQ @@ -350,4 +349,5 @@ do_like_escape(text *pat, text *esc) #ifdef MATCH_LOWER #undef MATCH_LOWER + #endif diff --git a/src/backend/utils/adt/lockfuncs.c b/src/backend/utils/adt/lockfuncs.c index e78d74f9ef..78b8c1bf8c 100644 --- a/src/backend/utils/adt/lockfuncs.c +++ b/src/backend/utils/adt/lockfuncs.c @@ -6,7 +6,7 @@ * Copyright (c) 2002-2007, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/lockfuncs.c,v 1.29 2007/09/05 18:10:48 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/lockfuncs.c,v 1.30 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -53,7 +53,7 @@ VXIDGetDatum(BackendId bid, LocalTransactionId lxid) * The representation is "<bid>/<lxid>", decimal and unsigned decimal * respectively. Note that elog.c also knows how to format a vxid. */ - char vxidstr[32]; + char vxidstr[32]; snprintf(vxidstr, sizeof(vxidstr), "%d/%u", bid, lxid); diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c index 10c1285bd6..7eb6ffe306 100644 --- a/src/backend/utils/adt/network.c +++ b/src/backend/utils/adt/network.c @@ -1,7 +1,7 @@ /* * PostgreSQL type definitions for the INET and CIDR types. * - * $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.71 2007/06/05 21:31:06 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.72 2007/11/15 21:14:39 momjian Exp $ * * Jon Postel RIP 16 Oct 1998 */ @@ -29,7 +29,7 @@ static int ip_addrsize(inet *inetptr); static inet *internal_inetpl(inet *ip, int64 addend); /* - * Access macros. We use VARDATA_ANY so that we can process short-header + * Access macros. We use VARDATA_ANY so that we can process short-header * varlena values without detoasting them. This requires a trick: * VARDATA_ANY assumes the varlena header is already filled in, which is * not the case when constructing a new value (until SET_INET_VARSIZE is @@ -1466,9 +1466,9 @@ inetmi(PG_FUNCTION_ARGS) * XXX This should go away someday! * * This is a kluge needed because we don't yet support zones in stored inet - * values. Since the result of getnameinfo() might include a zone spec, + * values. Since the result of getnameinfo() might include a zone spec, * call this to remove it anywhere we want to feed getnameinfo's output to - * network_in. Beats failing entirely. + * network_in. Beats failing entirely. * * An alternative approach would be to let network_in ignore %-parts for * itself, but that would mean we'd silently drop zone specs in user input, @@ -1480,7 +1480,7 @@ clean_ipv6_addr(int addr_family, char *addr) #ifdef HAVE_IPV6 if (addr_family == AF_INET6) { - char *pct = strchr(addr, '%'); + char *pct = strchr(addr, '%'); if (pct) *pct = '\0'; diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c index e40e0470fb..5a22269d09 100644 --- a/src/backend/utils/adt/numeric.c +++ b/src/backend/utils/adt/numeric.c @@ -14,7 +14,7 @@ * Copyright (c) 1998-2007, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.106 2007/07/09 16:13:57 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.107 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -472,7 +472,7 @@ numeric_send(PG_FUNCTION_ARGS) * scale of the attribute have to be applied on the value. */ Datum -numeric(PG_FUNCTION_ARGS) +numeric (PG_FUNCTION_ARGS) { Numeric num = PG_GETARG_NUMERIC(0); int32 typmod = PG_GETARG_INT32(1); @@ -542,8 +542,8 @@ numeric(PG_FUNCTION_ARGS) Datum numerictypmodin(PG_FUNCTION_ARGS) { - ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); - int32 *tl; + ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); + int32 *tl; int n; int32 typmod; @@ -559,8 +559,8 @@ numerictypmodin(PG_FUNCTION_ARGS) if (tl[1] < 0 || tl[1] > tl[0]) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("NUMERIC scale %d must be between 0 and precision %d", - tl[1], tl[0]))); + errmsg("NUMERIC scale %d must be between 0 and precision %d", + tl[1], tl[0]))); typmod = ((tl[0] << 16) | tl[1]) + VARHDRSZ; } else if (n == 1) @@ -577,7 +577,7 @@ numerictypmodin(PG_FUNCTION_ARGS) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("invalid NUMERIC type modifier"))); + errmsg("invalid NUMERIC type modifier"))); typmod = 0; /* keep compiler quiet */ } @@ -587,8 +587,8 @@ numerictypmodin(PG_FUNCTION_ARGS) Datum numerictypmodout(PG_FUNCTION_ARGS) { - int32 typmod = PG_GETARG_INT32(0); - char *res = (char *) palloc(64); + int32 typmod = PG_GETARG_INT32(0); + char *res = (char *) palloc(64); if (typmod >= 0) snprintf(res, 64, "(%d,%d)", @@ -909,7 +909,7 @@ width_bucket_numeric(PG_FUNCTION_ARGS) NUMERIC_IS_NAN(bound2)) ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION), - errmsg("operand, lower bound and upper bound cannot be NaN"))); + errmsg("operand, lower bound and upper bound cannot be NaN"))); init_var(&result_var); init_var(&count_var); @@ -1154,29 +1154,28 @@ cmp_numerics(Numeric num1, Numeric num2) Datum hash_numeric(PG_FUNCTION_ARGS) { - Numeric key = PG_GETARG_NUMERIC(0); - Datum digit_hash; - Datum result; - int weight; - int start_offset; - int end_offset; - int i; - int hash_len; + Numeric key = PG_GETARG_NUMERIC(0); + Datum digit_hash; + Datum result; + int weight; + int start_offset; + int end_offset; + int i; + int hash_len; /* If it's NaN, don't try to hash the rest of the fields */ if (NUMERIC_IS_NAN(key)) PG_RETURN_UINT32(0); - weight = key->n_weight; + weight = key->n_weight; start_offset = 0; - end_offset = 0; + end_offset = 0; /* - * Omit any leading or trailing zeros from the input to the - * hash. The numeric implementation *should* guarantee that - * leading and trailing zeros are suppressed, but we're - * paranoid. Note that we measure the starting and ending offsets - * in units of NumericDigits, not bytes. + * Omit any leading or trailing zeros from the input to the hash. The + * numeric implementation *should* guarantee that leading and trailing + * zeros are suppressed, but we're paranoid. Note that we measure the + * starting and ending offsets in units of NumericDigits, not bytes. */ for (i = 0; i < NUMERIC_NDIGITS(key); i++) { @@ -1184,17 +1183,17 @@ hash_numeric(PG_FUNCTION_ARGS) break; start_offset++; + /* - * The weight is effectively the # of digits before the - * decimal point, so decrement it for each leading zero we - * skip. + * The weight is effectively the # of digits before the decimal point, + * so decrement it for each leading zero we skip. */ weight--; } /* - * If there are no non-zero digits, then the value of the number - * is zero, regardless of any other fields. + * If there are no non-zero digits, then the value of the number is zero, + * regardless of any other fields. */ if (NUMERIC_NDIGITS(key) == start_offset) PG_RETURN_UINT32(-1); @@ -1211,14 +1210,14 @@ hash_numeric(PG_FUNCTION_ARGS) Assert(start_offset + end_offset < NUMERIC_NDIGITS(key)); /* - * Note that we don't hash on the Numeric's scale, since two - * numerics can compare equal but have different scales. We also - * don't hash on the sign, although we could: since a sign - * difference implies inequality, this shouldn't affect correctness. + * Note that we don't hash on the Numeric's scale, since two numerics can + * compare equal but have different scales. We also don't hash on the + * sign, although we could: since a sign difference implies inequality, + * this shouldn't affect correctness. */ hash_len = NUMERIC_NDIGITS(key) - start_offset - end_offset; digit_hash = hash_any((unsigned char *) (NUMERIC_DIGITS(key) + start_offset), - hash_len * sizeof(NumericDigit)); + hash_len * sizeof(NumericDigit)); /* Mix in the weight, via XOR */ result = digit_hash ^ weight; @@ -2436,9 +2435,9 @@ numeric_stddev_internal(ArrayType *transarray, else { if (sample) - mul_var(&vN, &vNminus1, &vNminus1, 0); /* N * (N - 1) */ + mul_var(&vN, &vNminus1, &vNminus1, 0); /* N * (N - 1) */ else - mul_var(&vN, &vN, &vNminus1, 0); /* N * N */ + mul_var(&vN, &vN, &vNminus1, 0); /* N * N */ rscale = select_div_scale(&vsumX2, &vNminus1); div_var(&vsumX2, &vNminus1, &vsumX, rscale, true); /* variance */ if (!variance) diff --git a/src/backend/utils/adt/oracle_compat.c b/src/backend/utils/adt/oracle_compat.c index 56fe7a607f..4bf1e54466 100644 --- a/src/backend/utils/adt/oracle_compat.c +++ b/src/backend/utils/adt/oracle_compat.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/oracle_compat.c,v 1.73 2007/09/22 05:35:42 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/oracle_compat.c,v 1.74 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -46,8 +46,8 @@ */ #if defined(HAVE_WCSTOMBS) && defined(HAVE_TOWLOWER) #define USE_WIDE_UPPER_LOWER -char *wstring_lower (char *str); -char *wstring_upper(char *str); +char *wstring_lower(char *str); +char *wstring_upper(char *str); #endif static text *dotrim(const char *string, int stringlen, @@ -229,7 +229,7 @@ win32_utf8_wcstotext(const wchar_t *str) errmsg("UTF-16 to UTF-8 translation failed: %lu", GetLastError()))); - SET_VARSIZE(result, nbytes + VARHDRSZ - 1); /* -1 to ignore null */ + SET_VARSIZE(result, nbytes + VARHDRSZ - 1); /* -1 to ignore null */ return result; } @@ -261,21 +261,21 @@ win32_wcstotext(const wchar_t *str, int ncodes) #endif /* WIN32 */ #ifdef USE_WIDE_UPPER_LOWER -/* - * string_upper and string_lower are used for correct multibyte upper/lower +/* + * string_upper and string_lower are used for correct multibyte upper/lower * transformations localized strings. Returns pointers to transformated * string. */ char * wstring_upper(char *str) { - wchar_t *workspace; - text *in_text; - text *out_text; - char *result; - int nbytes = strlen(str); - int i; - + wchar_t *workspace; + text *in_text; + text *out_text; + char *result; + int nbytes = strlen(str); + int i; + in_text = palloc(nbytes + VARHDRSZ); memcpy(VARDATA(in_text), str, nbytes); SET_VARSIZE(in_text, nbytes + VARHDRSZ); @@ -286,7 +286,7 @@ wstring_upper(char *str) workspace[i] = towupper(workspace[i]); out_text = wcstotext(workspace, i); - + nbytes = VARSIZE(out_text) - VARHDRSZ; result = palloc(nbytes + 1); memcpy(result, VARDATA(out_text), nbytes); @@ -296,20 +296,20 @@ wstring_upper(char *str) pfree(workspace); pfree(in_text); pfree(out_text); - + return result; } char * wstring_lower(char *str) { - wchar_t *workspace; - text *in_text; - text *out_text; - char *result; - int nbytes = strlen(str); - int i; - + wchar_t *workspace; + text *in_text; + text *out_text; + char *result; + int nbytes = strlen(str); + int i; + in_text = palloc(nbytes + VARHDRSZ); memcpy(VARDATA(in_text), str, nbytes); SET_VARSIZE(in_text, nbytes + VARHDRSZ); @@ -320,8 +320,8 @@ wstring_lower(char *str) workspace[i] = towlower(workspace[i]); out_text = wcstotext(workspace, i); - - nbytes = VARSIZE(out_text) - VARHDRSZ; + + nbytes = VARSIZE(out_text) - VARHDRSZ; result = palloc(nbytes + 1); memcpy(result, VARDATA(out_text), nbytes); @@ -330,10 +330,10 @@ wstring_lower(char *str) pfree(workspace); pfree(in_text); pfree(out_text); - + return result; } -#endif /* USE_WIDE_UPPER_LOWER */ +#endif /* USE_WIDE_UPPER_LOWER */ /******************************************************************** * @@ -979,13 +979,13 @@ byteatrim(PG_FUNCTION_ARGS) *ptr2, *ptr2start, *end2; - int m, - stringlen, + int m, + stringlen, setlen; stringlen = VARSIZE_ANY_EXHDR(string); setlen = VARSIZE_ANY_EXHDR(set); - + if (stringlen <= 0 || setlen <= 0) PG_RETURN_BYTEA_P(string); @@ -1178,8 +1178,8 @@ translate(PG_FUNCTION_ARGS) to_ptr = VARDATA_ANY(to); /* - * The worst-case expansion is to substitute a max-length character for - * a single-byte character at each position of the string. + * The worst-case expansion is to substitute a max-length character for a + * single-byte character at each position of the string. */ worst_len = pg_database_encoding_max_length() * m; @@ -1242,9 +1242,9 @@ translate(PG_FUNCTION_ARGS) SET_VARSIZE(result, retlen + VARHDRSZ); /* - * The function result is probably much bigger than needed, if we're - * using a multibyte encoding, but it's not worth reallocating it; - * the result probably won't live long anyway. + * The function result is probably much bigger than needed, if we're using + * a multibyte encoding, but it's not worth reallocating it; the result + * probably won't live long anyway. */ PG_RETURN_TEXT_P(result); @@ -1262,13 +1262,13 @@ translate(PG_FUNCTION_ARGS) * * Returns the decimal representation of the first character from * string. - * If the string is empty we return 0. - * If the database encoding is UTF8, we return the Unicode codepoint. - * If the database encoding is any other multi-byte encoding, we - * return the value of the first byte if it is an ASCII character - * (range 1 .. 127), or raise an error. - * For all other encodings we return the value of the first byte, - * (range 1..255). + * If the string is empty we return 0. + * If the database encoding is UTF8, we return the Unicode codepoint. + * If the database encoding is any other multi-byte encoding, we + * return the value of the first byte if it is an ASCII character + * (range 1 .. 127), or raise an error. + * For all other encodings we return the value of the first byte, + * (range 1..255). * ********************************************************************/ @@ -1276,7 +1276,7 @@ Datum ascii(PG_FUNCTION_ARGS) { text *string = PG_GETARG_TEXT_PP(0); - int encoding = GetDatabaseEncoding(); + int encoding = GetDatabaseEncoding(); unsigned char *data; if (VARSIZE_ANY_EXHDR(string) <= 0) @@ -1288,7 +1288,9 @@ ascii(PG_FUNCTION_ARGS) { /* return the code point for Unicode */ - int result = 0, tbytes = 0, i; + int result = 0, + tbytes = 0, + i; if (*data >= 0xF0) { @@ -1302,16 +1304,16 @@ ascii(PG_FUNCTION_ARGS) } else { - Assert (*data > 0xC0); + Assert(*data > 0xC0); result = *data & 0x1f; tbytes = 1; } - Assert (tbytes > 0); + Assert(tbytes > 0); for (i = 1; i <= tbytes; i++) { - Assert ((data[i] & 0xC0) == 0x80); + Assert((data[i] & 0xC0) == 0x80); result = (result << 6) + (data[i] & 0x3f); } @@ -1352,23 +1354,23 @@ ascii(PG_FUNCTION_ARGS) ********************************************************************/ Datum -chr(PG_FUNCTION_ARGS) +chr (PG_FUNCTION_ARGS) { uint32 cvalue = PG_GETARG_UINT32(0); text *result; - int encoding = GetDatabaseEncoding(); + int encoding = GetDatabaseEncoding(); if (encoding == PG_UTF8 && cvalue > 127) { /* for Unicode we treat the argument as a code point */ - int bytes ; - char *wch; + int bytes; + char *wch; /* We only allow valid Unicode code points */ if (cvalue > 0x001fffff) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("requested character too large for encoding: %d", + errmsg("requested character too large for encoding: %d", cvalue))); if (cvalue > 0xffff) @@ -1400,15 +1402,16 @@ chr(PG_FUNCTION_ARGS) wch[2] = 0x80 | ((cvalue >> 6) & 0x3F); wch[3] = 0x80 | (cvalue & 0x3F); } - + } else { - bool is_mb; + bool is_mb; - /* Error out on arguments that make no sense or that we - * can't validly represent in the encoding. + /* + * Error out on arguments that make no sense or that we can't validly + * represent in the encoding. */ if (cvalue == 0) @@ -1418,12 +1421,12 @@ chr(PG_FUNCTION_ARGS) is_mb = pg_encoding_max_length(encoding) > 1; - if ((is_mb && (cvalue > 255)) || (! is_mb && (cvalue > 127))) + if ((is_mb && (cvalue > 255)) || (!is_mb && (cvalue > 127))) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("requested character too large for encoding: %d", cvalue))); - + result = (text *) palloc(VARHDRSZ + 1); SET_VARSIZE(result, VARHDRSZ + 1); diff --git a/src/backend/utils/adt/pg_lzcompress.c b/src/backend/utils/adt/pg_lzcompress.c index f843232ba6..10f7b4389e 100644 --- a/src/backend/utils/adt/pg_lzcompress.c +++ b/src/backend/utils/adt/pg_lzcompress.c @@ -166,7 +166,7 @@ * * Copyright (c) 1999-2007, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/backend/utils/adt/pg_lzcompress.c,v 1.27 2007/08/04 21:53:00 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/pg_lzcompress.c,v 1.28 2007/11/15 21:14:39 momjian Exp $ * ---------- */ #include "postgres.h" @@ -222,7 +222,7 @@ static const PGLZ_Strategy strategy_default_data = { 10 /* Lower good match size by 10% at every * lookup loop iteration */ }; -const PGLZ_Strategy * const PGLZ_strategy_default = &strategy_default_data; +const PGLZ_Strategy *const PGLZ_strategy_default = &strategy_default_data; static const PGLZ_Strategy strategy_always_data = { @@ -233,7 +233,7 @@ static const PGLZ_Strategy strategy_always_data = { * is found */ 6 /* Look harder for a good match */ }; -const PGLZ_Strategy * const PGLZ_strategy_always = &strategy_always_data; +const PGLZ_Strategy *const PGLZ_strategy_always = &strategy_always_data; /* ---------- @@ -605,8 +605,8 @@ pglz_compress(const char *source, int32 slen, PGLZ_Header *dest, } /* - * Write out the last control byte and check that we haven't overrun - * the output size allowed by the strategy. + * Write out the last control byte and check that we haven't overrun the + * output size allowed by the strategy. */ *ctrlp = ctrlb; result_size = bp - bstart; @@ -697,8 +697,8 @@ pglz_decompress(const PGLZ_Header *source, char *dest) /* * Check we decompressed the right amount, else die. This is a FATAL - * condition if we tromped on more memory than expected (we assume we - * have not tromped on shared memory, though, so need not PANIC). + * condition if we tromped on more memory than expected (we assume we have + * not tromped on shared memory, though, so need not PANIC). */ destsize = (char *) bp - dest; if (destsize != source->rawsize) diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index f162381745..3e4faea474 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.46 2007/09/25 20:03:38 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.47 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -190,32 +190,32 @@ pg_stat_get_tuples_hot_updated(PG_FUNCTION_ARGS) Datum pg_stat_get_live_tuples(PG_FUNCTION_ARGS) -{ - Oid relid = PG_GETARG_OID(0); - int64 result; - PgStat_StatTabEntry *tabentry; - +{ + Oid relid = PG_GETARG_OID(0); + int64 result; + PgStat_StatTabEntry *tabentry; + if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) result = 0; else result = (int64) (tabentry->n_live_tuples); - + PG_RETURN_INT64(result); } - + Datum pg_stat_get_dead_tuples(PG_FUNCTION_ARGS) { - Oid relid = PG_GETARG_OID(0); - int64 result; - PgStat_StatTabEntry *tabentry; + Oid relid = PG_GETARG_OID(0); + int64 result; + PgStat_StatTabEntry *tabentry; if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) result = 0; else result = (int64) (tabentry->n_dead_tuples); - + PG_RETURN_INT64(result); } diff --git a/src/backend/utils/adt/regexp.c b/src/backend/utils/adt/regexp.c index 744b55069f..3b84a831bd 100644 --- a/src/backend/utils/adt/regexp.c +++ b/src/backend/utils/adt/regexp.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.75 2007/09/22 04:37:53 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.76 2007/11/15 21:14:39 momjian Exp $ * * Alistair Crooks added the code for the regex caching * agc - cached the regular expressions used - there's a good chance @@ -48,7 +48,7 @@ typedef struct pg_re_flags { int cflags; /* compile flags for Spencer's regex code */ bool glob; /* do it globally (for each occurrence) */ -} pg_re_flags; +} pg_re_flags; /* cross-call state for regexp_matches(), also regexp_split() */ typedef struct regexp_matches_ctx @@ -63,7 +63,7 @@ typedef struct regexp_matches_ctx /* workspace for build_regexp_matches_result() */ Datum *elems; /* has npatterns elements */ bool *nulls; /* has npatterns elements */ -} regexp_matches_ctx; +} regexp_matches_ctx; /* * We cache precompiled regular expressions using a "self organizing list" @@ -109,13 +109,13 @@ static cached_re_str re_array[MAX_CACHED_RES]; /* cached re's */ /* Local functions */ static regexp_matches_ctx *setup_regexp_matches(text *orig_str, text *pattern, - text *flags, - bool force_glob, - bool use_subpatterns, - bool ignore_degenerate); -static void cleanup_regexp_matches(regexp_matches_ctx *matchctx); -static ArrayType *build_regexp_matches_result(regexp_matches_ctx *matchctx); -static Datum build_regexp_split_result(regexp_matches_ctx *splitctx); + text *flags, + bool force_glob, + bool use_subpatterns, + bool ignore_degenerate); +static void cleanup_regexp_matches(regexp_matches_ctx * matchctx); +static ArrayType *build_regexp_matches_result(regexp_matches_ctx * matchctx); +static Datum build_regexp_split_result(regexp_matches_ctx * splitctx); /* @@ -196,9 +196,9 @@ RE_compile_and_cache(text *text_re, int cflags) /* * We use malloc/free for the cre_pat field because the storage has to - * persist across transactions, and because we want to get control back - * on out-of-memory. The Max() is because some malloc implementations - * return NULL for malloc(0). + * persist across transactions, and because we want to get control back on + * out-of-memory. The Max() is because some malloc implementations return + * NULL for malloc(0). */ re_temp.cre_pat = malloc(Max(text_re_len, 1)); if (re_temp.cre_pat == NULL) @@ -286,7 +286,7 @@ RE_wchar_execute(regex_t *re, pg_wchar *data, int data_len, * dat_len --- the length of the data string * nmatch, pmatch --- optional return area for match details * - * Data is given in the database encoding. We internally + * Data is given in the database encoding. We internally * convert to array of pg_wchar which is what Spencer's regex package wants. */ static bool @@ -345,7 +345,7 @@ RE_compile_and_execute(text *text_re, char *dat, int dat_len, * don't want some have to reject them after the fact. */ static void -parse_re_flags(pg_re_flags *flags, text *opts) +parse_re_flags(pg_re_flags * flags, text *opts) { /* regex_flavor is always folded into the compile flags */ flags->cflags = regex_flavor; @@ -353,9 +353,9 @@ parse_re_flags(pg_re_flags *flags, text *opts) if (opts) { - char *opt_p = VARDATA_ANY(opts); - int opt_len = VARSIZE_ANY_EXHDR(opts); - int i; + char *opt_p = VARDATA_ANY(opts); + int opt_len = VARSIZE_ANY_EXHDR(opts); + int i; for (i = 0; i < opt_len; i++) { @@ -364,42 +364,42 @@ parse_re_flags(pg_re_flags *flags, text *opts) case 'g': flags->glob = true; break; - case 'b': /* BREs (but why???) */ + case 'b': /* BREs (but why???) */ flags->cflags &= ~(REG_ADVANCED | REG_EXTENDED | REG_QUOTE); break; - case 'c': /* case sensitive */ + case 'c': /* case sensitive */ flags->cflags &= ~REG_ICASE; break; - case 'e': /* plain EREs */ + case 'e': /* plain EREs */ flags->cflags |= REG_EXTENDED; flags->cflags &= ~(REG_ADVANCED | REG_QUOTE); break; - case 'i': /* case insensitive */ + case 'i': /* case insensitive */ flags->cflags |= REG_ICASE; break; - case 'm': /* Perloid synonym for n */ - case 'n': /* \n affects ^ $ . [^ */ + case 'm': /* Perloid synonym for n */ + case 'n': /* \n affects ^ $ . [^ */ flags->cflags |= REG_NEWLINE; break; - case 'p': /* ~Perl, \n affects . [^ */ + case 'p': /* ~Perl, \n affects . [^ */ flags->cflags |= REG_NLSTOP; flags->cflags &= ~REG_NLANCH; break; - case 'q': /* literal string */ + case 'q': /* literal string */ flags->cflags |= REG_QUOTE; flags->cflags &= ~(REG_ADVANCED | REG_EXTENDED); break; - case 's': /* single line, \n ordinary */ + case 's': /* single line, \n ordinary */ flags->cflags &= ~REG_NEWLINE; break; - case 't': /* tight syntax */ + case 't': /* tight syntax */ flags->cflags &= ~REG_EXPANDED; break; - case 'w': /* weird, \n affects ^ $ only */ + case 'w': /* weird, \n affects ^ $ only */ flags->cflags &= ~REG_NLSTOP; flags->cflags |= REG_NLANCH; break; - case 'x': /* expanded syntax */ + case 'x': /* expanded syntax */ flags->cflags |= REG_EXPANDED; break; default: @@ -785,14 +785,14 @@ similar_escape(PG_FUNCTION_ARGS) Datum regexp_matches(PG_FUNCTION_ARGS) { - FuncCallContext *funcctx; - regexp_matches_ctx *matchctx; + FuncCallContext *funcctx; + regexp_matches_ctx *matchctx; if (SRF_IS_FIRSTCALL()) { - text *pattern = PG_GETARG_TEXT_PP(1); - text *flags = PG_GETARG_TEXT_PP_IF_EXISTS(2); - MemoryContext oldcontext; + text *pattern = PG_GETARG_TEXT_PP(1); + text *flags = PG_GETARG_TEXT_PP_IF_EXISTS(2); + MemoryContext oldcontext; funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); @@ -814,7 +814,7 @@ regexp_matches(PG_FUNCTION_ARGS) if (matchctx->next_match < matchctx->nmatches) { - ArrayType *result_ary; + ArrayType *result_ary; result_ary = build_regexp_matches_result(matchctx); matchctx->next_match++; @@ -855,8 +855,8 @@ setup_regexp_matches(text *orig_str, text *pattern, text *flags, int orig_len; pg_wchar *wide_str; int wide_len; - pg_re_flags re_flags; - regex_t *cpattern; + pg_re_flags re_flags; + regex_t *cpattern; regmatch_t *pmatch; int pmatch_len; int array_len; @@ -880,7 +880,7 @@ setup_regexp_matches(text *orig_str, text *pattern, text *flags, if (re_flags.glob) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("regexp_split does not support the global option"))); + errmsg("regexp_split does not support the global option"))); /* but we find all the matches anyway */ re_flags.glob = true; } @@ -917,8 +917,8 @@ setup_regexp_matches(text *orig_str, text *pattern, text *flags, { /* * If requested, ignore degenerate matches, which are zero-length - * matches occurring at the start or end of a string or just after - * a previous match. + * matches occurring at the start or end of a string or just after a + * previous match. */ if (!ignore_degenerate || (pmatch[0].rm_so < wide_len && @@ -929,13 +929,13 @@ setup_regexp_matches(text *orig_str, text *pattern, text *flags, { array_len *= 2; matchctx->match_locs = (int *) repalloc(matchctx->match_locs, - sizeof(int) * array_len); + sizeof(int) * array_len); } /* save this match's locations */ if (use_subpatterns) { - int i; + int i; for (i = 1; i <= matchctx->npatterns; i++) { @@ -957,10 +957,10 @@ setup_regexp_matches(text *orig_str, text *pattern, text *flags, break; /* - * Advance search position. Normally we start just after the end - * of the previous match, but always advance at least one character - * (the special case can occur if the pattern matches zero characters - * just after the prior match or at the end of the string). + * Advance search position. Normally we start just after the end of + * the previous match, but always advance at least one character (the + * special case can occur if the pattern matches zero characters just + * after the prior match or at the end of the string). */ if (start_search < pmatch[0].rm_eo) start_search = pmatch[0].rm_eo; @@ -981,7 +981,7 @@ setup_regexp_matches(text *orig_str, text *pattern, text *flags, * cleanup_regexp_matches - release memory of a regexp_matches_ctx */ static void -cleanup_regexp_matches(regexp_matches_ctx *matchctx) +cleanup_regexp_matches(regexp_matches_ctx * matchctx) { pfree(matchctx->orig_str); pfree(matchctx->match_locs); @@ -996,12 +996,12 @@ cleanup_regexp_matches(regexp_matches_ctx *matchctx) * build_regexp_matches_result - build output array for current match */ static ArrayType * -build_regexp_matches_result(regexp_matches_ctx *matchctx) +build_regexp_matches_result(regexp_matches_ctx * matchctx) { Datum *elems = matchctx->elems; bool *nulls = matchctx->nulls; - int dims[1]; - int lbs[1]; + int dims[1]; + int lbs[1]; int loc; int i; @@ -1009,8 +1009,8 @@ build_regexp_matches_result(regexp_matches_ctx *matchctx) loc = matchctx->next_match * matchctx->npatterns * 2; for (i = 0; i < matchctx->npatterns; i++) { - int so = matchctx->match_locs[loc++]; - int eo = matchctx->match_locs[loc++]; + int so = matchctx->match_locs[loc++]; + int eo = matchctx->match_locs[loc++]; if (so < 0 || eo < 0) { @@ -1020,7 +1020,7 @@ build_regexp_matches_result(regexp_matches_ctx *matchctx) else { elems[i] = DirectFunctionCall3(text_substr, - PointerGetDatum(matchctx->orig_str), + PointerGetDatum(matchctx->orig_str), Int32GetDatum(so + 1), Int32GetDatum(eo - so)); nulls[i] = false; @@ -1043,14 +1043,14 @@ build_regexp_matches_result(regexp_matches_ctx *matchctx) Datum regexp_split_to_table(PG_FUNCTION_ARGS) { - FuncCallContext *funcctx; + FuncCallContext *funcctx; regexp_matches_ctx *splitctx; if (SRF_IS_FIRSTCALL()) { - text *pattern = PG_GETARG_TEXT_PP(1); - text *flags = PG_GETARG_TEXT_PP_IF_EXISTS(2); - MemoryContext oldcontext; + text *pattern = PG_GETARG_TEXT_PP(1); + text *flags = PG_GETARG_TEXT_PP_IF_EXISTS(2); + MemoryContext oldcontext; funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); @@ -1068,7 +1068,7 @@ regexp_split_to_table(PG_FUNCTION_ARGS) if (splitctx->next_match <= splitctx->nmatches) { - Datum result = build_regexp_split_result(splitctx); + Datum result = build_regexp_split_result(splitctx); splitctx->next_match++; SRF_RETURN_NEXT(funcctx, result); @@ -1081,7 +1081,8 @@ regexp_split_to_table(PG_FUNCTION_ARGS) } /* This is separate to keep the opr_sanity regression test from complaining */ -Datum regexp_split_to_table_no_flags(PG_FUNCTION_ARGS) +Datum +regexp_split_to_table_no_flags(PG_FUNCTION_ARGS) { return regexp_split_to_table(fcinfo); } @@ -1091,10 +1092,11 @@ Datum regexp_split_to_table_no_flags(PG_FUNCTION_ARGS) * Split the string at matches of the pattern, returning the * split-out substrings as an array. */ -Datum regexp_split_to_array(PG_FUNCTION_ARGS) +Datum +regexp_split_to_array(PG_FUNCTION_ARGS) { - ArrayBuildState *astate = NULL; - regexp_matches_ctx *splitctx; + ArrayBuildState *astate = NULL; + regexp_matches_ctx *splitctx; splitctx = setup_regexp_matches(PG_GETARG_TEXT_PP(0), PG_GETARG_TEXT_PP(1), @@ -1112,16 +1114,17 @@ Datum regexp_split_to_array(PG_FUNCTION_ARGS) } /* - * We don't call cleanup_regexp_matches here; it would try to pfree - * the input string, which we didn't copy. The space is not in a - * long-lived memory context anyway. + * We don't call cleanup_regexp_matches here; it would try to pfree the + * input string, which we didn't copy. The space is not in a long-lived + * memory context anyway. */ PG_RETURN_ARRAYTYPE_P(makeArrayResult(astate, CurrentMemoryContext)); } /* This is separate to keep the opr_sanity regression test from complaining */ -Datum regexp_split_to_array_no_flags(PG_FUNCTION_ARGS) +Datum +regexp_split_to_array_no_flags(PG_FUNCTION_ARGS) { return regexp_split_to_array(fcinfo); } @@ -1133,10 +1136,10 @@ Datum regexp_split_to_array_no_flags(PG_FUNCTION_ARGS) * or the string after the last match when next_match == nmatches. */ static Datum -build_regexp_split_result(regexp_matches_ctx *splitctx) +build_regexp_split_result(regexp_matches_ctx * splitctx) { - int startpos; - int endpos; + int startpos; + int endpos; if (splitctx->next_match > 0) startpos = splitctx->match_locs[splitctx->next_match * 2 - 1]; diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c index e49f323daa..1d12820976 100644 --- a/src/backend/utils/adt/regproc.c +++ b/src/backend/utils/adt/regproc.c @@ -13,7 +13,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/regproc.c,v 1.103 2007/08/21 01:11:18 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/regproc.c,v 1.104 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -1207,7 +1207,7 @@ regdictionaryin(PG_FUNCTION_ARGS) strspn(dict_name_or_oid, "0123456789") == strlen(dict_name_or_oid)) { result = DatumGetObjectId(DirectFunctionCall1(oidin, - CStringGetDatum(dict_name_or_oid))); + CStringGetDatum(dict_name_or_oid))); PG_RETURN_OID(result); } @@ -1249,8 +1249,8 @@ regdictionaryout(PG_FUNCTION_ARGS) char *nspname; /* - * Would this dictionary be found by regdictionaryin? - * If not, qualify it. + * Would this dictionary be found by regdictionaryin? If not, qualify + * it. */ if (TSDictionaryIsVisible(dictid)) nspname = NULL; diff --git a/src/backend/utils/adt/ri_triggers.c b/src/backend/utils/adt/ri_triggers.c index e3a01ed76a..5a27f08f3c 100644 --- a/src/backend/utils/adt/ri_triggers.c +++ b/src/backend/utils/adt/ri_triggers.c @@ -15,7 +15,7 @@ * * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.97 2007/09/11 00:06:42 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.98 2007/11/15 21:14:39 momjian Exp $ * * ---------- */ @@ -72,8 +72,8 @@ #define MAX_QUOTED_NAME_LEN (NAMEDATALEN*2+3) #define MAX_QUOTED_REL_NAME_LEN (MAX_QUOTED_NAME_LEN*2) -#define RIAttName(rel, attnum) NameStr(*attnumAttName(rel, attnum)) -#define RIAttType(rel, attnum) SPI_gettypeid(RelationGetDescr(rel), attnum) +#define RIAttName(rel, attnum) NameStr(*attnumAttName(rel, attnum)) +#define RIAttType(rel, attnum) SPI_gettypeid(RelationGetDescr(rel), attnum) #define RI_TRIGTYPE_INSERT 1 #define RI_TRIGTYPE_UPDATE 2 @@ -100,12 +100,15 @@ typedef struct RI_ConstraintInfo char confdeltype; /* foreign key's ON DELETE action */ char confmatchtype; /* foreign key's match type */ int nkeys; /* number of key columns */ - int16 pk_attnums[RI_MAX_NUMKEYS]; /* attnums of referenced cols */ - int16 fk_attnums[RI_MAX_NUMKEYS]; /* attnums of referencing cols */ - Oid pf_eq_oprs[RI_MAX_NUMKEYS]; /* equality operators (PK = FK) */ - Oid pp_eq_oprs[RI_MAX_NUMKEYS]; /* equality operators (PK = PK) */ - Oid ff_eq_oprs[RI_MAX_NUMKEYS]; /* equality operators (FK = FK) */ -} RI_ConstraintInfo; + int16 pk_attnums[RI_MAX_NUMKEYS]; /* attnums of referenced cols */ + int16 fk_attnums[RI_MAX_NUMKEYS]; /* attnums of referencing cols */ + Oid pf_eq_oprs[RI_MAX_NUMKEYS]; /* equality operators (PK = + * FK) */ + Oid pp_eq_oprs[RI_MAX_NUMKEYS]; /* equality operators (PK = + * PK) */ + Oid ff_eq_oprs[RI_MAX_NUMKEYS]; /* equality operators (FK = + * FK) */ +} RI_ConstraintInfo; /* ---------- @@ -147,7 +150,7 @@ typedef struct RI_CompareKey { Oid eq_opr; /* the equality operator to apply */ Oid typeid; /* the data type to apply it to */ -} RI_CompareKey; +} RI_CompareKey; /* ---------- @@ -157,10 +160,10 @@ typedef struct RI_CompareKey typedef struct RI_CompareHashEntry { RI_CompareKey key; - bool valid; /* successfully initialized? */ - FmgrInfo eq_opr_finfo; /* call info for equality fn */ + bool valid; /* successfully initialized? */ + FmgrInfo eq_opr_finfo; /* call info for equality fn */ FmgrInfo cast_func_finfo; /* in case we must coerce input */ -} RI_CompareHashEntry; +} RI_CompareHashEntry; /* ---------- @@ -178,30 +181,30 @@ static HTAB *ri_compare_cache = NULL; static void quoteOneName(char *buffer, const char *name); static void quoteRelationName(char *buffer, Relation rel); static void ri_GenerateQual(StringInfo buf, - const char *sep, - const char *leftop, Oid leftoptype, - Oid opoid, - const char *rightop, Oid rightoptype); + const char *sep, + const char *leftop, Oid leftoptype, + Oid opoid, + const char *rightop, Oid rightoptype); static int ri_NullCheck(Relation rel, HeapTuple tup, RI_QueryKey *key, int pairidx); static void ri_BuildQueryKeyFull(RI_QueryKey *key, - const RI_ConstraintInfo *riinfo, - int32 constr_queryno); + const RI_ConstraintInfo * riinfo, + int32 constr_queryno); static void ri_BuildQueryKeyPkCheck(RI_QueryKey *key, - const RI_ConstraintInfo *riinfo, - int32 constr_queryno); + const RI_ConstraintInfo * riinfo, + int32 constr_queryno); static bool ri_KeysEqual(Relation rel, HeapTuple oldtup, HeapTuple newtup, - const RI_ConstraintInfo *riinfo, bool rel_is_pk); + const RI_ConstraintInfo * riinfo, bool rel_is_pk); static bool ri_AllKeysUnequal(Relation rel, HeapTuple oldtup, HeapTuple newtup, - const RI_ConstraintInfo *riinfo, bool rel_is_pk); + const RI_ConstraintInfo * riinfo, bool rel_is_pk); static bool ri_OneKeyEqual(Relation rel, int column, HeapTuple oldtup, HeapTuple newtup, - const RI_ConstraintInfo *riinfo, bool rel_is_pk); + const RI_ConstraintInfo * riinfo, bool rel_is_pk); static bool ri_AttributesEqual(Oid eq_opr, Oid typeid, - Datum oldvalue, Datum newvalue); + Datum oldvalue, Datum newvalue); static bool ri_Check_Pk_Match(Relation pk_rel, Relation fk_rel, HeapTuple old_row, - const RI_ConstraintInfo *riinfo); + const RI_ConstraintInfo * riinfo); static void ri_InitHashTables(void); static SPIPlanPtr ri_FetchPreparedPlan(RI_QueryKey *key); @@ -210,7 +213,7 @@ static RI_CompareHashEntry *ri_HashCompareOp(Oid eq_opr, Oid typeid); static void ri_CheckTrigger(FunctionCallInfo fcinfo, const char *funcname, int tgkind); -static void ri_FetchConstraintInfo(RI_ConstraintInfo *riinfo, +static void ri_FetchConstraintInfo(RI_ConstraintInfo * riinfo, Trigger *trigger, Relation trig_rel, bool rel_is_pk); static SPIPlanPtr ri_PlanCheck(const char *querystr, int nargs, Oid *argtypes, RI_QueryKey *qkey, Relation fk_rel, Relation pk_rel, @@ -258,7 +261,7 @@ RI_FKey_check(PG_FUNCTION_ARGS) * Get arguments. */ ri_FetchConstraintInfo(&riinfo, - trigdata->tg_trigger, trigdata->tg_relation, false); + trigdata->tg_trigger, trigdata->tg_relation, false); if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event)) { @@ -284,9 +287,9 @@ RI_FKey_check(PG_FUNCTION_ARGS) * here because we know that AfterTriggerExecute just fetched the tuple * successfully, so there cannot be a VACUUM compaction in progress on the * page (either heap_fetch would have waited for the VACUUM, or the - * VACUUM's LockBufferForCleanup would be waiting for us to drop pin). - * And since this is a row inserted by our open transaction, no one else - * can be entitled to change its xmin/xmax. + * VACUUM's LockBufferForCleanup would be waiting for us to drop pin). And + * since this is a row inserted by our open transaction, no one else can + * be entitled to change its xmin/xmax. */ Assert(new_row_buf != InvalidBuffer); if (!HeapTupleSatisfiesVisibility(new_row, SnapshotSelf, new_row_buf)) @@ -462,8 +465,8 @@ RI_FKey_check(PG_FUNCTION_ARGS) querysep = "WHERE"; for (i = 0; i < riinfo.nkeys; i++) { - Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); - Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); + Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); + Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); quoteOneName(attname, RIAttName(pk_rel, riinfo.pk_attnums[i])); @@ -538,7 +541,7 @@ RI_FKey_check_upd(PG_FUNCTION_ARGS) static bool ri_Check_Pk_Match(Relation pk_rel, Relation fk_rel, HeapTuple old_row, - const RI_ConstraintInfo *riinfo) + const RI_ConstraintInfo * riinfo) { SPIPlanPtr qplan; RI_QueryKey qkey; @@ -624,7 +627,7 @@ ri_Check_Pk_Match(Relation pk_rel, Relation fk_rel, querysep = "WHERE"; for (i = 0; i < riinfo->nkeys; i++) { - Oid pk_type = RIAttType(pk_rel, riinfo->pk_attnums[i]); + Oid pk_type = RIAttType(pk_rel, riinfo->pk_attnums[i]); quoteOneName(attname, RIAttName(pk_rel, riinfo->pk_attnums[i])); @@ -780,8 +783,8 @@ RI_FKey_noaction_del(PG_FUNCTION_ARGS) querysep = "WHERE"; for (i = 0; i < riinfo.nkeys; i++) { - Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); - Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); + Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); + Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); quoteOneName(attname, RIAttName(fk_rel, riinfo.fk_attnums[i])); @@ -968,8 +971,8 @@ RI_FKey_noaction_upd(PG_FUNCTION_ARGS) querysep = "WHERE"; for (i = 0; i < riinfo.nkeys; i++) { - Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); - Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); + Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); + Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); quoteOneName(attname, RIAttName(fk_rel, riinfo.fk_attnums[i])); @@ -1130,8 +1133,8 @@ RI_FKey_cascade_del(PG_FUNCTION_ARGS) querysep = "WHERE"; for (i = 0; i < riinfo.nkeys; i++) { - Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); - Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); + Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); + Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); quoteOneName(attname, RIAttName(fk_rel, riinfo.fk_attnums[i])); @@ -1313,8 +1316,8 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS) qualsep = "WHERE"; for (i = 0, j = riinfo.nkeys; i < riinfo.nkeys; i++, j++) { - Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); - Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); + Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); + Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); quoteOneName(attname, RIAttName(fk_rel, riinfo.fk_attnums[i])); @@ -1489,8 +1492,8 @@ RI_FKey_restrict_del(PG_FUNCTION_ARGS) querysep = "WHERE"; for (i = 0; i < riinfo.nkeys; i++) { - Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); - Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); + Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); + Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); quoteOneName(attname, RIAttName(fk_rel, riinfo.fk_attnums[i])); @@ -1672,8 +1675,8 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS) querysep = "WHERE"; for (i = 0; i < riinfo.nkeys; i++) { - Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); - Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); + Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); + Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); quoteOneName(attname, RIAttName(fk_rel, riinfo.fk_attnums[i])); @@ -1839,8 +1842,8 @@ RI_FKey_setnull_del(PG_FUNCTION_ARGS) qualsep = "WHERE"; for (i = 0; i < riinfo.nkeys; i++) { - Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); - Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); + Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); + Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); quoteOneName(attname, RIAttName(fk_rel, riinfo.fk_attnums[i])); @@ -2041,11 +2044,12 @@ RI_FKey_setnull_upd(PG_FUNCTION_ARGS) qualsep = "WHERE"; for (i = 0; i < riinfo.nkeys; i++) { - Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); - Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); + Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); + Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); quoteOneName(attname, RIAttName(fk_rel, riinfo.fk_attnums[i])); + /* * MATCH <unspecified> - only change columns corresponding * to changed columns in pk_rel's key @@ -2226,8 +2230,8 @@ RI_FKey_setdefault_del(PG_FUNCTION_ARGS) qualsep = "WHERE"; for (i = 0; i < riinfo.nkeys; i++) { - Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); - Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); + Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); + Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); quoteOneName(attname, RIAttName(fk_rel, riinfo.fk_attnums[i])); @@ -2419,8 +2423,8 @@ RI_FKey_setdefault_upd(PG_FUNCTION_ARGS) qualsep = "WHERE"; for (i = 0; i < riinfo.nkeys; i++) { - Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); - Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); + Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); + Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); quoteOneName(attname, RIAttName(fk_rel, riinfo.fk_attnums[i])); @@ -2685,8 +2689,8 @@ RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel) sep = "("; for (i = 0; i < riinfo.nkeys; i++) { - Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); - Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); + Oid pk_type = RIAttType(pk_rel, riinfo.pk_attnums[i]); + Oid fk_type = RIAttType(fk_rel, riinfo.fk_attnums[i]); quoteOneName(pkattname + 3, RIAttName(pk_rel, riinfo.pk_attnums[i])); @@ -2941,7 +2945,7 @@ ri_GenerateQual(StringInfo buf, * ---------- */ static void -ri_BuildQueryKeyFull(RI_QueryKey *key, const RI_ConstraintInfo *riinfo, +ri_BuildQueryKeyFull(RI_QueryKey *key, const RI_ConstraintInfo * riinfo, int32 constr_queryno) { int i; @@ -3018,7 +3022,7 @@ ri_CheckTrigger(FunctionCallInfo fcinfo, const char *funcname, int tgkind) * Fetch the pg_constraint entry for the FK constraint, and fill *riinfo */ static void -ri_FetchConstraintInfo(RI_ConstraintInfo *riinfo, +ri_FetchConstraintInfo(RI_ConstraintInfo * riinfo, Trigger *trigger, Relation trig_rel, bool rel_is_pk) { Oid constraintOid = trigger->tgconstraint; @@ -3030,15 +3034,15 @@ ri_FetchConstraintInfo(RI_ConstraintInfo *riinfo, int numkeys; /* - * Check that the FK constraint's OID is available; it might not be - * if we've been invoked via an ordinary trigger or an old-style - * "constraint trigger". + * Check that the FK constraint's OID is available; it might not be if + * we've been invoked via an ordinary trigger or an old-style "constraint + * trigger". */ if (!OidIsValid(constraintOid)) ereport(ERROR, (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), - errmsg("no pg_constraint entry for trigger \"%s\" on table \"%s\"", - trigger->tgname, RelationGetRelationName(trig_rel)), + errmsg("no pg_constraint entry for trigger \"%s\" on table \"%s\"", + trigger->tgname, RelationGetRelationName(trig_rel)), errhint("Remove this referential integrity trigger and its mates, then do ALTER TABLE ADD CONSTRAINT."))); /* OK, fetch the tuple */ @@ -3078,14 +3082,14 @@ ri_FetchConstraintInfo(RI_ConstraintInfo *riinfo, /* * We expect the arrays to be 1-D arrays of the right types; verify that. - * We don't need to use deconstruct_array() since the array data is - * just going to look like a C array of values. + * We don't need to use deconstruct_array() since the array data is just + * going to look like a C array of values. */ adatum = SysCacheGetAttr(CONSTROID, tup, Anum_pg_constraint_conkey, &isNull); if (isNull) elog(ERROR, "null conkey for constraint %u", constraintOid); - arr = DatumGetArrayTypeP(adatum); /* ensure not toasted */ + arr = DatumGetArrayTypeP(adatum); /* ensure not toasted */ numkeys = ARR_DIMS(arr)[0]; if (ARR_NDIM(arr) != 1 || numkeys < 0 || @@ -3100,7 +3104,7 @@ ri_FetchConstraintInfo(RI_ConstraintInfo *riinfo, Anum_pg_constraint_confkey, &isNull); if (isNull) elog(ERROR, "null confkey for constraint %u", constraintOid); - arr = DatumGetArrayTypeP(adatum); /* ensure not toasted */ + arr = DatumGetArrayTypeP(adatum); /* ensure not toasted */ numkeys = ARR_DIMS(arr)[0]; if (ARR_NDIM(arr) != 1 || numkeys != riinfo->nkeys || @@ -3114,7 +3118,7 @@ ri_FetchConstraintInfo(RI_ConstraintInfo *riinfo, Anum_pg_constraint_conpfeqop, &isNull); if (isNull) elog(ERROR, "null conpfeqop for constraint %u", constraintOid); - arr = DatumGetArrayTypeP(adatum); /* ensure not toasted */ + arr = DatumGetArrayTypeP(adatum); /* ensure not toasted */ numkeys = ARR_DIMS(arr)[0]; if (ARR_NDIM(arr) != 1 || numkeys != riinfo->nkeys || @@ -3128,7 +3132,7 @@ ri_FetchConstraintInfo(RI_ConstraintInfo *riinfo, Anum_pg_constraint_conppeqop, &isNull); if (isNull) elog(ERROR, "null conppeqop for constraint %u", constraintOid); - arr = DatumGetArrayTypeP(adatum); /* ensure not toasted */ + arr = DatumGetArrayTypeP(adatum); /* ensure not toasted */ numkeys = ARR_DIMS(arr)[0]; if (ARR_NDIM(arr) != 1 || numkeys != riinfo->nkeys || @@ -3142,7 +3146,7 @@ ri_FetchConstraintInfo(RI_ConstraintInfo *riinfo, Anum_pg_constraint_conffeqop, &isNull); if (isNull) elog(ERROR, "null conffeqop for constraint %u", constraintOid); - arr = DatumGetArrayTypeP(adatum); /* ensure not toasted */ + arr = DatumGetArrayTypeP(adatum); /* ensure not toasted */ numkeys = ARR_DIMS(arr)[0]; if (ARR_NDIM(arr) != 1 || numkeys != riinfo->nkeys || @@ -3482,7 +3486,7 @@ ri_ReportViolation(RI_QueryKey *qkey, const char *constrname, * ---------- */ static void -ri_BuildQueryKeyPkCheck(RI_QueryKey *key, const RI_ConstraintInfo *riinfo, +ri_BuildQueryKeyPkCheck(RI_QueryKey *key, const RI_ConstraintInfo * riinfo, int32 constr_queryno) { int i; @@ -3632,7 +3636,7 @@ ri_HashPreparedPlan(RI_QueryKey *key, SPIPlanPtr plan) */ static bool ri_KeysEqual(Relation rel, HeapTuple oldtup, HeapTuple newtup, - const RI_ConstraintInfo *riinfo, bool rel_is_pk) + const RI_ConstraintInfo * riinfo, bool rel_is_pk) { TupleDesc tupdesc = RelationGetDescr(rel); const int16 *attnums; @@ -3690,7 +3694,7 @@ ri_KeysEqual(Relation rel, HeapTuple oldtup, HeapTuple newtup, */ static bool ri_AllKeysUnequal(Relation rel, HeapTuple oldtup, HeapTuple newtup, - const RI_ConstraintInfo *riinfo, bool rel_is_pk) + const RI_ConstraintInfo * riinfo, bool rel_is_pk) { TupleDesc tupdesc = RelationGetDescr(rel); const int16 *attnums; @@ -3752,7 +3756,7 @@ ri_AllKeysUnequal(Relation rel, HeapTuple oldtup, HeapTuple newtup, */ static bool ri_OneKeyEqual(Relation rel, int column, HeapTuple oldtup, HeapTuple newtup, - const RI_ConstraintInfo *riinfo, bool rel_is_pk) + const RI_ConstraintInfo * riinfo, bool rel_is_pk) { TupleDesc tupdesc = RelationGetDescr(rel); const int16 *attnums; @@ -3867,9 +3871,9 @@ ri_HashCompareOp(Oid eq_opr, Oid typeid) */ if (!entry->valid) { - Oid lefttype, - righttype, - castfunc; + Oid lefttype, + righttype, + castfunc; CoercionPathType pathtype; /* We always need to know how to call the equality operator */ @@ -3877,13 +3881,13 @@ ri_HashCompareOp(Oid eq_opr, Oid typeid) TopMemoryContext); /* - * If we chose to use a cast from FK to PK type, we may have to - * apply the cast function to get to the operator's input type. + * If we chose to use a cast from FK to PK type, we may have to apply + * the cast function to get to the operator's input type. * * XXX eventually it would be good to support array-coercion cases - * here and in ri_AttributesEqual(). At the moment there is no - * point because cases involving nonidentical array types will - * be rejected at constraint creation time. + * here and in ri_AttributesEqual(). At the moment there is no point + * because cases involving nonidentical array types will be rejected + * at constraint creation time. * * XXX perhaps also consider supporting CoerceViaIO? No need at the * moment since that will never be generated for implicit coercions. @@ -3891,7 +3895,7 @@ ri_HashCompareOp(Oid eq_opr, Oid typeid) op_input_types(eq_opr, &lefttype, &righttype); Assert(lefttype == righttype); if (typeid == lefttype) - castfunc = InvalidOid; /* simplest case */ + castfunc = InvalidOid; /* simplest case */ else { pathtype = find_coercion_pathway(lefttype, typeid, diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 0aafb3b139..168da20aa2 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.264 2007/10/13 15:55:40 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.265 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -158,7 +158,7 @@ static Node *get_rule_sortgroupclause(SortClause *srt, List *tlist, bool force_colno, deparse_context *context); static char *get_variable(Var *var, int levelsup, bool showstar, - deparse_context *context); + deparse_context *context); static RangeTblEntry *find_rte_by_refname(const char *refname, deparse_context *context); static const char *get_simple_binary_op_name(OpExpr *expr); @@ -173,10 +173,10 @@ static void get_func_expr(FuncExpr *expr, deparse_context *context, bool showimplicit); static void get_agg_expr(Aggref *aggref, deparse_context *context); static void get_coercion_expr(Node *arg, deparse_context *context, - Oid resulttype, int32 resulttypmod, - Node *parentNode); + Oid resulttype, int32 resulttypmod, + Node *parentNode); static void get_const_expr(Const *constval, deparse_context *context, - bool showtype); + bool showtype); static void get_sublink_expr(SubLink *sublink, deparse_context *context); static void get_from_clause(Query *query, const char *prefix, deparse_context *context); @@ -532,8 +532,8 @@ pg_get_triggerdef(PG_FUNCTION_ARGS) int i; val = DatumGetByteaP(fastgetattr(ht_trig, - Anum_pg_trigger_tgargs, - tgrel->rd_att, &isnull)); + Anum_pg_trigger_tgargs, + tgrel->rd_att, &isnull)); if (isnull) elog(ERROR, "tgargs is null for trigger %u", trigid); p = (char *) VARDATA(val); @@ -604,7 +604,7 @@ pg_get_indexdef_ext(PG_FUNCTION_ARGS) prettyFlags = pretty ? PRETTYFLAG_PAREN | PRETTYFLAG_INDENT : 0; PG_RETURN_TEXT_P(string_to_text(pg_get_indexdef_worker(indexrelid, colno, - false, prettyFlags))); + false, prettyFlags))); } /* Internal version that returns a palloc'd C string */ @@ -816,7 +816,7 @@ pg_get_indexdef_worker(Oid indexrelid, int colno, bool showTblSpc, tblspc = get_rel_tablespace(indexrelid); if (OidIsValid(tblspc)) appendStringInfo(&buf, " TABLESPACE %s", - quote_identifier(get_tablespace_name(tblspc))); + quote_identifier(get_tablespace_name(tblspc))); } /* @@ -1068,7 +1068,7 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, tblspc = get_rel_tablespace(indexId); if (OidIsValid(tblspc)) appendStringInfo(&buf, " USING INDEX TABLESPACE %s", - quote_identifier(get_tablespace_name(tblspc))); + quote_identifier(get_tablespace_name(tblspc))); } break; @@ -1978,7 +1978,7 @@ get_select_query_def(Query *query, deparse_context *context, TYPECACHE_LT_OPR | TYPECACHE_GT_OPR); if (srt->sortop == typentry->lt_opr) { - /* ASC is default, so emit nothing for it */ + /* ASC is default, so emit nothing for it */ if (srt->nulls_first) appendStringInfo(buf, " NULLS FIRST"); } @@ -2624,7 +2624,7 @@ get_utility_query_def(Query *query, deparse_context *context) * push_plan: set up deparse_namespace to recurse into the tlist of a subplan * * When expanding an OUTER or INNER reference, we must push new outer/inner - * subplans in case the referenced expression itself uses OUTER/INNER. We + * subplans in case the referenced expression itself uses OUTER/INNER. We * modify the top stack entry in-place to avoid affecting levelsup issues * (although in a Plan tree there really shouldn't be any). * @@ -2641,6 +2641,7 @@ push_plan(deparse_namespace *dpns, Plan *subplan) dpns->outer_plan = (Plan *) linitial(((Append *) subplan)->appendplans); else dpns->outer_plan = outerPlan(subplan); + /* * For a SubqueryScan, pretend the subplan is INNER referent. (We don't * use OUTER because that could someday conflict with the normal meaning.) @@ -2697,8 +2698,8 @@ get_variable(Var *var, int levelsup, bool showstar, deparse_context *context) else if (var->varno == OUTER && dpns->outer_plan) { TargetEntry *tle; - Plan *save_outer; - Plan *save_inner; + Plan *save_outer; + Plan *save_inner; tle = get_tle_by_resno(dpns->outer_plan->targetlist, var->varattno); if (!tle) @@ -2726,8 +2727,8 @@ get_variable(Var *var, int levelsup, bool showstar, deparse_context *context) else if (var->varno == INNER && dpns->inner_plan) { TargetEntry *tle; - Plan *save_outer; - Plan *save_inner; + Plan *save_outer; + Plan *save_inner; tle = get_tle_by_resno(dpns->inner_plan->targetlist, var->varattno); if (!tle) @@ -2755,7 +2756,7 @@ get_variable(Var *var, int levelsup, bool showstar, deparse_context *context) else { elog(ERROR, "bogus varno: %d", var->varno); - return NULL; /* keep compiler quiet */ + return NULL; /* keep compiler quiet */ } /* Identify names to use */ @@ -2900,8 +2901,8 @@ get_name_for_var_field(Var *var, int fieldno, else if (var->varno == OUTER && dpns->outer_plan) { TargetEntry *tle; - Plan *save_outer; - Plan *save_inner; + Plan *save_outer; + Plan *save_inner; const char *result; tle = get_tle_by_resno(dpns->outer_plan->targetlist, var->varattno); @@ -2923,8 +2924,8 @@ get_name_for_var_field(Var *var, int fieldno, else if (var->varno == INNER && dpns->inner_plan) { TargetEntry *tle; - Plan *save_outer; - Plan *save_inner; + Plan *save_outer; + Plan *save_inner; const char *result; tle = get_tle_by_resno(dpns->inner_plan->targetlist, var->varattno); @@ -2946,7 +2947,7 @@ get_name_for_var_field(Var *var, int fieldno, else { elog(ERROR, "bogus varno: %d", var->varno); - return NULL; /* keep compiler quiet */ + return NULL; /* keep compiler quiet */ } if (attnum == InvalidAttrNumber) @@ -2958,9 +2959,9 @@ get_name_for_var_field(Var *var, int fieldno, /* * This part has essentially the same logic as the parser's * expandRecordVariable() function, but we are dealing with a different - * representation of the input context, and we only need one field name not - * a TupleDesc. Also, we need a special case for deparsing Plan trees, - * because the subquery field has been removed from SUBQUERY RTEs. + * representation of the input context, and we only need one field name + * not a TupleDesc. Also, we need a special case for deparsing Plan + * trees, because the subquery field has been removed from SUBQUERY RTEs. */ expr = (Node *) var; /* default if we can't drill down */ @@ -3020,13 +3021,13 @@ get_name_for_var_field(Var *var, int fieldno, /* * We're deparsing a Plan tree so we don't have complete * RTE entries. But the only place we'd see a Var - * directly referencing a SUBQUERY RTE is in a SubqueryScan - * plan node, and we can look into the child plan's tlist - * instead. + * directly referencing a SUBQUERY RTE is in a + * SubqueryScan plan node, and we can look into the child + * plan's tlist instead. */ TargetEntry *tle; - Plan *save_outer; - Plan *save_inner; + Plan *save_outer; + Plan *save_inner; const char *result; if (!dpns->inner_plan) @@ -3298,7 +3299,7 @@ isSimpleNode(Node *node, Node *parentNode, int prettyFlags) case T_RowExpr: /* other separators */ case T_CoalesceExpr: /* own parentheses */ case T_MinMaxExpr: /* own parentheses */ - case T_XmlExpr: /* own parentheses */ + case T_XmlExpr: /* own parentheses */ case T_NullIfExpr: /* other separators */ case T_Aggref: /* own parentheses */ case T_CaseExpr: /* other separators */ @@ -3347,7 +3348,7 @@ isSimpleNode(Node *node, Node *parentNode, int prettyFlags) case T_RowExpr: /* other separators */ case T_CoalesceExpr: /* own parentheses */ case T_MinMaxExpr: /* own parentheses */ - case T_XmlExpr: /* own parentheses */ + case T_XmlExpr: /* own parentheses */ case T_NullIfExpr: /* other separators */ case T_Aggref: /* own parentheses */ case T_CaseExpr: /* other separators */ @@ -3970,8 +3971,8 @@ get_rule_expr(Node *node, deparse_context *context, case T_XmlExpr: { - XmlExpr *xexpr = (XmlExpr *) node; - bool needcomma = false; + XmlExpr *xexpr = (XmlExpr *) node; + bool needcomma = false; ListCell *arg; ListCell *narg; Const *con; @@ -4026,8 +4027,8 @@ get_rule_expr(Node *node, deparse_context *context, } forboth(arg, xexpr->named_args, narg, xexpr->arg_names) { - Node *e = (Node *) lfirst(arg); - char *argname = strVal(lfirst(narg)); + Node *e = (Node *) lfirst(arg); + char *argname = strVal(lfirst(narg)); if (needcomma) appendStringInfoString(buf, ", "); @@ -4064,7 +4065,7 @@ get_rule_expr(Node *node, deparse_context *context, Assert(!con->constisnull); if (DatumGetBool(con->constvalue)) appendStringInfoString(buf, - " PRESERVE WHITESPACE"); + " PRESERVE WHITESPACE"); else appendStringInfoString(buf, " STRIP WHITESPACE"); @@ -4086,22 +4087,22 @@ get_rule_expr(Node *node, deparse_context *context, con = (Const *) lthird(xexpr->args); Assert(IsA(con, Const)); if (con->constisnull) - /* suppress STANDALONE NO VALUE */ ; + /* suppress STANDALONE NO VALUE */ ; else { switch (DatumGetInt32(con->constvalue)) { case XML_STANDALONE_YES: appendStringInfoString(buf, - ", STANDALONE YES"); + ", STANDALONE YES"); break; case XML_STANDALONE_NO: appendStringInfoString(buf, - ", STANDALONE NO"); + ", STANDALONE NO"); break; case XML_STANDALONE_NO_VALUE: appendStringInfoString(buf, - ", STANDALONE NO VALUE"); + ", STANDALONE NO VALUE"); break; default: break; @@ -4116,7 +4117,7 @@ get_rule_expr(Node *node, deparse_context *context, } if (xexpr->op == IS_XMLSERIALIZE) appendStringInfo(buf, " AS %s", format_type_with_typemod(xexpr->type, - xexpr->typmod)); + xexpr->typmod)); if (xexpr->op == IS_DOCUMENT) appendStringInfoString(buf, " IS DOCUMENT"); else @@ -4435,11 +4436,11 @@ get_coercion_expr(Node *arg, deparse_context *context, /* * Since parse_coerce.c doesn't immediately collapse application of - * length-coercion functions to constants, what we'll typically see - * in such cases is a Const with typmod -1 and a length-coercion - * function right above it. Avoid generating redundant output. - * However, beware of suppressing casts when the user actually wrote - * something like 'foo'::text::char(3). + * length-coercion functions to constants, what we'll typically see in + * such cases is a Const with typmod -1 and a length-coercion function + * right above it. Avoid generating redundant output. However, beware of + * suppressing casts when the user actually wrote something like + * 'foo'::text::char(3). */ if (arg && IsA(arg, Const) && ((Const *) arg)->consttype == resulttype && @@ -4581,6 +4582,7 @@ get_const_expr(Const *constval, deparse_context *context, bool showtype) needlabel = false; break; case NUMERICOID: + /* * Float-looking constants will be typed as numeric, but if * there's a specific typmod we need to show it. @@ -5553,7 +5555,8 @@ unflatten_reloptions(char *reloptstring) if (reloptstring) { - Datum sep, relopts; + Datum sep, + relopts; /* * We want to use text_to_array(reloptstring, ', ') --- but diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index 9ae33ac456..299addec85 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.239 2007/11/09 20:10:02 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.240 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -923,8 +923,8 @@ patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype, bool negate) /* * If this is for a NOT LIKE or similar operator, get the corresponding - * positive-match operator and work with that. Set result to the - * correct default estimate, too. + * positive-match operator and work with that. Set result to the correct + * default estimate, too. */ if (negate) { @@ -1396,7 +1396,7 @@ nulltestsel(PlannerInfo *root, NullTestType nulltesttype, * be taken at face value, since it's very likely being used to select the * outer-side rows that don't have a match, and thus its selectivity has * nothing whatever to do with the statistics of the original table - * column. We do not have nearly enough context here to determine its + * column. We do not have nearly enough context here to determine its * true selectivity, so for the moment punt and guess at 0.5. Eventually * the planner should be made to provide enough info about the clause's * context to let us do better. @@ -1539,7 +1539,7 @@ scalararraysel(PlannerInfo *root, /* get nominal (after relabeling) element type of rightop */ nominal_element_type = get_element_type(exprType(rightop)); if (!OidIsValid(nominal_element_type)) - return (Selectivity) 0.5; /* probably shouldn't happen */ + return (Selectivity) 0.5; /* probably shouldn't happen */ /* look through any binary-compatible relabeling of rightop */ rightop = strip_array_coercion(rightop); @@ -2228,8 +2228,8 @@ mergejoinscansel(PlannerInfo *root, Node *clause, Assert(!op_recheck); /* - * Look up the various operators we need. If we don't find them all, - * it probably means the opfamily is broken, but we cope anyway. + * Look up the various operators we need. If we don't find them all, it + * probably means the opfamily is broken, but we cope anyway. */ switch (strategy) { @@ -2274,7 +2274,7 @@ mergejoinscansel(PlannerInfo *root, Node *clause, /* * Now, the fraction of the left variable that will be scanned is the * fraction that's <= the right-side maximum value. But only believe - * non-default estimates, else stick with our 1.0. Also, if the sort + * non-default estimates, else stick with our 1.0. Also, if the sort * order is nulls-first, we're going to have to read over any nulls too. */ selec = scalarineqsel(root, leop, false, &leftvar, @@ -3151,12 +3151,14 @@ convert_string_datum(Datum value, Oid typid) * out of a paper bag? * * XXX: strxfrm doesn't support UTF-8 encoding on Win32, it can return - * bogus data or set an error. This is not really a problem unless it - * crashes since it will only give an estimation error and nothing fatal. + * bogus data or set an error. This is not really a problem unless it + * crashes since it will only give an estimation error and nothing + * fatal. */ #if _MSC_VER == 1400 /* VS.Net 2005 */ /* + * * http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx * ?FeedbackID=99694 */ @@ -3169,9 +3171,10 @@ convert_string_datum(Datum value, Oid typid) xfrmlen = strxfrm(NULL, val, 0); #endif #ifdef WIN32 + /* - * On Windows, strxfrm returns INT_MAX when an error occurs. Instead of - * trying to allocate this much memory (and fail), just return the + * On Windows, strxfrm returns INT_MAX when an error occurs. Instead + * of trying to allocate this much memory (and fail), just return the * original string unmodified as if we were in the C locale. */ if (xfrmlen == INT_MAX) @@ -4081,9 +4084,9 @@ regex_fixed_prefix(Const *patt_const, bool case_insensitive, /* * If '|' is present in pattern, then there may be multiple alternatives - * for the start of the string. (There are cases where this isn't so, - * for instance if the '|' is inside parens, but detecting that reliably - * is too hard.) + * for the start of the string. (There are cases where this isn't so, for + * instance if the '|' is inside parens, but detecting that reliably is + * too hard.) */ if (strchr(patt + pos, '|') != NULL) { @@ -4101,7 +4104,7 @@ regex_fixed_prefix(Const *patt_const, bool case_insensitive, /* * We special-case the syntax '^(...)$' because psql uses it. But beware: - * in BRE mode these parentheses are just ordinary characters. Also, + * in BRE mode these parentheses are just ordinary characters. Also, * sequences beginning "(?" are not what they seem, unless they're "(?:". * (We should recognize that, too, because of similar_escape().) * @@ -4171,10 +4174,10 @@ regex_fixed_prefix(Const *patt_const, bool case_insensitive, /* * Normally, backslash quotes the next character. But in AREs, * backslash followed by alphanumeric is an escape, not a quoted - * character. Must treat it as having multiple possible matches. - * In BREs, \( is a parenthesis, so don't trust that either. - * Note: since only ASCII alphanumerics are escapes, we don't have - * to be paranoid about multibyte here. + * character. Must treat it as having multiple possible matches. In + * BREs, \( is a parenthesis, so don't trust that either. Note: since + * only ASCII alphanumerics are escapes, we don't have to be paranoid + * about multibyte here. */ if (patt[pos] == '\\') { @@ -4598,7 +4601,7 @@ pattern_selectivity(Const *patt, Pattern_Type ptype) * that is not a bulletproof guarantee that an extension of the string might * not sort after it; an example is that "foo " is less than "foo!", but it * is not clear that a "dictionary" sort ordering will consider "foo!" less - * than "foo bar". CAUTION: Therefore, this function should be used only for + * than "foo bar". CAUTION: Therefore, this function should be used only for * estimation purposes when working in a non-C locale. * * To try to catch most cases where an extended string might otherwise sort @@ -4624,11 +4627,10 @@ make_greater_string(const Const *str_const, FmgrInfo *ltproc) text *cmptxt = NULL; /* - * Get a modifiable copy of the prefix string in C-string format, - * and set up the string we will compare to as a Datum. In C locale - * this can just be the given prefix string, otherwise we need to add - * a suffix. Types NAME and BYTEA sort bytewise so they don't need - * a suffix either. + * Get a modifiable copy of the prefix string in C-string format, and set + * up the string we will compare to as a Datum. In C locale this can just + * be the given prefix string, otherwise we need to add a suffix. Types + * NAME and BYTEA sort bytewise so they don't need a suffix either. */ if (datatype == NAMEOID) { @@ -4662,7 +4664,7 @@ make_greater_string(const Const *str_const, FmgrInfo *ltproc) if (!suffixchar) { - char *best; + char *best; best = "Z"; if (varstr_cmp(best, 1, "z", 1) < 0) @@ -4859,8 +4861,8 @@ genericcostestimate(PlannerInfo *root, foreach(l, index->indpred) { - Node *predQual = (Node *) lfirst(l); - List *oneQual = list_make1(predQual); + Node *predQual = (Node *) lfirst(l); + List *oneQual = list_make1(predQual); if (!predicate_implied_by(oneQual, indexQuals)) predExtraQuals = list_concat(predExtraQuals, oneQual); @@ -5018,7 +5020,7 @@ genericcostestimate(PlannerInfo *root, * evaluated once at the start of the scan to reduce them to runtime keys * to pass to the index AM (see nodeIndexscan.c). We model the per-tuple * CPU costs as cpu_index_tuple_cost plus one cpu_operator_cost per - * indexqual operator. Because we have numIndexTuples as a per-scan + * indexqual operator. Because we have numIndexTuples as a per-scan * number, we have to multiply by num_sa_scans to get the correct result * for ScalarArrayOpExpr cases. * @@ -5038,17 +5040,17 @@ genericcostestimate(PlannerInfo *root, *indexTotalCost += numIndexTuples * num_sa_scans * (cpu_index_tuple_cost + qual_op_cost); /* - * We also add a CPU-cost component to represent the general costs of - * starting an indexscan, such as analysis of btree index keys and - * initial tree descent. This is estimated at 100x cpu_operator_cost, - * which is a bit arbitrary but seems the right order of magnitude. - * (As noted above, we don't charge any I/O for touching upper tree - * levels, but charging nothing at all has been found too optimistic.) + * We also add a CPU-cost component to represent the general costs of + * starting an indexscan, such as analysis of btree index keys and initial + * tree descent. This is estimated at 100x cpu_operator_cost, which is a + * bit arbitrary but seems the right order of magnitude. (As noted above, + * we don't charge any I/O for touching upper tree levels, but charging + * nothing at all has been found too optimistic.) * - * Although this is startup cost with respect to any one scan, we add - * it to the "total" cost component because it's only very interesting - * in the many-ScalarArrayOpExpr-scan case, and there it will be paid - * over the life of the scan node. + * Although this is startup cost with respect to any one scan, we add it + * to the "total" cost component because it's only very interesting in the + * many-ScalarArrayOpExpr-scan case, and there it will be paid over the + * life of the scan node. */ *indexTotalCost += num_sa_scans * 100.0 * cpu_operator_cost; @@ -5198,7 +5200,7 @@ btcostestimate(PG_FUNCTION_ARGS) { op_strategy = get_op_opfamily_strategy(clause_op, index->opfamily[indexcol]); - Assert(op_strategy != 0); /* not a member of opfamily?? */ + Assert(op_strategy != 0); /* not a member of opfamily?? */ if (op_strategy == BTEqualStrategyNumber) eqQualHere = true; } @@ -5234,10 +5236,11 @@ btcostestimate(PG_FUNCTION_ARGS) index->rel->relid, JOIN_INNER); numIndexTuples = btreeSelectivity * index->rel->tuples; + /* * As in genericcostestimate(), we have to adjust for any - * ScalarArrayOpExpr quals included in indexBoundQuals, and then - * round to integer. + * ScalarArrayOpExpr quals included in indexBoundQuals, and then round + * to integer. */ numIndexTuples = rint(numIndexTuples / num_sa_scans); } @@ -5313,9 +5316,9 @@ btcostestimate(PG_FUNCTION_ARGS) varCorrelation = numbers[0]; if (index->ncolumns > 1) - *indexCorrelation = - varCorrelation * 0.75; + *indexCorrelation = -varCorrelation * 0.75; else - *indexCorrelation = - varCorrelation; + *indexCorrelation = -varCorrelation; free_attstatsslot(InvalidOid, NULL, 0, numbers, nnumbers); } @@ -5374,7 +5377,7 @@ gincostestimate(PG_FUNCTION_ARGS) Cost *indexTotalCost = (Cost *) PG_GETARG_POINTER(5); Selectivity *indexSelectivity = (Selectivity *) PG_GETARG_POINTER(6); double *indexCorrelation = (double *) PG_GETARG_POINTER(7); - + genericcostestimate(root, index, indexQuals, outer_rel, 0.0, indexStartupCost, indexTotalCost, indexSelectivity, indexCorrelation); diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index 9f5eee5c07..4ad53a9d3f 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.182 2007/09/16 15:56:20 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.183 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -60,9 +60,9 @@ static TimestampTz timestamp2timestamptz(Timestamp timestamp); static int32 anytimestamp_typmodin(bool istz, ArrayType *ta) { - int32 typmod; - int32 *tl; - int n; + int32 typmod; + int32 *tl; + int n; tl = ArrayGetIntegerTypmods(ta, &n); @@ -84,11 +84,12 @@ anytimestamp_typmodin(bool istz, ArrayType *ta) { ereport(WARNING, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("TIMESTAMP(%d)%s precision reduced to maximum allowed, %d", - *tl, (istz ? " WITH TIME ZONE" : ""), - MAX_TIMESTAMP_PRECISION))); + errmsg("TIMESTAMP(%d)%s precision reduced to maximum allowed, %d", + *tl, (istz ? " WITH TIME ZONE" : ""), + MAX_TIMESTAMP_PRECISION))); typmod = MAX_TIMESTAMP_PRECISION; - } else + } + else typmod = *tl; return typmod; @@ -98,7 +99,7 @@ anytimestamp_typmodin(bool istz, ArrayType *ta) static char * anytimestamp_typmodout(bool istz, int32 typmod) { - char *res = (char *) palloc(64); + char *res = (char *) palloc(64); const char *tz = istz ? " with time zone" : " without time zone"; if (typmod >= 0) @@ -272,7 +273,7 @@ timestamp_send(PG_FUNCTION_ARGS) Datum timestamptypmodin(PG_FUNCTION_ARGS) { - ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); + ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); PG_RETURN_INT32(anytimestamp_typmodin(false, ta)); } @@ -280,7 +281,7 @@ timestamptypmodin(PG_FUNCTION_ARGS) Datum timestamptypmodout(PG_FUNCTION_ARGS) { - int32 typmod = PG_GETARG_INT32(0); + int32 typmod = PG_GETARG_INT32(0); PG_RETURN_CSTRING(anytimestamp_typmodout(false, typmod)); } @@ -534,7 +535,7 @@ timestamptz_send(PG_FUNCTION_ARGS) Datum timestamptztypmodin(PG_FUNCTION_ARGS) { - ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); + ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); PG_RETURN_INT32(anytimestamp_typmodin(true, ta)); } @@ -542,7 +543,7 @@ timestamptztypmodin(PG_FUNCTION_ARGS) Datum timestamptztypmodout(PG_FUNCTION_ARGS) { - int32 typmod = PG_GETARG_INT32(0); + int32 typmod = PG_GETARG_INT32(0); PG_RETURN_CSTRING(anytimestamp_typmodout(true, typmod)); } @@ -714,16 +715,15 @@ interval_send(PG_FUNCTION_ARGS) Datum intervaltypmodin(PG_FUNCTION_ARGS) { - ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); - int32 *tl; - int n; + ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); + int32 *tl; + int n; int32 typmod; tl = ArrayGetIntegerTypmods(ta, &n); /* - * tl[0] - opt_interval - * tl[1] - Iconst (optional) + * tl[0] - opt_interval tl[1] - Iconst (optional) * * Note we must validate tl[0] even though it's normally guaranteed * correct by the grammar --- consider SELECT 'foo'::"interval"(1000). @@ -768,13 +768,13 @@ intervaltypmodin(PG_FUNCTION_ARGS) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("INTERVAL(%d) precision must not be negative", - tl[1]))); + tl[1]))); if (tl[1] > MAX_INTERVAL_PRECISION) { ereport(WARNING, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("INTERVAL(%d) precision reduced to maximum allowed, %d", - tl[1], MAX_INTERVAL_PRECISION))); + errmsg("INTERVAL(%d) precision reduced to maximum allowed, %d", + tl[1], MAX_INTERVAL_PRECISION))); typmod = INTERVAL_TYPMOD(MAX_INTERVAL_PRECISION, tl[0]); } else @@ -784,7 +784,7 @@ intervaltypmodin(PG_FUNCTION_ARGS) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("invalid INTERVAL type modifier"))); + errmsg("invalid INTERVAL type modifier"))); typmod = 0; /* keep compiler quiet */ } @@ -794,10 +794,10 @@ intervaltypmodin(PG_FUNCTION_ARGS) Datum intervaltypmodout(PG_FUNCTION_ARGS) { - int32 typmod = PG_GETARG_INT32(0); + int32 typmod = PG_GETARG_INT32(0); char *res = (char *) palloc(64); - int fields; - int precision; + int fields; + int precision; const char *fieldstr; if (typmod < 0) @@ -1305,13 +1305,13 @@ timestamptz_to_time_t(TimestampTz t) * Produce a C-string representation of a TimestampTz. * * This is mostly for use in emitting messages. The primary difference - * from timestamptz_out is that we force the output format to ISO. Note + * from timestamptz_out is that we force the output format to ISO. Note * also that the result is in a static buffer, not pstrdup'd. */ const char * timestamptz_to_str(TimestampTz t) { - static char buf[MAXDATELEN + 1]; + static char buf[MAXDATELEN + 1]; int tz; struct pg_tm tt, *tm = &tt; @@ -1494,7 +1494,7 @@ recalc_t: if ((Timestamp) utime == dt) { struct pg_tm *tx = pg_localtime(&utime, - attimezone ? attimezone : session_timezone); + attimezone ? attimezone : session_timezone); tm->tm_year = tx->tm_year + 1900; tm->tm_mon = tx->tm_mon + 1; @@ -2129,17 +2129,17 @@ interval_hash(PG_FUNCTION_ARGS) uint32 mhash; /* - * To avoid any problems with padding bytes in the struct, - * we figure the field hashes separately and XOR them. This also - * provides a convenient framework for dealing with the fact that - * the time field might be either double or int64. + * To avoid any problems with padding bytes in the struct, we figure the + * field hashes separately and XOR them. This also provides a convenient + * framework for dealing with the fact that the time field might be either + * double or int64. */ #ifdef HAVE_INT64_TIMESTAMP thash = DatumGetUInt32(DirectFunctionCall1(hashint8, Int64GetDatumFast(key->time))); #else thash = DatumGetUInt32(DirectFunctionCall1(hashfloat8, - Float8GetDatumFast(key->time))); + Float8GetDatumFast(key->time))); #endif thash ^= DatumGetUInt32(hash_uint32(key->day)); /* Shift so "k days" and "k months" don't hash to the same thing */ @@ -3664,8 +3664,8 @@ interval_trunc(PG_FUNCTION_ARGS) /* isoweek2j() * - * Return the Julian day which corresponds to the first day (Monday) of the given ISO 8601 year and week. - * Julian days are used to convert between ISO week dates and Gregorian dates. + * Return the Julian day which corresponds to the first day (Monday) of the given ISO 8601 year and week. + * Julian days are used to convert between ISO week dates and Gregorian dates. */ int isoweek2j(int year, int week) @@ -3700,14 +3700,14 @@ isoweek2date(int woy, int *year, int *mon, int *mday) /* isoweekdate2date() * - * Convert an ISO 8601 week date (ISO year, ISO week and day of week) into a Gregorian date. - * Populates year, mon, and mday with the correct Gregorian values. - * year must be passed in as the ISO year. + * Convert an ISO 8601 week date (ISO year, ISO week and day of week) into a Gregorian date. + * Populates year, mon, and mday with the correct Gregorian values. + * year must be passed in as the ISO year. */ void isoweekdate2date(int isoweek, int isowday, int *year, int *mon, int *mday) { - int jday; + int jday; jday = isoweek2j(*year, isoweek); jday += isowday - 1; @@ -3827,8 +3827,8 @@ date2isoyear(int year, int mon, int mday) /* date2isoyearday() * - * Returns the ISO 8601 day-of-year, given a Gregorian year, month and day. - * Possible return values are 1 through 371 (364 in non-leap years). + * Returns the ISO 8601 day-of-year, given a Gregorian year, month and day. + * Possible return values are 1 through 371 (364 in non-leap years). */ int date2isoyearday(int year, int mon, int mday) diff --git a/src/backend/utils/adt/tsginidx.c b/src/backend/utils/adt/tsginidx.c index 075c921d40..d6b9965d1c 100644 --- a/src/backend/utils/adt/tsginidx.c +++ b/src/backend/utils/adt/tsginidx.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/tsginidx.c,v 1.5 2007/10/20 21:06:20 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/tsginidx.c,v 1.6 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -113,7 +113,7 @@ typedef struct { QueryItem *frst; bool *mapped_check; -} GinChkVal; +} GinChkVal; static bool checkcondition_gin(void *checkval, QueryOperand * val) @@ -127,6 +127,7 @@ Datum gin_ts_consistent(PG_FUNCTION_ARGS) { bool *check = (bool *) PG_GETARG_POINTER(0); + /* StrategyNumber strategy = PG_GETARG_UINT16(1); */ TSQuery query = PG_GETARG_TSQUERY(2); bool res = FALSE; @@ -141,8 +142,8 @@ gin_ts_consistent(PG_FUNCTION_ARGS) /* * check-parameter array has one entry for each value (operand) in the * query. We expand that array into mapped_check, so that there's one - * entry in mapped_check for every node in the query, including - * operators, to allow quick lookups in checkcondition_gin. Only the + * entry in mapped_check for every node in the query, including + * operators, to allow quick lookups in checkcondition_gin. Only the * entries corresponding operands are actually used. */ diff --git a/src/backend/utils/adt/tsquery.c b/src/backend/utils/adt/tsquery.c index f8e84cb266..457468ee0e 100644 --- a/src/backend/utils/adt/tsquery.c +++ b/src/backend/utils/adt/tsquery.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/tsquery.c,v 1.8 2007/10/21 22:29:56 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/tsquery.c,v 1.9 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -29,18 +29,20 @@ struct TSQueryParserStateData char *buffer; /* entire string we are scanning */ char *buf; /* current scan point */ int state; - int count; /* nesting count, incremented by (, - decremented by ) */ + int count; /* nesting count, incremented by (, + * decremented by ) */ /* polish (prefix) notation in list, filled in by push* functions */ List *polstr; - /* Strings from operands are collected in op. curop is a pointer to - * the end of used space of op. */ + /* + * Strings from operands are collected in op. curop is a pointer to the + * end of used space of op. + */ char *op; char *curop; - int lenop; /* allocated size of op */ - int sumlen; /* used size of op */ + int lenop; /* allocated size of op */ + int sumlen; /* used size of op */ /* state for value's parser */ TSVectorParseState valstate; @@ -96,14 +98,15 @@ get_weight(char *buf, int16 *weight) /* * token types for parsing */ -typedef enum { +typedef enum +{ PT_END = 0, PT_ERR = 1, PT_VAL = 2, PT_OPR = 3, PT_OPEN = 4, PT_CLOSE = 5, -} ts_tokentype; +} ts_tokentype; /* * get token from query string @@ -112,7 +115,7 @@ typedef enum { * *strval, *lenval and *weight are filled in when return value is PT_VAL */ static ts_tokentype -gettoken_query(TSQueryParserState state, +gettoken_query(TSQueryParserState state, int8 *operator, int *lenval, char **strval, int16 *weight) { @@ -146,7 +149,10 @@ gettoken_query(TSQueryParserState state, } else if (!t_isspace(state->buf)) { - /* We rely on the tsvector parser to parse the value for us */ + /* + * We rely on the tsvector parser to parse the value for + * us + */ reset_tsvector_parser(state->valstate, state->buf); if (gettoken_tsvector(state->valstate, strval, lenval, NULL, NULL, &state->buf)) { @@ -215,7 +221,7 @@ pushOperator(TSQueryParserState state, int8 oper) QueryOperator *tmp; Assert(oper == OP_NOT || oper == OP_AND || oper == OP_OR); - + tmp = (QueryOperator *) palloc(sizeof(QueryOperator)); tmp->type = QI_OPR; tmp->oper = oper; @@ -275,7 +281,7 @@ pushValue(TSQueryParserState state, char *strval, int lenval, int2 weight) /* append the value string to state.op, enlarging buffer if needed first */ while (state->curop - state->op + lenval + 1 >= state->lenop) { - int used = state->curop - state->op; + int used = state->curop - state->op; state->lenop *= 2; state->op = (char *) repalloc((void *) state->op, state->lenop); @@ -312,7 +318,7 @@ pushStop(TSQueryParserState state) * See parse_tsquery for explanation of pushval. */ static void -makepol(TSQueryParserState state, +makepol(TSQueryParserState state, PushFunction pushval, Datum opaque) { @@ -345,7 +351,7 @@ makepol(TSQueryParserState state, pushOperator(state, OP_OR); else { - if (lenstack == STACKDEPTH) /* internal error */ + if (lenstack == STACKDEPTH) /* internal error */ elog(ERROR, "tsquery stack too small"); opstack[lenstack] = operator; lenstack++; @@ -384,7 +390,7 @@ makepol(TSQueryParserState state, } static void -findoprnd_recurse(QueryItem *ptr, uint32 *pos, int nnodes) +findoprnd_recurse(QueryItem * ptr, uint32 *pos, int nnodes) { /* since this function recurses, it could be driven to stack overflow. */ check_stack_depth(); @@ -393,14 +399,12 @@ findoprnd_recurse(QueryItem *ptr, uint32 *pos, int nnodes) elog(ERROR, "malformed tsquery; operand not found"); if (ptr[*pos].type == QI_VAL || - ptr[*pos].type == QI_VALSTOP) /* need to handle VALSTOP here, - * they haven't been cleaned - * away yet. - */ + ptr[*pos].type == QI_VALSTOP) /* need to handle VALSTOP here, they + * haven't been cleaned away yet. */ { (*pos)++; } - else + else { Assert(ptr[*pos].type == QI_OPR); @@ -412,8 +416,8 @@ findoprnd_recurse(QueryItem *ptr, uint32 *pos, int nnodes) } else { - QueryOperator *curitem = &ptr[*pos].operator; - int tmp = *pos; + QueryOperator *curitem = &ptr[*pos].operator; + int tmp = *pos; Assert(curitem->oper == OP_AND || curitem->oper == OP_OR); @@ -428,12 +432,12 @@ findoprnd_recurse(QueryItem *ptr, uint32 *pos, int nnodes) /* * Fills in the left-fields previously left unfilled. The input - * QueryItems must be in polish (prefix) notation. + * QueryItems must be in polish (prefix) notation. */ static void -findoprnd(QueryItem *ptr, int size) +findoprnd(QueryItem * ptr, int size) { - uint32 pos; + uint32 pos; pos = 0; findoprnd_recurse(ptr, &pos, size); @@ -451,14 +455,14 @@ findoprnd(QueryItem *ptr, int size) * with pushStop, otherwise the prefix notation representation will be broken, * having an operator with no operand. * - * opaque is passed on to pushval as is, pushval can use it to store its + * opaque is passed on to pushval as is, pushval can use it to store its * private state. * * The returned query might contain QI_STOPVAL nodes. The caller is responsible * for cleaning them up (with clean_fakeval) */ TSQuery -parse_tsquery(char *buf, +parse_tsquery(char *buf, PushFunction pushval, Datum opaque, bool isplain) @@ -513,9 +517,9 @@ parse_tsquery(char *buf, i = 0; foreach(cell, state.polstr) { - QueryItem *item = (QueryItem *) lfirst(cell); + QueryItem *item = (QueryItem *) lfirst(cell); - switch(item->type) + switch (item->type) { case QI_VAL: memcpy(&ptr[i], item, sizeof(QueryOperand)); @@ -572,7 +576,7 @@ typedef struct char *cur; char *op; int buflen; -} INFIX; +} INFIX; /* Makes sure inf->buf is large enough for adding 'addsize' bytes */ #define RESIZEBUF(inf, addsize) \ @@ -699,7 +703,7 @@ infix(INFIX * in, bool first) /* print operator & right operand */ RESIZEBUF(in, 3 + (nrm.cur - nrm.buf)); - switch(op) + switch (op) { case OP_OR: sprintf(in->cur, " | %s", nrm.buf); @@ -708,7 +712,7 @@ infix(INFIX * in, bool first) sprintf(in->cur, " & %s", nrm.buf); break; default: - /* OP_NOT is handled in above if-branch*/ + /* OP_NOT is handled in above if-branch */ elog(ERROR, "unexpected operator type %d", op); } in->cur = strchr(in->cur, '\0'); @@ -752,13 +756,13 @@ tsqueryout(PG_FUNCTION_ARGS) * Binary Input / Output functions. The binary format is as follows: * * uint32 number of operators/operands in the query - * + * * Followed by the operators and operands, in prefix notation. For each * operand: * * uint8 type, QI_VAL * uint8 weight - * operand text in client encoding, null-terminated + * operand text in client encoding, null-terminated * * For each operator: * uint8 type, QI_OPR @@ -779,7 +783,7 @@ tsquerysend(PG_FUNCTION_ARGS) { pq_sendint(&buf, item->type, sizeof(item->type)); - switch(item->type) + switch (item->type) { case QI_VAL: pq_sendint(&buf, item->operand.weight, sizeof(uint8)); @@ -832,12 +836,12 @@ tsqueryrecv(PG_FUNCTION_ARGS) if (item->type == QI_VAL) { - size_t val_len; /* length after recoding to server encoding */ - uint8 weight; + size_t val_len; /* length after recoding to server encoding */ + uint8 weight; const char *val; - pg_crc32 valcrc; + pg_crc32 valcrc; - weight = (uint8) pq_getmsgint(buf, sizeof(uint8)); + weight = (uint8) pq_getmsgint(buf, sizeof(uint8)); val = pq_getmsgstring(buf); val_len = strlen(val); @@ -848,7 +852,7 @@ tsqueryrecv(PG_FUNCTION_ARGS) if (val_len > MAXSTRLEN) elog(ERROR, "invalid tsquery; operand too long"); - + if (datalen > MAXSTRPOS) elog(ERROR, "invalid tsquery; total operand length exceeded"); @@ -863,17 +867,18 @@ tsqueryrecv(PG_FUNCTION_ARGS) item->operand.length = val_len; item->operand.distance = datalen; - /* + /* * Operand strings are copied to the final struct after this loop; * here we just collect them to an array */ operands[i] = val; datalen += val_len + 1; /* + 1 for the '\0' terminator */ - } + } else if (item->type == QI_OPR) { - int8 oper; + int8 oper; + oper = (int8) pq_getmsgint(buf, sizeof(int8)); if (oper != OP_NOT && oper != OP_OR && oper != OP_AND) elog(ERROR, "invalid tsquery; unknown operator type %d", (int) oper); @@ -882,7 +887,7 @@ tsqueryrecv(PG_FUNCTION_ARGS) item->operator.oper = oper; } - else + else elog(ERROR, "unknown tsquery node type %d", item->type); item++; @@ -893,9 +898,9 @@ tsqueryrecv(PG_FUNCTION_ARGS) item = GETQUERY(query); ptr = GETOPERAND(query); - /* - * Fill in the left-pointers. Checks that the tree is well-formed - * as a side-effect. + /* + * Fill in the left-pointers. Checks that the tree is well-formed as a + * side-effect. */ findoprnd(item, size); diff --git a/src/backend/utils/adt/tsquery_cleanup.c b/src/backend/utils/adt/tsquery_cleanup.c index 62de4ee6ec..a4ec1bff59 100644 --- a/src/backend/utils/adt/tsquery_cleanup.c +++ b/src/backend/utils/adt/tsquery_cleanup.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_cleanup.c,v 1.5 2007/09/20 23:27:11 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_cleanup.c,v 1.6 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -24,7 +24,7 @@ typedef struct NODE struct NODE *left; struct NODE *right; QueryItem *valnode; -} NODE; +} NODE; /* * make query tree from plain view of query @@ -51,9 +51,9 @@ maketree(QueryItem * in) typedef struct { QueryItem *ptr; - int len; /* allocated size of ptr */ - int cur; /* number of elements in ptr */ -} PLAINTREE; + int len; /* allocated size of ptr */ + int cur; /* number of elements in ptr */ +} PLAINTREE; static void plainnode(PLAINTREE * state, NODE * node) @@ -77,7 +77,7 @@ plainnode(PLAINTREE * state, NODE * node) } else { - int cur = state->cur; + int cur = state->cur; state->cur++; plainnode(state, node->right); @@ -157,7 +157,7 @@ clean_NOT_intree(NODE * node) else { NODE *res = node; - + Assert(node->valnode->operator.oper == OP_AND); node->left = clean_NOT_intree(node->left); @@ -201,10 +201,13 @@ clean_NOT(QueryItem * ptr, int *len) /* * output values for result output parameter of clean_fakeval_intree */ -#define V_UNKNOWN 0 /* the expression can't be evaluated statically */ -#define V_TRUE 1 /* the expression is always true (not implemented) */ -#define V_FALSE 2 /* the expression is always false (not implemented) */ -#define V_STOP 3 /* the expression is a stop word */ +#define V_UNKNOWN 0 /* the expression can't be evaluated + * statically */ +#define V_TRUE 1 /* the expression is always true (not + * implemented) */ +#define V_FALSE 2 /* the expression is always false (not + * implemented) */ +#define V_STOP 3 /* the expression is a stop word */ /* * Clean query tree from values which is always in @@ -221,8 +224,7 @@ clean_fakeval_intree(NODE * node, char *result) if (node->valnode->type == QI_VAL) return node; - else - if (node->valnode->type == QI_VALSTOP) + else if (node->valnode->type == QI_VALSTOP) { pfree(node); *result = V_STOP; diff --git a/src/backend/utils/adt/tsquery_gist.c b/src/backend/utils/adt/tsquery_gist.c index 0deca10075..2d79920960 100644 --- a/src/backend/utils/adt/tsquery_gist.c +++ b/src/backend/utils/adt/tsquery_gist.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_gist.c,v 1.1 2007/08/21 01:11:19 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_gist.c,v 1.2 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -142,7 +142,7 @@ typedef struct { OffsetNumber pos; int4 cost; -} SPLITCOST; +} SPLITCOST; static int comparecost(const void *a, const void *b) diff --git a/src/backend/utils/adt/tsquery_rewrite.c b/src/backend/utils/adt/tsquery_rewrite.c index 51f05a0d69..1dedf138b2 100644 --- a/src/backend/utils/adt/tsquery_rewrite.c +++ b/src/backend/utils/adt/tsquery_rewrite.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_rewrite.c,v 1.8 2007/11/13 22:14:50 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_rewrite.c,v 1.9 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -43,16 +43,16 @@ addone(int *counters, int last, int total) * by returning either node or a copy of subs. */ static QTNode * -findeq(QTNode *node, QTNode *ex, QTNode *subs, bool *isfind) +findeq(QTNode * node, QTNode * ex, QTNode * subs, bool *isfind) { - if ((node->sign & ex->sign) != ex->sign || + if ((node->sign & ex->sign) != ex->sign || node->valnode->type != ex->valnode->type) return node; if (node->flags & QTN_NOCHANGE) return node; - + if (node->valnode->type == QI_OPR) { if (node->valnode->operator.oper != ex->valnode->operator.oper) @@ -77,9 +77,8 @@ findeq(QTNode *node, QTNode *ex, QTNode *subs, bool *isfind) { /* * AND and NOT are commutative, so we check if a subset of the - * children match. For example, if tnode is A | B | C, and - * ex is B | C, we have a match after we convert tnode to - * A | (B | C). + * children match. For example, if tnode is A | B | C, and ex is B + * | C, we have a match after we convert tnode to A | (B | C). */ int *counters = (int *) palloc(sizeof(int) * node->nchild); int i; @@ -149,7 +148,7 @@ findeq(QTNode *node, QTNode *ex, QTNode *subs, bool *isfind) pfree(counters); } } - else + else { Assert(node->valnode->type == QI_VAL); @@ -175,7 +174,7 @@ findeq(QTNode *node, QTNode *ex, QTNode *subs, bool *isfind) } static QTNode * -dofindsubquery(QTNode *root, QTNode *ex, QTNode *subs, bool *isfind) +dofindsubquery(QTNode * root, QTNode * ex, QTNode * subs, bool *isfind) { /* since this function recurses, it could be driven to stack overflow. */ check_stack_depth(); @@ -234,7 +233,7 @@ dropvoidsubtree(QTNode * root) } QTNode * -findsubquery(QTNode *root, QTNode *ex, QTNode *subs, bool *isfind) +findsubquery(QTNode * root, QTNode * ex, QTNode * subs, bool *isfind) { bool DidFind = false; diff --git a/src/backend/utils/adt/tsquery_util.c b/src/backend/utils/adt/tsquery_util.c index 0756192002..8d13db8c98 100644 --- a/src/backend/utils/adt/tsquery_util.c +++ b/src/backend/utils/adt/tsquery_util.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_util.c,v 1.5 2007/10/23 01:44:39 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_util.c,v 1.6 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -91,13 +91,13 @@ QTNodeCompare(QTNode * an, QTNode * bn) if (an->valnode->type != bn->valnode->type) return (an->valnode->type > bn->valnode->type) ? -1 : 1; - + if (an->valnode->type == QI_OPR) { QueryOperator *ao = &an->valnode->operator; QueryOperator *bo = &bn->valnode->operator; - if(ao->oper != bo->oper) + if (ao->oper != bo->oper) return (ao->oper > bo->oper) ? -1 : 1; if (an->nchild != bn->nchild) @@ -169,9 +169,9 @@ QTNEq(QTNode * a, QTNode * b) /* * Remove unnecessary intermediate nodes. For example: * - * OR OR - * a OR -> a b c - * b c + * OR OR + * a OR -> a b c + * b c */ void QTNTernary(QTNode * in) @@ -205,7 +205,7 @@ QTNTernary(QTNode * in) memcpy(in->child + i, cc->child, cc->nchild * sizeof(QTNode *)); i += cc->nchild - 1; - if(cc->flags & QTN_NEEDFREE) + if (cc->flags & QTN_NEEDFREE) pfree(cc->valnode); pfree(cc); } @@ -285,10 +285,10 @@ typedef struct QueryItem *curitem; char *operand; char *curoperand; -} QTN2QTState; +} QTN2QTState; static void -fillQT(QTN2QTState *state, QTNode *in) +fillQT(QTN2QTState * state, QTNode * in) { /* since this function recurses, it could be driven to stack overflow. */ check_stack_depth(); @@ -325,7 +325,7 @@ fillQT(QTN2QTState *state, QTNode *in) } TSQuery -QTN2QT(QTNode *in) +QTN2QT(QTNode * in) { TSQuery out; int len; @@ -348,7 +348,7 @@ QTN2QT(QTNode *in) } QTNode * -QTNCopy(QTNode *in) +QTNCopy(QTNode * in) { QTNode *out; @@ -383,7 +383,7 @@ QTNCopy(QTNode *in) } void -QTNClearFlags(QTNode *in, uint32 flags) +QTNClearFlags(QTNode * in, uint32 flags) { /* since this function recurses, it could be driven to stack overflow. */ check_stack_depth(); diff --git a/src/backend/utils/adt/tsrank.c b/src/backend/utils/adt/tsrank.c index 297724710f..a918ee3d3c 100644 --- a/src/backend/utils/adt/tsrank.c +++ b/src/backend/utils/adt/tsrank.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/tsrank.c,v 1.9 2007/11/14 23:43:27 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/tsrank.c,v 1.10 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -58,7 +58,7 @@ cnt_length(TSVector t) while (ptr < end) { - int clen = POSDATALEN(t, ptr); + int clen = POSDATALEN(t, ptr); if (clen == 0) len += 1; @@ -72,7 +72,7 @@ cnt_length(TSVector t) } static int -WordECompareQueryItem(char *eval, char *qval, WordEntry *ptr, QueryOperand *item) +WordECompareQueryItem(char *eval, char *qval, WordEntry * ptr, QueryOperand * item) { if (ptr->len == item->length) return strncmp( @@ -88,7 +88,7 @@ WordECompareQueryItem(char *eval, char *qval, WordEntry *ptr, QueryOperand *item * is the TSQuery containing 'item'. Returns NULL if not found. */ static WordEntry * -find_wordentry(TSVector t, TSQuery q, QueryOperand *item) +find_wordentry(TSVector t, TSQuery q, QueryOperand * item) { WordEntry *StopLow = ARRPTR(t); WordEntry *StopHigh = (WordEntry *) STRPTR(t); @@ -141,8 +141,8 @@ compareQueryOperand(const void *a, const void *b, void *arg) static QueryOperand ** SortAndUniqItems(TSQuery q, int *size) { - char *operand = GETOPERAND(q); - QueryItem * item = GETQUERY(q); + char *operand = GETOPERAND(q); + QueryItem *item = GETQUERY(q); QueryOperand **res, **ptr, **prevptr; @@ -186,14 +186,14 @@ SortAndUniqItems(TSQuery q, int *size) /* A dummy WordEntryPos array to use when haspos is false */ static WordEntryPosVector POSNULL = { - 1, /* Number of elements that follow */ - { 0 } + 1, /* Number of elements that follow */ + {0} }; static float calc_rank_and(float *w, TSVector t, TSQuery q) { - WordEntryPosVector **pos; + WordEntryPosVector **pos; int i, k, l, @@ -469,7 +469,7 @@ typedef struct int16 nitem; uint8 wclass; int32 pos; -} DocRepresentation; +} DocRepresentation; static int compareDocR(const void *va, const void *vb) @@ -482,19 +482,20 @@ compareDocR(const void *va, const void *vb) return (a->pos > b->pos) ? 1 : -1; } -typedef struct +typedef struct { TSQuery query; bool *operandexist; -} QueryRepresentation; +} QueryRepresentation; -#define QR_GET_OPERAND_EXISTS(q, v) ( (q)->operandexist[ ((QueryItem*)(v)) - GETQUERY((q)->query) ] ) -#define QR_SET_OPERAND_EXISTS(q, v) QR_GET_OPERAND_EXISTS(q,v) = true +#define QR_GET_OPERAND_EXISTS(q, v) ( (q)->operandexist[ ((QueryItem*)(v)) - GETQUERY((q)->query) ] ) +#define QR_SET_OPERAND_EXISTS(q, v) QR_GET_OPERAND_EXISTS(q,v) = true static bool -checkcondition_QueryOperand(void *checkval, QueryOperand *val) +checkcondition_QueryOperand(void *checkval, QueryOperand * val) { - QueryRepresentation *qr = (QueryRepresentation*)checkval; + QueryRepresentation *qr = (QueryRepresentation *) checkval; + return QR_GET_OPERAND_EXISTS(qr, val); } @@ -505,22 +506,24 @@ typedef struct int q; DocRepresentation *begin; DocRepresentation *end; -} Extention; +} Extention; static bool -Cover(DocRepresentation *doc, int len, QueryRepresentation *qr, Extention *ext) +Cover(DocRepresentation * doc, int len, QueryRepresentation * qr, Extention * ext) { DocRepresentation *ptr; int lastpos = ext->pos; int i; bool found = false; - /* since this function recurses, it could be driven to stack overflow. - * (though any decent compiler will optimize away the tail-recursion. */ + /* + * since this function recurses, it could be driven to stack overflow. + * (though any decent compiler will optimize away the tail-recursion. + */ check_stack_depth(); - memset( qr->operandexist, 0, sizeof(bool)*qr->query->size ); + memset(qr->operandexist, 0, sizeof(bool) * qr->query->size); ext->p = 0x7fffffff; ext->q = 0; @@ -531,10 +534,10 @@ Cover(DocRepresentation *doc, int len, QueryRepresentation *qr, Extention *ext) { for (i = 0; i < ptr->nitem; i++) { - if(ptr->item[i]->type == QI_VAL) + if (ptr->item[i]->type == QI_VAL) QR_SET_OPERAND_EXISTS(qr, ptr->item[i]); } - if (TS_execute(GETQUERY(qr->query), (void*)qr, false, checkcondition_QueryOperand)) + if (TS_execute(GETQUERY(qr->query), (void *) qr, false, checkcondition_QueryOperand)) { if (ptr->pos > ext->q) { @@ -551,7 +554,7 @@ Cover(DocRepresentation *doc, int len, QueryRepresentation *qr, Extention *ext) if (!found) return false; - memset( qr->operandexist, 0, sizeof(bool)*qr->query->size ); + memset(qr->operandexist, 0, sizeof(bool) * qr->query->size); ptr = doc + lastpos; @@ -559,9 +562,9 @@ Cover(DocRepresentation *doc, int len, QueryRepresentation *qr, Extention *ext) while (ptr >= doc + ext->pos) { for (i = 0; i < ptr->nitem; i++) - if(ptr->item[i]->type == QI_VAL) + if (ptr->item[i]->type == QI_VAL) QR_SET_OPERAND_EXISTS(qr, ptr->item[i]); - if (TS_execute(GETQUERY(qr->query), (void*)qr, true, checkcondition_QueryOperand)) + if (TS_execute(GETQUERY(qr->query), (void *) qr, true, checkcondition_QueryOperand)) { if (ptr->pos < ext->p) { @@ -588,7 +591,7 @@ Cover(DocRepresentation *doc, int len, QueryRepresentation *qr, Extention *ext) } static DocRepresentation * -get_docrep(TSVector txt, QueryRepresentation *qr, int *doclen) +get_docrep(TSVector txt, QueryRepresentation * qr, int *doclen) { QueryItem *item = GETQUERY(qr->query); WordEntry *entry; @@ -610,10 +613,10 @@ get_docrep(TSVector txt, QueryRepresentation *qr, int *doclen) if (item[i].type != QI_VAL) continue; - + curoperand = &item[i].operand; - - if(QR_GET_OPERAND_EXISTS(qr, &item[i])) + + if (QR_GET_OPERAND_EXISTS(qr, &item[i])) continue; entry = find_wordentry(txt, qr->query, curoperand); @@ -655,10 +658,13 @@ get_docrep(TSVector txt, QueryRepresentation *qr, int *doclen) (item[k].type == QI_VAL && compareQueryOperand(&kptr, &iptr, operand) == 0)) { - /* if k == i, we've already checked above that it's type == Q_VAL */ + /* + * if k == i, we've already checked above that it's + * type == Q_VAL + */ doc[cur].item[doc[cur].nitem] = item + k; doc[cur].nitem++; - QR_SET_OPERAND_EXISTS( qr, item+k ); + QR_SET_OPERAND_EXISTS(qr, item + k); } } } @@ -699,7 +705,7 @@ calc_rank_cd(float4 *arrdata, TSVector txt, TSQuery query, int method) PrevExtPos = 0.0, CurExtPos = 0.0; int NExtent = 0; - QueryRepresentation qr; + QueryRepresentation qr; for (i = 0; i < lengthof(weights); i++) @@ -713,12 +719,12 @@ calc_rank_cd(float4 *arrdata, TSVector txt, TSQuery query, int method) } qr.query = query; - qr.operandexist = (bool*)palloc0(sizeof(bool) * query->size); + qr.operandexist = (bool *) palloc0(sizeof(bool) * query->size); doc = get_docrep(txt, &qr, &doclen); if (!doc) { - pfree( qr.operandexist ); + pfree(qr.operandexist); return 0.0; } @@ -782,7 +788,7 @@ calc_rank_cd(float4 *arrdata, TSVector txt, TSQuery query, int method) pfree(doc); - pfree( qr.operandexist ); + pfree(qr.operandexist); return (float4) Wdoc; } diff --git a/src/backend/utils/adt/tsvector.c b/src/backend/utils/adt/tsvector.c index cb90274943..7977214b49 100644 --- a/src/backend/utils/adt/tsvector.c +++ b/src/backend/utils/adt/tsvector.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/tsvector.c,v 1.6 2007/10/23 00:51:23 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/tsvector.c,v 1.7 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -25,15 +25,15 @@ typedef struct WordEntry entry; /* must be first! */ WordEntryPos *pos; int poslen; /* number of elements in pos */ -} WordEntryIN; +} WordEntryIN; /* Compare two WordEntryPos values for qsort */ static int comparePos(const void *a, const void *b) { - int apos = WEP_GETPOS(*(const WordEntryPos *) a); - int bpos = WEP_GETPOS(*(const WordEntryPos *) b); + int apos = WEP_GETPOS(*(const WordEntryPos *) a); + int bpos = WEP_GETPOS(*(const WordEntryPos *) b); if (apos == bpos) return 0; @@ -102,7 +102,7 @@ compareentry(const void *va, const void *vb, void *arg) static int uniqueentry(WordEntryIN * a, int l, char *buf, int *outbuflen) { - int buflen; + int buflen; WordEntryIN *ptr, *res; @@ -137,7 +137,7 @@ uniqueentry(WordEntryIN * a, int l, char *buf, int *outbuflen) if (res->entry.haspos) { /* append ptr's positions to res's positions */ - int newlen = ptr->poslen + res->poslen; + int newlen = ptr->poslen + res->poslen; res->pos = (WordEntryPos *) repalloc(res->pos, newlen * sizeof(WordEntryPos)); @@ -184,7 +184,7 @@ tsvectorin(PG_FUNCTION_ARGS) TSVectorParseState state; WordEntryIN *arr; int totallen; - int arrlen; /* allocated size of arr */ + int arrlen; /* allocated size of arr */ WordEntry *inarr; int len = 0; TSVector in; @@ -197,17 +197,17 @@ tsvectorin(PG_FUNCTION_ARGS) int stroff; /* - * Tokens are appended to tmpbuf, cur is a pointer - * to the end of used space in tmpbuf. + * Tokens are appended to tmpbuf, cur is a pointer to the end of used + * space in tmpbuf. */ char *tmpbuf; char *cur; - int buflen = 256; /* allocated size of tmpbuf */ + int buflen = 256; /* allocated size of tmpbuf */ pg_verifymbstr(buf, strlen(buf), false); state = init_tsvector_parser(buf, false, false); - + arrlen = 64; arr = (WordEntryIN *) palloc(sizeof(WordEntryIN) * arrlen); cur = tmpbuf = (char *) palloc(buflen); @@ -219,7 +219,7 @@ tsvectorin(PG_FUNCTION_ARGS) (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("word is too long (%ld bytes, max %ld bytes)", (long) toklen, - (long) (MAXSTRLEN-1)))); + (long) (MAXSTRLEN - 1)))); if (cur - tmpbuf > MAXSTRPOS) ereport(ERROR, @@ -237,7 +237,7 @@ tsvectorin(PG_FUNCTION_ARGS) } while ((cur - tmpbuf) + toklen >= buflen) { - int dist = cur - tmpbuf; + int dist = cur - tmpbuf; buflen *= 2; tmpbuf = (char *) repalloc((void *) tmpbuf, buflen); @@ -394,11 +394,11 @@ tsvectorout(PG_FUNCTION_ARGS) * Binary Input / Output functions. The binary format is as follows: * * uint32 number of lexemes - * + * * for each lexeme: * lexeme text in client encoding, null-terminated - * uint16 number of positions - * for each position: + * uint16 number of positions + * for each position: * uint16 WordEntryPos */ @@ -416,10 +416,11 @@ tsvectorsend(PG_FUNCTION_ARGS) pq_sendint(&buf, vec->size, sizeof(int32)); for (i = 0; i < vec->size; i++) { - uint16 npos; + uint16 npos; - /* the strings in the TSVector array are not null-terminated, so - * we have to send the null-terminator separately + /* + * the strings in the TSVector array are not null-terminated, so we + * have to send the null-terminator separately */ pq_sendtext(&buf, STRPTR(vec) + weptr->pos, weptr->len); pq_sendbyte(&buf, '\0'); @@ -427,7 +428,7 @@ tsvectorsend(PG_FUNCTION_ARGS) npos = POSDATALEN(vec, weptr); pq_sendint(&buf, npos, sizeof(uint16)); - if(npos > 0) + if (npos > 0) { WordEntryPos *wepptr = POSDATAPTR(vec, weptr); @@ -447,11 +448,11 @@ tsvectorrecv(PG_FUNCTION_ARGS) TSVector vec; int i; int32 nentries; - int datalen; /* number of bytes used in the variable size area - * after fixed size TSVector header and WordEntries - */ + int datalen; /* number of bytes used in the variable size + * area after fixed size TSVector header and + * WordEntries */ Size hdrlen; - Size len; /* allocated size of vec */ + Size len; /* allocated size of vec */ nentries = pq_getmsgint(buf, sizeof(int32)); if (nentries < 0 || nentries > (MaxAllocSize / sizeof(WordEntry))) @@ -459,7 +460,7 @@ tsvectorrecv(PG_FUNCTION_ARGS) hdrlen = DATAHDRSIZE + sizeof(WordEntry) * nentries; - len = hdrlen * 2; /* times two to make room for lexemes */ + len = hdrlen * 2; /* times two to make room for lexemes */ vec = (TSVector) palloc0(len); vec->size = nentries; @@ -467,8 +468,8 @@ tsvectorrecv(PG_FUNCTION_ARGS) for (i = 0; i < nentries; i++) { const char *lexeme; - uint16 npos; - size_t lex_len; + uint16 npos; + size_t lex_len; lexeme = pq_getmsgstring(buf); npos = (uint16) pq_getmsgint(buf, sizeof(uint16)); @@ -480,7 +481,7 @@ tsvectorrecv(PG_FUNCTION_ARGS) elog(ERROR, "invalid tsvector; lexeme too long"); if (datalen > MAXSTRPOS) - elog(ERROR, "invalid tsvector; maximum total lexeme length exceeded"); + elog(ERROR, "invalid tsvector; maximum total lexeme length exceeded"); if (npos > MAXNUMPOS) elog(ERROR, "unexpected number of positions"); @@ -518,8 +519,8 @@ tsvectorrecv(PG_FUNCTION_ARGS) /* * Pad to 2-byte alignment if necessary. Though we used palloc0 - * for the initial allocation, subsequent repalloc'd memory - * areas are not initialized to zero. + * for the initial allocation, subsequent repalloc'd memory areas + * are not initialized to zero. */ if (datalen != SHORTALIGN(datalen)) { diff --git a/src/backend/utils/adt/tsvector_parser.c b/src/backend/utils/adt/tsvector_parser.c index 5ee8bb7842..d1d4a79295 100644 --- a/src/backend/utils/adt/tsvector_parser.c +++ b/src/backend/utils/adt/tsvector_parser.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_parser.c,v 1.2 2007/10/21 22:29:56 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_parser.c,v 1.3 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -29,13 +29,13 @@ */ struct TSVectorParseStateData { - char *prsbuf; /* next input character */ - char *bufstart; /* whole string (used only for errors) */ - char *word; /* buffer to hold the current word */ - int len; /* size in bytes allocated for 'word' */ - int eml; /* max bytes per character */ - bool oprisdelim; /* treat ! | * ( ) as delimiters? */ - bool is_tsquery; /* say "tsquery" not "tsvector" in errors? */ + char *prsbuf; /* next input character */ + char *bufstart; /* whole string (used only for errors) */ + char *word; /* buffer to hold the current word */ + int len; /* size in bytes allocated for 'word' */ + int eml; /* max bytes per character */ + bool oprisdelim; /* treat ! | * ( ) as delimiters? */ + bool is_tsquery; /* say "tsquery" not "tsvector" in errors? */ }; @@ -67,7 +67,7 @@ init_tsvector_parser(char *input, bool oprisdelim, bool is_tsquery) void reset_tsvector_parser(TSVectorParseState state, char *input) { - state->prsbuf = input; + state->prsbuf = input; } /* @@ -142,11 +142,11 @@ prssyntaxerror(TSVectorParseState state) * Get next token from string being parsed. Returns true if successful, * false if end of input string is reached. On success, these output * parameters are filled in: - * - * *strval pointer to token - * *lenval length of *strval + * + * *strval pointer to token + * *lenval length of *strval * *pos_ptr pointer to a palloc'd array of positions and weights - * associated with the token. If the caller is not interested + * associated with the token. If the caller is not interested * in the information, NULL can be supplied. Otherwise * the caller is responsible for pfreeing the array. * *poslen number of elements in *pos_ptr @@ -155,21 +155,22 @@ prssyntaxerror(TSVectorParseState state) * Pass NULL for unwanted output parameters. */ bool -gettoken_tsvector(TSVectorParseState state, +gettoken_tsvector(TSVectorParseState state, char **strval, int *lenval, - WordEntryPos **pos_ptr, int *poslen, + WordEntryPos ** pos_ptr, int *poslen, char **endptr) { - int oldstate = 0; - char *curpos = state->word; - int statecode = WAITWORD; + int oldstate = 0; + char *curpos = state->word; + int statecode = WAITWORD; - /* pos is for collecting the comma delimited list of positions followed - * by the actual token. + /* + * pos is for collecting the comma delimited list of positions followed by + * the actual token. */ WordEntryPos *pos = NULL; - int npos = 0; /* elements of pos used */ - int posalen = 0; /* allocated size of pos */ + int npos = 0; /* elements of pos used */ + int posalen = 0; /* allocated size of pos */ while (1) { @@ -357,7 +358,7 @@ gettoken_tsvector(TSVectorParseState state, else if (!t_isdigit(state->prsbuf)) PRSSYNTAXERROR; } - else /* internal error */ + else /* internal error */ elog(ERROR, "internal error in gettoken_tsvector"); /* get next char */ diff --git a/src/backend/utils/adt/txid.c b/src/backend/utils/adt/txid.c index f4267dfbdb..4fc2276ece 100644 --- a/src/backend/utils/adt/txid.c +++ b/src/backend/utils/adt/txid.c @@ -14,7 +14,7 @@ * Author: Jan Wieck, Afilias USA INC. * 64-bit txids: Marko Kreen, Skype Technologies * - * $PostgreSQL: pgsql/src/backend/utils/adt/txid.c,v 1.1 2007/10/13 23:06:26 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/txid.c,v 1.2 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -57,16 +57,15 @@ typedef struct /* * 4-byte length hdr, should not be touched directly. * - * Explicit embedding is ok as we want always correct - * alignment anyway. + * Explicit embedding is ok as we want always correct alignment anyway. */ - int32 __varsz; - - uint32 nxip; /* number of txids in xip array */ - txid xmin; - txid xmax; - txid xip[1]; /* in-progress txids, xmin <= xip[i] < xmax */ -} TxidSnapshot; + int32 __varsz; + + uint32 nxip; /* number of txids in xip array */ + txid xmin; + txid xmax; + txid xip[1]; /* in-progress txids, xmin <= xip[i] < xmax */ +} TxidSnapshot; #define TXID_SNAPSHOT_SIZE(nxip) \ (offsetof(TxidSnapshot, xip) + sizeof(txid) * (nxip)) @@ -76,8 +75,8 @@ typedef struct */ typedef struct { - TransactionId last_xid; - uint32 epoch; + TransactionId last_xid; + uint32 epoch; } TxidEpoch; @@ -85,7 +84,7 @@ typedef struct * Fetch epoch data from xact.c. */ static void -load_xid_epoch(TxidEpoch *state) +load_xid_epoch(TxidEpoch * state) { GetNextXidAndEpoch(&state->last_xid, &state->epoch); } @@ -94,10 +93,10 @@ load_xid_epoch(TxidEpoch *state) * do a TransactionId -> txid conversion for an XID near the given epoch */ static txid -convert_xid(TransactionId xid, const TxidEpoch *state) +convert_xid(TransactionId xid, const TxidEpoch * state) { #ifndef INT64_IS_BUSTED - uint64 epoch; + uint64 epoch; /* return special xid's as-is */ if (!TransactionIdIsNormal(xid)) @@ -113,10 +112,10 @@ convert_xid(TransactionId xid, const TxidEpoch *state) epoch++; return (epoch << 32) | xid; -#else /* INT64_IS_BUSTED */ +#else /* INT64_IS_BUSTED */ /* we can't do anything with the epoch, so ignore it */ return (txid) xid & MAX_TXID; -#endif /* INT64_IS_BUSTED */ +#endif /* INT64_IS_BUSTED */ } /* @@ -125,8 +124,8 @@ convert_xid(TransactionId xid, const TxidEpoch *state) static int cmp_txid(const void *aa, const void *bb) { - txid a = *(const txid *) aa; - txid b = *(const txid *) bb; + txid a = *(const txid *) aa; + txid b = *(const txid *) bb; if (a < b) return -1; @@ -142,7 +141,7 @@ cmp_txid(const void *aa, const void *bb) * will not be used. */ static void -sort_snapshot(TxidSnapshot *snap) +sort_snapshot(TxidSnapshot * snap) { if (snap->nxip > 1) qsort(snap->xip, snap->nxip, sizeof(txid), cmp_txid); @@ -152,7 +151,7 @@ sort_snapshot(TxidSnapshot *snap) * check txid visibility. */ static bool -is_visible_txid(txid value, const TxidSnapshot *snap) +is_visible_txid(txid value, const TxidSnapshot * snap) { if (value < snap->xmin) return true; @@ -161,7 +160,7 @@ is_visible_txid(txid value, const TxidSnapshot *snap) #ifdef USE_BSEARCH_IF_NXIP_GREATER else if (snap->nxip > USE_BSEARCH_IF_NXIP_GREATER) { - void *res; + void *res; res = bsearch(&value, snap->xip, snap->nxip, sizeof(txid), cmp_txid); /* if found, transaction is still in progress */ @@ -170,7 +169,7 @@ is_visible_txid(txid value, const TxidSnapshot *snap) #endif else { - uint32 i; + uint32 i; for (i = 0; i < snap->nxip; i++) { @@ -189,32 +188,32 @@ static StringInfo buf_init(txid xmin, txid xmax) { TxidSnapshot snap; - StringInfo buf; + StringInfo buf; snap.xmin = xmin; snap.xmax = xmax; snap.nxip = 0; buf = makeStringInfo(); - appendBinaryStringInfo(buf, (char *)&snap, TXID_SNAPSHOT_SIZE(0)); + appendBinaryStringInfo(buf, (char *) &snap, TXID_SNAPSHOT_SIZE(0)); return buf; } static void buf_add_txid(StringInfo buf, txid xid) { - TxidSnapshot *snap = (TxidSnapshot *)buf->data; + TxidSnapshot *snap = (TxidSnapshot *) buf->data; /* do this before possible realloc */ snap->nxip++; - appendBinaryStringInfo(buf, (char *)&xid, sizeof(xid)); + appendBinaryStringInfo(buf, (char *) &xid, sizeof(xid)); } static TxidSnapshot * buf_finalize(StringInfo buf) { - TxidSnapshot *snap = (TxidSnapshot *)buf->data; + TxidSnapshot *snap = (TxidSnapshot *) buf->data; SET_VARSIZE(snap, buf->len); @@ -233,13 +232,13 @@ buf_finalize(StringInfo buf) static txid str2txid(const char *s, const char **endp) { - txid val = 0; - txid cutoff = MAX_TXID / 10; - txid cutlim = MAX_TXID % 10; + txid val = 0; + txid cutoff = MAX_TXID / 10; + txid cutlim = MAX_TXID % 10; for (; *s; s++) { - unsigned d; + unsigned d; if (*s < '0' || *s > '9') break; @@ -269,10 +268,11 @@ parse_snapshot(const char *str) { txid xmin; txid xmax; - txid last_val = 0, val; + txid last_val = 0, + val; const char *str_start = str; const char *endp; - StringInfo buf; + StringInfo buf; xmin = str2txid(str, &endp); if (*endp != ':') @@ -301,7 +301,7 @@ parse_snapshot(const char *str) /* require the input to be in order */ if (val < xmin || val >= xmax || val <= last_val) goto bad_format; - + buf_add_txid(buf, val); last_val = val; @@ -334,8 +334,8 @@ bad_format: Datum txid_current(PG_FUNCTION_ARGS) { - txid val; - TxidEpoch state; + txid val; + TxidEpoch state; load_xid_epoch(&state); @@ -355,9 +355,11 @@ Datum txid_current_snapshot(PG_FUNCTION_ARGS) { TxidSnapshot *snap; - uint32 nxip, i, size; - TxidEpoch state; - Snapshot cur; + uint32 nxip, + i, + size; + TxidEpoch state; + Snapshot cur; cur = ActiveSnapshot; if (cur == NULL) @@ -408,9 +410,9 @@ txid_snapshot_in(PG_FUNCTION_ARGS) Datum txid_snapshot_out(PG_FUNCTION_ARGS) { - TxidSnapshot *snap = (TxidSnapshot *) PG_GETARG_VARLENA_P(0); - StringInfoData str; - uint32 i; + TxidSnapshot *snap = (TxidSnapshot *) PG_GETARG_VARLENA_P(0); + StringInfoData str; + uint32 i; initStringInfo(&str); @@ -437,14 +439,15 @@ txid_snapshot_out(PG_FUNCTION_ARGS) Datum txid_snapshot_recv(PG_FUNCTION_ARGS) { - StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); + StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); TxidSnapshot *snap; - txid last = 0; - int nxip; - int i; - int avail; - int expect; - txid xmin, xmax; + txid last = 0; + int nxip; + int i; + int avail; + int expect; + txid xmin, + xmax; /* * load nxip and check for nonsense. @@ -470,7 +473,8 @@ txid_snapshot_recv(PG_FUNCTION_ARGS) for (i = 0; i < nxip; i++) { - txid cur = pq_getmsgint64(buf); + txid cur = pq_getmsgint64(buf); + if (cur <= last || cur < xmin || cur >= xmax) goto bad_format; snap->xip[i] = cur; @@ -480,7 +484,7 @@ txid_snapshot_recv(PG_FUNCTION_ARGS) bad_format: elog(ERROR, "invalid snapshot data"); - return (Datum)NULL; + return (Datum) NULL; } /* @@ -493,9 +497,9 @@ bad_format: Datum txid_snapshot_send(PG_FUNCTION_ARGS) { - TxidSnapshot *snap = (TxidSnapshot *)PG_GETARG_VARLENA_P(0); + TxidSnapshot *snap = (TxidSnapshot *) PG_GETARG_VARLENA_P(0); StringInfoData buf; - uint32 i; + uint32 i; pq_begintypsend(&buf); pq_sendint(&buf, snap->nxip, 4); @@ -514,9 +518,9 @@ txid_snapshot_send(PG_FUNCTION_ARGS) Datum txid_visible_in_snapshot(PG_FUNCTION_ARGS) { - txid value = PG_GETARG_INT64(0); + txid value = PG_GETARG_INT64(0); TxidSnapshot *snap = (TxidSnapshot *) PG_GETARG_VARLENA_P(1); - + PG_RETURN_BOOL(is_visible_txid(value, snap)); } @@ -556,10 +560,11 @@ txid_snapshot_xip(PG_FUNCTION_ARGS) { FuncCallContext *fctx; TxidSnapshot *snap; - txid value; + txid value; /* on first call initialize snap_state and get copy of snapshot */ - if (SRF_IS_FIRSTCALL()) { + if (SRF_IS_FIRSTCALL()) + { TxidSnapshot *arg = (TxidSnapshot *) PG_GETARG_VARLENA_P(0); fctx = SRF_FIRSTCALL_INIT(); @@ -574,10 +579,13 @@ txid_snapshot_xip(PG_FUNCTION_ARGS) /* return values one-by-one */ fctx = SRF_PERCALL_SETUP(); snap = fctx->user_fctx; - if (fctx->call_cntr < snap->nxip) { + if (fctx->call_cntr < snap->nxip) + { value = snap->xip[fctx->call_cntr]; SRF_RETURN_NEXT(fctx, Int64GetDatum(value)); - } else { + } + else + { SRF_RETURN_DONE(fctx); } } diff --git a/src/backend/utils/adt/uuid.c b/src/backend/utils/adt/uuid.c index 24b05f3426..24ce92e751 100644 --- a/src/backend/utils/adt/uuid.c +++ b/src/backend/utils/adt/uuid.c @@ -6,7 +6,7 @@ * Copyright (c) 2007, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/uuid.c,v 1.4 2007/06/05 21:31:06 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/uuid.c,v 1.5 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -24,17 +24,17 @@ /* pg_uuid_t is declared to be struct pg_uuid_t in uuid.h */ struct pg_uuid_t { - unsigned char data[UUID_LEN]; + unsigned char data[UUID_LEN]; }; -static void string_to_uuid(const char *source, pg_uuid_t *uuid); -static int uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2); +static void string_to_uuid(const char *source, pg_uuid_t * uuid); +static int uuid_internal_cmp(const pg_uuid_t * arg1, const pg_uuid_t * arg2); Datum uuid_in(PG_FUNCTION_ARGS) { - char *uuid_str = PG_GETARG_CSTRING(0); - pg_uuid_t *uuid; + char *uuid_str = PG_GETARG_CSTRING(0); + pg_uuid_t *uuid; uuid = (pg_uuid_t *) palloc(sizeof(*uuid)); string_to_uuid(uuid_str, uuid); @@ -44,22 +44,21 @@ uuid_in(PG_FUNCTION_ARGS) Datum uuid_out(PG_FUNCTION_ARGS) { - pg_uuid_t *uuid = PG_GETARG_UUID_P(0); + pg_uuid_t *uuid = PG_GETARG_UUID_P(0); static const char hex_chars[] = "0123456789abcdef"; - StringInfoData buf; - int i; + StringInfoData buf; + int i; initStringInfo(&buf); for (i = 0; i < UUID_LEN; i++) { - int hi; - int lo; + int hi; + int lo; /* * We print uuid values as a string of 8, 4, 4, 4, and then 12 - * hexadecimal characters, with each group is separated by a - * hyphen ("-"). Therefore, add the hyphens at the appropriate - * places here. + * hexadecimal characters, with each group is separated by a hyphen + * ("-"). Therefore, add the hyphens at the appropriate places here. */ if (i == 4 || i == 6 || i == 8 || i == 10) appendStringInfoChar(&buf, '-'); @@ -81,11 +80,11 @@ uuid_out(PG_FUNCTION_ARGS) * two formats into the latter format before further processing. */ static void -string_to_uuid(const char *source, pg_uuid_t *uuid) +string_to_uuid(const char *source, pg_uuid_t * uuid) { - char hex_buf[32]; /* not NUL terminated */ - int i; - int src_len; + char hex_buf[32]; /* not NUL terminated */ + int i; + int src_len; src_len = strlen(source); if (src_len != 32 && src_len != 36 && src_len != 38) @@ -102,7 +101,7 @@ string_to_uuid(const char *source, pg_uuid_t *uuid) if (str[0] != '{' || str[37] != '}') goto syntax_error; - str++; /* skip the first character */ + str++; /* skip the first character */ } if (str[8] != '-' || str[13] != '-' || @@ -118,7 +117,7 @@ string_to_uuid(const char *source, pg_uuid_t *uuid) for (i = 0; i < UUID_LEN; i++) { - char str_buf[3]; + char str_buf[3]; memcpy(str_buf, &hex_buf[i * 2], 2); if (!isxdigit((unsigned char) str_buf[0]) || @@ -132,17 +131,17 @@ string_to_uuid(const char *source, pg_uuid_t *uuid) return; syntax_error: - ereport(ERROR, - (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), - errmsg("invalid input syntax for uuid: \"%s\"", - source))); + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + errmsg("invalid input syntax for uuid: \"%s\"", + source))); } Datum uuid_recv(PG_FUNCTION_ARGS) { - StringInfo buffer = (StringInfo) PG_GETARG_POINTER(0); - pg_uuid_t *uuid; + StringInfo buffer = (StringInfo) PG_GETARG_POINTER(0); + pg_uuid_t *uuid; uuid = (pg_uuid_t *) palloc(UUID_LEN); memcpy(uuid->data, pq_getmsgbytes(buffer, UUID_LEN), UUID_LEN); @@ -152,8 +151,8 @@ uuid_recv(PG_FUNCTION_ARGS) Datum uuid_send(PG_FUNCTION_ARGS) { - pg_uuid_t *uuid = PG_GETARG_UUID_P(0); - StringInfoData buffer; + pg_uuid_t *uuid = PG_GETARG_UUID_P(0); + StringInfoData buffer; pq_begintypsend(&buffer); pq_sendbytes(&buffer, (char *) uuid->data, UUID_LEN); @@ -162,7 +161,7 @@ uuid_send(PG_FUNCTION_ARGS) /* internal uuid compare function */ static int -uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2) +uuid_internal_cmp(const pg_uuid_t * arg1, const pg_uuid_t * arg2) { return memcmp(arg1->data, arg2->data, UUID_LEN); } @@ -170,8 +169,8 @@ uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2) Datum uuid_lt(PG_FUNCTION_ARGS) { - pg_uuid_t *arg1 = PG_GETARG_UUID_P(0); - pg_uuid_t *arg2 = PG_GETARG_UUID_P(1); + pg_uuid_t *arg1 = PG_GETARG_UUID_P(0); + pg_uuid_t *arg2 = PG_GETARG_UUID_P(1); PG_RETURN_BOOL(uuid_internal_cmp(arg1, arg2) < 0); } @@ -179,8 +178,8 @@ uuid_lt(PG_FUNCTION_ARGS) Datum uuid_le(PG_FUNCTION_ARGS) { - pg_uuid_t *arg1 = PG_GETARG_UUID_P(0); - pg_uuid_t *arg2 = PG_GETARG_UUID_P(1); + pg_uuid_t *arg1 = PG_GETARG_UUID_P(0); + pg_uuid_t *arg2 = PG_GETARG_UUID_P(1); PG_RETURN_BOOL(uuid_internal_cmp(arg1, arg2) <= 0); } @@ -188,8 +187,8 @@ uuid_le(PG_FUNCTION_ARGS) Datum uuid_eq(PG_FUNCTION_ARGS) { - pg_uuid_t *arg1 = PG_GETARG_UUID_P(0); - pg_uuid_t *arg2 = PG_GETARG_UUID_P(1); + pg_uuid_t *arg1 = PG_GETARG_UUID_P(0); + pg_uuid_t *arg2 = PG_GETARG_UUID_P(1); PG_RETURN_BOOL(uuid_internal_cmp(arg1, arg2) == 0); } @@ -197,8 +196,8 @@ uuid_eq(PG_FUNCTION_ARGS) Datum uuid_ge(PG_FUNCTION_ARGS) { - pg_uuid_t *arg1 = PG_GETARG_UUID_P(0); - pg_uuid_t *arg2 = PG_GETARG_UUID_P(1); + pg_uuid_t *arg1 = PG_GETARG_UUID_P(0); + pg_uuid_t *arg2 = PG_GETARG_UUID_P(1); PG_RETURN_BOOL(uuid_internal_cmp(arg1, arg2) >= 0); } @@ -206,8 +205,8 @@ uuid_ge(PG_FUNCTION_ARGS) Datum uuid_gt(PG_FUNCTION_ARGS) { - pg_uuid_t *arg1 = PG_GETARG_UUID_P(0); - pg_uuid_t *arg2 = PG_GETARG_UUID_P(1); + pg_uuid_t *arg1 = PG_GETARG_UUID_P(0); + pg_uuid_t *arg2 = PG_GETARG_UUID_P(1); PG_RETURN_BOOL(uuid_internal_cmp(arg1, arg2) > 0); } @@ -215,8 +214,8 @@ uuid_gt(PG_FUNCTION_ARGS) Datum uuid_ne(PG_FUNCTION_ARGS) { - pg_uuid_t *arg1 = PG_GETARG_UUID_P(0); - pg_uuid_t *arg2 = PG_GETARG_UUID_P(1); + pg_uuid_t *arg1 = PG_GETARG_UUID_P(0); + pg_uuid_t *arg2 = PG_GETARG_UUID_P(1); PG_RETURN_BOOL(uuid_internal_cmp(arg1, arg2) != 0); } @@ -225,8 +224,8 @@ uuid_ne(PG_FUNCTION_ARGS) Datum uuid_cmp(PG_FUNCTION_ARGS) { - pg_uuid_t *arg1 = PG_GETARG_UUID_P(0); - pg_uuid_t *arg2 = PG_GETARG_UUID_P(1); + pg_uuid_t *arg1 = PG_GETARG_UUID_P(0); + pg_uuid_t *arg2 = PG_GETARG_UUID_P(1); PG_RETURN_INT32(uuid_internal_cmp(arg1, arg2)); } @@ -235,6 +234,7 @@ uuid_cmp(PG_FUNCTION_ARGS) Datum uuid_hash(PG_FUNCTION_ARGS) { - pg_uuid_t *key = PG_GETARG_UUID_P(0); + pg_uuid_t *key = PG_GETARG_UUID_P(0); + return hash_any(key->data, UUID_LEN); } diff --git a/src/backend/utils/adt/varbit.c b/src/backend/utils/adt/varbit.c index b6ab6bb1e7..6d5b5a0c16 100644 --- a/src/backend/utils/adt/varbit.c +++ b/src/backend/utils/adt/varbit.c @@ -9,7 +9,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/varbit.c,v 1.55 2007/08/21 02:40:06 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/varbit.c,v 1.56 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -28,9 +28,9 @@ static int32 anybit_typmodin(ArrayType *ta, const char *typename) { - int32 typmod; - int32 *tl; - int n; + int32 typmod; + int32 *tl; + int n; tl = ArrayGetIntegerTypmods(ta, &n); @@ -63,7 +63,7 @@ anybit_typmodin(ArrayType *ta, const char *typename) static char * anybit_typmodout(int32 typmod) { - char *res = (char *) palloc(64); + char *res = (char *) palloc(64); if (typmod >= 0) snprintf(res, 64, "(%d)", typmod); @@ -380,7 +380,7 @@ bit(PG_FUNCTION_ARGS) Datum bittypmodin(PG_FUNCTION_ARGS) { - ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); + ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); PG_RETURN_INT32(anybit_typmodin(ta, "bit")); } @@ -388,7 +388,7 @@ bittypmodin(PG_FUNCTION_ARGS) Datum bittypmodout(PG_FUNCTION_ARGS) { - int32 typmod = PG_GETARG_INT32(0); + int32 typmod = PG_GETARG_INT32(0); PG_RETURN_CSTRING(anybit_typmodout(typmod)); } @@ -680,7 +680,7 @@ varbit(PG_FUNCTION_ARGS) Datum varbittypmodin(PG_FUNCTION_ARGS) { - ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); + ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); PG_RETURN_INT32(anybit_typmodin(ta, "varbit")); } @@ -688,7 +688,7 @@ varbittypmodin(PG_FUNCTION_ARGS) Datum varbittypmodout(PG_FUNCTION_ARGS) { - int32 typmod = PG_GETARG_INT32(0); + int32 typmod = PG_GETARG_INT32(0); PG_RETURN_CSTRING(anybit_typmodout(typmod)); } diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c index 43315dd9eb..2682dea8bc 100644 --- a/src/backend/utils/adt/varchar.c +++ b/src/backend/utils/adt/varchar.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/varchar.c,v 1.124 2007/06/15 20:56:51 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/varchar.c,v 1.125 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -27,9 +27,9 @@ static int32 anychar_typmodin(ArrayType *ta, const char *typename) { - int32 typmod; - int32 *tl; - int n; + int32 typmod; + int32 *tl; + int n; tl = ArrayGetIntegerTypmods(ta, &n); @@ -53,9 +53,9 @@ anychar_typmodin(ArrayType *ta, const char *typename) typename, MaxAttrSize))); /* - * For largely historical reasons, the typmod is VARHDRSZ plus the - * number of characters; there is enough client-side code that knows - * about that that we'd better not change it. + * For largely historical reasons, the typmod is VARHDRSZ plus the number + * of characters; there is enough client-side code that knows about that + * that we'd better not change it. */ typmod = VARHDRSZ + *tl; @@ -66,7 +66,7 @@ anychar_typmodin(ArrayType *ta, const char *typename) static char * anychar_typmodout(int32 typmod) { - char *res = (char *) palloc(64); + char *res = (char *) palloc(64); if (typmod > VARHDRSZ) snprintf(res, 64, "(%d)", (int) (typmod - VARHDRSZ)); @@ -314,24 +314,24 @@ bpchar(PG_FUNCTION_ARGS) len = maxmblen; /* - * At this point, maxlen is the necessary byte length, - * not the number of CHARACTERS! + * At this point, maxlen is the necessary byte length, not the number + * of CHARACTERS! */ maxlen = len; } else { /* - * At this point, maxlen is the necessary byte length, - * not the number of CHARACTERS! + * At this point, maxlen is the necessary byte length, not the number + * of CHARACTERS! */ maxlen = len + (maxlen - charlen); } Assert(maxlen >= len); - result = palloc(maxlen+VARHDRSZ); - SET_VARSIZE(result, maxlen+VARHDRSZ); + result = palloc(maxlen + VARHDRSZ); + SET_VARSIZE(result, maxlen + VARHDRSZ); r = VARDATA(result); memcpy(r, s, len); @@ -369,7 +369,7 @@ Datum bpchar_name(PG_FUNCTION_ARGS) { BpChar *s = PG_GETARG_BPCHAR_PP(0); - char *s_data; + char *s_data; Name result; int len; @@ -422,7 +422,7 @@ name_bpchar(PG_FUNCTION_ARGS) Datum bpchartypmodin(PG_FUNCTION_ARGS) { - ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); + ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); PG_RETURN_INT32(anychar_typmodin(ta, "char")); } @@ -430,7 +430,7 @@ bpchartypmodin(PG_FUNCTION_ARGS) Datum bpchartypmodout(PG_FUNCTION_ARGS) { - int32 typmod = PG_GETARG_INT32(0); + int32 typmod = PG_GETARG_INT32(0); PG_RETURN_CSTRING(anychar_typmodout(typmod)); } @@ -579,10 +579,11 @@ varchar(PG_FUNCTION_ARGS) int32 typmod = PG_GETARG_INT32(1); bool isExplicit = PG_GETARG_BOOL(2); VarChar *result; - int32 len, maxlen; + int32 len, + maxlen; size_t maxmblen; int i; - char *s_data; + char *s_data; len = VARSIZE_ANY_EXHDR(source); s_data = VARDATA_ANY(source); @@ -603,8 +604,8 @@ varchar(PG_FUNCTION_ARGS) if (s_data[i] != ' ') ereport(ERROR, (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION), - errmsg("value too long for type character varying(%d)", - maxlen))); + errmsg("value too long for type character varying(%d)", + maxlen))); } result = palloc(maxmblen + VARHDRSZ); @@ -617,7 +618,7 @@ varchar(PG_FUNCTION_ARGS) Datum varchartypmodin(PG_FUNCTION_ARGS) { - ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); + ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); PG_RETURN_INT32(anychar_typmodin(ta, "varchar")); } @@ -625,7 +626,7 @@ varchartypmodin(PG_FUNCTION_ARGS) Datum varchartypmodout(PG_FUNCTION_ARGS) { - int32 typmod = PG_GETARG_INT32(0); + int32 typmod = PG_GETARG_INT32(0); PG_RETURN_CSTRING(anychar_typmodout(typmod)); } @@ -671,7 +672,7 @@ bpcharlen(PG_FUNCTION_ARGS) Datum bpcharoctetlen(PG_FUNCTION_ARGS) { - Datum arg = PG_GETARG_DATUM(0); + Datum arg = PG_GETARG_DATUM(0); /* We need not detoast the input at all */ PG_RETURN_INT32(toast_raw_datum_size(arg) - VARHDRSZ); diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index 5ef1b0c337..e71bb81f83 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.159 2007/09/22 04:40:03 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.160 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -40,7 +40,7 @@ typedef struct pg_wchar *wstr2; /* note: these are palloc'd */ int len1; /* string lengths in logical characters */ int len2; -} TextPositionState; +} TextPositionState; #define DatumGetUnknownP(X) ((unknown *) PG_DETOAST_DATUM(X)) #define DatumGetUnknownPCopy(X) ((unknown *) PG_DETOAST_DATUM_COPY(X)) @@ -60,9 +60,9 @@ typedef struct static int text_cmp(text *arg1, text *arg2); static int32 text_length(Datum str); static int text_position(text *t1, text *t2); -static void text_position_setup(text *t1, text *t2, TextPositionState *state); -static int text_position_next(int start_pos, TextPositionState *state); -static void text_position_cleanup(TextPositionState *state); +static void text_position_setup(text *t1, text *t2, TextPositionState * state); +static int text_position_next(int start_pos, TextPositionState * state); +static void text_position_cleanup(TextPositionState * state); static text *text_substring(Datum str, int32 start, int32 length, @@ -414,7 +414,7 @@ text_length(Datum str) { text *t = DatumGetTextPP(str); - PG_RETURN_INT32(pg_mbstrlen_with_len(VARDATA_ANY(t), + PG_RETURN_INT32(pg_mbstrlen_with_len(VARDATA_ANY(t), VARSIZE_ANY_EXHDR(t))); } } @@ -680,8 +680,8 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified) } /* - * If we're working with an untoasted source, no need to do an - * extra copying step. + * If we're working with an untoasted source, no need to do an extra + * copying step. */ if (VARATT_IS_COMPRESSED(str) || VARATT_IS_EXTERNAL(str)) slice = DatumGetTextPSlice(str, slice_start, slice_size); @@ -807,7 +807,7 @@ text_position(text *t1, text *t2) */ static void -text_position_setup(text *t1, text *t2, TextPositionState *state) +text_position_setup(text *t1, text *t2, TextPositionState * state) { int len1 = VARSIZE_ANY_EXHDR(t1); int len2 = VARSIZE_ANY_EXHDR(t2); @@ -841,7 +841,7 @@ text_position_setup(text *t1, text *t2, TextPositionState *state) } static int -text_position_next(int start_pos, TextPositionState *state) +text_position_next(int start_pos, TextPositionState * state) { int pos = 0, p, @@ -899,7 +899,7 @@ text_position_next(int start_pos, TextPositionState *state) } static void -text_position_cleanup(TextPositionState *state) +text_position_cleanup(TextPositionState * state) { if (state->use_wchar) { @@ -1064,7 +1064,7 @@ text_cmp(text *arg1, text *arg2) len1 = VARSIZE_ANY_EXHDR(arg1); len2 = VARSIZE_ANY_EXHDR(arg2); - + return varstr_cmp(a1p, len1, a2p, len2); } @@ -2219,7 +2219,7 @@ check_replace_text_has_escape_char(const text *replace_text) * appendStringInfoRegexpSubstr * * Append replace_text to str, substituting regexp back references for - * \n escapes. start_ptr is the start of the match in the source string, + * \n escapes. start_ptr is the start of the match in the source string, * at logical character position data_pos. */ static void @@ -2302,8 +2302,8 @@ appendStringInfoRegexpSubstr(StringInfo str, text *replace_text, if (so != -1 && eo != -1) { /* - * Copy the text that is back reference of regexp. Note so and - * eo are counted in characters not bytes. + * Copy the text that is back reference of regexp. Note so and eo + * are counted in characters not bytes. */ char *chunk_start; int chunk_len; @@ -2386,8 +2386,8 @@ replace_text_regexp(text *src_text, void *regexp, } /* - * Copy the text to the left of the match position. Note we are - * given character not byte indexes. + * Copy the text to the left of the match position. Note we are given + * character not byte indexes. */ if (pmatch[0].rm_so - data_pos > 0) { @@ -2396,9 +2396,10 @@ replace_text_regexp(text *src_text, void *regexp, chunk_len = charlen_to_bytelen(start_ptr, pmatch[0].rm_so - data_pos); appendBinaryStringInfo(&buf, start_ptr, chunk_len); + /* - * Advance start_ptr over that text, to avoid multiple rescans - * of it if the replace_text contains multiple back-references. + * Advance start_ptr over that text, to avoid multiple rescans of + * it if the replace_text contains multiple back-references. */ start_ptr += chunk_len; data_pos = pmatch[0].rm_so; diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index e9d9703c9f..98fe39871f 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.56 2007/11/10 19:29:54 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.57 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -19,7 +19,7 @@ * fail. For one thing, this avoids having to manage variant catalog * installations. But it also has nice effects such as that you can * dump a database containing XML type data even if the server is not - * linked with libxml. Thus, make sure xml_out() works even if nothing + * linked with libxml. Thus, make sure xml_out() works even if nothing * else does. */ @@ -49,7 +49,7 @@ #include <libxml/xmlwriter.h> #include <libxml/xpath.h> #include <libxml/xpathInternals.h> -#endif /* USE_LIBXML */ +#endif /* USE_LIBXML */ #include "catalog/namespace.h" #include "catalog/pg_type.h" @@ -81,40 +81,39 @@ XmlOptionType xmloption; static StringInfo xml_err_buf = NULL; -static void xml_init(void); -static void *xml_palloc(size_t size); -static void *xml_repalloc(void *ptr, size_t size); -static void xml_pfree(void *ptr); -static char *xml_pstrdup(const char *string); -static void xml_ereport(int level, int sqlcode, const char *msg); -static void xml_errorHandler(void *ctxt, const char *msg, ...); -static void xml_ereport_by_code(int level, int sqlcode, - const char *msg, int errcode); +static void xml_init(void); +static void *xml_palloc(size_t size); +static void *xml_repalloc(void *ptr, size_t size); +static void xml_pfree(void *ptr); +static char *xml_pstrdup(const char *string); +static void xml_ereport(int level, int sqlcode, const char *msg); +static void xml_errorHandler(void *ctxt, const char *msg,...); +static void xml_ereport_by_code(int level, int sqlcode, + const char *msg, int errcode); static xmlChar *xml_text2xmlChar(text *in); -static int parse_xml_decl(const xmlChar *str, size_t *lenp, - xmlChar **version, xmlChar **encoding, int *standalone); -static bool print_xml_decl(StringInfo buf, const xmlChar *version, - pg_enc encoding, int standalone); +static int parse_xml_decl(const xmlChar * str, size_t *lenp, + xmlChar ** version, xmlChar ** encoding, int *standalone); +static bool print_xml_decl(StringInfo buf, const xmlChar * version, + pg_enc encoding, int standalone); static xmlDocPtr xml_parse(text *data, XmlOptionType xmloption_arg, - bool preserve_whitespace, xmlChar *encoding); -static text *xml_xmlnodetoxmltype(xmlNodePtr cur); - -#endif /* USE_LIBXML */ + bool preserve_whitespace, xmlChar * encoding); +static text *xml_xmlnodetoxmltype(xmlNodePtr cur); +#endif /* USE_LIBXML */ static StringInfo query_to_xml_internal(const char *query, char *tablename, const char *xmlschema, bool nulls, bool tableforest, const char *targetns, bool top_level); static const char *map_sql_table_to_xmlschema(TupleDesc tupdesc, Oid relid, - bool nulls, bool tableforest, const char *targetns); + bool nulls, bool tableforest, const char *targetns); static const char *map_sql_schema_to_xmlschema_types(Oid nspid, List *relid_list, bool nulls, bool tableforest, const char *targetns); static const char *map_sql_catalog_to_xmlschema_types(List *nspid_list, bool nulls, bool tableforest, const char *targetns); -static const char * map_sql_type_to_xml_name(Oid typeoid, int typmod); -static const char * map_sql_typecoll_to_xmlschema_types(List *tupdesc_list); -static const char * map_sql_type_to_xmlschema_type(Oid typeoid, int typmod); +static const char *map_sql_type_to_xml_name(Oid typeoid, int typmod); +static const char *map_sql_typecoll_to_xmlschema_types(List *tupdesc_list); +static const char *map_sql_type_to_xmlschema_type(Oid typeoid, int typmod); static void SPI_sql_row_to_xmlelement(int rownum, StringInfo result, char *tablename, bool nulls, bool tableforest, const char *targetns, bool top_level); @@ -140,9 +139,9 @@ static void SPI_sql_row_to_xmlelement(int rownum, StringInfo result, #ifdef USE_LIBXML static int -xmlChar_to_encoding(xmlChar *encoding_name) +xmlChar_to_encoding(xmlChar * encoding_name) { - int encoding = pg_char_to_encoding((char *) encoding_name); + int encoding = pg_char_to_encoding((char *) encoding_name); if (encoding < 0) ereport(ERROR, @@ -151,7 +150,6 @@ xmlChar_to_encoding(xmlChar *encoding_name) (char *) encoding_name))); return encoding; } - #endif @@ -159,10 +157,10 @@ Datum xml_in(PG_FUNCTION_ARGS) { #ifdef USE_LIBXML - char *s = PG_GETARG_CSTRING(0); + char *s = PG_GETARG_CSTRING(0); size_t len; - xmltype *vardata; - xmlDocPtr doc; + xmltype *vardata; + xmlDocPtr doc; len = strlen(s); vardata = palloc(len + VARHDRSZ); @@ -170,8 +168,8 @@ xml_in(PG_FUNCTION_ARGS) memcpy(VARDATA(vardata), s, len); /* - * Parse the data to check if it is well-formed XML data. Assume - * that ERROR occurred if parsing failed. + * Parse the data to check if it is well-formed XML data. Assume that + * ERROR occurred if parsing failed. */ doc = xml_parse(vardata, xmloption, true, NULL); xmlFreeDoc(doc); @@ -188,13 +186,14 @@ xml_in(PG_FUNCTION_ARGS) static char * -xml_out_internal(xmltype *x, pg_enc target_encoding) +xml_out_internal(xmltype * x, pg_enc target_encoding) { - char *str; + char *str; size_t len; + #ifdef USE_LIBXML - xmlChar *version; - xmlChar *encoding; + xmlChar *version; + xmlChar *encoding; int standalone; int res_code; #endif @@ -206,7 +205,7 @@ xml_out_internal(xmltype *x, pg_enc target_encoding) #ifdef USE_LIBXML if ((res_code = parse_xml_decl((xmlChar *) str, - &len, &version, &encoding, &standalone)) == 0) + &len, &version, &encoding, &standalone)) == 0) { StringInfoData buf; @@ -215,9 +214,9 @@ xml_out_internal(xmltype *x, pg_enc target_encoding) if (!print_xml_decl(&buf, version, target_encoding, standalone)) { /* - * If we are not going to produce an XML declaration, eat - * a single newline in the original string to prevent - * empty first lines in the output. + * If we are not going to produce an XML declaration, eat a single + * newline in the original string to prevent empty first lines in + * the output. */ if (*(str + len) == '\n') len += 1; @@ -238,13 +237,13 @@ xml_out_internal(xmltype *x, pg_enc target_encoding) Datum xml_out(PG_FUNCTION_ARGS) { - xmltype *x = PG_GETARG_XML_P(0); + xmltype *x = PG_GETARG_XML_P(0); /* - * xml_out removes the encoding property in all cases. This is - * because we cannot control from here whether the datum will be - * converted to a different client encoding, so we'd do more harm - * than good by including it. + * xml_out removes the encoding property in all cases. This is because we + * cannot control from here whether the datum will be converted to a + * different client encoding, so we'd do more harm than good by including + * it. */ PG_RETURN_CSTRING(xml_out_internal(x, 0)); } @@ -255,17 +254,17 @@ xml_recv(PG_FUNCTION_ARGS) { #ifdef USE_LIBXML StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); - xmltype *result; + xmltype *result; char *str; char *newstr; int nbytes; xmlDocPtr doc; - xmlChar *encoding = NULL; + xmlChar *encoding = NULL; /* - * Read the data in raw format. We don't know yet what the encoding - * is, as that information is embedded in the xml declaration; so we - * have to parse that before converting to server encoding. + * Read the data in raw format. We don't know yet what the encoding is, as + * that information is embedded in the xml declaration; so we have to + * parse that before converting to server encoding. */ nbytes = buf->len - buf->cursor; str = (char *) pq_getmsgbytes(buf, nbytes); @@ -284,8 +283,8 @@ xml_recv(PG_FUNCTION_ARGS) parse_xml_decl((xmlChar *) str, NULL, NULL, &encoding, NULL); /* - * Parse the data to check if it is well-formed XML data. Assume - * that xml_parse will throw ERROR if not. + * Parse the data to check if it is well-formed XML data. Assume that + * xml_parse will throw ERROR if not. */ doc = xml_parse(result, xmloption, true, encoding); xmlFreeDoc(doc); @@ -294,7 +293,7 @@ xml_recv(PG_FUNCTION_ARGS) newstr = (char *) pg_do_encoding_conversion((unsigned char *) str, nbytes, encoding ? - xmlChar_to_encoding(encoding) : + xmlChar_to_encoding(encoding) : PG_UTF8, GetDatabaseEncoding()); @@ -322,13 +321,13 @@ xml_recv(PG_FUNCTION_ARGS) Datum xml_send(PG_FUNCTION_ARGS) { - xmltype *x = PG_GETARG_XML_P(0); + xmltype *x = PG_GETARG_XML_P(0); char *outval; StringInfoData buf; - + /* - * xml_out_internal doesn't convert the encoding, it just prints - * the right declaration. pq_sendtext will do the conversion. + * xml_out_internal doesn't convert the encoding, it just prints the right + * declaration. pq_sendtext will do the conversion. */ outval = xml_out_internal(x, pg_get_client_encoding()); @@ -351,8 +350,8 @@ appendStringInfoText(StringInfo str, const text *t) static xmltype * stringinfo_to_xmltype(StringInfo buf) { - int32 len; - xmltype *result; + int32 len; + xmltype *result; len = buf->len + VARHDRSZ; result = palloc(len); @@ -367,7 +366,7 @@ static xmltype * cstring_to_xmltype(const char *string) { int32 len; - xmltype *result; + xmltype *result; len = strlen(string) + VARHDRSZ; result = palloc(len); @@ -383,7 +382,7 @@ static xmltype * xmlBuffer_to_xmltype(xmlBufferPtr buf) { int32 len; - xmltype *result; + xmltype *result; len = xmlBufferLength(buf) + VARHDRSZ; result = palloc(len); @@ -399,11 +398,11 @@ Datum xmlcomment(PG_FUNCTION_ARGS) { #ifdef USE_LIBXML - text *arg = PG_GETARG_TEXT_P(0); - char *argdata = VARDATA(arg); - int len = VARSIZE(arg) - VARHDRSZ; + text *arg = PG_GETARG_TEXT_P(0); + char *argdata = VARDATA(arg); + int len = VARSIZE(arg) - VARHDRSZ; StringInfoData buf; - int i; + int i; /* check for "--" in string or "-" at the end */ for (i = 1; i < len; i++) @@ -434,14 +433,14 @@ xmlcomment(PG_FUNCTION_ARGS) /* * TODO: xmlconcat needs to merge the notations and unparsed entities - * of the argument values. Not very important in practice, though. + * of the argument values. Not very important in practice, though. */ xmltype * xmlconcat(List *args) { #ifdef USE_LIBXML int global_standalone = 1; - xmlChar *global_version = NULL; + xmlChar *global_version = NULL; bool global_version_no_value = false; StringInfoData buf; ListCell *v; @@ -449,9 +448,9 @@ xmlconcat(List *args) initStringInfo(&buf); foreach(v, args) { - xmltype *x = DatumGetXmlP(PointerGetDatum(lfirst(v))); + xmltype *x = DatumGetXmlP(PointerGetDatum(lfirst(v))); size_t len; - xmlChar *version; + xmlChar *version; int standalone; char *str; @@ -534,14 +533,14 @@ texttoxml(PG_FUNCTION_ARGS) Datum xmltotext(PG_FUNCTION_ARGS) { - xmltype *data = PG_GETARG_XML_P(0); + xmltype *data = PG_GETARG_XML_P(0); PG_RETURN_TEXT_P(xmltotext_with_xmloption(data, xmloption)); } text * -xmltotext_with_xmloption(xmltype *data, XmlOptionType xmloption_arg) +xmltotext_with_xmloption(xmltype * data, XmlOptionType xmloption_arg) { if (xmloption_arg == XMLOPTION_DOCUMENT && !xml_is_document(data)) ereport(ERROR, @@ -554,11 +553,11 @@ xmltotext_with_xmloption(xmltype *data, XmlOptionType xmloption_arg) xmltype * -xmlelement(XmlExprState *xmlExpr, ExprContext *econtext) +xmlelement(XmlExprState * xmlExpr, ExprContext *econtext) { #ifdef USE_LIBXML - XmlExpr *xexpr = (XmlExpr *) xmlExpr->xprstate.expr; - xmltype *result; + XmlExpr *xexpr = (XmlExpr *) xmlExpr->xprstate.expr; + xmltype *result; List *named_arg_strings; List *arg_strings; int i; @@ -568,16 +567,16 @@ xmlelement(XmlExprState *xmlExpr, ExprContext *econtext) xmlTextWriterPtr writer; /* - * We first evaluate all the arguments, then start up libxml and - * create the result. This avoids issues if one of the arguments - * involves a call to some other function or subsystem that wants to use - * libxml on its own terms. + * We first evaluate all the arguments, then start up libxml and create + * the result. This avoids issues if one of the arguments involves a call + * to some other function or subsystem that wants to use libxml on its own + * terms. */ named_arg_strings = NIL; i = 0; foreach(arg, xmlExpr->named_args) { - ExprState *e = (ExprState *) lfirst(arg); + ExprState *e = (ExprState *) lfirst(arg); Datum value; bool isnull; char *str; @@ -594,7 +593,7 @@ xmlelement(XmlExprState *xmlExpr, ExprContext *econtext) arg_strings = NIL; foreach(arg, xmlExpr->args) { - ExprState *e = (ExprState *) lfirst(arg); + ExprState *e = (ExprState *) lfirst(arg); Datum value; bool isnull; char *str; @@ -619,8 +618,8 @@ xmlelement(XmlExprState *xmlExpr, ExprContext *econtext) forboth(arg, named_arg_strings, narg, xexpr->arg_names) { - char *str = (char *) lfirst(arg); - char *argname = strVal(lfirst(narg)); + char *str = (char *) lfirst(arg); + char *argname = strVal(lfirst(narg)); if (str) { @@ -633,7 +632,7 @@ xmlelement(XmlExprState *xmlExpr, ExprContext *econtext) foreach(arg, arg_strings) { - char *str = (char *) lfirst(arg); + char *str = (char *) lfirst(arg); xmlTextWriterWriteRaw(writer, (xmlChar *) str); } @@ -673,22 +672,22 @@ xmltype * xmlpi(char *target, text *arg, bool arg_is_null, bool *result_is_null) { #ifdef USE_LIBXML - xmltype *result; + xmltype *result; StringInfoData buf; if (pg_strcasecmp(target, "xml") == 0) ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), /* really */ + (errcode(ERRCODE_SYNTAX_ERROR), /* really */ errmsg("invalid XML processing instruction"), errdetail("XML processing instruction target name cannot be \"%s\".", target))); /* - * Following the SQL standard, the null check comes after the - * syntax check above. + * Following the SQL standard, the null check comes after the syntax check + * above. */ *result_is_null = arg_is_null; if (*result_is_null) - return NULL; + return NULL; initStringInfo(&buf); @@ -696,14 +695,14 @@ xmlpi(char *target, text *arg, bool arg_is_null, bool *result_is_null) if (arg != NULL) { - char *string; + char *string; string = _textout(arg); if (strstr(string, "?>") != NULL) - ereport(ERROR, - (errcode(ERRCODE_INVALID_XML_PROCESSING_INSTRUCTION), - errmsg("invalid XML processing instruction"), - errdetail("XML processing instruction cannot contain \"?>\"."))); + ereport(ERROR, + (errcode(ERRCODE_INVALID_XML_PROCESSING_INSTRUCTION), + errmsg("invalid XML processing instruction"), + errdetail("XML processing instruction cannot contain \"?>\"."))); appendStringInfoChar(&buf, ' '); appendStringInfoString(&buf, string + strspn(string, " ")); @@ -722,12 +721,12 @@ xmlpi(char *target, text *arg, bool arg_is_null, bool *result_is_null) xmltype * -xmlroot(xmltype *data, text *version, int standalone) +xmlroot(xmltype * data, text *version, int standalone) { #ifdef USE_LIBXML char *str; size_t len; - xmlChar *orig_version; + xmlChar *orig_version; int orig_standalone; StringInfoData buf; @@ -781,12 +780,12 @@ Datum xmlvalidate(PG_FUNCTION_ARGS) { #ifdef USE_LIBXML - text *data = PG_GETARG_TEXT_P(0); - text *dtdOrUri = PG_GETARG_TEXT_P(1); - bool result = false; - xmlParserCtxtPtr ctxt = NULL; - xmlDocPtr doc = NULL; - xmlDtdPtr dtd = NULL; + text *data = PG_GETARG_TEXT_P(0); + text *dtdOrUri = PG_GETARG_TEXT_P(1); + bool result = false; + xmlParserCtxtPtr ctxt = NULL; + xmlDocPtr doc = NULL; + xmlDtdPtr dtd = NULL; xml_init(); @@ -864,15 +863,15 @@ xmlvalidate(PG_FUNCTION_ARGS) PG_END_TRY(); PG_RETURN_BOOL(result); -#else /* not USE_LIBXML */ +#else /* not USE_LIBXML */ NO_XML_SUPPORT(); return 0; -#endif /* not USE_LIBXML */ +#endif /* not USE_LIBXML */ } bool -xml_is_document(xmltype *arg) +xml_is_document(xmltype * arg) { #ifdef USE_LIBXML bool result; @@ -886,7 +885,7 @@ xml_is_document(xmltype *arg) } PG_CATCH(); { - ErrorData *errdata; + ErrorData *errdata; MemoryContext ecxt; ecxt = MemoryContextSwitchTo(ccxt); @@ -908,10 +907,10 @@ xml_is_document(xmltype *arg) xmlFreeDoc(doc); return result; -#else /* not USE_LIBXML */ +#else /* not USE_LIBXML */ NO_XML_SUPPORT(); return false; -#endif /* not USE_LIBXML */ +#endif /* not USE_LIBXML */ } @@ -935,8 +934,8 @@ xml_init(void) MemoryContext oldcontext; /* - * Currently, we have no pure UTF-8 support for internals -- check - * if we can work. + * Currently, we have no pure UTF-8 support for internals -- check if + * we can work. */ if (sizeof(char) != sizeof(xmlChar)) ereport(ERROR, @@ -970,8 +969,8 @@ xml_init(void) * We re-establish the callback functions every time. This makes it * safe for other subsystems (PL/Perl, say) to also use libxml with * their own callbacks ... so long as they likewise set up the - * callbacks on every use. It's cheap enough to not be worth - * worrying about, anyway. + * callbacks on every use. It's cheap enough to not be worth worrying + * about, anyway. */ xmlSetGenericErrorFunc(NULL, xml_errorHandler); xmlMemSetup(xml_pfree, xml_palloc, xml_repalloc, xml_pstrdup); @@ -1007,8 +1006,8 @@ xml_init(void) || xmlIsExtender_ch(c)) static int -parse_xml_decl(const xmlChar *str, size_t *lenp, - xmlChar **version, xmlChar **encoding, int *standalone) +parse_xml_decl(const xmlChar * str, size_t *lenp, + xmlChar ** version, xmlChar ** encoding, int *standalone) { const xmlChar *p; const xmlChar *save_p; @@ -1027,12 +1026,12 @@ parse_xml_decl(const xmlChar *str, size_t *lenp, p = str; - if (xmlStrncmp(p, (xmlChar *)"<?xml", 5) != 0) + if (xmlStrncmp(p, (xmlChar *) "<?xml", 5) != 0) goto finished; /* if next char is name char, it's a PI like <?xml-stylesheet ...?> */ - utf8len = strlen((const char *) (p+5)); - utf8char = xmlGetUTF8Char(p+5, &utf8len); + utf8len = strlen((const char *) (p + 5)); + utf8char = xmlGetUTF8Char(p + 5, &utf8len); if (PG_XMLISNAMECHAR(utf8char)) goto finished; @@ -1041,7 +1040,7 @@ parse_xml_decl(const xmlChar *str, size_t *lenp, /* version */ CHECK_XML_SPACE(p); SKIP_XML_SPACE(p); - if (xmlStrncmp(p, (xmlChar *)"version", 7) != 0) + if (xmlStrncmp(p, (xmlChar *) "version", 7) != 0) return XML_ERR_VERSION_MISSING; p += 7; SKIP_XML_SPACE(p); @@ -1068,7 +1067,7 @@ parse_xml_decl(const xmlChar *str, size_t *lenp, /* encoding */ save_p = p; SKIP_XML_SPACE(p); - if (xmlStrncmp(p, (xmlChar *)"encoding", 8) == 0) + if (xmlStrncmp(p, (xmlChar *) "encoding", 8) == 0) { CHECK_XML_SPACE(save_p); p += 8; @@ -1087,7 +1086,7 @@ parse_xml_decl(const xmlChar *str, size_t *lenp, return XML_ERR_MISSING_ENCODING; if (encoding) - *encoding = xmlStrndup(p + 1, q - p - 1); + *encoding = xmlStrndup(p + 1, q - p - 1); p = q + 1; } else @@ -1101,7 +1100,7 @@ parse_xml_decl(const xmlChar *str, size_t *lenp, /* standalone */ save_p = p; SKIP_XML_SPACE(p); - if (xmlStrncmp(p, (xmlChar *)"standalone", 10) == 0) + if (xmlStrncmp(p, (xmlChar *) "standalone", 10) == 0) { CHECK_XML_SPACE(save_p); p += 10; @@ -1110,12 +1109,12 @@ parse_xml_decl(const xmlChar *str, size_t *lenp, return XML_ERR_STANDALONE_VALUE; p += 1; SKIP_XML_SPACE(p); - if (xmlStrncmp(p, (xmlChar *)"'yes'", 5) == 0 || xmlStrncmp(p, (xmlChar *)"\"yes\"", 5) == 0) + if (xmlStrncmp(p, (xmlChar *) "'yes'", 5) == 0 || xmlStrncmp(p, (xmlChar *) "\"yes\"", 5) == 0) { *standalone = 1; p += 5; } - else if (xmlStrncmp(p, (xmlChar *)"'no'", 4) == 0 || xmlStrncmp(p, (xmlChar *)"\"no\"", 4) == 0) + else if (xmlStrncmp(p, (xmlChar *) "'no'", 4) == 0 || xmlStrncmp(p, (xmlChar *) "\"no\"", 4) == 0) { *standalone = 0; p += 4; @@ -1129,7 +1128,7 @@ parse_xml_decl(const xmlChar *str, size_t *lenp, } SKIP_XML_SPACE(p); - if (xmlStrncmp(p, (xmlChar *)"?>", 2) != 0) + if (xmlStrncmp(p, (xmlChar *) "?>", 2) != 0) return XML_ERR_XMLDECL_NOT_FINISHED; p += 2; @@ -1149,7 +1148,7 @@ finished: /* * Write an XML declaration. On output, we adjust the XML declaration - * as follows. (These rules are the moral equivalent of the clause + * as follows. (These rules are the moral equivalent of the clause * "Serialization of an XML value" in the SQL standard.) * * We try to avoid generating an XML declaration if possible. This is @@ -1162,7 +1161,7 @@ finished: * which is the default version specified in SQL:2003. */ static bool -print_xml_decl(StringInfo buf, const xmlChar *version, +print_xml_decl(StringInfo buf, const xmlChar * version, pg_enc encoding, int standalone) { xml_init(); @@ -1181,8 +1180,8 @@ print_xml_decl(StringInfo buf, const xmlChar *version, if (encoding && encoding != PG_UTF8) { /* - * XXX might be useful to convert this to IANA names - * (ISO-8859-1 instead of LATIN1 etc.); needs field experience + * XXX might be useful to convert this to IANA names (ISO-8859-1 + * instead of LATIN1 etc.); needs field experience */ appendStringInfo(buf, " encoding=\"%s\"", pg_encoding_to_char(encoding)); @@ -1209,15 +1208,15 @@ print_xml_decl(StringInfo buf, const xmlChar *version, */ static xmlDocPtr xml_parse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace, - xmlChar *encoding) + xmlChar * encoding) { - int32 len; - xmlChar *string; - xmlChar *utf8string; - xmlParserCtxtPtr ctxt = NULL; - xmlDocPtr doc = NULL; + int32 len; + xmlChar *string; + xmlChar *utf8string; + xmlParserCtxtPtr ctxt = NULL; + xmlDocPtr doc = NULL; - len = VARSIZE(data) - VARHDRSZ; /* will be useful later */ + len = VARSIZE(data) - VARHDRSZ; /* will be useful later */ string = xml_text2xmlChar(data); utf8string = pg_do_encoding_conversion(string, @@ -1242,16 +1241,15 @@ xml_parse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace, { /* * Note, that here we try to apply DTD defaults - * (XML_PARSE_DTDATTR) according to SQL/XML:10.16.7.d: - * 'Default valies defined by internal DTD are applied'. - * As for external DTDs, we try to support them too, (see - * SQL/XML:10.16.7.e) + * (XML_PARSE_DTDATTR) according to SQL/XML:10.16.7.d: 'Default + * valies defined by internal DTD are applied'. As for external + * DTDs, we try to support them too, (see SQL/XML:10.16.7.e) */ doc = xmlCtxtReadDoc(ctxt, utf8string, NULL, "UTF-8", XML_PARSE_NOENT | XML_PARSE_DTDATTR - | (preserve_whitespace ? 0 : XML_PARSE_NOBLANKS)); + | (preserve_whitespace ? 0 : XML_PARSE_NOBLANKS)); if (doc == NULL) xml_ereport(ERROR, ERRCODE_INVALID_XML_DOCUMENT, "invalid XML document"); @@ -1259,16 +1257,16 @@ xml_parse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace, else { int res_code; - size_t count; - xmlChar *version = NULL; - int standalone = -1; + size_t count; + xmlChar *version = NULL; + int standalone = -1; doc = xmlNewDoc(NULL); res_code = parse_xml_decl(utf8string, &count, &version, NULL, &standalone); if (res_code != 0) xml_ereport_by_code(ERROR, ERRCODE_INVALID_XML_CONTENT, - "invalid XML content: invalid XML declaration", res_code); + "invalid XML content: invalid XML declaration", res_code); res_code = xmlParseBalancedChunkMemory(doc, NULL, NULL, 0, utf8string + count, NULL); if (res_code != 0) @@ -1307,14 +1305,14 @@ xml_parse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace, static xmlChar * xml_text2xmlChar(text *in) { - int32 len = VARSIZE(in) - VARHDRSZ; - xmlChar *res; + int32 len = VARSIZE(in) - VARHDRSZ; + xmlChar *res; res = palloc(len + 1); memcpy(res, VARDATA(in), len); res[len] = '\0'; - return(res); + return (res); } @@ -1358,7 +1356,7 @@ xml_pstrdup(const char *string) static void xml_ereport(int level, int sqlcode, const char *msg) { - char *detail; + char *detail; if (xml_err_buf->len > 0) { @@ -1371,11 +1369,11 @@ xml_ereport(int level, int sqlcode, const char *msg) /* libxml error messages end in '\n'; get rid of it */ if (detail) { - size_t len; + size_t len; len = strlen(detail); - if (len > 0 && detail[len-1] == '\n') - detail[len-1] = '\0'; + if (len > 0 && detail[len - 1] == '\n') + detail[len - 1] = '\0'; ereport(level, (errcode(sqlcode), @@ -1428,9 +1426,9 @@ static void xml_ereport_by_code(int level, int sqlcode, const char *msg, int code) { - const char *det; + const char *det; - switch (code) + switch (code) { case XML_ERR_INVALID_CHAR: det = "Invalid character value"; @@ -1450,8 +1448,8 @@ xml_ereport_by_code(int level, int sqlcode, case XML_ERR_XMLDECL_NOT_FINISHED: det = "Parsing XML declaration: '?>' expected"; break; - default: - det = "Unrecognized libxml error code: %d"; + default: + det = "Unrecognized libxml error code: %d"; break; } @@ -1468,8 +1466,8 @@ xml_ereport_by_code(int level, int sqlcode, static pg_wchar sqlchar_to_unicode(char *s) { - char *utf8string; - pg_wchar ret[2]; /* need space for trailing zero */ + char *utf8string; + pg_wchar ret[2]; /* need space for trailing zero */ utf8string = (char *) pg_do_encoding_conversion((unsigned char *) s, pg_mblen(s), @@ -1501,7 +1499,7 @@ is_valid_xml_namechar(pg_wchar c) || xmlIsCombiningQ(c) || xmlIsExtenderQ(c)); } -#endif /* USE_LIBXML */ +#endif /* USE_LIBXML */ /* @@ -1513,11 +1511,11 @@ map_sql_identifier_to_xml_name(char *ident, bool fully_escaped, { #ifdef USE_LIBXML StringInfoData buf; - char *p; + char *p; /* - * SQL/XML doesn't make use of this case anywhere, so it's - * probably a mistake. + * SQL/XML doesn't make use of this case anywhere, so it's probably a + * mistake. */ Assert(fully_escaped || !escape_period); @@ -1527,7 +1525,7 @@ map_sql_identifier_to_xml_name(char *ident, bool fully_escaped, { if (*p == ':' && (p == ident || fully_escaped)) appendStringInfo(&buf, "_x003A_"); - else if (*p == '_' && *(p+1) == 'x') + else if (*p == '_' && *(p + 1) == 'x') appendStringInfo(&buf, "_x005F_"); else if (fully_escaped && p == ident && pg_strncasecmp(p, "xml", 3) == 0) @@ -1541,7 +1539,7 @@ map_sql_identifier_to_xml_name(char *ident, bool fully_escaped, appendStringInfo(&buf, "_x002E_"); else { - pg_wchar u = sqlchar_to_unicode(p); + pg_wchar u = sqlchar_to_unicode(p); if ((p == ident) ? !is_valid_xml_namefirst(u) @@ -1553,10 +1551,10 @@ map_sql_identifier_to_xml_name(char *ident, bool fully_escaped, } return buf.data; -#else /* not USE_LIBXML */ +#else /* not USE_LIBXML */ NO_XML_SUPPORT(); return NULL; -#endif /* not USE_LIBXML */ +#endif /* not USE_LIBXML */ } @@ -1566,7 +1564,7 @@ map_sql_identifier_to_xml_name(char *ident, bool fully_escaped, static char * unicode_to_sqlchar(pg_wchar c) { - static unsigned char utf8string[5]; /* need trailing zero */ + static unsigned char utf8string[5]; /* need trailing zero */ if (c <= 0x7F) { @@ -1605,18 +1603,18 @@ char * map_xml_name_to_sql_identifier(char *name) { StringInfoData buf; - char *p; + char *p; initStringInfo(&buf); for (p = name; *p; p += pg_mblen(p)) { - if (*p == '_' && *(p+1) == 'x' - && isxdigit((unsigned char) *(p+2)) - && isxdigit((unsigned char) *(p+3)) - && isxdigit((unsigned char) *(p+4)) - && isxdigit((unsigned char) *(p+5)) - && *(p+6) == '_') + if (*p == '_' && *(p + 1) == 'x' + && isxdigit((unsigned char) *(p + 2)) + && isxdigit((unsigned char) *(p + 3)) + && isxdigit((unsigned char) *(p + 4)) + && isxdigit((unsigned char) *(p + 5)) + && *(p + 6) == '_') { unsigned int u; @@ -1643,15 +1641,15 @@ map_sql_value_to_xml_value(Datum value, Oid type) if (type_is_array(type)) { - ArrayType *array; - Oid elmtype; - int16 elmlen; - bool elmbyval; - char elmalign; + ArrayType *array; + Oid elmtype; + int16 elmlen; + bool elmbyval; + char elmalign; int num_elems; Datum *elem_values; bool *elem_nulls; - int i; + int i; array = DatumGetArrayTypeP(value); elmtype = ARR_ELEMTYPE(array); @@ -1678,9 +1676,10 @@ map_sql_value_to_xml_value(Datum value, Oid type) } else { - Oid typeOut; - bool isvarlena; - char *p, *str; + Oid typeOut; + bool isvarlena; + char *p, + *str; /* * Special XSD formatting for some data types @@ -1694,69 +1693,69 @@ map_sql_value_to_xml_value(Datum value, Oid type) return "false"; case DATEOID: - { - DateADT date; - struct pg_tm tm; - char buf[MAXDATELEN + 1]; + { + DateADT date; + struct pg_tm tm; + char buf[MAXDATELEN + 1]; - date = DatumGetDateADT(value); - j2date(date + POSTGRES_EPOCH_JDATE, - &(tm.tm_year), &(tm.tm_mon), &(tm.tm_mday)); - EncodeDateOnly(&tm, USE_XSD_DATES, buf); + date = DatumGetDateADT(value); + j2date(date + POSTGRES_EPOCH_JDATE, + &(tm.tm_year), &(tm.tm_mon), &(tm.tm_mday)); + EncodeDateOnly(&tm, USE_XSD_DATES, buf); - return pstrdup(buf); - } + return pstrdup(buf); + } case TIMESTAMPOID: - { - Timestamp timestamp; - struct pg_tm tm; - fsec_t fsec; - char *tzn = NULL; - char buf[MAXDATELEN + 1]; - - timestamp = DatumGetTimestamp(value); - - /* XSD doesn't support infinite values */ - if (TIMESTAMP_NOT_FINITE(timestamp)) - ereport(ERROR, - (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), - errmsg("timestamp out of range"))); - else if (timestamp2tm(timestamp, NULL, &tm, &fsec, NULL, NULL) == 0) - EncodeDateTime(&tm, fsec, NULL, &tzn, USE_XSD_DATES, buf); - else - ereport(ERROR, - (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), - errmsg("timestamp out of range"))); - - return pstrdup(buf); - } + { + Timestamp timestamp; + struct pg_tm tm; + fsec_t fsec; + char *tzn = NULL; + char buf[MAXDATELEN + 1]; + + timestamp = DatumGetTimestamp(value); + + /* XSD doesn't support infinite values */ + if (TIMESTAMP_NOT_FINITE(timestamp)) + ereport(ERROR, + (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), + errmsg("timestamp out of range"))); + else if (timestamp2tm(timestamp, NULL, &tm, &fsec, NULL, NULL) == 0) + EncodeDateTime(&tm, fsec, NULL, &tzn, USE_XSD_DATES, buf); + else + ereport(ERROR, + (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), + errmsg("timestamp out of range"))); + + return pstrdup(buf); + } case TIMESTAMPTZOID: - { - TimestampTz timestamp; - struct pg_tm tm; - int tz; - fsec_t fsec; - char *tzn = NULL; - char buf[MAXDATELEN + 1]; - - timestamp = DatumGetTimestamp(value); - - /* XSD doesn't support infinite values */ - if (TIMESTAMP_NOT_FINITE(timestamp)) - ereport(ERROR, - (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), - errmsg("timestamp out of range"))); - else if (timestamp2tm(timestamp, &tz, &tm, &fsec, &tzn, NULL) == 0) - EncodeDateTime(&tm, fsec, &tz, &tzn, USE_XSD_DATES, buf); - else - ereport(ERROR, - (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), - errmsg("timestamp out of range"))); - - return pstrdup(buf); - } + { + TimestampTz timestamp; + struct pg_tm tm; + int tz; + fsec_t fsec; + char *tzn = NULL; + char buf[MAXDATELEN + 1]; + + timestamp = DatumGetTimestamp(value); + + /* XSD doesn't support infinite values */ + if (TIMESTAMP_NOT_FINITE(timestamp)) + ereport(ERROR, + (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), + errmsg("timestamp out of range"))); + else if (timestamp2tm(timestamp, &tz, &tm, &fsec, &tzn, NULL) == 0) + EncodeDateTime(&tm, fsec, &tz, &tzn, USE_XSD_DATES, buf); + else + ereport(ERROR, + (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), + errmsg("timestamp out of range"))); + + return pstrdup(buf); + } } getTypeOutputInfo(type, &typeOut, &isvarlena); @@ -1770,7 +1769,7 @@ map_sql_value_to_xml_value(Datum value, Oid type) { xmlBufferPtr buf; xmlTextWriterPtr writer; - char *result; + char *result; xml_init(); @@ -1787,7 +1786,7 @@ map_sql_value_to_xml_value(Datum value, Oid type) xmlBufferFree(buf); return result; } -#endif /* USE_LIBXML */ +#endif /* USE_LIBXML */ for (p = str; *p; p += pg_mblen(p)) { @@ -1819,7 +1818,8 @@ map_sql_value_to_xml_value(Datum value, Oid type) static char * _SPI_strdup(const char *s) { - char *ret = SPI_palloc(strlen(s) + 1); + char *ret = SPI_palloc(strlen(s) + 1); + strcpy(ret, s); return ret; } @@ -1829,7 +1829,7 @@ _SPI_strdup(const char *s) * SQL to XML mapping functions * * What follows below is intentionally organized so that you can read - * along in the SQL/XML:2003 standard. The functions are mostly split + * along in the SQL/XML:2003 standard. The functions are mostly split * up and ordered they way the clauses lay out in the standards * document, and the identifiers are also aligned with the standard * text. (SQL/XML:2006 appears to be ordered differently, @@ -1839,13 +1839,13 @@ _SPI_strdup(const char *s) * * There are two kinds of mappings: Mapping SQL data (table contents) * to XML documents, and mapping SQL structure (the "schema") to XML - * Schema. And there are functions that do both at the same time. + * Schema. And there are functions that do both at the same time. * * Then you can map a database, a schema, or a table, each in both * ways. This breaks down recursively: Mapping a database invokes * mapping schemas, which invokes mapping tables, which invokes * mapping rows, which invokes mapping columns, although you can't - * call the last two from the outside. Because of this, there are a + * call the last two from the outside. Because of this, there are a * number of xyz_internal() functions which are to be called both from * the function manager wrapper and from some upper layer in a * recursive call. @@ -1854,7 +1854,7 @@ _SPI_strdup(const char *s) * nulls, tableforest, and targetns mean. * * Some style guidelines for XML output: Use double quotes for quoting - * XML attributes. Indent XML elements by two spaces, but remember + * XML attributes. Indent XML elements by two spaces, but remember * that a lot of code is called recursively at different levels, so * it's better not to indent rather than create output that indents * and outdents weirdly. Add newlines to make the output look nice. @@ -1880,8 +1880,8 @@ query_to_oid_list(const char *query) for (i = 0; i < SPI_processed; i++) { - Datum oid; - bool isnull; + Datum oid; + bool isnull; oid = SPI_getbinval(SPI_tuptable->vals[i], SPI_tuptable->tupdesc, @@ -1907,7 +1907,7 @@ schema_get_xml_visible_tables(Oid nspid) } -/* +/* * Including the system schemas is probably not useful for a database * mapping. */ @@ -1946,7 +1946,7 @@ table_to_xml_internal(Oid relid, initStringInfo(&query); appendStringInfo(&query, "SELECT * FROM %s", DatumGetCString(DirectFunctionCall1(regclassout, - ObjectIdGetDatum(relid)))); + ObjectIdGetDatum(relid)))); return query_to_xml_internal(query.data, get_rel_name(relid), xmlschema, nulls, tableforest, targetns, top_level); @@ -1962,8 +1962,8 @@ table_to_xml(PG_FUNCTION_ARGS) const char *targetns = _textout(PG_GETARG_TEXT_P(3)); PG_RETURN_XML_P(stringinfo_to_xmltype(table_to_xml_internal(relid, NULL, - nulls, tableforest, - targetns, true))); + nulls, tableforest, + targetns, true))); } @@ -1977,7 +1977,7 @@ query_to_xml(PG_FUNCTION_ARGS) PG_RETURN_XML_P(stringinfo_to_xmltype(query_to_xml_internal(query, NULL, NULL, nulls, tableforest, - targetns, true))); + targetns, true))); } @@ -2018,12 +2018,12 @@ cursor_to_xml(PG_FUNCTION_ARGS) * Write the start tag of the root element of a data mapping. * * top_level means that this is the very top level of the eventual - * output. For example, when the user calls table_to_xml, then a call + * output. For example, when the user calls table_to_xml, then a call * with a table name to this function is the top level. When the user * calls database_to_xml, then a call with a schema name to this * function is not the top level. If top_level is false, then the XML * namespace declarations are omitted, because they supposedly already - * appeared earlier in the output. Repeating them is not wrong, but + * appeared earlier in the output. Repeating them is not wrong, but * it looks ugly. */ static void @@ -2089,7 +2089,7 @@ query_to_xml_internal(const char *query, char *tablename, if (xmlschema) appendStringInfo(result, "%s\n\n", xmlschema); - for(i = 0; i < SPI_processed; i++) + for (i = 0; i < SPI_processed; i++) SPI_sql_row_to_xmlelement(i, result, tablename, nulls, tableforest, targetns, top_level); @@ -2110,7 +2110,7 @@ table_to_xmlschema(PG_FUNCTION_ARGS) bool tableforest = PG_GETARG_BOOL(2); const char *targetns = _textout(PG_GETARG_TEXT_P(3)); const char *result; - Relation rel; + Relation rel; rel = heap_open(relid, AccessShareLock); result = map_sql_table_to_xmlschema(rel->rd_att, relid, nulls, @@ -2164,7 +2164,7 @@ cursor_to_xmlschema(PG_FUNCTION_ARGS) xmlschema = _SPI_strdup(map_sql_table_to_xmlschema(portal->tupDesc, InvalidOid, nulls, - tableforest, targetns)); + tableforest, targetns)); SPI_finish(); PG_RETURN_XML_P(cstring_to_xmltype(xmlschema)); @@ -2187,8 +2187,8 @@ table_to_xml_and_xmlschema(PG_FUNCTION_ARGS) heap_close(rel, NoLock); PG_RETURN_XML_P(stringinfo_to_xmltype(table_to_xml_internal(relid, - xmlschema, nulls, tableforest, - targetns, true))); + xmlschema, nulls, tableforest, + targetns, true))); } @@ -2208,13 +2208,13 @@ query_to_xml_and_xmlschema(PG_FUNCTION_ARGS) plan = SPI_prepare(query, 0, NULL); portal = SPI_cursor_open(NULL, plan, NULL, NULL, true); xmlschema = _SPI_strdup(map_sql_table_to_xmlschema(portal->tupDesc, - InvalidOid, nulls, tableforest, targetns)); + InvalidOid, nulls, tableforest, targetns)); SPI_cursor_close(portal); SPI_finish(); PG_RETURN_XML_P(stringinfo_to_xmltype(query_to_xml_internal(query, NULL, - xmlschema, nulls, tableforest, - targetns, true))); + xmlschema, nulls, tableforest, + targetns, true))); } @@ -2249,8 +2249,8 @@ schema_to_xml_internal(Oid nspid, const char *xmlschema, bool nulls, foreach(cell, relid_list) { - Oid relid = lfirst_oid(cell); - StringInfo subres; + Oid relid = lfirst_oid(cell); + StringInfo subres; subres = table_to_xml_internal(relid, NULL, nulls, tableforest, targetns, false); @@ -2283,7 +2283,7 @@ schema_to_xml(PG_FUNCTION_ARGS) nspid = LookupExplicitNamespace(schemaname); PG_RETURN_XML_P(stringinfo_to_xmltype(schema_to_xml_internal(nspid, NULL, - nulls, tableforest, targetns, true))); + nulls, tableforest, targetns, true))); } @@ -2335,9 +2335,9 @@ schema_to_xmlschema_internal(const char *schemaname, bool nulls, relid_list = schema_get_xml_visible_tables(nspid); tupdesc_list = NIL; - foreach (cell, relid_list) + foreach(cell, relid_list) { - Relation rel; + Relation rel; rel = heap_open(lfirst_oid(cell), AccessShareLock); tupdesc_list = lappend(tupdesc_list, CreateTupleDescCopy(rel->rd_att)); @@ -2348,8 +2348,8 @@ schema_to_xmlschema_internal(const char *schemaname, bool nulls, map_sql_typecoll_to_xmlschema_types(tupdesc_list)); appendStringInfoString(result, - map_sql_schema_to_xmlschema_types(nspid, relid_list, - nulls, tableforest, targetns)); + map_sql_schema_to_xmlschema_types(nspid, relid_list, + nulls, tableforest, targetns)); xsd_schema_element_end(result); @@ -2368,7 +2368,7 @@ schema_to_xmlschema(PG_FUNCTION_ARGS) const char *targetns = _textout(PG_GETARG_TEXT_P(3)); PG_RETURN_XML_P(stringinfo_to_xmltype(schema_to_xmlschema_internal(NameStr(*name), - nulls, tableforest, targetns))); + nulls, tableforest, targetns))); } @@ -2390,8 +2390,8 @@ schema_to_xml_and_xmlschema(PG_FUNCTION_ARGS) tableforest, targetns); PG_RETURN_XML_P(stringinfo_to_xmltype(schema_to_xml_internal(nspid, - xmlschema->data, nulls, - tableforest, targetns, true))); + xmlschema->data, nulls, + tableforest, targetns, true))); } @@ -2426,8 +2426,8 @@ database_to_xml_internal(const char *xmlschema, bool nulls, foreach(cell, nspid_list) { - Oid nspid = lfirst_oid(cell); - StringInfo subres; + Oid nspid = lfirst_oid(cell); + StringInfo subres; subres = schema_to_xml_internal(nspid, NULL, nulls, tableforest, targetns, false); @@ -2453,7 +2453,7 @@ database_to_xml(PG_FUNCTION_ARGS) const char *targetns = _textout(PG_GETARG_TEXT_P(2)); PG_RETURN_XML_P(stringinfo_to_xmltype(database_to_xml_internal(NULL, nulls, - tableforest, targetns))); + tableforest, targetns))); } @@ -2477,9 +2477,9 @@ database_to_xmlschema_internal(bool nulls, bool tableforest, nspid_list = database_get_xml_visible_schemas(); tupdesc_list = NIL; - foreach (cell, relid_list) + foreach(cell, relid_list) { - Relation rel; + Relation rel; rel = heap_open(lfirst_oid(cell), AccessShareLock); tupdesc_list = lappend(tupdesc_list, CreateTupleDescCopy(rel->rd_att)); @@ -2508,7 +2508,7 @@ database_to_xmlschema(PG_FUNCTION_ARGS) const char *targetns = _textout(PG_GETARG_TEXT_P(2)); PG_RETURN_XML_P(stringinfo_to_xmltype(database_to_xmlschema_internal(nulls, - tableforest, targetns))); + tableforest, targetns))); } @@ -2523,7 +2523,7 @@ database_to_xml_and_xmlschema(PG_FUNCTION_ARGS) xmlschema = database_to_xmlschema_internal(nulls, tableforest, targetns); PG_RETURN_XML_P(stringinfo_to_xmltype(database_to_xml_internal(xmlschema->data, - nulls, tableforest, targetns))); + nulls, tableforest, targetns))); } @@ -2576,7 +2576,7 @@ map_sql_table_to_xmlschema(TupleDesc tupdesc, Oid relid, bool nulls, if (OidIsValid(relid)) { - HeapTuple tuple; + HeapTuple tuple; Form_pg_class reltuple; tuple = SearchSysCache(RELOID, @@ -2590,14 +2590,14 @@ map_sql_table_to_xmlschema(TupleDesc tupdesc, Oid relid, bool nulls, true, false); tabletypename = map_multipart_sql_identifier_to_xml_name("TableType", - get_database_name(MyDatabaseId), - get_namespace_name(reltuple->relnamespace), - NameStr(reltuple->relname)); + get_database_name(MyDatabaseId), + get_namespace_name(reltuple->relnamespace), + NameStr(reltuple->relname)); rowtypename = map_multipart_sql_identifier_to_xml_name("RowType", - get_database_name(MyDatabaseId), - get_namespace_name(reltuple->relnamespace), - NameStr(reltuple->relname)); + get_database_name(MyDatabaseId), + get_namespace_name(reltuple->relnamespace), + NameStr(reltuple->relname)); ReleaseSysCache(tuple); } @@ -2615,7 +2615,7 @@ map_sql_table_to_xmlschema(TupleDesc tupdesc, Oid relid, bool nulls, xsd_schema_element_start(&result, targetns); appendStringInfoString(&result, - map_sql_typecoll_to_xmlschema_types(list_make1(tupdesc))); + map_sql_typecoll_to_xmlschema_types(list_make1(tupdesc))); appendStringInfo(&result, "<xsd:complexType name=\"%s\">\n" @@ -2624,10 +2624,10 @@ map_sql_table_to_xmlschema(TupleDesc tupdesc, Oid relid, bool nulls, for (i = 0; i < tupdesc->natts; i++) appendStringInfo(&result, - " <xsd:element name=\"%s\" type=\"%s\"%s></xsd:element>\n", - map_sql_identifier_to_xml_name(NameStr(tupdesc->attrs[i]->attname), - true, false), - map_sql_type_to_xml_name(tupdesc->attrs[i]->atttypid, -1), + " <xsd:element name=\"%s\" type=\"%s\"%s></xsd:element>\n", + map_sql_identifier_to_xml_name(NameStr(tupdesc->attrs[i]->attname), + true, false), + map_sql_type_to_xml_name(tupdesc->attrs[i]->atttypid, -1), nulls ? " nillable=\"true\"" : " minOccurs=\"0\""); appendStringInfoString(&result, @@ -2695,15 +2695,15 @@ map_sql_schema_to_xmlschema_types(Oid nspid, List *relid_list, bool nulls, appendStringInfoString(&result, " <xsd:sequence>\n"); - foreach (cell, relid_list) + foreach(cell, relid_list) { - Oid relid = lfirst_oid(cell); - char *relname = get_rel_name(relid); - char *xmltn = map_sql_identifier_to_xml_name(relname, true, false); - char *tabletypename = map_multipart_sql_identifier_to_xml_name(tableforest ? "RowType" : "TableType", - dbname, - nspname, - relname); + Oid relid = lfirst_oid(cell); + char *relname = get_rel_name(relid); + char *xmltn = map_sql_identifier_to_xml_name(relname, true, false); + char *tabletypename = map_multipart_sql_identifier_to_xml_name(tableforest ? "RowType" : "TableType", + dbname, + nspname, + relname); if (!tableforest) appendStringInfo(&result, @@ -2762,15 +2762,15 @@ map_sql_catalog_to_xmlschema_types(List *nspid_list, bool nulls, appendStringInfoString(&result, " <xsd:all>\n"); - foreach (cell, nspid_list) + foreach(cell, nspid_list) { - Oid nspid = lfirst_oid(cell); + Oid nspid = lfirst_oid(cell); char *nspname = get_namespace_name(nspid); - char *xmlsn = map_sql_identifier_to_xml_name(nspname, true, false); - char *schematypename = map_multipart_sql_identifier_to_xml_name("SchemaType", - dbname, - nspname, - NULL); + char *xmlsn = map_sql_identifier_to_xml_name(nspname, true, false); + char *schematypename = map_multipart_sql_identifier_to_xml_name("SchemaType", + dbname, + nspname, + NULL); appendStringInfo(&result, " <xsd:element name=\"%s\" type=\"%s\"/>\n", @@ -2800,7 +2800,7 @@ map_sql_type_to_xml_name(Oid typeoid, int typmod) initStringInfo(&result); - switch(typeoid) + switch (typeoid) { case BPCHAROID: if (typmod == -1) @@ -2871,25 +2871,25 @@ map_sql_type_to_xml_name(Oid typeoid, int typmod) appendStringInfo(&result, "XML"); break; default: - { - HeapTuple tuple; - Form_pg_type typtuple; - - tuple = SearchSysCache(TYPEOID, - ObjectIdGetDatum(typeoid), - 0, 0, 0); - if (!HeapTupleIsValid(tuple)) - elog(ERROR, "cache lookup failed for type %u", typeoid); - typtuple = (Form_pg_type) GETSTRUCT(tuple); - - appendStringInfoString(&result, - map_multipart_sql_identifier_to_xml_name((typtuple->typtype == TYPTYPE_DOMAIN) ? "Domain" : "UDT", - get_database_name(MyDatabaseId), - get_namespace_name(typtuple->typnamespace), - NameStr(typtuple->typname))); - - ReleaseSysCache(tuple); - } + { + HeapTuple tuple; + Form_pg_type typtuple; + + tuple = SearchSysCache(TYPEOID, + ObjectIdGetDatum(typeoid), + 0, 0, 0); + if (!HeapTupleIsValid(tuple)) + elog(ERROR, "cache lookup failed for type %u", typeoid); + typtuple = (Form_pg_type) GETSTRUCT(tuple); + + appendStringInfoString(&result, + map_multipart_sql_identifier_to_xml_name((typtuple->typtype == TYPTYPE_DOMAIN) ? "Domain" : "UDT", + get_database_name(MyDatabaseId), + get_namespace_name(typtuple->typnamespace), + NameStr(typtuple->typname))); + + ReleaseSysCache(tuple); + } } return result.data; @@ -2911,7 +2911,7 @@ map_sql_typecoll_to_xmlschema_types(List *tupdesc_list) /* extract all column types used in the set of TupleDescs */ foreach(cell0, tupdesc_list) { - TupleDesc tupdesc = (TupleDesc) lfirst(cell0); + TupleDesc tupdesc = (TupleDesc) lfirst(cell0); for (i = 0; i < tupdesc->natts; i++) { @@ -2925,8 +2925,8 @@ map_sql_typecoll_to_xmlschema_types(List *tupdesc_list) /* add base types of domains */ foreach(cell0, uniquetypes) { - Oid typid = lfirst_oid(cell0); - Oid basetypid = getBaseType(typid); + Oid typid = lfirst_oid(cell0); + Oid basetypid = getBaseType(typid); if (basetypid != typid) uniquetypes = list_append_unique_oid(uniquetypes, basetypid); @@ -2951,7 +2951,7 @@ map_sql_typecoll_to_xmlschema_types(List *tupdesc_list) * sections 9.11 and 9.15. * * (The distinction between 9.11 and 9.15 is basically that 9.15 adds - * a name attribute, which this function does. The name-less version + * a name attribute, which this function does. The name-less version * 9.11 doesn't appear to be required anywhere.) */ static const char * @@ -2976,14 +2976,14 @@ map_sql_type_to_xmlschema_type(Oid typeoid, int typmod) appendStringInfo(&result, "<xsd:simpleType name=\"%s\">\n", typename); - switch(typeoid) + switch (typeoid) { case BPCHAROID: case VARCHAROID: case TEXTOID: if (typmod != -1) appendStringInfo(&result, - " <xsd:restriction base=\"xsd:string\">\n" + " <xsd:restriction base=\"xsd:string\">\n" " <xsd:maxLength value=\"%d\"/>\n" " </xsd:restriction>\n", typmod - VARHDRSZ); @@ -2993,14 +2993,14 @@ map_sql_type_to_xmlschema_type(Oid typeoid, int typmod) appendStringInfo(&result, " <xsd:restriction base=\"xsd:%s\">\n" " </xsd:restriction>\n", - xmlbinary == XMLBINARY_BASE64 ? "base64Binary" : "hexBinary"); + xmlbinary == XMLBINARY_BASE64 ? "base64Binary" : "hexBinary"); case NUMERICOID: if (typmod != -1) appendStringInfo(&result, - " <xsd:restriction base=\"xsd:decimal\">\n" + " <xsd:restriction base=\"xsd:decimal\">\n" " <xsd:totalDigits value=\"%d\"/>\n" - " <xsd:fractionDigits value=\"%d\"/>\n" + " <xsd:fractionDigits value=\"%d\"/>\n" " </xsd:restriction>\n", ((typmod - VARHDRSZ) >> 16) & 0xffff, (typmod - VARHDRSZ) & 0xffff); @@ -3027,16 +3027,16 @@ map_sql_type_to_xmlschema_type(Oid typeoid, int typmod) case INT8OID: appendStringInfo(&result, " <xsd:restriction base=\"xsd:long\">\n" - " <xsd:maxInclusive value=\"" INT64_FORMAT "\"/>\n" - " <xsd:minInclusive value=\"" INT64_FORMAT "\"/>\n" + " <xsd:maxInclusive value=\"" INT64_FORMAT "\"/>\n" + " <xsd:minInclusive value=\"" INT64_FORMAT "\"/>\n" " </xsd:restriction>\n", - (((uint64) 1) << (sizeof(int64) * 8 - 1)) - 1, + (((uint64) 1) << (sizeof(int64) * 8 - 1)) - 1, (((uint64) 1) << (sizeof(int64) * 8 - 1))); break; case FLOAT4OID: appendStringInfo(&result, - " <xsd:restriction base=\"xsd:float\"></xsd:restriction>\n"); + " <xsd:restriction base=\"xsd:float\"></xsd:restriction>\n"); break; case FLOAT8OID: @@ -3051,49 +3051,49 @@ map_sql_type_to_xmlschema_type(Oid typeoid, int typmod) case TIMEOID: case TIMETZOID: - { - const char *tz = (typeoid == TIMETZOID ? "(+|-)\\p{Nd}{2}:\\p{Nd}{2}" : ""); - - if (typmod == -1) - appendStringInfo(&result, - " <xsd:restriction base=\"xsd:time\">\n" - " <xsd:pattern value=\"\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}(.\\p{Nd}+)?%s\"/>\n" - " </xsd:restriction>\n", tz); - else if (typmod == 0) - appendStringInfo(&result, - " <xsd:restriction base=\"xsd:time\">\n" - " <xsd:pattern value=\"\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}%s\"/>\n" - " </xsd:restriction>\n", tz); - else - appendStringInfo(&result, - " <xsd:restriction base=\"xsd:time\">\n" - " <xsd:pattern value=\"\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}.\\p{Nd}{%d}%s\"/>\n" - " </xsd:restriction>\n", typmod - VARHDRSZ, tz); - break; - } + { + const char *tz = (typeoid == TIMETZOID ? "(+|-)\\p{Nd}{2}:\\p{Nd}{2}" : ""); + + if (typmod == -1) + appendStringInfo(&result, + " <xsd:restriction base=\"xsd:time\">\n" + " <xsd:pattern value=\"\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}(.\\p{Nd}+)?%s\"/>\n" + " </xsd:restriction>\n", tz); + else if (typmod == 0) + appendStringInfo(&result, + " <xsd:restriction base=\"xsd:time\">\n" + " <xsd:pattern value=\"\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}%s\"/>\n" + " </xsd:restriction>\n", tz); + else + appendStringInfo(&result, + " <xsd:restriction base=\"xsd:time\">\n" + " <xsd:pattern value=\"\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}.\\p{Nd}{%d}%s\"/>\n" + " </xsd:restriction>\n", typmod - VARHDRSZ, tz); + break; + } case TIMESTAMPOID: case TIMESTAMPTZOID: - { - const char *tz = (typeoid == TIMESTAMPTZOID ? "(+|-)\\p{Nd}{2}:\\p{Nd}{2}" : ""); - - if (typmod == -1) - appendStringInfo(&result, - " <xsd:restriction base=\"xsd:dateTime\">\n" - " <xsd:pattern value=\"\\p{Nd}{4}-\\p{Nd}{2}-\\p{Nd}{2}T\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}(.\\p{Nd}+)?%s\"/>\n" - " </xsd:restriction>\n", tz); - else if (typmod == 0) - appendStringInfo(&result, - " <xsd:restriction base=\"xsd:dateTime\">\n" - " <xsd:pattern value=\"\\p{Nd}{4}-\\p{Nd}{2}-\\p{Nd}{2}T\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}%s\"/>\n" - " </xsd:restriction>\n", tz); - else - appendStringInfo(&result, - " <xsd:restriction base=\"xsd:dateTime\">\n" - " <xsd:pattern value=\"\\p{Nd}{4}-\\p{Nd}{2}-\\p{Nd}{2}T\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}.\\p{Nd}{%d}%s\"/>\n" - " </xsd:restriction>\n", typmod - VARHDRSZ, tz); - break; - } + { + const char *tz = (typeoid == TIMESTAMPTZOID ? "(+|-)\\p{Nd}{2}:\\p{Nd}{2}" : ""); + + if (typmod == -1) + appendStringInfo(&result, + " <xsd:restriction base=\"xsd:dateTime\">\n" + " <xsd:pattern value=\"\\p{Nd}{4}-\\p{Nd}{2}-\\p{Nd}{2}T\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}(.\\p{Nd}+)?%s\"/>\n" + " </xsd:restriction>\n", tz); + else if (typmod == 0) + appendStringInfo(&result, + " <xsd:restriction base=\"xsd:dateTime\">\n" + " <xsd:pattern value=\"\\p{Nd}{4}-\\p{Nd}{2}-\\p{Nd}{2}T\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}%s\"/>\n" + " </xsd:restriction>\n", tz); + else + appendStringInfo(&result, + " <xsd:restriction base=\"xsd:dateTime\">\n" + " <xsd:pattern value=\"\\p{Nd}{4}-\\p{Nd}{2}-\\p{Nd}{2}T\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}.\\p{Nd}{%d}%s\"/>\n" + " </xsd:restriction>\n", typmod - VARHDRSZ, tz); + break; + } case DATEOID: appendStringInfo(&result, @@ -3105,14 +3105,14 @@ map_sql_type_to_xmlschema_type(Oid typeoid, int typmod) default: if (get_typtype(typeoid) == TYPTYPE_DOMAIN) { - Oid base_typeoid; - int32 base_typmod = -1; + Oid base_typeoid; + int32 base_typmod = -1; base_typeoid = getBaseTypeAndTypmod(typeoid, &base_typmod); appendStringInfo(&result, " <xsd:restriction base=\"%s\"/>\n", - map_sql_type_to_xml_name(base_typeoid, base_typmod)); + map_sql_type_to_xml_name(base_typeoid, base_typmod)); } break; } @@ -3126,7 +3126,7 @@ map_sql_type_to_xmlschema_type(Oid typeoid, int typmod) /* * Map an SQL row to an XML element, taking the row from the active - * SPI cursor. See also SQL/XML:2003 section 9.12. + * SPI cursor. See also SQL/XML:2003 section 9.12. */ static void SPI_sql_row_to_xmlelement(int rownum, StringInfo result, char *tablename, @@ -3151,11 +3151,11 @@ SPI_sql_row_to_xmlelement(int rownum, StringInfo result, char *tablename, else appendStringInfoString(result, "<row>\n"); - for(i = 1; i <= SPI_tuptable->tupdesc->natts; i++) + for (i = 1; i <= SPI_tuptable->tupdesc->natts; i++) { - char *colname; - Datum colval; - bool isnull; + char *colname; + Datum colval; + bool isnull; colname = map_sql_identifier_to_xml_name(SPI_fname(SPI_tuptable->tupdesc, i), true, false); @@ -3172,7 +3172,7 @@ SPI_sql_row_to_xmlelement(int rownum, StringInfo result, char *tablename, appendStringInfo(result, " <%s>%s</%s>\n", colname, map_sql_value_to_xml_value(colval, - SPI_gettypeid(SPI_tuptable->tupdesc, i)), + SPI_gettypeid(SPI_tuptable->tupdesc, i)), colname); } @@ -3191,18 +3191,18 @@ SPI_sql_row_to_xmlelement(int rownum, StringInfo result, char *tablename, */ #ifdef USE_LIBXML -/* +/* * Convert XML node to text (dump subtree in case of element, * return value otherwise) */ static text * xml_xmlnodetoxmltype(xmlNodePtr cur) { - xmlChar *str; - xmltype *result; - size_t len; - xmlBufferPtr buf; - + xmlChar *str; + xmltype *result; + size_t len; + xmlBufferPtr buf; + if (cur->type == XML_ELEMENT_NODE) { buf = xmlBufferCreate(); @@ -3218,7 +3218,7 @@ xml_xmlnodetoxmltype(xmlNodePtr cur) SET_VARSIZE(result, len + VARHDRSZ); memcpy(VARDATA(result), str, len); } - + return result; } #endif @@ -3239,19 +3239,19 @@ xpath(PG_FUNCTION_ARGS) { #ifdef USE_LIBXML text *xpath_expr_text = PG_GETARG_TEXT_P(0); - xmltype *data = PG_GETARG_XML_P(1); + xmltype *data = PG_GETARG_XML_P(1); ArrayType *namespaces = PG_GETARG_ARRAYTYPE_P(2); - ArrayBuildState *astate = NULL; - xmlParserCtxtPtr ctxt = NULL; - xmlDocPtr doc = NULL; - xmlXPathContextPtr xpathctx = NULL; - xmlXPathCompExprPtr xpathcomp = NULL; - xmlXPathObjectPtr xpathobj = NULL; + ArrayBuildState *astate = NULL; + xmlParserCtxtPtr ctxt = NULL; + xmlDocPtr doc = NULL; + xmlXPathContextPtr xpathctx = NULL; + xmlXPathCompExprPtr xpathcomp = NULL; + xmlXPathObjectPtr xpathobj = NULL; char *datastr; int32 len; int32 xpath_len; - xmlChar *string; - xmlChar *xpath_expr; + xmlChar *string; + xmlChar *xpath_expr; int i; int res_nitems; int ndim; @@ -3260,13 +3260,13 @@ xpath(PG_FUNCTION_ARGS) int ns_count; /* - * Namespace mappings are passed as text[]. If an empty array is - * passed (ndim = 0, "0-dimensional"), then there are no namespace - * mappings. Else, a 2-dimensional array with length of the - * second axis being equal to 2 should be passed, i.e., every - * subarray contains 2 elements, the first element defining the - * name, the second one the URI. Example: ARRAY[ARRAY['myns', - * 'http://example.com'], ARRAY['myns2', 'http://example2.com']]. + * Namespace mappings are passed as text[]. If an empty array is passed + * (ndim = 0, "0-dimensional"), then there are no namespace mappings. + * Else, a 2-dimensional array with length of the second axis being equal + * to 2 should be passed, i.e., every subarray contains 2 elements, the + * first element defining the name, the second one the URI. Example: + * ARRAY[ARRAY['myns', 'http://example.com'], ARRAY['myns2', + * 'http://example2.com']]. */ ndim = ARR_NDIM(namespaces); if (ndim != 0) @@ -3287,7 +3287,7 @@ xpath(PG_FUNCTION_ARGS) &ns_names_uris, &ns_names_uris_nulls, &ns_count); - Assert((ns_count % 2) == 0); /* checked above */ + Assert((ns_count % 2) == 0); /* checked above */ ns_count /= 2; /* count pairs only */ } else @@ -3306,11 +3306,10 @@ xpath(PG_FUNCTION_ARGS) errmsg("empty XPath expression"))); /* - * To handle both documents and fragments, regardless of the fact - * whether the XML datum has a single root (XML well-formedness), - * we wrap the XML datum in a dummy element (<x>...</x>) and - * extend the XPath expression accordingly. To do it, throw away - * the XML prolog, if any. + * To handle both documents and fragments, regardless of the fact whether + * the XML datum has a single root (XML well-formedness), we wrap the XML + * datum in a dummy element (<x>...</x>) and extend the XPath expression + * accordingly. To do it, throw away the XML prolog, if any. */ if (len >= 5 && xmlStrncmp((xmlChar *) datastr, (xmlChar *) "<?xml", 5) == 0) @@ -3335,7 +3334,7 @@ xpath(PG_FUNCTION_ARGS) string = xmlStrncat(string, (xmlChar *) "</x>", 5); len += 7; xpath_expr = xmlStrncatNew((xmlChar *) "/x", - (xmlChar *) VARDATA(xpath_expr_text), xpath_len); + (xmlChar *) VARDATA(xpath_expr_text), xpath_len); xpath_len += 2; xml_init(); @@ -3344,9 +3343,10 @@ xpath(PG_FUNCTION_ARGS) PG_TRY(); { xmlInitParser(); + /* - * redundant XML parsing (two parsings for the same value - * during one command execution are possible) + * redundant XML parsing (two parsings for the same value during one + * command execution are possible) */ ctxt = xmlNewParserCtxt(); if (ctxt == NULL) @@ -3370,20 +3370,20 @@ xpath(PG_FUNCTION_ARGS) { for (i = 0; i < ns_count; i++) { - char *ns_name; - char *ns_uri; + char *ns_name; + char *ns_uri; if (ns_names_uris_nulls[i * 2] || ns_names_uris_nulls[i * 2 + 1]) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), - errmsg("neither namespace name nor URI may be null"))); + errmsg("neither namespace name nor URI may be null"))); ns_name = _textout(ns_names_uris[i * 2]); ns_uri = _textout(ns_names_uris[i * 2 + 1]); if (xmlXPathRegisterNs(xpathctx, (xmlChar *) ns_name, (xmlChar *) ns_uri) != 0) - ereport(ERROR, /* is this an internal error??? */ + ereport(ERROR, /* is this an internal error??? */ (errmsg("could not register XML namespace with name \"%s\" and URI \"%s\"", ns_name, ns_uri))); } @@ -3413,6 +3413,7 @@ xpath(PG_FUNCTION_ARGS) { Datum elem; bool elemisnull = false; + elem = PointerGetDatum(xml_xmlnodetoxmltype(xpathobj->nodesetval->nodeTab[i])); astate = accumArrayResult(astate, elem, elemisnull, XMLOID, diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c index 9413d5ad36..bfaa14771d 100644 --- a/src/backend/utils/cache/catcache.c +++ b/src/backend/utils/cache/catcache.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/cache/catcache.c,v 1.138 2007/08/21 01:11:19 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/cache/catcache.c,v 1.139 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -1043,10 +1043,10 @@ IndexScanOK(CatCache *cache, ScanKey cur_skey) if (cache->id == INDEXRELID) { /* - * Rather than tracking exactly which indexes have to be loaded - * before we can use indexscans (which changes from time to time), - * just force all pg_index searches to be heap scans until we've - * built the critical relcaches. + * Rather than tracking exactly which indexes have to be loaded before + * we can use indexscans (which changes from time to time), just force + * all pg_index searches to be heap scans until we've built the + * critical relcaches. */ if (!criticalRelcachesBuilt) return false; diff --git a/src/backend/utils/cache/inval.c b/src/backend/utils/cache/inval.c index a9b5bd4b1c..844dbc2be0 100644 --- a/src/backend/utils/cache/inval.c +++ b/src/backend/utils/cache/inval.c @@ -80,7 +80,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/cache/inval.c,v 1.80 2007/05/02 21:08:46 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/cache/inval.c,v 1.81 2007/11/15 21:14:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -592,7 +592,7 @@ PrepareForTupleInvalidation(Relation relation, HeapTuple tuple) * This essentially means that only backends in this same database * will react to the relcache flush request. This is in fact * appropriate, since only those backends could see our pg_attribute - * change anyway. It looks a bit ugly though. (In practice, shared + * change anyway. It looks a bit ugly though. (In practice, shared * relations can't have schema changes after bootstrap, so we should * never come here for a shared rel anyway.) */ @@ -604,7 +604,7 @@ PrepareForTupleInvalidation(Relation relation, HeapTuple tuple) /* * When a pg_index row is updated, we should send out a relcache inval - * for the index relation. As above, we don't know the shared status + * for the index relation. As above, we don't know the shared status * of the index, but in practice it doesn't matter since indexes of * shared catalogs can't have such updates. */ diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index d82e7debf5..ac2d026ec7 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/cache/lsyscache.c,v 1.153 2007/10/13 15:55:40 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/cache/lsyscache.c,v 1.154 2007/11/15 21:14:40 momjian Exp $ * * NOTES * Eventually, the index information should go through here, too. @@ -149,13 +149,13 @@ get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, * (This indicates that the operator is not a valid ordering operator.) * * Note: the operator could be registered in multiple families, for example - * if someone were to build a "reverse sort" opfamily. This would result in + * if someone were to build a "reverse sort" opfamily. This would result in * uncertainty as to whether "ORDER BY USING op" would default to NULLS FIRST * or NULLS LAST, as well as inefficient planning due to failure to match up * pathkeys that should be the same. So we want a determinate result here. * Because of the way the syscache search works, we'll use the interpretation * associated with the opfamily with smallest OID, which is probably - * determinate enough. Since there is no longer any particularly good reason + * determinate enough. Since there is no longer any particularly good reason * to build reverse-sort opfamilies, it doesn't seem worth expending any * additional effort on ensuring consistency. */ @@ -238,7 +238,7 @@ get_compare_function_for_ordering_op(Oid opno, Oid *cmpfunc, bool *reverse) opcintype, opcintype, BTORDER_PROC); - if (!OidIsValid(*cmpfunc)) /* should not happen */ + if (!OidIsValid(*cmpfunc)) /* should not happen */ elog(ERROR, "missing support function %d(%u,%u) in opfamily %u", BTORDER_PROC, opcintype, opcintype, opfamily); *reverse = (strategy == BTGreaterStrategyNumber); @@ -322,7 +322,7 @@ get_ordering_op_for_equality_op(Oid opno, bool use_lhs_type) if (aform->amopstrategy == BTEqualStrategyNumber) { /* Found a suitable opfamily, get matching ordering operator */ - Oid typid; + Oid typid; typid = use_lhs_type ? aform->amoplefttype : aform->amoprighttype; result = get_opfamily_member(aform->amopfamily, @@ -350,7 +350,7 @@ get_ordering_op_for_equality_op(Oid opno, bool use_lhs_type) * * The planner currently uses simple equal() tests to compare the lists * returned by this function, which makes the list order relevant, though - * strictly speaking it should not be. Because of the way syscache list + * strictly speaking it should not be. Because of the way syscache list * searches are handled, in normal operation the result will be sorted by OID * so everything works fine. If running with system index usage disabled, * the result ordering is unspecified and hence the planner might fail to @@ -445,6 +445,7 @@ get_compatible_hash_operators(Oid opno, result = true; break; } + /* * Get the matching single-type operator(s). Failure probably * shouldn't happen --- it implies a bogus opfamily --- but @@ -2162,7 +2163,7 @@ type_is_rowtype(Oid typid) /* * type_is_enum - * Returns true if the given type is an enum type. + * Returns true if the given type is an enum type. */ bool type_is_enum(Oid typid) @@ -2239,7 +2240,7 @@ Oid get_array_type(Oid typid) { HeapTuple tp; - Oid result = InvalidOid; + Oid result = InvalidOid; tp = SearchSysCache(TYPEOID, ObjectIdGetDatum(typid), @@ -2444,7 +2445,7 @@ get_typmodout(Oid typid) else return InvalidOid; } -#endif /* NOT_USED */ +#endif /* NOT_USED */ /* ---------- STATISTICS CACHE ---------- */ diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c index 2f52ed7a8c..b299bc659b 100644 --- a/src/backend/utils/cache/plancache.c +++ b/src/backend/utils/cache/plancache.c @@ -15,7 +15,7 @@ * the tables they depend on. When (and if) the next demand for a cached * plan occurs, the query will be replanned. Note that this could result * in an error, for example if a column referenced by the query is no - * longer present. The creator of a cached plan can specify whether it + * longer present. The creator of a cached plan can specify whether it * is allowable for the query to change output tupdesc on replan (this * could happen with "SELECT *" for example) --- if so, it's up to the * caller to notice changes and cope with them. @@ -33,7 +33,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/cache/plancache.c,v 1.12 2007/10/11 18:05:27 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/cache/plancache.c,v 1.13 2007/11/15 21:14:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -55,35 +55,35 @@ typedef struct { - void (*callback) (); + void (*callback) (); void *arg; -} ScanQueryWalkerContext; +} ScanQueryWalkerContext; typedef struct { Oid inval_relid; CachedPlan *plan; -} InvalRelidContext; +} InvalRelidContext; static List *cached_plans_list = NIL; -static void StoreCachedPlan(CachedPlanSource *plansource, List *stmt_list, - MemoryContext plan_context); +static void StoreCachedPlan(CachedPlanSource * plansource, List *stmt_list, + MemoryContext plan_context); static List *do_planning(List *querytrees, int cursorOptions); static void AcquireExecutorLocks(List *stmt_list, bool acquire); static void AcquirePlannerLocks(List *stmt_list, bool acquire); static void LockRelid(Oid relid, LOCKMODE lockmode, void *arg); static void UnlockRelid(Oid relid, LOCKMODE lockmode, void *arg); static void ScanQueryForRelids(Query *parsetree, - void (*callback) (), - void *arg); -static bool ScanQueryWalker(Node *node, ScanQueryWalkerContext *context); + void (*callback) (), + void *arg); +static bool ScanQueryWalker(Node *node, ScanQueryWalkerContext * context); static bool rowmark_member(List *rowMarks, int rt_index); static bool plan_list_is_transient(List *stmt_list); static void PlanCacheCallback(Datum arg, Oid relid); static void InvalRelid(Oid relid, LOCKMODE lockmode, - InvalRelidContext *context); + InvalRelidContext * context); /* @@ -153,7 +153,7 @@ CreateCachedPlan(Node *raw_parse_tree, plansource = (CachedPlanSource *) palloc(sizeof(CachedPlanSource)); plansource->raw_parse_tree = copyObject(raw_parse_tree); plansource->query_string = query_string ? pstrdup(query_string) : NULL; - plansource->commandTag = commandTag; /* no copying needed */ + plansource->commandTag = commandTag; /* no copying needed */ if (num_params > 0) { plansource->param_types = (Oid *) palloc(num_params * sizeof(Oid)); @@ -166,7 +166,7 @@ CreateCachedPlan(Node *raw_parse_tree, plansource->fully_planned = fully_planned; plansource->fixed_result = fixed_result; plansource->search_path = search_path; - plansource->generation = 0; /* StoreCachedPlan will increment */ + plansource->generation = 0; /* StoreCachedPlan will increment */ plansource->resultDesc = PlanCacheComputeResultDesc(stmt_list); plansource->plan = NULL; plansource->context = source_context; @@ -200,7 +200,7 @@ CreateCachedPlan(Node *raw_parse_tree, * avoids extra copy steps during plan construction. If the query ever does * need replanning, we'll generate a separate new CachedPlan at that time, but * the CachedPlanSource and the initial CachedPlan share the caller-provided - * context and go away together when neither is needed any longer. (Because + * context and go away together when neither is needed any longer. (Because * the parser and planner generate extra cruft in addition to their real * output, this approach means that the context probably contains a bunch of * useless junk as well as the useful trees. Hence, this method is a @@ -241,14 +241,14 @@ FastCreateCachedPlan(Node *raw_parse_tree, plansource = (CachedPlanSource *) palloc(sizeof(CachedPlanSource)); plansource->raw_parse_tree = raw_parse_tree; plansource->query_string = query_string; - plansource->commandTag = commandTag; /* no copying needed */ + plansource->commandTag = commandTag; /* no copying needed */ plansource->param_types = param_types; plansource->num_params = num_params; plansource->cursor_options = cursor_options; plansource->fully_planned = fully_planned; plansource->fixed_result = fixed_result; plansource->search_path = search_path; - plansource->generation = 0; /* StoreCachedPlan will increment */ + plansource->generation = 0; /* StoreCachedPlan will increment */ plansource->resultDesc = PlanCacheComputeResultDesc(stmt_list); plansource->plan = NULL; plansource->context = context; @@ -284,7 +284,7 @@ FastCreateCachedPlan(Node *raw_parse_tree, * Common subroutine for CreateCachedPlan and RevalidateCachedPlan. */ static void -StoreCachedPlan(CachedPlanSource *plansource, +StoreCachedPlan(CachedPlanSource * plansource, List *stmt_list, MemoryContext plan_context) { @@ -295,8 +295,8 @@ StoreCachedPlan(CachedPlanSource *plansource, { /* * Make a dedicated memory context for the CachedPlan and its - * subsidiary data. It's probably not going to be large, but - * just in case, use the default maxsize parameter. + * subsidiary data. It's probably not going to be large, but just in + * case, use the default maxsize parameter. */ plan_context = AllocSetContextCreate(CacheMemoryContext, "CachedPlan", @@ -345,12 +345,12 @@ StoreCachedPlan(CachedPlanSource *plansource, * DropCachedPlan: destroy a cached plan. * * Actually this only destroys the CachedPlanSource: the referenced CachedPlan - * is released, but not destroyed until its refcount goes to zero. That + * is released, but not destroyed until its refcount goes to zero. That * handles the situation where DropCachedPlan is called while the plan is * still in use. */ void -DropCachedPlan(CachedPlanSource *plansource) +DropCachedPlan(CachedPlanSource * plansource) { /* Validity check that we were given a CachedPlanSource */ Assert(list_member_ptr(cached_plans_list, plansource)); @@ -393,7 +393,7 @@ DropCachedPlan(CachedPlanSource *plansource) * is used for that work. */ CachedPlan * -RevalidateCachedPlan(CachedPlanSource *plansource, bool useResOwner) +RevalidateCachedPlan(CachedPlanSource * plansource, bool useResOwner) { CachedPlan *plan; @@ -402,9 +402,8 @@ RevalidateCachedPlan(CachedPlanSource *plansource, bool useResOwner) /* * If the plan currently appears valid, acquire locks on the referenced - * objects; then check again. We need to do it this way to cover the - * race condition that an invalidation message arrives before we get - * the lock. + * objects; then check again. We need to do it this way to cover the race + * condition that an invalidation message arrives before we get the lock. */ plan = plansource->plan; if (plan && !plan->dead) @@ -430,8 +429,8 @@ RevalidateCachedPlan(CachedPlanSource *plansource, bool useResOwner) plan->dead = true; /* - * By now, if any invalidation has happened, PlanCacheCallback - * will have marked the plan dead. + * By now, if any invalidation has happened, PlanCacheCallback will + * have marked the plan dead. */ if (plan->dead) { @@ -458,8 +457,8 @@ RevalidateCachedPlan(CachedPlanSource *plansource, bool useResOwner) */ if (!plan) { - List *slist; - TupleDesc resultDesc; + List *slist; + TupleDesc resultDesc; /* * Restore the search_path that was in use when the plan was made. @@ -486,7 +485,7 @@ RevalidateCachedPlan(CachedPlanSource *plansource, bool useResOwner) } /* - * Check or update the result tupdesc. XXX should we use a weaker + * Check or update the result tupdesc. XXX should we use a weaker * condition than equalTupleDescs() here? */ resultDesc = PlanCacheComputeResultDesc(slist); @@ -550,12 +549,12 @@ do_planning(List *querytrees, int cursorOptions) /* * If a snapshot is already set (the normal case), we can just use that * for planning. But if it isn't, we have to tell pg_plan_queries to make - * a snap if it needs one. In that case we should arrange to reset + * a snap if it needs one. In that case we should arrange to reset * ActiveSnapshot afterward, to ensure that RevalidateCachedPlan has no - * caller-visible effects on the snapshot. Having to replan is an unusual + * caller-visible effects on the snapshot. Having to replan is an unusual * case, and it seems a really bad idea for RevalidateCachedPlan to affect - * the snapshot only in unusual cases. (Besides, the snap might have - * been created in a short-lived context.) + * the snapshot only in unusual cases. (Besides, the snap might have been + * created in a short-lived context.) */ if (ActiveSnapshot != NULL) stmt_list = pg_plan_queries(querytrees, cursorOptions, NULL, false); @@ -589,10 +588,10 @@ do_planning(List *querytrees, int cursorOptions) * * Note: useResOwner = false is used for releasing references that are in * persistent data structures, such as the parent CachedPlanSource or a - * Portal. Transient references should be protected by a resource owner. + * Portal. Transient references should be protected by a resource owner. */ void -ReleaseCachedPlan(CachedPlan *plan, bool useResOwner) +ReleaseCachedPlan(CachedPlan * plan, bool useResOwner) { if (useResOwner) ResourceOwnerForgetPlanCacheRef(CurrentResourceOwner, plan); @@ -633,10 +632,10 @@ AcquireExecutorLocks(List *stmt_list, bool acquire) continue; /* - * Acquire the appropriate type of lock on each relation OID. - * Note that we don't actually try to open the rel, and hence - * will not fail if it's been dropped entirely --- we'll just - * transiently acquire a non-conflicting lock. + * Acquire the appropriate type of lock on each relation OID. Note + * that we don't actually try to open the rel, and hence will not + * fail if it's been dropped entirely --- we'll just transiently + * acquire a non-conflicting lock. */ if (list_member_int(plannedstmt->resultRelations, rt_index)) lockmode = RowExclusiveLock; @@ -719,6 +718,7 @@ ScanQueryForRelids(Query *parsetree, switch (rte->rtekind) { case RTE_RELATION: + /* * Determine the lock type required for this RTE. */ @@ -767,7 +767,7 @@ ScanQueryForRelids(Query *parsetree, * Walker to find sublink subqueries for ScanQueryForRelids */ static bool -ScanQueryWalker(Node *node, ScanQueryWalkerContext *context) +ScanQueryWalker(Node *node, ScanQueryWalkerContext * context) { if (node == NULL) return false; @@ -782,8 +782,8 @@ ScanQueryWalker(Node *node, ScanQueryWalkerContext *context) } /* - * Do NOT recurse into Query nodes, because ScanQueryForRelids - * already processed subselects of subselects for us. + * Do NOT recurse into Query nodes, because ScanQueryForRelids already + * processed subselects of subselects for us. */ return expression_tree_walker(node, ScanQueryWalker, (void *) context); @@ -818,20 +818,20 @@ plan_list_is_transient(List *stmt_list) foreach(lc, stmt_list) { PlannedStmt *plannedstmt = (PlannedStmt *) lfirst(lc); - + if (!IsA(plannedstmt, PlannedStmt)) continue; /* Ignore utility statements */ if (plannedstmt->transientPlan) return true; - } + } return false; } /* * PlanCacheComputeResultDesc: given a list of either fully-planned statements - * or Queries, determine the result tupledesc it will produce. Returns NULL + * or Queries, determine the result tupledesc it will produce. Returns NULL * if the execution will not return tuples. * * Note: the result is created or copied into current memory context. @@ -924,22 +924,22 @@ PlanCacheCallback(Datum arg, Oid relid) Assert(!IsA(plannedstmt, Query)); if (!IsA(plannedstmt, PlannedStmt)) - continue; /* Ignore utility statements */ + continue; /* Ignore utility statements */ if ((relid == InvalidOid) ? plannedstmt->relationOids != NIL : list_member_oid(plannedstmt->relationOids, relid)) { /* Invalidate the plan! */ plan->dead = true; - break; /* out of stmt_list scan */ + break; /* out of stmt_list scan */ } } } else { /* - * For not-fully-planned entries we use ScanQueryForRelids, - * since a recursive traversal is needed. The callback API - * is a bit tedious but avoids duplication of coding. + * For not-fully-planned entries we use ScanQueryForRelids, since + * a recursive traversal is needed. The callback API is a bit + * tedious but avoids duplication of coding. */ InvalRelidContext context; @@ -970,7 +970,7 @@ ResetPlanCache(void) * ScanQueryForRelids callback function for PlanCacheCallback */ static void -InvalRelid(Oid relid, LOCKMODE lockmode, InvalRelidContext *context) +InvalRelid(Oid relid, LOCKMODE lockmode, InvalRelidContext * context) { if (relid == context->inval_relid || context->inval_relid == InvalidOid) context->plan->dead = true; diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 8efa9e6c4e..e28a79134e 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.263 2007/09/20 17:56:31 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.264 2007/11/15 21:14:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -932,7 +932,7 @@ RelationInitIndexAccessInfo(Relation relation) Datum indoptionDatum; bool isnull; oidvector *indclass; - int2vector *indoption; + int2vector *indoption; MemoryContext indexcxt; MemoryContext oldcontext; int natts; @@ -1030,8 +1030,8 @@ RelationInitIndexAccessInfo(Relation relation) /* * indclass cannot be referenced directly through the C struct, because it - * comes after the variable-width indkey field. Must extract the - * datum the hard way... + * comes after the variable-width indkey field. Must extract the datum + * the hard way... */ indclassDatum = fastgetattr(relation->rd_indextuple, Anum_pg_index_indclass, @@ -1041,9 +1041,9 @@ RelationInitIndexAccessInfo(Relation relation) indclass = (oidvector *) DatumGetPointer(indclassDatum); /* - * Fill the operator and support procedure OID arrays, as well as the - * info about opfamilies and opclass input types. (aminfo and - * supportinfo are left as zeroes, and are filled on-the-fly when used) + * Fill the operator and support procedure OID arrays, as well as the info + * about opfamilies and opclass input types. (aminfo and supportinfo are + * left as zeroes, and are filled on-the-fly when used) */ IndexSupportInitialize(indclass, relation->rd_operator, relation->rd_support, @@ -1655,8 +1655,8 @@ RelationReloadIndexInfo(Relation relation) ObjectIdGetDatum(RelationGetRelid(relation)), 0, 0, 0); if (!HeapTupleIsValid(tuple)) - elog(ERROR, "cache lookup failed for index %u", - RelationGetRelid(relation)); + elog(ERROR, "cache lookup failed for index %u", + RelationGetRelid(relation)); index = (Form_pg_index) GETSTRUCT(tuple); relation->rd_index->indisvalid = index->indisvalid; @@ -2078,7 +2078,7 @@ AtEOXact_RelationCache(bool isCommit) * for us to do here, so we keep a static flag that gets set if there is * anything to do. (Currently, this means either a relation is created in * the current xact, or one is given a new relfilenode, or an index list - * is forced.) For simplicity, the flag remains set till end of top-level + * is forced.) For simplicity, the flag remains set till end of top-level * transaction, even though we could clear it at subtransaction end in * some cases. */ @@ -2201,7 +2201,8 @@ AtEOSubXact_RelationCache(bool isCommit, SubTransactionId mySubid, } /* - * Likewise, update or drop any new-relfilenode-in-subtransaction hint. + * Likewise, update or drop any new-relfilenode-in-subtransaction + * hint. */ if (relation->rd_newRelfilenodeSubid == mySubid) { @@ -2228,7 +2229,7 @@ AtEOSubXact_RelationCache(bool isCommit, SubTransactionId mySubid, * RelationCacheMarkNewRelfilenode * * Mark the rel as having been given a new relfilenode in the current - * (sub) transaction. This is a hint that can be used to optimize + * (sub) transaction. This is a hint that can be used to optimize * later operations on the rel in the same transaction. */ void @@ -3165,9 +3166,9 @@ RelationGetIndexPredicate(Relation relation) Bitmapset * RelationGetIndexAttrBitmap(Relation relation) { - Bitmapset *indexattrs; - List *indexoidlist; - ListCell *l; + Bitmapset *indexattrs; + List *indexoidlist; + ListCell *l; MemoryContext oldcxt; /* Quick exit if we already computed the result. */ @@ -3196,7 +3197,7 @@ RelationGetIndexAttrBitmap(Relation relation) Oid indexOid = lfirst_oid(l); Relation indexDesc; IndexInfo *indexInfo; - int i; + int i; indexDesc = index_open(indexOid, AccessShareLock); @@ -3206,11 +3207,11 @@ RelationGetIndexAttrBitmap(Relation relation) /* Collect simple attribute references */ for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++) { - int attrnum = indexInfo->ii_KeyAttrNumbers[i]; + int attrnum = indexInfo->ii_KeyAttrNumbers[i]; if (attrnum != 0) indexattrs = bms_add_member(indexattrs, - attrnum - FirstLowInvalidHeapAttributeNumber); + attrnum - FirstLowInvalidHeapAttributeNumber); } /* Collect all attributes used in expressions, too */ diff --git a/src/backend/utils/cache/ts_cache.c b/src/backend/utils/cache/ts_cache.c index 63c5790556..921431d064 100644 --- a/src/backend/utils/cache/ts_cache.c +++ b/src/backend/utils/cache/ts_cache.c @@ -12,7 +12,7 @@ * safe to hold onto a pointer to the cache entry while doing things that * might result in recognizing a cache invalidation. Beware however that * subsidiary information might be deleted and reallocated somewhere else - * if a cache inval and reval happens! This does not look like it will be + * if a cache inval and reval happens! This does not look like it will be * a big problem as long as parser and dictionary methods do not attempt * any database access. * @@ -20,7 +20,7 @@ * Copyright (c) 2006-2007, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/cache/ts_cache.c,v 1.3 2007/09/10 00:57:21 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/cache/ts_cache.c,v 1.4 2007/11/15 21:14:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -143,8 +143,8 @@ lookup_ts_parser_cache(Oid prsId) if (entry == NULL || !entry->isvalid) { /* - * If we didn't find one, we want to make one. - * But first look up the object to be sure the OID is real. + * If we didn't find one, we want to make one. But first look up the + * object to be sure the OID is real. */ HeapTuple tp; Form_pg_ts_parser prs; @@ -245,8 +245,8 @@ lookup_ts_dictionary_cache(Oid dictId) if (entry == NULL || !entry->isvalid) { /* - * If we didn't find one, we want to make one. - * But first look up the object to be sure the OID is real. + * If we didn't find one, we want to make one. But first look up the + * object to be sure the OID is real. */ HeapTuple tpdict, tptmpl; @@ -325,8 +325,8 @@ lookup_ts_dictionary_cache(Oid dictId) MemoryContext oldcontext; /* - * Init method runs in dictionary's private memory context, - * and we make sure the options are stored there too + * Init method runs in dictionary's private memory context, and we + * make sure the options are stored there too */ oldcontext = MemoryContextSwitchTo(entry->dictCtx); @@ -340,7 +340,7 @@ lookup_ts_dictionary_cache(Oid dictId) entry->dictData = DatumGetPointer(OidFunctionCall1(template->tmplinit, - PointerGetDatum(dictoptions))); + PointerGetDatum(dictoptions))); MemoryContextSwitchTo(oldcontext); } @@ -410,8 +410,8 @@ lookup_ts_config_cache(Oid cfgId) if (entry == NULL || !entry->isvalid) { /* - * If we didn't find one, we want to make one. - * But first look up the object to be sure the OID is real. + * If we didn't find one, we want to make one. But first look up the + * object to be sure the OID is real. */ HeapTuple tp; Form_pg_ts_config cfg; @@ -492,7 +492,7 @@ lookup_ts_config_cache(Oid cfgId) while ((maptup = index_getnext(mapscan, ForwardScanDirection)) != NULL) { Form_pg_ts_config_map cfgmap = (Form_pg_ts_config_map) GETSTRUCT(maptup); - int toktype = cfgmap->maptokentype; + int toktype = cfgmap->maptokentype; if (toktype <= 0 || toktype > MAXTOKENTYPE) elog(ERROR, "maptokentype value %d is out of range", toktype); diff --git a/src/backend/utils/cache/typcache.c b/src/backend/utils/cache/typcache.c index a8a2409911..c80f3f6b0d 100644 --- a/src/backend/utils/cache/typcache.c +++ b/src/backend/utils/cache/typcache.c @@ -36,7 +36,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/cache/typcache.c,v 1.25 2007/04/02 03:49:39 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/cache/typcache.c,v 1.26 2007/11/15 21:14:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -169,7 +169,7 @@ lookup_type_cache(Oid type_id, int flags) TYPECACHE_BTREE_OPFAMILY)) && typentry->btree_opf == InvalidOid) { - Oid opclass; + Oid opclass; opclass = GetDefaultOpClass(type_id, BTREE_AM_OID); if (OidIsValid(opclass)) diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index c8ba87efab..bb010162ba 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -42,7 +42,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.197 2007/09/27 18:15:36 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.198 2007/11/15 21:14:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -250,9 +250,9 @@ errstart(int elevel, const char *filename, int lineno, /* * If we recurse more than once, the problem might be something broken - * in a context traceback routine. Abandon them too. We also - * abandon attempting to print the error statement (which, if long, - * could itself be the source of the recursive failure). + * in a context traceback routine. Abandon them too. We also abandon + * attempting to print the error statement (which, if long, could + * itself be the source of the recursive failure). */ if (recursion_depth > 2) { @@ -1129,10 +1129,10 @@ pg_re_throw(void) /* * If we get here, elog(ERROR) was thrown inside a PG_TRY block, which * we have now exited only to discover that there is no outer setjmp - * handler to pass the error to. Had the error been thrown outside the - * block to begin with, we'd have promoted the error to FATAL, so the - * correct behavior is to make it FATAL now; that is, emit it and then - * call proc_exit. + * handler to pass the error to. Had the error been thrown outside + * the block to begin with, we'd have promoted the error to FATAL, so + * the correct behavior is to make it FATAL now; that is, emit it and + * then call proc_exit. */ ErrorData *edata = &errordata[errordata_stack_depth]; @@ -1497,7 +1497,7 @@ log_line_prefix(StringInfo buf) } break; case 'c': - appendStringInfo(buf, "%lx.%x", (long)(MyStartTime),MyProcPid); + appendStringInfo(buf, "%lx.%x", (long) (MyStartTime), MyProcPid); break; case 'p': appendStringInfo(buf, "%d", MyProcPid); @@ -1517,14 +1517,14 @@ log_line_prefix(StringInfo buf) /* * Normally we print log timestamps in log_timezone, but - * during startup we could get here before that's set. - * If so, fall back to gmt_timezone (which guc.c ensures - * is set up before Log_line_prefix can become nonempty). + * during startup we could get here before that's set. If + * so, fall back to gmt_timezone (which guc.c ensures is + * set up before Log_line_prefix can become nonempty). */ tz = log_timezone ? log_timezone : gmt_timezone; pg_strftime(formatted_log_time, FORMATTED_TS_LEN, - /* leave room for milliseconds... */ + /* leave room for milliseconds... */ "%Y-%m-%d %H:%M:%S %Z", pg_localtime(&stamp_time, tz)); @@ -1618,25 +1618,25 @@ log_line_prefix(StringInfo buf) * We use the PostgreSQL defaults for CSV, i.e. quote = escape = '"' */ -static inline void -appendCSVLiteral(StringInfo buf, const char* data) +static inline void +appendCSVLiteral(StringInfo buf, const char *data) { - const char * p = data; - char c; - - appendStringInfoCharMacro(buf, '"'); - while ( (c = *p++) != '\0' ) - { - if (c == '"') - appendStringInfoCharMacro(buf, '"'); - appendStringInfoCharMacro(buf, c); - } - appendStringInfoCharMacro(buf, '"'); + const char *p = data; + char c; + + appendStringInfoCharMacro(buf, '"'); + while ((c = *p++) != '\0') + { + if (c == '"') + appendStringInfoCharMacro(buf, '"'); + appendStringInfoCharMacro(buf, c); + } + appendStringInfoCharMacro(buf, '"'); } -/* - * Constructs the error message, depending on the Errordata it gets, - * in CSV (comma separated values) format. The COPY command +/* + * Constructs the error message, depending on the Errordata it gets, + * in CSV (comma separated values) format. The COPY command * can then be used to load the messages into a table. */ static void @@ -1645,42 +1645,43 @@ write_csvlog(ErrorData *edata) StringInfoData msgbuf; StringInfoData buf; - /* static counter for line numbers */ - static long log_line_number = 0; - - /* has counter been reset in current process? */ - static int log_my_pid = 0; - - /* - * This is one of the few places where we'd rather not inherit a static - * variable's value from the postmaster. But since we will, reset it when - * MyProcPid changes. - */ - if (log_my_pid != MyProcPid) - { - log_line_number = 0; - log_my_pid = MyProcPid; + /* static counter for line numbers */ + static long log_line_number = 0; + + /* has counter been reset in current process? */ + static int log_my_pid = 0; + + /* + * This is one of the few places where we'd rather not inherit a static + * variable's value from the postmaster. But since we will, reset it when + * MyProcPid changes. + */ + if (log_my_pid != MyProcPid) + { + log_line_number = 0; + log_my_pid = MyProcPid; formatted_start_time[0] = '\0'; - } - log_line_number++; + } + log_line_number++; initStringInfo(&msgbuf); initStringInfo(&buf); - /* - * The format of the log output in CSV format: - * timestamp with milliseconds, username, databasename, session id, - * host and port number, process id, process line number, command tag, - * session start time, virtual transaction id, regular transaction id, - * error severity, sql state code, error message. + /* + * The format of the log output in CSV format: timestamp with + * milliseconds, username, databasename, session id, host and port number, + * process id, process line number, command tag, session start time, + * virtual transaction id, regular transaction id, error severity, sql + * state code, error message. */ - + /* timestamp_with_milliseconds */ - /* - * Check if the timestamp is already calculated for the syslog message, - * if it is, then no need to calculate it again, will use the same, - * else get the current timestamp. This is done to put same timestamp - * in both syslog and csvlog messages. + + /* + * Check if the timestamp is already calculated for the syslog message, if + * it is, then no need to calculate it again, will use the same, else get + * the current timestamp. This is done to put same timestamp in both + * syslog and csvlog messages. */ if (formatted_log_time[0] == '\0') { @@ -1688,20 +1689,20 @@ write_csvlog(ErrorData *edata) pg_time_t stamp_time; pg_tz *tz; char msbuf[8]; - + gettimeofday(&tv, NULL); stamp_time = (pg_time_t) tv.tv_sec; - + /* - * Normally we print log timestamps in log_timezone, but - * during startup we could get here before that's set. - * If so, fall back to gmt_timezone (which guc.c ensures - * is set up before Log_line_prefix can become nonempty). + * Normally we print log timestamps in log_timezone, but during + * startup we could get here before that's set. If so, fall back to + * gmt_timezone (which guc.c ensures is set up before Log_line_prefix + * can become nonempty). */ tz = log_timezone ? log_timezone : gmt_timezone; - + pg_strftime(formatted_log_time, FORMATTED_TS_LEN, - /* leave room for milliseconds... */ + /* leave room for milliseconds... */ "%Y-%m-%d %H:%M:%S %Z", pg_localtime(&stamp_time, tz)); @@ -1716,6 +1717,7 @@ write_csvlog(ErrorData *edata) if (MyProcPort) { const char *username = MyProcPort->user_name; + if (username == NULL || *username == '\0') username = _("[unknown]"); @@ -1730,7 +1732,7 @@ write_csvlog(ErrorData *edata) if (dbname == NULL || *dbname == '\0') dbname = _("[unknown]"); - + appendCSVLiteral(&buf, dbname); } appendStringInfoChar(&buf, ','); @@ -1761,7 +1763,7 @@ write_csvlog(ErrorData *edata) if (MyProcPort) { const char *psdisp; - int displen; + int displen; psdisp = get_ps_display(&displen); appendStringInfo(&msgbuf, "%.*s", displen, psdisp); @@ -1798,7 +1800,7 @@ write_csvlog(ErrorData *edata) /* SQL state code */ appendStringInfo(&buf, "%s,", unpack_sql_state(edata->sqlerrcode)); - + /* Error message and cursor position if any */ get_csv_error_message(&buf, edata); @@ -1808,8 +1810,8 @@ write_csvlog(ErrorData *edata) if (am_syslogger) write_syslogger_file(buf.data, buf.len, LOG_DESTINATION_CSVLOG); else - write_pipe_chunks(buf.data, buf.len, LOG_DESTINATION_CSVLOG); - + write_pipe_chunks(buf.data, buf.len, LOG_DESTINATION_CSVLOG); + pfree(msgbuf.data); pfree(buf.data); } @@ -1821,16 +1823,16 @@ write_csvlog(ErrorData *edata) static void get_csv_error_message(StringInfo buf, ErrorData *edata) { - char *msg = edata->message ? edata->message : _("missing error text"); - char c; + char *msg = edata->message ? edata->message : _("missing error text"); + char c; appendStringInfoCharMacro(buf, '"'); - while ( (c = *msg++) != '\0' ) + while ((c = *msg++) != '\0') { - if (c == '"') - appendStringInfoCharMacro(buf, '"'); - appendStringInfoCharMacro(buf, c); + if (c == '"') + appendStringInfoCharMacro(buf, '"'); + appendStringInfoCharMacro(buf, c); } if (edata->cursorpos > 0) @@ -2010,13 +2012,14 @@ send_message_to_server_log(ErrorData *edata) if ((Log_destination & LOG_DESTINATION_STDERR) || whereToSendOutput == DestDebug) { /* - * Use the chunking protocol if we know the syslogger should - * be catching stderr output, and we are not ourselves the - * syslogger. Otherwise, just do a vanilla write to stderr. + * Use the chunking protocol if we know the syslogger should be + * catching stderr output, and we are not ourselves the syslogger. + * Otherwise, just do a vanilla write to stderr. */ if (redirection_done && !am_syslogger) write_pipe_chunks(buf.data, buf.len, LOG_DESTINATION_STDERR); #ifdef WIN32 + /* * In a win32 service environment, there is no usable stderr. Capture * anything going there and write it to the eventlog instead. @@ -2040,18 +2043,20 @@ send_message_to_server_log(ErrorData *edata) { if (redirection_done || am_syslogger) { - /* send CSV data if it's safe to do so (syslogger doesn't need - * the pipe). First get back the space in the message buffer. + /* + * send CSV data if it's safe to do so (syslogger doesn't need the + * pipe). First get back the space in the message buffer. */ pfree(buf.data); write_csvlog(edata); } else { - char * msg = _("Not safe to send CSV data\n"); - write(fileno(stderr),msg,strlen(msg)); - if ( ! (Log_destination & LOG_DESTINATION_STDERR) && - whereToSendOutput != DestDebug) + char *msg = _("Not safe to send CSV data\n"); + + write(fileno(stderr), msg, strlen(msg)); + if (!(Log_destination & LOG_DESTINATION_STDERR) && + whereToSendOutput != DestDebug) { /* write message to stderr unless we just sent it above */ write(fileno(stderr), buf.data, buf.len); @@ -2073,7 +2078,7 @@ write_pipe_chunks(char *data, int len, int dest) { PipeProtoChunk p; - int fd = fileno(stderr); + int fd = fileno(stderr); Assert(len > 0); @@ -2325,9 +2330,9 @@ useful_strerror(int errnum) if (str == NULL || *str == '\0') { snprintf(errorstr_buf, sizeof(errorstr_buf), - /*------ - translator: This string will be truncated at 47 - characters expanded. */ + /*------ + translator: This string will be truncated at 47 + characters expanded. */ _("operating system error %d"), errnum); str = errorstr_buf; } diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c index ea5cd4bf2d..8ef2f2094e 100644 --- a/src/backend/utils/fmgr/fmgr.c +++ b/src/backend/utils/fmgr/fmgr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.110 2007/09/11 00:06:42 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.111 2007/11/15 21:14:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -68,7 +68,7 @@ typedef struct /* fn_oid is the hash key and so must be first! */ Oid fn_oid; /* OID of an external C function */ TransactionId fn_xmin; /* for checking up-to-dateness */ - ItemPointerData fn_tid; + ItemPointerData fn_tid; PGFunction user_fn; /* the function's address */ const Pg_finfo_record *inforec; /* address of its info record */ } CFuncHashTabEntry; @@ -835,7 +835,7 @@ fmgr_oldstyle(PG_FUNCTION_ARGS) /* - * Support for security-definer and proconfig-using functions. We support + * Support for security-definer and proconfig-using functions. We support * both of these features using the same call handler, because they are * often used together and it would be inefficient (as well as notationally * messy) to have two levels of call handler involved. @@ -850,11 +850,11 @@ struct fmgr_security_definer_cache /* * Function handler for security-definer/proconfig functions. We extract the * OID of the actual function and do a fmgr lookup again. Then we fetch the - * pg_proc row and copy the owner ID and proconfig fields. (All this info + * pg_proc row and copy the owner ID and proconfig fields. (All this info * is cached for the duration of the current query.) To execute a call, * we temporarily replace the flinfo with the cached/looked-up one, while * keeping the outer fcinfo (which contains all the actual arguments, etc.) - * intact. This is not re-entrant, but then the fcinfo itself can't be used + * intact. This is not re-entrant, but then the fcinfo itself can't be used * re-entrantly anyway. */ static Datum @@ -2204,8 +2204,8 @@ get_call_expr_argtype(Node *expr, int argnum) /* * special hack for ScalarArrayOpExpr and ArrayCoerceExpr: what the - * underlying function will actually get passed is the element type of - * the array. + * underlying function will actually get passed is the element type of the + * array. */ if (IsA(expr, ScalarArrayOpExpr) && argnum == 1) diff --git a/src/backend/utils/hash/dynahash.c b/src/backend/utils/hash/dynahash.c index d59f35a548..bdddaa2c3d 100644 --- a/src/backend/utils/hash/dynahash.c +++ b/src/backend/utils/hash/dynahash.c @@ -26,7 +26,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/hash/dynahash.c,v 1.76 2007/09/11 16:17:46 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/hash/dynahash.c,v 1.77 2007/11/15 21:14:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -946,7 +946,7 @@ hash_search_with_hash_value(HTAB *hashp, * to check cheaper conditions first. */ if (!IS_PARTITIONED(hctl) && - hctl->nentries / (long) (hctl->max_bucket + 1) >= hctl->ffactor && + hctl->nentries / (long) (hctl->max_bucket + 1) >= hctl->ffactor && !has_seq_scans(hashp)) { /* @@ -1397,7 +1397,7 @@ my_log2(long num) /************************* SEQ SCAN TRACKING ************************/ /* - * We track active hash_seq_search scans here. The need for this mechanism + * We track active hash_seq_search scans here. The need for this mechanism * comes from the fact that a scan will get confused if a bucket split occurs * while it's in progress: it might visit entries twice, or even miss some * entirely (if it's partway through the same bucket that splits). Hence @@ -1417,7 +1417,7 @@ my_log2(long num) * * This arrangement is reasonably robust if a transient hashtable is deleted * without notifying us. The absolute worst case is we might inhibit splits - * in another table created later at exactly the same address. We will give + * in another table created later at exactly the same address. We will give * a warning at transaction end for reference leaks, so any bugs leading to * lack of notification should be easy to catch. */ @@ -1445,7 +1445,7 @@ register_seq_scan(HTAB *hashp) static void deregister_seq_scan(HTAB *hashp) { - int i; + int i; /* Search backward since it's most likely at the stack top */ for (i = num_seq_scans - 1; i >= 0; i--) @@ -1466,7 +1466,7 @@ deregister_seq_scan(HTAB *hashp) static bool has_seq_scans(HTAB *hashp) { - int i; + int i; for (i = 0; i < num_seq_scans; i++) { @@ -1491,7 +1491,7 @@ AtEOXact_HashTables(bool isCommit) */ if (isCommit) { - int i; + int i; for (i = 0; i < num_seq_scans; i++) { @@ -1506,7 +1506,7 @@ AtEOXact_HashTables(bool isCommit) void AtEOSubXact_HashTables(bool isCommit, int nestDepth) { - int i; + int i; /* * Search backward to make cleanup easy. Note we must check all entries, diff --git a/src/backend/utils/init/flatfiles.c b/src/backend/utils/init/flatfiles.c index 8a51ebed83..3cc5cb0c4f 100644 --- a/src/backend/utils/init/flatfiles.c +++ b/src/backend/utils/init/flatfiles.c @@ -23,7 +23,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/utils/init/flatfiles.c,v 1.28 2007/10/15 15:11:29 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/init/flatfiles.c,v 1.29 2007/11/15 21:14:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -169,7 +169,7 @@ name_okay(const char *str) * so we can set or update the XID wrap limit. * * Also, if "startup" is true, we tell relcache.c to clear out the relcache - * init file in each database. That's a bit nonmodular, but scanning + * init file in each database. That's a bit nonmodular, but scanning * pg_database twice during system startup seems too high a price for keeping * things better separated. */ @@ -223,8 +223,8 @@ write_database_file(Relation drel, bool startup) datfrozenxid = dbform->datfrozenxid; /* - * Identify the oldest datfrozenxid. This must match - * the logic in vac_truncate_clog() in vacuum.c. + * Identify the oldest datfrozenxid. This must match the logic in + * vac_truncate_clog() in vacuum.c. */ if (TransactionIdIsNormal(datfrozenxid)) { @@ -261,7 +261,7 @@ write_database_file(Relation drel, bool startup) */ if (startup) { - char *dbpath = GetDatabasePath(datoid, dattablespace); + char *dbpath = GetDatabasePath(datoid, dattablespace); RelationCacheInitFileRemove(dbpath); pfree(dbpath); @@ -437,10 +437,10 @@ write_auth_file(Relation rel_authid, Relation rel_authmem) * We can't use heap_getattr() here because during startup we will not * have any tupdesc for pg_authid. Fortunately it's not too hard to * work around this. rolpassword is the first possibly-null field so - * we can compute its offset directly. Note that this only works + * we can compute its offset directly. Note that this only works * reliably because the preceding field (rolconnlimit) is int4, and - * therefore rolpassword is always 4-byte-aligned, and will be at - * the same offset no matter whether it uses 1-byte or 4-byte header. + * therefore rolpassword is always 4-byte-aligned, and will be at the + * same offset no matter whether it uses 1-byte or 4-byte header. */ tp = (char *) tup + tup->t_hoff; off = offsetof(FormData_pg_authid, rolpassword); @@ -634,21 +634,21 @@ write_auth_file(Relation rel_authid, Relation rel_authmem) for (curr_role = 0; curr_role < total_roles; curr_role++) { auth_entry *arole = &auth_info[curr_role]; - ListCell *mem; + ListCell *mem; - fputs_quote(arole->rolname, fp); - fputs(" ", fp); - fputs_quote(arole->rolpassword, fp); - fputs(" ", fp); - fputs_quote(arole->rolvaliduntil, fp); + fputs_quote(arole->rolname, fp); + fputs(" ", fp); + fputs_quote(arole->rolpassword, fp); + fputs(" ", fp); + fputs_quote(arole->rolvaliduntil, fp); - foreach(mem, arole->member_of) - { - fputs(" ", fp); - fputs_quote((char *) lfirst(mem), fp); - } + foreach(mem, arole->member_of) + { + fputs(" ", fp); + fputs_quote((char *) lfirst(mem), fp); + } - fputs("\n", fp); + fputs("\n", fp); } if (FreeFile(fp)) @@ -845,10 +845,10 @@ AtEOXact_UpdateFlatFiles(bool isCommit) SendPostmasterSignal(PMSIGNAL_PASSWORD_CHANGE); /* - * Force synchronous commit, to minimize the window between changing - * the flat files on-disk and marking the transaction committed. It's - * not great that there is any window at all, but definitely we don't - * want to make it larger than necessary. + * Force synchronous commit, to minimize the window between changing the + * flat files on-disk and marking the transaction committed. It's not + * great that there is any window at all, but definitely we don't want to + * make it larger than necessary. */ ForceSyncCommit(); } diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c index 37ce52401c..cf59cda8bd 100644 --- a/src/backend/utils/init/globals.c +++ b/src/backend/utils/init/globals.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.102 2007/08/02 23:39:44 adunstan Exp $ + * $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.103 2007/11/15 21:14:40 momjian Exp $ * * NOTES * Globals used all over the place should be declared here and not @@ -33,7 +33,7 @@ volatile uint32 InterruptHoldoffCount = 0; volatile uint32 CritSectionCount = 0; int MyProcPid; -time_t MyStartTime; +time_t MyStartTime; struct Port *MyProcPort; long MyCancelKey; diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index d1bc2af876..43a7e34639 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.178 2007/09/11 00:06:42 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.179 2007/11/15 21:14:40 momjian Exp $ * * *------------------------------------------------------------------------- @@ -107,8 +107,8 @@ FindMyDatabase(const char *name, Oid *db_id, Oid *db_tablespace) /* * FindMyDatabaseByOid * - * As above, but the actual database Id is known. Return its name and the - * tablespace OID. Return TRUE if found, FALSE if not. The same restrictions + * As above, but the actual database Id is known. Return its name and the + * tablespace OID. Return TRUE if found, FALSE if not. The same restrictions * as FindMyDatabase apply. */ static bool @@ -320,7 +320,7 @@ BaseInit(void) * Initialize POSTGRES. * * The database can be specified by name, using the in_dbname parameter, or by - * OID, using the dboid parameter. In the latter case, the computed database + * OID, using the dboid parameter. In the latter case, the computed database * name is passed out to the caller as a palloc'ed string in out_dbname. * * In bootstrap mode no parameters are used. @@ -361,9 +361,10 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, else { /* - * Find tablespace of the database we're about to open. Since we're not - * yet up and running we have to use one of the hackish FindMyDatabase - * variants, which look in the flat-file copy of pg_database. + * Find tablespace of the database we're about to open. Since we're + * not yet up and running we have to use one of the hackish + * FindMyDatabase variants, which look in the flat-file copy of + * pg_database. * * If the in_dbname param is NULL, lookup database by OID. */ diff --git a/src/backend/utils/mb/conversion_procs/euc_jis_2004_and_shift_jis_2004/euc_jis_2004_and_shift_jis_2004.c b/src/backend/utils/mb/conversion_procs/euc_jis_2004_and_shift_jis_2004/euc_jis_2004_and_shift_jis_2004.c index 5b1ceb49c2..a2ff4a9093 100644 --- a/src/backend/utils/mb/conversion_procs/euc_jis_2004_and_shift_jis_2004/euc_jis_2004_and_shift_jis_2004.c +++ b/src/backend/utils/mb/conversion_procs/euc_jis_2004_and_shift_jis_2004/euc_jis_2004_and_shift_jis_2004.c @@ -5,7 +5,7 @@ * Copyright (c) 2007, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_jis_2004_and_shift_jis_2004/euc_jis_2004_and_shift_jis_2004.c,v 1.1 2007/03/25 11:56:02 ishii Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_jis_2004_and_shift_jis_2004/euc_jis_2004_and_shift_jis_2004.c,v 1.2 2007/11/15 21:14:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -76,7 +76,7 @@ euc_jis_20042shift_jis_2004(const unsigned char *euc, unsigned char *p, int len) { int c1, ku, - ten; + ten; int l; while (len > 0) @@ -104,7 +104,7 @@ euc_jis_20042shift_jis_2004(const unsigned char *euc, unsigned char *p, int len) { *p++ = euc[1]; } - else if (c1 == SS3 && l == 3) /* JIS X 0213 plane 2? */ + else if (c1 == SS3 && l == 3) /* JIS X 0213 plane 2? */ { ku = euc[1] - 0xa0; ten = euc[2] - 0xa0; @@ -146,7 +146,7 @@ euc_jis_20042shift_jis_2004(const unsigned char *euc, unsigned char *p, int len) *p++ = ten + 0x9e; } - else if (l == 2) /* JIS X 0213 plane 1? */ + else if (l == 2) /* JIS X 0213 plane 1? */ { ku = c1 - 0xa0; ten = euc[1] - 0xa0; @@ -187,26 +187,29 @@ euc_jis_20042shift_jis_2004(const unsigned char *euc, unsigned char *p, int len) * *ku = 0: "ku" = even * *ku = 1: "ku" = odd */ -static int get_ten(int b, int *ku) +static int +get_ten(int b, int *ku) { - int ten; + int ten; if (b >= 0x40 && b <= 0x7e) { ten = b - 0x3f; *ku = 1; - } else if (b >= 0x80 && b <= 0x9e) + } + else if (b >= 0x80 && b <= 0x9e) { ten = b - 0x40; *ku = 1; - } else if (b >= 0x9f && b <= 0xfc) + } + else if (b >= 0x9f && b <= 0xfc) { ten = b - 0x9e; *ku = 0; } else { - ten = -1; /* error */ + ten = -1; /* error */ } return ten; } @@ -219,8 +222,10 @@ static void shift_jis_20042euc_jis_2004(const unsigned char *sjis, unsigned char *p, int len) { int c1, - c2; - int ku, ten, kubun; + c2; + int ku, + ten, + kubun; int plane; int l; @@ -281,7 +286,8 @@ shift_jis_20042euc_jis_2004(const unsigned char *sjis, unsigned char *p, int len (const char *) sjis, len); ku -= kubun; } - else if (c1 >= 0xf0 && c1 <= 0xf3) /* plane 2 1,3,4,5,8,12,13,14,15 ku */ + else if (c1 >= 0xf0 && c1 <= 0xf3) /* plane 2 + * 1,3,4,5,8,12,13,14,15 ku */ { plane = 2; ten = get_ten(c2, &kubun); @@ -291,16 +297,16 @@ shift_jis_20042euc_jis_2004(const unsigned char *sjis, unsigned char *p, int len switch (c1) { case 0xf0: - ku = kubun == 0? 8: 1; + ku = kubun == 0 ? 8 : 1; break; case 0xf1: - ku = kubun == 0? 4: 3; + ku = kubun == 0 ? 4 : 3; break; case 0xf2: - ku = kubun == 0? 12: 5; + ku = kubun == 0 ? 12 : 5; break; default: - ku = kubun == 0? 14: 13; + ku = kubun == 0 ? 14 : 13; break; } } diff --git a/src/backend/utils/mb/conversion_procs/utf8_and_big5/utf8_and_big5.c b/src/backend/utils/mb/conversion_procs/utf8_and_big5/utf8_and_big5.c index f0dc157d70..e5d4836823 100644 --- a/src/backend/utils/mb/conversion_procs/utf8_and_big5/utf8_and_big5.c +++ b/src/backend/utils/mb/conversion_procs/utf8_and_big5/utf8_and_big5.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_big5/utf8_and_big5.c,v 1.16 2007/03/25 11:56:02 ishii Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_big5/utf8_and_big5.c,v 1.17 2007/11/15 21:14:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -46,7 +46,7 @@ big5_to_utf8(PG_FUNCTION_ARGS) Assert(PG_GETARG_INT32(1) == PG_UTF8); Assert(len >= 0); - LocalToUtf(src, dest, LUmapBIG5, NULL, + LocalToUtf(src, dest, LUmapBIG5, NULL, sizeof(LUmapBIG5) / sizeof(pg_local_to_utf), 0, PG_BIG5, len); PG_RETURN_VOID(); @@ -63,7 +63,7 @@ utf8_to_big5(PG_FUNCTION_ARGS) Assert(PG_GETARG_INT32(1) == PG_BIG5); Assert(len >= 0); - UtfToLocal(src, dest, ULmapBIG5, NULL, + UtfToLocal(src, dest, ULmapBIG5, NULL, sizeof(ULmapBIG5) / sizeof(pg_utf_to_local), 0, PG_BIG5, len); PG_RETURN_VOID(); diff --git a/src/backend/utils/mb/conversion_procs/utf8_and_cyrillic/utf8_and_cyrillic.c b/src/backend/utils/mb/conversion_procs/utf8_and_cyrillic/utf8_and_cyrillic.c index 4ff61b90e3..de4f9d2415 100644 --- a/src/backend/utils/mb/conversion_procs/utf8_and_cyrillic/utf8_and_cyrillic.c +++ b/src/backend/utils/mb/conversion_procs/utf8_and_cyrillic/utf8_and_cyrillic.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_cyrillic/utf8_and_cyrillic.c,v 1.19 2007/03/25 11:56:02 ishii Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_cyrillic/utf8_and_cyrillic.c,v 1.20 2007/11/15 21:14:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -47,8 +47,8 @@ utf8_to_koi8r(PG_FUNCTION_ARGS) Assert(PG_GETARG_INT32(1) == PG_KOI8R); Assert(len >= 0); - UtfToLocal(src, dest, ULmapKOI8R, NULL, - sizeof(ULmapKOI8R) / sizeof(pg_utf_to_local), 0, PG_KOI8R, len); + UtfToLocal(src, dest, ULmapKOI8R, NULL, + sizeof(ULmapKOI8R) / sizeof(pg_utf_to_local), 0, PG_KOI8R, len); PG_RETURN_VOID(); } @@ -65,7 +65,7 @@ koi8r_to_utf8(PG_FUNCTION_ARGS) Assert(len >= 0); LocalToUtf(src, dest, LUmapKOI8R, NULL, - sizeof(LUmapKOI8R) / sizeof(pg_local_to_utf), 0, PG_KOI8R, len); + sizeof(LUmapKOI8R) / sizeof(pg_local_to_utf), 0, PG_KOI8R, len); PG_RETURN_VOID(); } diff --git a/src/backend/utils/mb/conversion_procs/utf8_and_euc_cn/utf8_and_euc_cn.c b/src/backend/utils/mb/conversion_procs/utf8_and_euc_cn/utf8_and_euc_cn.c index d88e152d66..913deb985c 100644 --- a/src/backend/utils/mb/conversion_procs/utf8_and_euc_cn/utf8_and_euc_cn.c +++ b/src/backend/utils/mb/conversion_procs/utf8_and_euc_cn/utf8_and_euc_cn.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_cn/utf8_and_euc_cn.c,v 1.17 2007/03/25 11:56:02 ishii Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_cn/utf8_and_euc_cn.c,v 1.18 2007/11/15 21:14:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -47,7 +47,7 @@ euc_cn_to_utf8(PG_FUNCTION_ARGS) Assert(len >= 0); LocalToUtf(src, dest, LUmapEUC_CN, NULL, - sizeof(LUmapEUC_CN) / sizeof(pg_local_to_utf), 0, PG_EUC_CN, len); + sizeof(LUmapEUC_CN) / sizeof(pg_local_to_utf), 0, PG_EUC_CN, len); PG_RETURN_VOID(); } @@ -64,7 +64,7 @@ utf8_to_euc_cn(PG_FUNCTION_ARGS) Assert(len >= 0); UtfToLocal(src, dest, ULmapEUC_CN, NULL, - sizeof(ULmapEUC_CN) / sizeof(pg_utf_to_local), 0, PG_EUC_CN, len); + sizeof(ULmapEUC_CN) / sizeof(pg_utf_to_local), 0, PG_EUC_CN, len); PG_RETURN_VOID(); } diff --git a/src/backend/utils/mb/conversion_procs/utf8_and_euc_jis_2004/utf8_and_euc_jis_2004.c b/src/backend/utils/mb/conversion_procs/utf8_and_euc_jis_2004/utf8_and_euc_jis_2004.c index 60a095d810..bcc9ef3d32 100644 --- a/src/backend/utils/mb/conversion_procs/utf8_and_euc_jis_2004/utf8_and_euc_jis_2004.c +++ b/src/backend/utils/mb/conversion_procs/utf8_and_euc_jis_2004/utf8_and_euc_jis_2004.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_jis_2004/utf8_and_euc_jis_2004.c,v 1.1 2007/03/25 11:56:03 ishii Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_jis_2004/utf8_and_euc_jis_2004.c,v 1.2 2007/11/15 21:14:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -50,7 +50,7 @@ euc_jis_2004_to_utf8(PG_FUNCTION_ARGS) LocalToUtf(src, dest, LUmapEUC_JIS_2004, LUmapEUC_JIS_2004_combined, sizeof(LUmapEUC_JIS_2004) / sizeof(pg_local_to_utf), - sizeof(LUmapEUC_JIS_2004_combined) / sizeof(pg_local_to_utf_combined), + sizeof(LUmapEUC_JIS_2004_combined) / sizeof(pg_local_to_utf_combined), PG_EUC_JIS_2004, len); PG_RETURN_VOID(); @@ -69,7 +69,7 @@ utf8_to_euc_jis_2004(PG_FUNCTION_ARGS) UtfToLocal(src, dest, ULmapEUC_JIS_2004, ULmapEUC_JIS_2004_combined, sizeof(ULmapEUC_JIS_2004) / sizeof(pg_utf_to_local), - sizeof(ULmapEUC_JIS_2004_combined) / sizeof(pg_utf_to_local_combined), + sizeof(ULmapEUC_JIS_2004_combined) / sizeof(pg_utf_to_local_combined), PG_EUC_JIS_2004, len); PG_RETURN_VOID(); diff --git a/src/backend/utils/mb/conversion_procs/utf8_and_euc_jp/utf8_and_euc_jp.c b/src/backend/utils/mb/conversion_procs/utf8_and_euc_jp/utf8_and_euc_jp.c index 6d12ab256e..35f651b8a5 100644 --- a/src/backend/utils/mb/conversion_procs/utf8_and_euc_jp/utf8_and_euc_jp.c +++ b/src/backend/utils/mb/conversion_procs/utf8_and_euc_jp/utf8_and_euc_jp.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_jp/utf8_and_euc_jp.c,v 1.17 2007/03/25 11:56:03 ishii Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_jp/utf8_and_euc_jp.c,v 1.18 2007/11/15 21:14:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -47,7 +47,7 @@ euc_jp_to_utf8(PG_FUNCTION_ARGS) Assert(len >= 0); LocalToUtf(src, dest, LUmapEUC_JP, NULL, - sizeof(LUmapEUC_JP) / sizeof(pg_local_to_utf), 0, PG_EUC_JP, len); + sizeof(LUmapEUC_JP) / sizeof(pg_local_to_utf), 0, PG_EUC_JP, len); PG_RETURN_VOID(); } @@ -64,7 +64,7 @@ utf8_to_euc_jp(PG_FUNCTION_ARGS) Assert(len >= 0); UtfToLocal(src, dest, ULmapEUC_JP, NULL, - sizeof(ULmapEUC_JP) / sizeof(pg_utf_to_local), 0, PG_EUC_JP, len); + sizeof(ULmapEUC_JP) / sizeof(pg_utf_to_local), 0, PG_EUC_JP, len); PG_RETURN_VOID(); } diff --git a/src/backend/utils/mb/conversion_procs/utf8_and_euc_kr/utf8_and_euc_kr.c b/src/backend/utils/mb/conversion_procs/utf8_and_euc_kr/utf8_and_euc_kr.c index de57e30cfe..8572b52244 100644 --- a/src/backend/utils/mb/conversion_procs/utf8_and_euc_kr/utf8_and_euc_kr.c +++ b/src/backend/utils/mb/conversion_procs/utf8_and_euc_kr/utf8_and_euc_kr.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_kr/utf8_and_euc_kr.c,v 1.17 2007/03/25 11:56:03 ishii Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_kr/utf8_and_euc_kr.c,v 1.18 2007/11/15 21:14:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -47,7 +47,7 @@ euc_kr_to_utf8(PG_FUNCTION_ARGS) Assert(len >= 0); LocalToUtf(src, dest, LUmapEUC_KR, NULL, - sizeof(LUmapEUC_KR) / sizeof(pg_local_to_utf), 0, PG_EUC_KR, len); + sizeof(LUmapEUC_KR) / sizeof(pg_local_to_utf), 0, PG_EUC_KR, len); PG_RETURN_VOID(); } @@ -64,7 +64,7 @@ utf8_to_euc_kr(PG_FUNCTION_ARGS) Assert(len >= 0); UtfToLocal(src, dest, ULmapEUC_KR, NULL, - sizeof(ULmapEUC_KR) / sizeof(pg_utf_to_local), 0, PG_EUC_KR, len); + sizeof(ULmapEUC_KR) / sizeof(pg_utf_to_local), 0, PG_EUC_KR, len); PG_RETURN_VOID(); } diff --git a/src/backend/utils/mb/conversion_procs/utf8_and_euc_tw/utf8_and_euc_tw.c b/src/backend/utils/mb/conversion_procs/utf8_and_euc_tw/utf8_and_euc_tw.c index 1e428f4356..6b481c1e4c 100644 --- a/src/backend/utils/mb/conversion_procs/utf8_and_euc_tw/utf8_and_euc_tw.c +++ b/src/backend/utils/mb/conversion_procs/utf8_and_euc_tw/utf8_and_euc_tw.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_tw/utf8_and_euc_tw.c,v 1.17 2007/03/25 11:56:03 ishii Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_tw/utf8_and_euc_tw.c,v 1.18 2007/11/15 21:14:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -47,7 +47,7 @@ euc_tw_to_utf8(PG_FUNCTION_ARGS) Assert(len >= 0); LocalToUtf(src, dest, LUmapEUC_TW, NULL, - sizeof(LUmapEUC_TW) / sizeof(pg_local_to_utf), 0, PG_EUC_TW, len); + sizeof(LUmapEUC_TW) / sizeof(pg_local_to_utf), 0, PG_EUC_TW, len); PG_RETURN_VOID(); } @@ -64,7 +64,7 @@ utf8_to_euc_tw(PG_FUNCTION_ARGS) Assert(len >= 0); UtfToLocal(src, dest, ULmapEUC_TW, NULL, - sizeof(ULmapEUC_TW) / sizeof(pg_utf_to_local), 0, PG_EUC_TW, len); + sizeof(ULmapEUC_TW) / sizeof(pg_utf_to_local), 0, PG_EUC_TW, len); PG_RETURN_VOID(); } diff --git a/src/backend/utils/mb/conversion_procs/utf8_and_gb18030/utf8_and_gb18030.c b/src/backend/utils/mb/conversion_procs/utf8_and_gb18030/utf8_and_gb18030.c index e533237bc8..1c14dc7c19 100644 --- a/src/backend/utils/mb/conversion_procs/utf8_and_gb18030/utf8_and_gb18030.c +++ b/src/backend/utils/mb/conversion_procs/utf8_and_gb18030/utf8_and_gb18030.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_gb18030/utf8_and_gb18030.c,v 1.18 2007/03/25 11:56:03 ishii Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_gb18030/utf8_and_gb18030.c,v 1.19 2007/11/15 21:14:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -47,7 +47,7 @@ gb18030_to_utf8(PG_FUNCTION_ARGS) Assert(len >= 0); LocalToUtf(src, dest, LUmapGB18030, NULL, - sizeof(LUmapGB18030) / sizeof(pg_local_to_utf), 0, PG_GB18030, len); + sizeof(LUmapGB18030) / sizeof(pg_local_to_utf), 0, PG_GB18030, len); PG_RETURN_VOID(); } @@ -64,7 +64,7 @@ utf8_to_gb18030(PG_FUNCTION_ARGS) Assert(len >= 0); UtfToLocal(src, dest, ULmapGB18030, NULL, - sizeof(ULmapGB18030) / sizeof(pg_utf_to_local), 0, PG_GB18030, len); + sizeof(ULmapGB18030) / sizeof(pg_utf_to_local), 0, PG_GB18030, len); PG_RETURN_VOID(); } diff --git a/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c b/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c index e720303605..3cc0e9b6f6 100644 --- a/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c +++ b/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c,v 1.26 2007/03/25 11:56:03 ishii Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c,v 1.27 2007/11/15 21:14:41 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -134,7 +134,7 @@ iso8859_to_utf8(PG_FUNCTION_ARGS) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), - errmsg("unexpected encoding ID %d for ISO 8859 character sets", encoding))); + errmsg("unexpected encoding ID %d for ISO 8859 character sets", encoding))); PG_RETURN_VOID(); } @@ -162,7 +162,7 @@ utf8_to_iso8859(PG_FUNCTION_ARGS) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), - errmsg("unexpected encoding ID %d for ISO 8859 character sets", encoding))); + errmsg("unexpected encoding ID %d for ISO 8859 character sets", encoding))); PG_RETURN_VOID(); } diff --git a/src/backend/utils/mb/conversion_procs/utf8_and_johab/utf8_and_johab.c b/src/backend/utils/mb/conversion_procs/utf8_and_johab/utf8_and_johab.c index b197da61f0..29ec545297 100644 --- a/src/backend/utils/mb/conversion_procs/utf8_and_johab/utf8_and_johab.c +++ b/src/backend/utils/mb/conversion_procs/utf8_and_johab/utf8_and_johab.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_johab/utf8_and_johab.c,v 1.17 2007/03/25 11:56:03 ishii Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_johab/utf8_and_johab.c,v 1.18 2007/11/15 21:14:41 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -47,7 +47,7 @@ johab_to_utf8(PG_FUNCTION_ARGS) Assert(len >= 0); LocalToUtf(src, dest, LUmapJOHAB, NULL, - sizeof(LUmapJOHAB) / sizeof(pg_local_to_utf), 0, PG_JOHAB, len); + sizeof(LUmapJOHAB) / sizeof(pg_local_to_utf), 0, PG_JOHAB, len); PG_RETURN_VOID(); } @@ -64,7 +64,7 @@ utf8_to_johab(PG_FUNCTION_ARGS) Assert(len >= 0); UtfToLocal(src, dest, ULmapJOHAB, NULL, - sizeof(ULmapJOHAB) / sizeof(pg_utf_to_local), 0, PG_JOHAB, len); + sizeof(ULmapJOHAB) / sizeof(pg_utf_to_local), 0, PG_JOHAB, len); PG_RETURN_VOID(); } diff --git a/src/backend/utils/mb/conversion_procs/utf8_and_shift_jis_2004/utf8_and_shift_jis_2004.c b/src/backend/utils/mb/conversion_procs/utf8_and_shift_jis_2004/utf8_and_shift_jis_2004.c index 887890cabe..f691a4a3ef 100644 --- a/src/backend/utils/mb/conversion_procs/utf8_and_shift_jis_2004/utf8_and_shift_jis_2004.c +++ b/src/backend/utils/mb/conversion_procs/utf8_and_shift_jis_2004/utf8_and_shift_jis_2004.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_shift_jis_2004/utf8_and_shift_jis_2004.c,v 1.1 2007/03/25 11:56:03 ishii Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_shift_jis_2004/utf8_and_shift_jis_2004.c,v 1.2 2007/11/15 21:14:41 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -50,7 +50,7 @@ shift_jis_2004_to_utf8(PG_FUNCTION_ARGS) LocalToUtf(src, dest, LUmapSHIFT_JIS_2004, LUmapSHIFT_JIS_2004_combined, sizeof(LUmapSHIFT_JIS_2004) / sizeof(pg_local_to_utf), - sizeof(LUmapSHIFT_JIS_2004_combined) / sizeof(pg_local_to_utf_combined), + sizeof(LUmapSHIFT_JIS_2004_combined) / sizeof(pg_local_to_utf_combined), PG_SHIFT_JIS_2004, len); PG_RETURN_VOID(); @@ -69,7 +69,7 @@ utf8_to_shift_jis_2004(PG_FUNCTION_ARGS) UtfToLocal(src, dest, ULmapSHIFT_JIS_2004, ULmapSHIFT_JIS_2004_combined, sizeof(ULmapSHIFT_JIS_2004) / sizeof(pg_utf_to_local), - sizeof(ULmapSHIFT_JIS_2004_combined) / sizeof(pg_utf_to_local_combined), + sizeof(ULmapSHIFT_JIS_2004_combined) / sizeof(pg_utf_to_local_combined), PG_SHIFT_JIS_2004, len); PG_RETURN_VOID(); diff --git a/src/backend/utils/mb/conversion_procs/utf8_and_win/utf8_and_win.c b/src/backend/utils/mb/conversion_procs/utf8_and_win/utf8_and_win.c index 0369283c99..3fb43ccc81 100644 --- a/src/backend/utils/mb/conversion_procs/utf8_and_win/utf8_and_win.c +++ b/src/backend/utils/mb/conversion_procs/utf8_and_win/utf8_and_win.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win/utf8_and_win.c,v 1.10 2007/03/25 11:56:04 ishii Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win/utf8_and_win.c,v 1.11 2007/11/15 21:14:41 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -124,7 +124,7 @@ win_to_utf8(PG_FUNCTION_ARGS) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), - errmsg("unexpected encoding ID %d for WIN character sets", encoding))); + errmsg("unexpected encoding ID %d for WIN character sets", encoding))); PG_RETURN_VOID(); } @@ -152,7 +152,7 @@ utf8_to_win(PG_FUNCTION_ARGS) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), - errmsg("unexpected encoding ID %d for WIN character sets", encoding))); + errmsg("unexpected encoding ID %d for WIN character sets", encoding))); PG_RETURN_VOID(); } diff --git a/src/backend/utils/mb/encnames.c b/src/backend/utils/mb/encnames.c index 9e8f210240..0167dffc06 100644 --- a/src/backend/utils/mb/encnames.c +++ b/src/backend/utils/mb/encnames.c @@ -2,7 +2,7 @@ * Encoding names and routines for work with it. All * in this file is shared bedween FE and BE. * - * $PostgreSQL: pgsql/src/backend/utils/mb/encnames.c,v 1.36 2007/10/15 22:46:27 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mb/encnames.c,v 1.37 2007/11/15 21:14:40 momjian Exp $ */ #ifdef FRONTEND #include "postgres_fe.h" @@ -47,8 +47,8 @@ pg_encname pg_encname_tbl[] = * Chinese */ { "eucjis2004", PG_EUC_JIS_2004 - }, /* EUC-JIS-2004; Extended UNIX Code fixed Width for - * Japanese, standard JIS X 0213 */ + }, /* EUC-JIS-2004; Extended UNIX Code fixed + * Width for Japanese, standard JIS X 0213 */ { "eucjp", PG_EUC_JP }, /* EUC-JP; Extended UNIX Code fixed Width for @@ -164,8 +164,8 @@ pg_encname pg_encname_tbl[] = { "shiftjis2004", PG_SHIFT_JIS_2004 - }, /* SHIFT-JIS-2004; Shift JIS for - * Japanese, standard JIS X 0213 */ + }, /* SHIFT-JIS-2004; Shift JIS for Japanese, + * standard JIS X 0213 */ { "sjis", PG_SJIS }, /* alias for Shift_JIS */ @@ -470,7 +470,7 @@ static char * clean_encoding_name(const char *key, char *newkey) { const char *p; - char *np; + char *np; for (p = key, np = newkey; *p != '\0'; p++) { diff --git a/src/backend/utils/mb/mbutils.c b/src/backend/utils/mb/mbutils.c index 91f65df36a..3cbd05f41a 100644 --- a/src/backend/utils/mb/mbutils.c +++ b/src/backend/utils/mb/mbutils.c @@ -4,7 +4,7 @@ * (currently mule internal code (mic) is used) * Tatsuo Ishii * - * $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.67 2007/10/13 20:18:41 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.68 2007/11/15 21:14:40 momjian Exp $ */ #include "postgres.h" @@ -277,8 +277,8 @@ pg_do_encoding_conversion(unsigned char *src, int len, ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("out of memory"), - errdetail("String of %d bytes is too long for encoding conversion.", - len))); + errdetail("String of %d bytes is too long for encoding conversion.", + len))); result = palloc(len * MAX_CONVERSION_GROWTH + 1); @@ -305,12 +305,13 @@ pg_convert_to(PG_FUNCTION_ARGS) namein, CStringGetDatum(DatabaseEncoding->name)); Datum result; - /* pg_convert expects a bytea as its first argument. We're passing it - * a text argument here, relying on the fact that they are both in fact + /* + * pg_convert expects a bytea as its first argument. We're passing it a + * text argument here, relying on the fact that they are both in fact * varlena types, and thus structurally identical. */ result = DirectFunctionCall3( - pg_convert, string, src_encoding_name, dest_encoding_name); + pg_convert, string, src_encoding_name, dest_encoding_name); /* free memory allocated by namein */ pfree((void *) src_encoding_name); @@ -333,13 +334,14 @@ pg_convert_from(PG_FUNCTION_ARGS) Datum result; result = DirectFunctionCall3( - pg_convert, string, src_encoding_name, dest_encoding_name); + pg_convert, string, src_encoding_name, dest_encoding_name); /* free memory allocated by namein */ pfree((void *) src_encoding_name); - /* pg_convert returns a bytea, which we in turn return as text, relying - * on the fact that they are both in fact varlena types, and thus + /* + * pg_convert returns a bytea, which we in turn return as text, relying on + * the fact that they are both in fact varlena types, and thus * structurally identical. Although not all bytea values are valid text, * in this case it will be because we've told pg_convert to return one * that is valid as text in the current database encoding. @@ -378,7 +380,7 @@ pg_convert(PG_FUNCTION_ARGS) /* make sure that source string is valid and null terminated */ len = VARSIZE(string) - VARHDRSZ; - pg_verify_mbstr(src_encoding,VARDATA(string),len,false); + pg_verify_mbstr(src_encoding, VARDATA(string), len, false); str = palloc(len + 1); memcpy(str, VARDATA(string), len); *(str + len) = '\0'; @@ -415,11 +417,11 @@ pg_convert(PG_FUNCTION_ARGS) Datum length_in_encoding(PG_FUNCTION_ARGS) { - bytea *string = PG_GETARG_BYTEA_P(0); + bytea *string = PG_GETARG_BYTEA_P(0); char *src_encoding_name = NameStr(*PG_GETARG_NAME(1)); int src_encoding = pg_char_to_encoding(src_encoding_name); - int len = VARSIZE(string) - VARHDRSZ; - int retval; + int len = VARSIZE(string) - VARHDRSZ; + int retval; if (src_encoding < 0) ereport(ERROR, @@ -429,7 +431,7 @@ length_in_encoding(PG_FUNCTION_ARGS) retval = pg_verify_mbstr_len(src_encoding, VARDATA(string), len, false); PG_RETURN_INT32(retval); - + } /* @@ -545,8 +547,8 @@ perform_default_encoding_conversion(const char *src, int len, bool is_client_to_ ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("out of memory"), - errdetail("String of %d bytes is too long for encoding conversion.", - len))); + errdetail("String of %d bytes is too long for encoding conversion.", + len))); result = palloc(len * MAX_CONVERSION_GROWTH + 1); diff --git a/src/backend/utils/mb/wchar.c b/src/backend/utils/mb/wchar.c index dd5cf210f9..348a57e4d6 100644 --- a/src/backend/utils/mb/wchar.c +++ b/src/backend/utils/mb/wchar.c @@ -1,7 +1,7 @@ /* * conversion functions between pg_wchar and multibyte streams. * Tatsuo Ishii - * $PostgreSQL: pgsql/src/backend/utils/mb/wchar.c,v 1.65 2007/10/15 22:46:27 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mb/wchar.c,v 1.66 2007/11/15 21:14:40 momjian Exp $ * */ /* can be used in either frontend or backend */ @@ -1310,7 +1310,7 @@ pg_wchar_tbl pg_wchar_table[] = { {pg_euckr2wchar_with_len, pg_euckr_mblen, pg_euckr_dsplen, pg_euckr_verifier, 3}, /* 3; PG_EUC_KR */ {pg_euctw2wchar_with_len, pg_euctw_mblen, pg_euctw_dsplen, pg_euctw_verifier, 4}, /* 4; PG_EUC_TW */ {pg_eucjp2wchar_with_len, pg_eucjp_mblen, pg_eucjp_dsplen, pg_eucjp_verifier, 3}, /* 5; PG_EUC_JIS_2004 */ - {pg_utf2wchar_with_len, pg_utf_mblen, pg_utf_dsplen, pg_utf8_verifier, 4}, /* 6; PG_UTF8 */ + {pg_utf2wchar_with_len, pg_utf_mblen, pg_utf_dsplen, pg_utf8_verifier, 4}, /* 6; PG_UTF8 */ {pg_mule2wchar_with_len, pg_mule_mblen, pg_mule_dsplen, pg_mule_verifier, 4}, /* 7; PG_MULE_INTERNAL */ {pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* 8; PG_LATIN1 */ {pg_latin12wchar_with_len, pg_latin1_mblen, pg_latin1_dsplen, pg_latin1_verifier, 1}, /* 9; PG_LATIN2 */ @@ -1343,7 +1343,7 @@ pg_wchar_tbl pg_wchar_table[] = { {0, pg_gbk_mblen, pg_gbk_dsplen, pg_gbk_verifier, 2}, /* 36; PG_GBK */ {0, pg_uhc_mblen, pg_uhc_dsplen, pg_uhc_verifier, 2}, /* 37; PG_UHC */ {0, pg_gb18030_mblen, pg_gb18030_dsplen, pg_gb18030_verifier, 4}, /* 38; PG_GB18030 */ - {0, pg_johab_mblen, pg_johab_dsplen, pg_johab_verifier, 3}, /* 39; PG_JOHAB */ + {0, pg_johab_mblen, pg_johab_dsplen, pg_johab_verifier, 3}, /* 39; PG_JOHAB */ {0, pg_sjis_mblen, pg_sjis_dsplen, pg_sjis_verifier, 2} /* 40; PG_SHIFT_JIS_2004 */ }; @@ -1427,7 +1427,7 @@ pg_database_encoding_max_length(void) bool pg_verifymbstr(const char *mbstr, int len, bool noError) { - return + return pg_verify_mbstr_len(GetDatabaseEncoding(), mbstr, len, noError) >= 0; } @@ -1441,22 +1441,22 @@ pg_verify_mbstr(int encoding, const char *mbstr, int len, bool noError) return pg_verify_mbstr_len(encoding, mbstr, len, noError) >= 0; } -/* +/* * Verify mbstr to make sure that it is validly encoded in the specified * encoding. * * mbstr is not necessarily zero terminated; length of mbstr is * specified by len. * - * If OK, return length of string in the encoding. + * If OK, return length of string in the encoding. * If a problem is found, return -1 when noError is * true; when noError is false, ereport() a descriptive message. - */ + */ int pg_verify_mbstr_len(int encoding, const char *mbstr, int len, bool noError) { mbverifier mbverify; - int mb_len; + int mb_len; Assert(PG_VALID_ENCODING(encoding)); @@ -1476,7 +1476,7 @@ pg_verify_mbstr_len(int encoding, const char *mbstr, int len, bool noError) /* fetch function pointer just once */ mbverify = pg_wchar_table[encoding].mbverify; - + mb_len = 0; while (len > 0) diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 02d5fd4bbe..3ce3d4ed04 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -10,7 +10,7 @@ * Written by Peter Eisentraut <peter_e@gmx.net>. * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.425 2007/11/11 19:22:49 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.426 2007/11/15 21:14:41 momjian Exp $ * *-------------------------------------------------------------------- */ @@ -142,7 +142,7 @@ static const char *assign_syslog_ident(const char *ident, static const char *assign_defaultxactisolevel(const char *newval, bool doit, GucSource source); static const char *assign_session_replication_role(const char *newval, bool doit, - GucSource source); + GucSource source); static const char *assign_log_min_messages(const char *newval, bool doit, GucSource source); static const char *assign_client_min_messages(const char *newval, @@ -1052,14 +1052,14 @@ static struct config_bool ConfigureNamesBool[] = false, NULL, NULL }, - { - {"archive_mode", PGC_POSTMASTER, WAL_SETTINGS, - gettext_noop("Allows archiving of WAL files using archive_command."), - NULL - }, - &XLogArchiveMode, - false, NULL, NULL - }, + { + {"archive_mode", PGC_POSTMASTER, WAL_SETTINGS, + gettext_noop("Allows archiving of WAL files using archive_command."), + NULL + }, + &XLogArchiveMode, + false, NULL, NULL + }, { {"allow_system_table_mods", PGC_POSTMASTER, DEVELOPER_OPTIONS, @@ -1181,7 +1181,7 @@ static struct config_int ConfigureNamesInt[] = GUC_UNIT_MS }, &DeadlockTimeout, - 1000, 1, INT_MAX/1000, NULL, NULL + 1000, 1, INT_MAX / 1000, NULL, NULL }, /* @@ -1193,8 +1193,8 @@ static struct config_int ConfigureNamesInt[] = * * MaxBackends is limited to INT_MAX/4 because some places compute * 4*MaxBackends without any overflow check. This check is made on - * assign_maxconnections, since MaxBackends is computed as MaxConnections + - * autovacuum_max_workers. + * assign_maxconnections, since MaxBackends is computed as MaxConnections + * + autovacuum_max_workers. * * Likewise we have to limit NBuffers to INT_MAX/2. */ @@ -2448,7 +2448,7 @@ static struct config_string ConfigureNamesString[] = &SSLCipherSuites, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH", NULL, NULL }, -#endif /* USE_SSL */ +#endif /* USE_SSL */ /* End-of-list marker */ { @@ -2499,7 +2499,7 @@ static void ReportGUCOption(struct config_generic * record); static void ShowGUCConfigOption(const char *name, DestReceiver *dest); static void ShowAllGUCConfig(DestReceiver *dest); static char *_ShowOption(struct config_generic * record, bool use_units); -static bool is_newvalue_equal(struct config_generic *record, const char *newvalue); +static bool is_newvalue_equal(struct config_generic * record, const char *newvalue); /* @@ -2630,7 +2630,7 @@ set_stack_value(struct config_generic * gconf, union config_var_value * val) * Support for discarding a no-longer-needed value in a stack entry */ static void -discard_stack_value(struct config_generic *gconf, union config_var_value *val) +discard_stack_value(struct config_generic * gconf, union config_var_value * val) { switch (gconf->vartype) { @@ -2806,8 +2806,8 @@ add_placeholder_variable(const char *name, int elevel) /* * The char* is allocated at the end of the struct since we have no - * 'static' place to point to. Note that the current value, as well - * as the boot and reset values, start out NULL. + * 'static' place to point to. Note that the current value, as well as + * the boot and reset values, start out NULL. */ var->variable = (char **) (var + 1); @@ -2969,8 +2969,8 @@ InitializeGUCOptions(void) long stack_rlimit; /* - * Before log_line_prefix could possibly receive a nonempty setting, - * make sure that timezone processing is minimally alive (see elog.c). + * Before log_line_prefix could possibly receive a nonempty setting, make + * sure that timezone processing is minimally alive (see elog.c). */ pg_timezone_pre_initialize(); @@ -3094,7 +3094,7 @@ InitializeGUCOptions(void) /* * For historical reasons, some GUC parameters can receive defaults from - * environment variables. Process those settings. NB: if you add or + * environment variables. Process those settings. NB: if you add or * remove anything here, see also ProcessConfigFile(). */ @@ -3118,11 +3118,11 @@ InitializeGUCOptions(void) stack_rlimit = get_stack_depth_rlimit(); if (stack_rlimit > 0) { - int new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L; + int new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L; if (new_limit > 100) { - char limbuf[16]; + char limbuf[16]; new_limit = Min(new_limit, 2048); sprintf(limbuf, "%d", new_limit); @@ -3470,9 +3470,9 @@ void AtStart_GUC(void) { /* - * The nest level should be 0 between transactions; if it isn't, - * somebody didn't call AtEOXact_GUC, or called it with the wrong - * nestLevel. We throw a warning but make no other effort to clean up. + * The nest level should be 0 between transactions; if it isn't, somebody + * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We + * throw a warning but make no other effort to clean up. */ if (GUCNestLevel != 0) elog(WARNING, "GUC nest level = %d at transaction start", @@ -3482,7 +3482,7 @@ AtStart_GUC(void) /* * Enter a new nesting level for GUC values. This is called at subtransaction - * start and when entering a function that has proconfig settings. NOTE that + * start and when entering a function that has proconfig settings. NOTE that * we must not risk error here, else subtransaction start will be unhappy. */ int @@ -3520,9 +3520,9 @@ AtEOXact_GUC(bool isCommit, int nestLevel) GucStack *stack; /* - * Process and pop each stack entry within the nest level. To - * simplify fmgr_security_definer(), we allow failure exit from - * a function-with-SET-options to be recovered at the surrounding + * Process and pop each stack entry within the nest level. To + * simplify fmgr_security_definer(), we allow failure exit from a + * function-with-SET-options to be recovered at the surrounding * transaction or subtransaction abort; so there could be more than * one stack entry to pop. */ @@ -3540,7 +3540,7 @@ AtEOXact_GUC(bool isCommit, int nestLevel) * stack entries to avoid leaking memory. If we do set one of * those flags, unused fields will be cleaned up after restoring. */ - if (!isCommit) /* if abort, always restore prior value */ + if (!isCommit) /* if abort, always restore prior value */ restorePrior = true; else if (stack->state == GUC_SAVE) restorePrior = true; @@ -3554,7 +3554,7 @@ AtEOXact_GUC(bool isCommit, int nestLevel) /* we keep the current active value */ discard_stack_value(gconf, &stack->prior); } - else /* must be GUC_LOCAL */ + else /* must be GUC_LOCAL */ restorePrior = true; } else if (prev == NULL || @@ -3567,13 +3567,13 @@ AtEOXact_GUC(bool isCommit, int nestLevel) else { /* - * We have to merge this stack entry into prev. - * See README for discussion of this bit. + * We have to merge this stack entry into prev. See README for + * discussion of this bit. */ switch (stack->state) { case GUC_SAVE: - Assert(false); /* can't get here */ + Assert(false); /* can't get here */ case GUC_SET: /* next level always becomes SET */ @@ -3631,98 +3631,99 @@ AtEOXact_GUC(bool isCommit, int nestLevel) switch (gconf->vartype) { case PGC_BOOL: - { - struct config_bool *conf = (struct config_bool *) gconf; - bool newval = newvalue.boolval; - - if (*conf->variable != newval) { - if (conf->assign_hook) - if (!(*conf->assign_hook) (newval, - true, PGC_S_OVERRIDE)) - elog(LOG, "failed to commit %s", - conf->gen.name); - *conf->variable = newval; - changed = true; + struct config_bool *conf = (struct config_bool *) gconf; + bool newval = newvalue.boolval; + + if (*conf->variable != newval) + { + if (conf->assign_hook) + if (!(*conf->assign_hook) (newval, + true, PGC_S_OVERRIDE)) + elog(LOG, "failed to commit %s", + conf->gen.name); + *conf->variable = newval; + changed = true; + } + break; } - break; - } case PGC_INT: - { - struct config_int *conf = (struct config_int *) gconf; - int newval = newvalue.intval; - - if (*conf->variable != newval) { - if (conf->assign_hook) - if (!(*conf->assign_hook) (newval, - true, PGC_S_OVERRIDE)) - elog(LOG, "failed to commit %s", - conf->gen.name); - *conf->variable = newval; - changed = true; + struct config_int *conf = (struct config_int *) gconf; + int newval = newvalue.intval; + + if (*conf->variable != newval) + { + if (conf->assign_hook) + if (!(*conf->assign_hook) (newval, + true, PGC_S_OVERRIDE)) + elog(LOG, "failed to commit %s", + conf->gen.name); + *conf->variable = newval; + changed = true; + } + break; } - break; - } case PGC_REAL: - { - struct config_real *conf = (struct config_real *) gconf; - double newval = newvalue.realval; - - if (*conf->variable != newval) { - if (conf->assign_hook) - if (!(*conf->assign_hook) (newval, - true, PGC_S_OVERRIDE)) - elog(LOG, "failed to commit %s", - conf->gen.name); - *conf->variable = newval; - changed = true; + struct config_real *conf = (struct config_real *) gconf; + double newval = newvalue.realval; + + if (*conf->variable != newval) + { + if (conf->assign_hook) + if (!(*conf->assign_hook) (newval, + true, PGC_S_OVERRIDE)) + elog(LOG, "failed to commit %s", + conf->gen.name); + *conf->variable = newval; + changed = true; + } + break; } - break; - } case PGC_STRING: - { - struct config_string *conf = (struct config_string *) gconf; - char *newval = newvalue.stringval; - - if (*conf->variable != newval) { - if (conf->assign_hook && newval) + struct config_string *conf = (struct config_string *) gconf; + char *newval = newvalue.stringval; + + if (*conf->variable != newval) { - const char *newstr; - - newstr = (*conf->assign_hook) (newval, true, - PGC_S_OVERRIDE); - if (newstr == NULL) - elog(LOG, "failed to commit %s", - conf->gen.name); - else if (newstr != newval) + if (conf->assign_hook && newval) { - /* - * If newval should now be freed, it'll be - * taken care of below. - * - * See notes in set_config_option about - * casting - */ - newval = (char *) newstr; + const char *newstr; + + newstr = (*conf->assign_hook) (newval, true, + PGC_S_OVERRIDE); + if (newstr == NULL) + elog(LOG, "failed to commit %s", + conf->gen.name); + else if (newstr != newval) + { + /* + * If newval should now be freed, + * it'll be taken care of below. + * + * See notes in set_config_option + * about casting + */ + newval = (char *) newstr; + } } + + set_string_field(conf, conf->variable, newval); + changed = true; } - set_string_field(conf, conf->variable, newval); - changed = true; + /* + * Release stacked values if not used anymore. We + * could use discard_stack_value() here, but since + * we have type-specific code anyway, might as + * well inline it. + */ + set_string_field(conf, &stack->prior.stringval, NULL); + set_string_field(conf, &stack->masked.stringval, NULL); + break; } - /* - * Release stacked values if not used anymore. - * We could use discard_stack_value() here, but since - * we have type-specific code anyway, might as well - * inline it. - */ - set_string_field(conf, &stack->prior.stringval, NULL); - set_string_field(conf, &stack->masked.stringval, NULL); - break; - } } gconf->source = newsource; @@ -3735,7 +3736,7 @@ AtEOXact_GUC(bool isCommit, int nestLevel) /* Report new value if we changed it */ if (changed && (gconf->flags & GUC_REPORT)) ReportGUCOption(gconf); - } /* end of stack-popping loop */ + } /* end of stack-popping loop */ if (stack != NULL) still_dirty = true; @@ -4196,10 +4197,10 @@ set_config_option(const char *name, const char *value, } /* - * If source is postgresql.conf, mark the found record with GUC_IS_IN_FILE. - * This is for the convenience of ProcessConfigFile. Note that we do it - * even if changeVal is false, since ProcessConfigFile wants the marking - * to occur during its testing pass. + * If source is postgresql.conf, mark the found record with + * GUC_IS_IN_FILE. This is for the convenience of ProcessConfigFile. Note + * that we do it even if changeVal is false, since ProcessConfigFile wants + * the marking to occur during its testing pass. */ if (source == PGC_S_FILE) record->status |= GUC_IS_IN_FILE; @@ -4229,7 +4230,7 @@ set_config_option(const char *name, const char *value, /* * We are reading a PGC_POSTMASTER var from postgresql.conf. * We can't change the setting, so give a warning if the DBA - * tries to change it. (Throwing an error would be more + * tries to change it. (Throwing an error would be more * consistent, but seems overly rigid.) */ if (changeVal && !is_newvalue_equal(record, value)) @@ -4304,10 +4305,10 @@ set_config_option(const char *name, const char *value, } /* - * Should we set reset/stacked values? (If so, the behavior is not - * transactional.) This is done either when we get a default - * value from the database's/user's/client's default settings or - * when we reset a value to its default. + * Should we set reset/stacked values? (If so, the behavior is not + * transactional.) This is done either when we get a default value from + * the database's/user's/client's default settings or when we reset a + * value to its default. */ makeDefault = changeVal && (source <= PGC_S_OVERRIDE) && ((value != NULL) || source == PGC_S_DEFAULT); @@ -4414,8 +4415,8 @@ set_config_option(const char *name, const char *value, { ereport(elevel, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("invalid value for parameter \"%s\": \"%s\"", - name, value), + errmsg("invalid value for parameter \"%s\": \"%s\"", + name, value), hintmsg ? errhint(hintmsg) : 0)); return false; } @@ -4920,7 +4921,7 @@ flatten_set_variable_args(const char *name, List *args) void ExecSetVariableStmt(VariableSetStmt *stmt) { - GucAction action = stmt->is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET; + GucAction action = stmt->is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET; switch (stmt->kind) { @@ -4934,9 +4935,10 @@ ExecSetVariableStmt(VariableSetStmt *stmt) true); break; case VAR_SET_MULTI: + /* - * Special case for special SQL syntax that effectively sets - * more than one variable per statement. + * Special case for special SQL syntax that effectively sets more + * than one variable per statement. */ if (strcmp(stmt->name, "TRANSACTION") == 0) { @@ -5121,7 +5123,7 @@ init_custom_variable(const char *name, * variable into the GUC variable array, replacing any placeholder. */ static void -define_custom_variable(struct config_generic *variable) +define_custom_variable(struct config_generic * variable) { const char *name = variable->name; const char **nameAddr = &name; @@ -5153,8 +5155,8 @@ define_custom_variable(struct config_generic *variable) pHolder = (struct config_string *) (*res); /* - * Replace the placeholder. - * We aren't changing the name, so no re-sorting is necessary + * Replace the placeholder. We aren't changing the name, so no re-sorting + * is necessary */ *res = variable; @@ -5900,7 +5902,7 @@ _ShowOption(struct config_generic * record, bool use_units) * effects of canonicalization of string values by assign_hooks. */ static bool -is_newvalue_equal(struct config_generic *record, const char *newvalue) +is_newvalue_equal(struct config_generic * record, const char *newvalue) { /* newvalue == NULL isn't supported */ Assert(newvalue != NULL); @@ -6175,7 +6177,7 @@ ParseLongOption(const char *string, char **name, char **value) /* * Handle options fetched from pg_database.datconfig, pg_authid.rolconfig, - * pg_proc.proconfig, etc. Caller must specify proper context/source/action. + * pg_proc.proconfig, etc. Caller must specify proper context/source/action. * * The array parameter must be an array of TEXT (it must not be NULL). */ @@ -6418,7 +6420,7 @@ assign_log_destination(const char *value, bool doit, GucSource source) if (pg_strcasecmp(tok, "stderr") == 0) newlogdest |= LOG_DESTINATION_STDERR; else if (pg_strcasecmp(tok, "csvlog") == 0) - newlogdest |= LOG_DESTINATION_CSVLOG; + newlogdest |= LOG_DESTINATION_CSVLOG; #ifdef HAVE_SYSLOG else if (pg_strcasecmp(tok, "syslog") == 0) newlogdest |= LOG_DESTINATION_SYSLOG; @@ -6527,7 +6529,7 @@ assign_defaultxactisolevel(const char *newval, bool doit, GucSource source) static const char * assign_session_replication_role(const char *newval, bool doit, GucSource source) { - int newrole; + int newrole; if (pg_strcasecmp(newval, "origin") == 0) newrole = SESSION_REPLICATION_ROLE_ORIGIN; diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c index 9f6774e5f7..23bdaf4bde 100644 --- a/src/backend/utils/misc/ps_status.c +++ b/src/backend/utils/misc/ps_status.c @@ -5,7 +5,7 @@ * to contain some useful information. Mechanism differs wildly across * platforms. * - * $PostgreSQL: pgsql/src/backend/utils/misc/ps_status.c,v 1.35 2007/02/16 21:34:04 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/misc/ps_status.c,v 1.36 2007/11/15 21:14:41 momjian Exp $ * * Copyright (c) 2000-2007, PostgreSQL Global Development Group * various details abducted from various places @@ -155,7 +155,7 @@ save_ps_display_args(int argc, char **argv) ps_buffer = argv[0]; last_status_len = ps_buffer_size = end_of_area - argv[0]; - + /* * move the environment out of the way */ diff --git a/src/backend/utils/mmgr/aset.c b/src/backend/utils/mmgr/aset.c index 7d080af86d..d1848854cf 100644 --- a/src/backend/utils/mmgr/aset.c +++ b/src/backend/utils/mmgr/aset.c @@ -11,7 +11,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/mmgr/aset.c,v 1.74 2007/08/12 20:39:14 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mmgr/aset.c,v 1.75 2007/11/15 21:14:41 momjian Exp $ * * NOTE: * This is a new (Feb. 05, 1999) implementation of the allocation set @@ -330,13 +330,13 @@ AllocSetContextCreate(MemoryContext parent, context->nextBlockSize = initBlockSize; /* - * Compute the allocation chunk size limit for this context. It can't - * be more than ALLOC_CHUNK_LIMIT because of the fixed number of - * freelists. If maxBlockSize is small then requests exceeding the - * maxBlockSize should be treated as large chunks, too. We have to - * have allocChunkLimit a power of two, because the requested and - * actually-allocated sizes of any chunk must be on the same side of - * the limit, else we get confused about whether the chunk is "big". + * Compute the allocation chunk size limit for this context. It can't be + * more than ALLOC_CHUNK_LIMIT because of the fixed number of freelists. + * If maxBlockSize is small then requests exceeding the maxBlockSize + * should be treated as large chunks, too. We have to have + * allocChunkLimit a power of two, because the requested and + * actually-allocated sizes of any chunk must be on the same side of the + * limit, else we get confused about whether the chunk is "big". */ context->allocChunkLimit = ALLOC_CHUNK_LIMIT; while (context->allocChunkLimit > @@ -935,9 +935,9 @@ AllocSetRealloc(MemoryContext context, void *pointer, Size size) * Small-chunk case. We just do this by brute force, ie, allocate a * new chunk and copy the data. Since we know the existing data isn't * huge, this won't involve any great memcpy expense, so it's not - * worth being smarter. (At one time we tried to avoid memcpy when - * it was possible to enlarge the chunk in-place, but that turns out - * to misbehave unpleasantly for repeated cycles of + * worth being smarter. (At one time we tried to avoid memcpy when it + * was possible to enlarge the chunk in-place, but that turns out to + * misbehave unpleasantly for repeated cycles of * palloc/repalloc/pfree: the eventually freed chunks go into the * wrong freelist for the next initial palloc request, and so we leak * memory indefinitely. See pgsql-hackers archives for 2007-08-11.) diff --git a/src/backend/utils/mmgr/portalmem.c b/src/backend/utils/mmgr/portalmem.c index 412e41952c..676012e329 100644 --- a/src/backend/utils/mmgr/portalmem.c +++ b/src/backend/utils/mmgr/portalmem.c @@ -12,7 +12,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.103 2007/04/26 23:24:44 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.104 2007/11/15 21:14:41 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -161,7 +161,7 @@ PortalListGetPrimaryStmt(List *stmts) foreach(lc, stmts) { - Node *stmt = (Node *) lfirst(lc); + Node *stmt = (Node *) lfirst(lc); if (IsA(stmt, PlannedStmt)) { @@ -292,16 +292,16 @@ PortalDefineQuery(Portal portal, const char *sourceText, const char *commandTag, List *stmts, - CachedPlan *cplan) + CachedPlan * cplan) { AssertArg(PortalIsValid(portal)); AssertState(portal->status == PORTAL_NEW); Assert(commandTag != NULL || stmts == NIL); - portal->prepStmtName = prepStmtName ? + portal->prepStmtName = prepStmtName ? MemoryContextStrdup(PortalGetHeapMemory(portal), prepStmtName) : NULL; - portal->sourceText = sourceText ? + portal->sourceText = sourceText ? MemoryContextStrdup(PortalGetHeapMemory(portal), sourceText) : NULL; portal->commandTag = commandTag; portal->stmts = stmts; @@ -468,7 +468,8 @@ PortalHashTableDeleteAll(void) hash_seq_init(&status, PortalHashTable); while ((hentry = hash_seq_search(&status)) != NULL) { - Portal portal = hentry->portal; + Portal portal = hentry->portal; + if (portal->status != PORTAL_ACTIVE) PortalDrop(portal, false); } @@ -883,8 +884,8 @@ pg_cursor(PG_FUNCTION_ARGS) oldcontext = MemoryContextSwitchTo(per_query_ctx); /* - * build tupdesc for result tuples. This must match the definition of - * the pg_cursors view in system_views.sql + * build tupdesc for result tuples. This must match the definition of the + * pg_cursors view in system_views.sql */ tupdesc = CreateTemplateTupleDesc(6, false); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name", diff --git a/src/backend/utils/resowner/resowner.c b/src/backend/utils/resowner/resowner.c index 92fe4742c7..a88fe9c05e 100644 --- a/src/backend/utils/resowner/resowner.c +++ b/src/backend/utils/resowner/resowner.c @@ -14,7 +14,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/resowner/resowner.c,v 1.24 2007/03/13 00:33:42 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/resowner/resowner.c,v 1.25 2007/11/15 21:14:41 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -95,7 +95,7 @@ static void ResourceOwnerReleaseInternal(ResourceOwner owner, bool isCommit, bool isTopLevel); static void PrintRelCacheLeakWarning(Relation rel); -static void PrintPlanCacheLeakWarning(CachedPlan *plan); +static void PrintPlanCacheLeakWarning(CachedPlan * plan); static void PrintTupleDescLeakWarning(TupleDesc tupdesc); @@ -811,7 +811,7 @@ ResourceOwnerEnlargePlanCacheRefs(ResourceOwner owner) * Caller must have previously done ResourceOwnerEnlargePlanCacheRefs() */ void -ResourceOwnerRememberPlanCacheRef(ResourceOwner owner, CachedPlan *plan) +ResourceOwnerRememberPlanCacheRef(ResourceOwner owner, CachedPlan * plan) { Assert(owner->nplanrefs < owner->maxplanrefs); owner->planrefs[owner->nplanrefs] = plan; @@ -822,7 +822,7 @@ ResourceOwnerRememberPlanCacheRef(ResourceOwner owner, CachedPlan *plan) * Forget that a plancache reference is owned by a ResourceOwner */ void -ResourceOwnerForgetPlanCacheRef(ResourceOwner owner, CachedPlan *plan) +ResourceOwnerForgetPlanCacheRef(ResourceOwner owner, CachedPlan * plan) { CachedPlan **planrefs = owner->planrefs; int np1 = owner->nplanrefs - 1; @@ -849,7 +849,7 @@ ResourceOwnerForgetPlanCacheRef(ResourceOwner owner, CachedPlan *plan) * Debugging subroutine */ static void -PrintPlanCacheLeakWarning(CachedPlan *plan) +PrintPlanCacheLeakWarning(CachedPlan * plan) { elog(WARNING, "plancache reference leak: plan %p not closed", plan); } diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c index 0c63d1e142..fd442d93c1 100644 --- a/src/backend/utils/sort/tuplesort.c +++ b/src/backend/utils/sort/tuplesort.c @@ -91,7 +91,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/sort/tuplesort.c,v 1.79 2007/10/29 21:31:28 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/sort/tuplesort.c,v 1.80 2007/11/15 21:14:41 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -246,8 +246,8 @@ struct Tuplesortstate int tapenum, unsigned int len); /* - * Function to reverse the sort direction from its current state. - * (We could dispense with this if we wanted to enforce that all variants + * Function to reverse the sort direction from its current state. (We + * could dispense with this if we wanted to enforce that all variants * represent the sort key information alike.) */ void (*reversedirection) (Tuplesortstate *state); @@ -572,8 +572,8 @@ tuplesort_begin_heap(TupleDesc tupDesc, for (i = 0; i < nkeys; i++) { - Oid sortFunction; - bool reverse; + Oid sortFunction; + bool reverse; AssertArg(attNums[i] != 0); AssertArg(sortOperators[i] != 0); @@ -699,7 +699,7 @@ tuplesort_begin_datum(Oid datumType, * * Advise tuplesort that at most the first N result tuples are required. * - * Must be called before inserting any tuples. (Actually, we could allow it + * Must be called before inserting any tuples. (Actually, we could allow it * as long as the sort hasn't spilled to disk, but there seems no need for * delayed calls at the moment.) * @@ -721,7 +721,7 @@ tuplesort_set_bound(Tuplesortstate *state, int64 bound) #endif /* We want to be able to compute bound * 2, so limit the setting */ - if (bound > (int64) (INT_MAX/2)) + if (bound > (int64) (INT_MAX / 2)) return; state->bounded = true; @@ -927,16 +927,16 @@ puttuple_common(Tuplesortstate *state, SortTuple *tuple) state->memtuples[state->memtupcount++] = *tuple; /* - * Check if it's time to switch over to a bounded heapsort. - * We do so if the input tuple count exceeds twice the desired - * tuple count (this is a heuristic for where heapsort becomes - * cheaper than a quicksort), or if we've just filled workMem - * and have enough tuples to meet the bound. + * Check if it's time to switch over to a bounded heapsort. We do + * so if the input tuple count exceeds twice the desired tuple + * count (this is a heuristic for where heapsort becomes cheaper + * than a quicksort), or if we've just filled workMem and have + * enough tuples to meet the bound. * - * Note that once we enter TSS_BOUNDED state we will always try - * to complete the sort that way. In the worst case, if later - * input tuples are larger than earlier ones, this might cause - * us to exceed workMem significantly. + * Note that once we enter TSS_BOUNDED state we will always try to + * complete the sort that way. In the worst case, if later input + * tuples are larger than earlier ones, this might cause us to + * exceed workMem significantly. */ if (state->bounded && (state->memtupcount > state->bound * 2 || @@ -970,14 +970,14 @@ puttuple_common(Tuplesortstate *state, SortTuple *tuple) break; case TSS_BOUNDED: + /* - * We don't want to grow the array here, so check whether the - * new tuple can be discarded before putting it in. This should - * be a good speed optimization, too, since when there are many - * more input tuples than the bound, most input tuples can be - * discarded with just this one comparison. Note that because - * we currently have the sort direction reversed, we must check - * for <= not >=. + * We don't want to grow the array here, so check whether the new + * tuple can be discarded before putting it in. This should be a + * good speed optimization, too, since when there are many more + * input tuples than the bound, most input tuples can be discarded + * with just this one comparison. Note that because we currently + * have the sort direction reversed, we must check for <= not >=. */ if (COMPARETUP(state, tuple, &state->memtuples[0]) <= 0) { @@ -1065,8 +1065,8 @@ tuplesort_performsort(Tuplesortstate *state) /* * We were able to accumulate all the tuples required for output - * in memory, using a heap to eliminate excess tuples. Now we have - * to transform the heap to a properly-sorted array. + * in memory, using a heap to eliminate excess tuples. Now we + * have to transform the heap to a properly-sorted array. */ sort_bounded_heap(state); state->current = 0; @@ -1140,7 +1140,7 @@ tuplesort_gettuple_common(Tuplesortstate *state, bool forward, /* * Complain if caller tries to retrieve more tuples than - * originally asked for in a bounded sort. This is because + * originally asked for in a bounded sort. This is because * returning EOF here might be the wrong thing. */ if (state->bounded && state->current >= state->bound) @@ -2139,11 +2139,11 @@ tuplesort_explain(Tuplesortstate *state) /* * Note: it might seem we should print both memory and disk usage for a * disk-based sort. However, the current code doesn't track memory space - * accurately once we have begun to return tuples to the caller (since - * we don't account for pfree's the caller is expected to do), so we - * cannot rely on availMem in a disk sort. This does not seem worth the - * overhead to fix. Is it worth creating an API for the memory context - * code to tell us how much is actually used in sortcontext? + * accurately once we have begun to return tuples to the caller (since we + * don't account for pfree's the caller is expected to do), so we cannot + * rely on availMem in a disk sort. This does not seem worth the overhead + * to fix. Is it worth creating an API for the memory context code to + * tell us how much is actually used in sortcontext? */ if (state->tapeset) spaceUsed = LogicalTapeSetBlocks(state->tapeset) * (BLCKSZ / 1024); @@ -2209,8 +2209,8 @@ tuplesort_explain(Tuplesortstate *state) static void make_bounded_heap(Tuplesortstate *state) { - int tupcount = state->memtupcount; - int i; + int tupcount = state->memtupcount; + int i; Assert(state->status == TSS_INITIAL); Assert(state->bounded); @@ -2220,10 +2220,10 @@ make_bounded_heap(Tuplesortstate *state) REVERSEDIRECTION(state); state->memtupcount = 0; /* make the heap empty */ - for (i=0; i<tupcount; i++) + for (i = 0; i < tupcount; i++) { if (state->memtupcount >= state->bound && - COMPARETUP(state, &state->memtuples[i], &state->memtuples[0]) <= 0) + COMPARETUP(state, &state->memtuples[i], &state->memtuples[0]) <= 0) { /* New tuple would just get thrown out, so skip it */ free_sort_tuple(state, &state->memtuples[i]); @@ -2232,7 +2232,7 @@ make_bounded_heap(Tuplesortstate *state) { /* Insert next tuple into heap */ /* Must copy source tuple to avoid possible overwrite */ - SortTuple stup = state->memtuples[i]; + SortTuple stup = state->memtuples[i]; tuplesort_heap_insert(state, &stup, 0, false); @@ -2255,7 +2255,7 @@ make_bounded_heap(Tuplesortstate *state) static void sort_bounded_heap(Tuplesortstate *state) { - int tupcount = state->memtupcount; + int tupcount = state->memtupcount; Assert(state->status == TSS_BOUNDED); Assert(state->bounded); @@ -2268,7 +2268,7 @@ sort_bounded_heap(Tuplesortstate *state) */ while (state->memtupcount > 1) { - SortTuple stup = state->memtuples[0]; + SortTuple stup = state->memtuples[0]; /* this sifts-up the next-largest entry and decreases memtupcount */ tuplesort_heap_siftup(state, false); @@ -2393,7 +2393,7 @@ markrunend(Tuplesortstate *state, int tapenum) /* - * Set up for an external caller of ApplySortFunction. This function + * Set up for an external caller of ApplySortFunction. This function * basically just exists to localize knowledge of the encoding of sk_flags * used in this module. */ @@ -2403,7 +2403,7 @@ SelectSortFunction(Oid sortOperator, Oid *sortFunction, int *sortFlags) { - bool reverse; + bool reverse; if (!get_compare_function_for_ordering_op(sortOperator, sortFunction, &reverse)) diff --git a/src/backend/utils/sort/tuplestore.c b/src/backend/utils/sort/tuplestore.c index 372dacaed4..9972b50c21 100644 --- a/src/backend/utils/sort/tuplestore.c +++ b/src/backend/utils/sort/tuplestore.c @@ -38,7 +38,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/sort/tuplestore.c,v 1.34 2007/08/02 17:48:52 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/utils/sort/tuplestore.c,v 1.35 2007/11/15 21:14:41 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -261,11 +261,11 @@ Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes) { Tuplestorestate *state; - int eflags; + int eflags; /* - * This interpretation of the meaning of randomAccess is compatible - * with the pre-8.3 behavior of tuplestores. + * This interpretation of the meaning of randomAccess is compatible with + * the pre-8.3 behavior of tuplestores. */ eflags = randomAccess ? (EXEC_FLAG_BACKWARD | EXEC_FLAG_REWIND | EXEC_FLAG_MARK) : @@ -288,7 +288,7 @@ tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes) * into the tuplestore. * * eflags is a bitmask following the meanings used for executor node - * startup flags (see executor.h). tuplestore pays attention to these bits: + * startup flags (see executor.h). tuplestore pays attention to these bits: * EXEC_FLAG_REWIND need rewind to start * EXEC_FLAG_BACKWARD need backward fetch * EXEC_FLAG_MARK need mark/restore @@ -723,10 +723,11 @@ tuplestore_markpos(Tuplestorestate *state) { case TSS_INMEM: state->markpos_current = state->current; + /* * We can truncate the tuplestore if neither backward scan nor - * rewind capability are required by the caller. There will - * never be a need to back up past the mark point. + * rewind capability are required by the caller. There will never + * be a need to back up past the mark point. * * Note: you might think we could remove all the tuples before * "current", since that one is the next to be returned. However, @@ -826,10 +827,10 @@ tuplestore_trim(Tuplestorestate *state, int ntuples) } /* - * Slide the array down and readjust pointers. This may look pretty + * Slide the array down and readjust pointers. This may look pretty * stupid, but we expect that there will usually not be very many - * tuple-pointers to move, so this isn't that expensive; and it keeps - * a lot of other logic simple. + * tuple-pointers to move, so this isn't that expensive; and it keeps a + * lot of other logic simple. * * In fact, in the current usage for merge joins, it's demonstrable that * there will always be exactly one non-removed tuple; so optimize that @@ -896,7 +897,7 @@ writetup_heap(Tuplestorestate *state, void *tup) if (BufFileWrite(state->myfile, (void *) tuple, tuplen) != (size_t) tuplen) elog(ERROR, "write failed"); - if (state->eflags & EXEC_FLAG_BACKWARD) /* need trailing length word? */ + if (state->eflags & EXEC_FLAG_BACKWARD) /* need trailing length word? */ if (BufFileWrite(state->myfile, (void *) &tuplen, sizeof(tuplen)) != sizeof(tuplen)) elog(ERROR, "write failed"); @@ -917,7 +918,7 @@ readtup_heap(Tuplestorestate *state, unsigned int len) if (BufFileRead(state->myfile, (void *) ((char *) tuple + sizeof(int)), len - sizeof(int)) != (size_t) (len - sizeof(int))) elog(ERROR, "unexpected end of data"); - if (state->eflags & EXEC_FLAG_BACKWARD) /* need trailing length word? */ + if (state->eflags & EXEC_FLAG_BACKWARD) /* need trailing length word? */ if (BufFileRead(state->myfile, (void *) &tuplen, sizeof(tuplen)) != sizeof(tuplen)) elog(ERROR, "unexpected end of data"); diff --git a/src/backend/utils/time/combocid.c b/src/backend/utils/time/combocid.c index 5ba76660fd..a26823fe44 100644 --- a/src/backend/utils/time/combocid.c +++ b/src/backend/utils/time/combocid.c @@ -15,7 +15,7 @@ * this module. * * To allow reusing existing combo cids, we also keep a hash table that - * maps cmin,cmax pairs to combo cids. This keeps the data structure size + * maps cmin,cmax pairs to combo cids. This keeps the data structure size * reasonable in most cases, since the number of unique pairs used by any * one transaction is likely to be small. * @@ -34,7 +34,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/time/combocid.c,v 1.1 2007/02/09 03:35:34 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/time/combocid.c,v 1.2 2007/11/15 21:14:41 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -54,17 +54,17 @@ static HTAB *comboHash = NULL; /* Key and entry structures for the hash table */ typedef struct { - CommandId cmin; - CommandId cmax; -} ComboCidKeyData; + CommandId cmin; + CommandId cmax; +} ComboCidKeyData; typedef ComboCidKeyData *ComboCidKey; typedef struct { ComboCidKeyData key; - CommandId combocid; -} ComboCidEntryData; + CommandId combocid; +} ComboCidEntryData; typedef ComboCidEntryData *ComboCidEntry; @@ -77,8 +77,8 @@ typedef ComboCidEntryData *ComboCidEntry; * To convert a combo cid to cmin and cmax, you do a simple array lookup. */ static ComboCidKey comboCids = NULL; -static int usedComboCids = 0; /* number of elements in comboCids */ -static int sizeComboCids = 0; /* allocated size of array */ +static int usedComboCids = 0; /* number of elements in comboCids */ +static int sizeComboCids = 0; /* allocated size of array */ /* Initial size of the array */ #define CCID_ARRAY_SIZE 100 @@ -102,7 +102,7 @@ static CommandId GetRealCmax(CommandId combocid); CommandId HeapTupleHeaderGetCmin(HeapTupleHeader tup) { - CommandId cid = HeapTupleHeaderGetRawCommandId(tup); + CommandId cid = HeapTupleHeaderGetRawCommandId(tup); Assert(!(tup->t_infomask & HEAP_MOVED)); Assert(TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmin(tup))); @@ -116,7 +116,7 @@ HeapTupleHeaderGetCmin(HeapTupleHeader tup) CommandId HeapTupleHeaderGetCmax(HeapTupleHeader tup) { - CommandId cid = HeapTupleHeaderGetRawCommandId(tup); + CommandId cid = HeapTupleHeaderGetRawCommandId(tup); /* We do not store cmax when locking a tuple */ Assert(!(tup->t_infomask & (HEAP_MOVED | HEAP_IS_LOCKED))); @@ -155,7 +155,7 @@ HeapTupleHeaderAdjustCmax(HeapTupleHeader tup, if (!(tup->t_infomask & HEAP_XMIN_COMMITTED) && TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmin(tup))) { - CommandId cmin = HeapTupleHeaderGetRawCommandId(tup); + CommandId cmin = HeapTupleHeaderGetRawCommandId(tup); *cmax = GetComboCommandId(cmin, *cmax); *iscombo = true; @@ -174,8 +174,8 @@ void AtEOXact_ComboCid(void) { /* - * Don't bother to pfree. These are allocated in TopTransactionContext, - * so they're going to go away at the end of transaction anyway. + * Don't bother to pfree. These are allocated in TopTransactionContext, so + * they're going to go away at the end of transaction anyway. */ comboHash = NULL; @@ -195,18 +195,18 @@ AtEOXact_ComboCid(void) static CommandId GetComboCommandId(CommandId cmin, CommandId cmax) { - CommandId combocid; + CommandId combocid; ComboCidKeyData key; ComboCidEntry entry; - bool found; + bool found; /* - * Create the hash table and array the first time we need to use - * combo cids in the transaction. + * Create the hash table and array the first time we need to use combo + * cids in the transaction. */ if (comboHash == NULL) { - HASHCTL hash_ctl; + HASHCTL hash_ctl; memset(&hash_ctl, 0, sizeof(hash_ctl)); hash_ctl.keysize = sizeof(ComboCidKeyData); @@ -243,13 +243,13 @@ GetComboCommandId(CommandId cmin, CommandId cmax) } /* - * We have to create a new combo cid. Check that there's room - * for it in the array, and grow it if there isn't. + * We have to create a new combo cid. Check that there's room for it in + * the array, and grow it if there isn't. */ if (usedComboCids >= sizeComboCids) { /* We need to grow the array */ - int newsize = sizeComboCids * 2; + int newsize = sizeComboCids * 2; comboCids = (ComboCidKeyData *) repalloc(comboCids, sizeof(ComboCidKeyData) * newsize); diff --git a/src/backend/utils/time/tqual.c b/src/backend/utils/time/tqual.c index e540186145..4c128e4446 100644 --- a/src/backend/utils/time/tqual.c +++ b/src/backend/utils/time/tqual.c @@ -31,7 +31,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/time/tqual.c,v 1.106 2007/09/21 18:24:28 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/time/tqual.c,v 1.107 2007/11/15 21:14:41 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -95,12 +95,12 @@ static bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot); * buffer, so we can't use the LSN to interlock this; we have to just refrain * from setting the hint bit until some future re-examination of the tuple. * - * We can always set hint bits when marking a transaction aborted. (Some + * We can always set hint bits when marking a transaction aborted. (Some * code in heapam.c relies on that!) * * Also, if we are cleaning up HEAP_MOVED_IN or HEAP_MOVED_OFF entries, then * we can always set the hint bits, since VACUUM FULL always uses synchronous - * commits and doesn't move tuples that weren't previously hinted. (This is + * commits and doesn't move tuples that weren't previously hinted. (This is * not known by this subroutine, but is applied by its callers.) * * Normal commits may be asynchronous, so for those we need to get the LSN @@ -116,7 +116,7 @@ SetHintBits(HeapTupleHeader tuple, Buffer buffer, if (TransactionIdIsValid(xid)) { /* NB: xid must be known committed here! */ - XLogRecPtr commitLSN = TransactionIdGetCommitLSN(xid); + XLogRecPtr commitLSN = TransactionIdGetCommitLSN(xid); if (XLogNeedsFlush(commitLSN)) return; /* not flushed yet, so don't set hint */ @@ -1127,10 +1127,11 @@ HeapTupleSatisfiesVacuum(HeapTupleHeader tuple, TransactionId OldestXmin, InvalidTransactionId); return HEAPTUPLE_DEAD; } + /* * At this point the xmin is known committed, but we might not have - * been able to set the hint bit yet; so we can no longer Assert - * that it's set. + * been able to set the hint bit yet; so we can no longer Assert that + * it's set. */ } @@ -1146,8 +1147,8 @@ HeapTupleSatisfiesVacuum(HeapTupleHeader tuple, TransactionId OldestXmin, /* * "Deleting" xact really only locked it, so the tuple is live in any * case. However, we should make sure that either XMAX_COMMITTED or - * XMAX_INVALID gets set once the xact is gone, to reduce the costs - * of examining the tuple for future xacts. Also, marking dead + * XMAX_INVALID gets set once the xact is gone, to reduce the costs of + * examining the tuple for future xacts. Also, marking dead * MultiXacts as invalid here provides defense against MultiXactId * wraparound (see also comments in heap_freeze_tuple()). */ @@ -1198,10 +1199,11 @@ HeapTupleSatisfiesVacuum(HeapTupleHeader tuple, TransactionId OldestXmin, InvalidTransactionId); return HEAPTUPLE_LIVE; } + /* * At this point the xmax is known committed, but we might not have - * been able to set the hint bit yet; so we can no longer Assert - * that it's set. + * been able to set the hint bit yet; so we can no longer Assert that + * it's set. */ } |