diff options
Diffstat (limited to 'src/backend/utils')
68 files changed, 3367 insertions, 2995 deletions
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c index 5a3b99f64a4..10e2f13bc32 100644 --- a/src/backend/utils/adt/acl.c +++ b/src/backend/utils/adt/acl.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.57 2001/01/24 19:43:12 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.58 2001/03/22 03:59:48 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -262,7 +262,7 @@ aclitemin(PG_FUNCTION_ARGS) Datum aclitemout(PG_FUNCTION_ARGS) { - AclItem *aip = PG_GETARG_ACLITEM_P(0); + AclItem *aip = PG_GETARG_ACLITEM_P(0); char *p; char *out; HeapTuple htup; @@ -281,7 +281,7 @@ aclitemout(PG_FUNCTION_ARGS) if (HeapTupleIsValid(htup)) { strncat(p, - NameStr(((Form_pg_shadow) GETSTRUCT(htup))->usename), + NameStr(((Form_pg_shadow) GETSTRUCT(htup))->usename), NAMEDATALEN); ReleaseSysCache(htup); } @@ -291,7 +291,7 @@ aclitemout(PG_FUNCTION_ARGS) char *tmp; tmp = DatumGetCString(DirectFunctionCall1(int4out, - Int32GetDatum((int32) aip->ai_id))); + Int32GetDatum((int32) aip->ai_id))); strcat(p, tmp); pfree(tmp); } @@ -307,7 +307,7 @@ aclitemout(PG_FUNCTION_ARGS) char *tmp; tmp = DatumGetCString(DirectFunctionCall1(int4out, - Int32GetDatum((int32) aip->ai_id))); + Int32GetDatum((int32) aip->ai_id))); strcat(p, tmp); pfree(tmp); } @@ -473,9 +473,9 @@ aclinsert3(Acl *old_acl, AclItem *mod_aip, unsigned modechg) } /* - * if the adjusted entry has no permissions, delete it from the - * list. For example, this helps in removing entries for users who no - * longer exist. EXCEPTION: never remove the world entry. + * if the adjusted entry has no permissions, delete it from the list. + * For example, this helps in removing entries for users who no longer + * exist. EXCEPTION: never remove the world entry. */ if (new_aip[dst].ai_mode == 0 && dst > 0) { @@ -502,7 +502,7 @@ Datum aclinsert(PG_FUNCTION_ARGS) { Acl *old_acl = PG_GETARG_ACL_P(0); - AclItem *mod_aip = PG_GETARG_ACLITEM_P(1); + AclItem *mod_aip = PG_GETARG_ACLITEM_P(1); PG_RETURN_ACL_P(aclinsert3(old_acl, mod_aip, ACL_MODECHG_EQL)); } @@ -511,7 +511,7 @@ Datum aclremove(PG_FUNCTION_ARGS) { Acl *old_acl = PG_GETARG_ACL_P(0); - AclItem *mod_aip = PG_GETARG_ACLITEM_P(1); + AclItem *mod_aip = PG_GETARG_ACLITEM_P(1); Acl *new_acl; AclItem *old_aip, *new_aip; @@ -575,7 +575,7 @@ Datum aclcontains(PG_FUNCTION_ARGS) { Acl *acl = PG_GETARG_ACL_P(0); - AclItem *aip = PG_GETARG_ACLITEM_P(1); + AclItem *aip = PG_GETARG_ACLITEM_P(1); AclItem *aidat; int i, num; @@ -599,7 +599,7 @@ aclcontains(PG_FUNCTION_ARGS) void ExecuteChangeACLStmt(ChangeACLStmt *stmt) { - AclItem aclitem; + AclItem aclitem; unsigned modechg; List *i; diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c index d76fe6d64fe..84c674071c1 100644 --- a/src/backend/utils/adt/arrayfuncs.c +++ b/src/backend/utils/adt/arrayfuncs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.69 2001/01/24 19:43:12 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.70 2001/03/22 03:59:49 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -60,29 +60,29 @@ static int ArrayCount(char *str, int *dim, int typdelim); static Datum *ReadArrayStr(char *arrayStr, int nitems, int ndim, int *dim, - FmgrInfo *inputproc, Oid typelem, int32 typmod, - char typdelim, int typlen, bool typbyval, - char typalign, int *nbytes); + FmgrInfo *inputproc, Oid typelem, int32 typmod, + char typdelim, int typlen, bool typbyval, + char typalign, int *nbytes); static void CopyArrayEls(char *p, Datum *values, int nitems, - bool typbyval, int typlen, char typalign, - bool freedata); + bool typbyval, int typlen, char typalign, + bool freedata); static void system_cache_lookup(Oid element_type, bool input, int *typlen, - bool *typbyval, char *typdelim, Oid *typelem, - Oid *proc, char *typalign); + bool *typbyval, char *typdelim, Oid *typelem, + Oid *proc, char *typalign); static Datum ArrayCast(char *value, bool byval, int len); static int ArrayCastAndSet(Datum src, bool typbyval, int typlen, char *dest); static int array_nelems_size(char *ptr, int eltsize, int nitems); static char *array_seek(char *ptr, int eltsize, int nitems); static int array_copy(char *destptr, int eltsize, int nitems, char *srcptr); -static int array_slice_size(int ndim, int *dim, int *lb, char *arraydataptr, - int eltsize, int *st, int *endp); +static int array_slice_size(int ndim, int *dim, int *lb, char *arraydataptr, + int eltsize, int *st, int *endp); static void array_extract_slice(int ndim, int *dim, int *lb, - char *arraydataptr, int eltsize, - int *st, int *endp, char *destPtr); + char *arraydataptr, int eltsize, + int *st, int *endp, char *destPtr); static void array_insert_slice(int ndim, int *dim, int *lb, - char *origPtr, int origdatasize, - char *destPtr, int eltsize, - int *st, int *endp, char *srcPtr); + char *origPtr, int origdatasize, + char *destPtr, int eltsize, + int *st, int *endp, char *srcPtr); /*--------------------------------------------------------------------- @@ -96,9 +96,11 @@ static void array_insert_slice(int ndim, int *dim, int *lb, Datum array_in(PG_FUNCTION_ARGS) { - char *string = PG_GETARG_CSTRING(0); /* external form */ - Oid element_type = PG_GETARG_OID(1); /* type of an array element */ - int32 typmod = PG_GETARG_INT32(2); /* typmod for array elements */ + char *string = PG_GETARG_CSTRING(0); /* external form */ + Oid element_type = PG_GETARG_OID(1); /* type of an array + * element */ + int32 typmod = PG_GETARG_INT32(2); /* typmod for array + * elements */ int typlen; bool typbyval; char typdelim; @@ -132,8 +134,8 @@ array_in(PG_FUNCTION_ARGS) * Otherwise, we require the input to be in curly-brace style, and we * prescan the input to determine dimensions. * - * Dimension info takes the form of one or more [n] or [m:n] items. - * The outer loop iterates once per dimension item. + * Dimension info takes the form of one or more [n] or [m:n] items. The + * outer loop iterates once per dimension item. */ p = string_save; ndim = 0; @@ -450,6 +452,7 @@ ReadArrayStr(char *arrayStr, ObjectIdGetDatum(typelem), Int32GetDatum(typmod)); p = ++q; + /* * if not at the end of the array skip white space */ @@ -460,6 +463,7 @@ ReadArrayStr(char *arrayStr, q++; } } + /* * Initialize any unset items and compute total data space needed */ @@ -511,7 +515,7 @@ ReadArrayStr(char *arrayStr, * referenced by Datums after copying them. * * If the input data is of varlena type, the caller must have ensured that - * the values are not toasted. (Doing it here doesn't work since the + * the values are not toasted. (Doing it here doesn't work since the * caller has already allocated space for the array...) *---------- */ @@ -601,7 +605,7 @@ array_out(PG_FUNCTION_ARGS) itemvalue = fetch_att(p, typbyval, typlen); values[i] = DatumGetCString(FunctionCall3(&outputproc, itemvalue, - ObjectIdGetDatum(typelem), + ObjectIdGetDatum(typelem), Int32GetDatum(-1))); if (typlen > 0) p += typlen; @@ -706,6 +710,7 @@ array_dims(PG_FUNCTION_ARGS) PG_RETURN_NULL(); nbytes = ARR_NDIM(v) * 33 + 1; + /* * 33 since we assume 15 digits per number + ':' +'[]' * @@ -759,6 +764,7 @@ array_ref(ArrayType *array, if (arraylen > 0) { + /* * fixed-length arrays -- these are assumed to be 1-d, 0-based */ @@ -809,7 +815,7 @@ array_ref(ArrayType *array, * lowerIndx[] and upperIndx[]. These are generally just temporaries. *----------------------------------------------------------------------------- */ -ArrayType * +ArrayType * array_get_slice(ArrayType *array, int nSubscripts, int *upperIndx, @@ -835,6 +841,7 @@ array_get_slice(ArrayType *array, if (arraylen > 0) { + /* * fixed-length arrays -- currently, cannot slice these because * parser labels output as being of the fixed-length array type! @@ -866,8 +873,9 @@ array_get_slice(ArrayType *array, /* * Check provided subscripts. A slice exceeding the current array - * limits is silently truncated to the array limits. If we end up with - * an empty slice, return NULL (should it be an empty array instead?) + * limits is silently truncated to the array limits. If we end up + * with an empty slice, return NULL (should it be an empty array + * instead?) */ if (ndim != nSubscripts || ndim <= 0 || ndim > MAXDIM) RETURN_NULL(ArrayType *); @@ -918,7 +926,7 @@ array_get_slice(ArrayType *array, * with NULL, which will probably not make him happy. *----------------------------------------------------------------------------- */ -ArrayType * +ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, @@ -950,9 +958,10 @@ array_set(ArrayType *array, if (arraylen > 0) { + /* - * fixed-length arrays -- these are assumed to be 1-d, 0-based. - * We cannot extend them, either. + * fixed-length arrays -- these are assumed to be 1-d, 0-based. We + * cannot extend them, either. */ if (nSubscripts != 1) elog(ERROR, "Invalid array subscripts"); @@ -994,9 +1003,7 @@ array_set(ArrayType *array, extendbefore = true; } else - { elog(ERROR, "Invalid array subscripts"); - } } if (indx[i] >= (dim[i] + lb[i])) { @@ -1006,9 +1013,7 @@ array_set(ArrayType *array, extendafter = true; } else - { elog(ERROR, "Invalid array subscripts"); - } } } @@ -1085,7 +1090,7 @@ array_set(ArrayType *array, * with NULL, which will probably not make him happy. *---------------------------------------------------------------------------- */ -ArrayType * +ArrayType * array_set_slice(ArrayType *array, int nSubscripts, int *upperIndx, @@ -1118,6 +1123,7 @@ array_set_slice(ArrayType *array, if (arraylen > 0) { + /* * fixed-length arrays -- not got round to doing this... */ @@ -1141,8 +1147,8 @@ array_set_slice(ArrayType *array, /* * Check provided subscripts. A slice exceeding the current array * limits throws an error, *except* in the 1-D case where we will - * extend the array as long as no hole is created. - * An empty slice is an error, too. + * extend the array as long as no hole is created. An empty slice is + * an error, too. */ for (i = 0; i < ndim; i++) { @@ -1156,26 +1162,20 @@ array_set_slice(ArrayType *array, lb[i] = lowerIndx[i]; } else - { elog(ERROR, "Invalid array subscripts"); - } } if (upperIndx[i] >= (dim[i] + lb[i])) { if (ndim == 1 && lowerIndx[i] <= (dim[i] + lb[i])) - { dim[i] = upperIndx[i] - lb[i] + 1; - } else - { elog(ERROR, "Invalid array subscripts"); - } } } /* - * Make sure source array has enough entries. Note we ignore the shape - * of the source array and just read entries serially. + * Make sure source array has enough entries. Note we ignore the + * shape of the source array and just read entries serially. */ mda_get_range(ndim, span, lowerIndx, upperIndx); nsrcitems = ArrayGetNItems(ndim, span); @@ -1192,24 +1192,27 @@ array_set_slice(ArrayType *array, olddatasize = ARR_SIZE(array) - overheadlen; if (ndim > 1) { + /* - * here we do not need to cope with extension of the array; - * it would be a lot more complicated if we had to do so... + * here we do not need to cope with extension of the array; it + * would be a lot more complicated if we had to do so... */ olditemsize = array_slice_size(ndim, dim, lb, ARR_DATA_PTR(array), elmlen, lowerIndx, upperIndx); - lenbefore = lenafter = 0; /* keep compiler quiet */ + lenbefore = lenafter = 0; /* keep compiler quiet */ } else { + /* - * here we must allow for possibility of slice larger than orig array + * here we must allow for possibility of slice larger than orig + * array */ - int oldlb = ARR_LBOUND(array)[0]; - int oldub = oldlb + ARR_DIMS(array)[0] - 1; - int slicelb = MAX(oldlb, lowerIndx[0]); - int sliceub = MIN(oldub, upperIndx[0]); - char *oldarraydata = ARR_DATA_PTR(array); + int oldlb = ARR_LBOUND(array)[0]; + int oldub = oldlb + ARR_DIMS(array)[0] - 1; + int slicelb = MAX(oldlb, lowerIndx[0]); + int sliceub = MIN(oldub, upperIndx[0]); + char *oldarraydata = ARR_DATA_PTR(array); lenbefore = array_nelems_size(oldarraydata, elmlen, @@ -1234,9 +1237,10 @@ array_set_slice(ArrayType *array, if (ndim > 1) { + /* - * here we do not need to cope with extension of the array; - * it would be a lot more complicated if we had to do so... + * here we do not need to cope with extension of the array; it + * would be a lot more complicated if we had to do so... */ array_insert_slice(ndim, dim, lb, ARR_DATA_PTR(array), olddatasize, ARR_DATA_PTR(newarray), elmlen, @@ -1261,7 +1265,7 @@ array_set_slice(ArrayType *array, /* * array_map() * - * Map an array through an arbitrary function. Return a new array with + * Map an array through an arbitrary function. Return a new array with * same dimensions and each source element transformed by fn(). Each * source element is passed as the first argument to fn(); additional * arguments to be passed to fn() can be specified by the caller. @@ -1269,15 +1273,15 @@ array_set_slice(ArrayType *array, * * Parameters are: * * fcinfo: a function-call data structure pre-constructed by the caller - * to be ready to call the desired function, with everything except the - * first argument position filled in. In particular, flinfo identifies - * the function fn(), and if nargs > 1 then argument positions after the - * first must be preset to the additional values to be passed. The - * first argument position initially holds the input array value. + * to be ready to call the desired function, with everything except the + * first argument position filled in. In particular, flinfo identifies + * the function fn(), and if nargs > 1 then argument positions after the + * first must be preset to the additional values to be passed. The + * first argument position initially holds the input array value. * * inpType: OID of element type of input array. This must be the same as, - * or binary-compatible with, the first argument type of fn(). - * * retType: OID of element type of output array. This must be the same as, - * or binary-compatible with, the result type of fn(). + * or binary-compatible with, the first argument type of fn(). + * * retType: OID of element type of output array. This must be the same as, + * or binary-compatible with, the result type of fn(). * * NB: caller must assure that input array is not NULL. Currently, * any additional parameters passed to fn() may not be specified as NULL @@ -1344,9 +1348,9 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType) /* * Apply the given function to source elt and extra args. * - * We assume the extra args are non-NULL, so need not check - * whether fn() is strict. Would need to do more work here - * to support arrays containing nulls, too. + * We assume the extra args are non-NULL, so need not check whether + * fn() is strict. Would need to do more work here to support + * arrays containing nulls, too. */ fcinfo->arg[0] = elt; fcinfo->argnull[0] = false; @@ -1374,7 +1378,10 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType) result->ndim = ndim; memcpy(ARR_DIMS(result), ARR_DIMS(v), 2 * ndim * sizeof(int)); - /* Note: do not risk trying to pfree the results of the called function */ + /* + * Note: do not risk trying to pfree the results of the called + * function + */ CopyArrayEls(ARR_DATA_PTR(result), values, nitems, typbyval, typlen, typalign, false); pfree(values); @@ -1383,7 +1390,7 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType) } /*---------- - * construct_array --- simple method for constructing an array object + * construct_array --- simple method for constructing an array object * * elems: array of Datum items to become the array contents * nelems: number of items @@ -1394,7 +1401,7 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType) * NULL element values are not supported. *---------- */ -ArrayType * +ArrayType * construct_array(Datum *elems, int nelems, bool elmbyval, int elmlen, char elmalign) { diff --git a/src/backend/utils/adt/ascii.c b/src/backend/utils/adt/ascii.c index ddc365f2004..bdcd24e44e0 100644 --- a/src/backend/utils/adt/ascii.c +++ b/src/backend/utils/adt/ascii.c @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------- * ascii.c * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/ascii.c,v 1.6 2001/01/24 19:43:13 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/ascii.c,v 1.7 2001/03/22 03:59:49 momjian Exp $ * * Portions Copyright (c) 1999-2000, PostgreSQL Global Development Group * @@ -33,21 +33,21 @@ multibyte_error(void) elog(ERROR, "Multi-byte support is not enabled"); } -Datum +Datum to_ascii_encname(PG_FUNCTION_ARGS) { multibyte_error(); return 0; /* keep compiler quiet */ } -Datum +Datum to_ascii_enc(PG_FUNCTION_ARGS) { multibyte_error(); return 0; /* keep compiler quiet */ } -Datum +Datum to_ascii_default(PG_FUNCTION_ARGS) { multibyte_error(); @@ -55,29 +55,29 @@ to_ascii_default(PG_FUNCTION_ARGS) } -#else /* with MULTIBYTE */ +#else /* with MULTIBYTE */ static text *encode_to_ascii(text *data, int enc); /* ---------- - * to_ascii + * to_ascii * ---------- */ char * pg_to_ascii(unsigned char *src, unsigned char *src_end, unsigned char *desc, int enc) { - unsigned char *x = NULL; - unsigned char *ascii = NULL ; - int range = 0; - - /* - * relevant start for an encoding - */ - #define RANGE_128 128 - #define RANGE_160 160 - - + unsigned char *x = NULL; + unsigned char *ascii = NULL; + int range = 0; + + /* + * relevant start for an encoding + */ +#define RANGE_128 128 +#define RANGE_160 160 + + if (enc == LATIN1) { /* ---------- @@ -107,24 +107,24 @@ pg_to_ascii(unsigned char *src, unsigned char *src_end, unsigned char *desc, int } else { - elog(ERROR, "pg_to_ascii(): unsupported encoding from %s", - pg_encoding_to_char(enc)); + elog(ERROR, "pg_to_ascii(): unsupported encoding from %s", + pg_encoding_to_char(enc)); } - + /* ---------- * Encode * ---------- */ for (x = src; x <= src_end; x++) { - if (*x < 128) + if (*x < 128) *desc++ = *x; else if (*x < range) - *desc++ = ' '; /* bogus 128 to 'range' */ + *desc++ = ' '; /* bogus 128 to 'range' */ else - *desc++ = ascii[*x - range]; - } - + *desc++ = ascii[*x - range]; + } + return desc; } @@ -136,11 +136,11 @@ static text * encode_to_ascii(text *data, int enc) { pg_to_ascii( - (unsigned char *) VARDATA(data), /* src */ - VARDATA(data) + VARSIZE(data), /* src end */ - (unsigned char *) VARDATA(data), /* desc */ - enc); /* encoding */ - + (unsigned char *) VARDATA(data), /* src */ + VARDATA(data) + VARSIZE(data), /* src end */ + (unsigned char *) VARDATA(data), /* desc */ + enc); /* encoding */ + return data; } @@ -152,30 +152,30 @@ Datum to_ascii_encname(PG_FUNCTION_ARGS) { PG_RETURN_TEXT_P - ( - encode_to_ascii - ( - PG_GETARG_TEXT_P_COPY(0), - pg_char_to_encoding( NameStr(*PG_GETARG_NAME(1)) ) - ) - ); + ( + encode_to_ascii + ( + PG_GETARG_TEXT_P_COPY(0), + pg_char_to_encoding(NameStr(*PG_GETARG_NAME(1))) + ) + ); } /* ---------- * convert to ASCII - enc is set as int4 * ---------- */ -Datum +Datum to_ascii_enc(PG_FUNCTION_ARGS) { PG_RETURN_TEXT_P - ( - encode_to_ascii - ( - PG_GETARG_TEXT_P_COPY(0), - PG_GETARG_INT32(1) - ) - ); + ( + encode_to_ascii + ( + PG_GETARG_TEXT_P_COPY(0), + PG_GETARG_INT32(1) + ) + ); } /* ---------- @@ -185,14 +185,14 @@ to_ascii_enc(PG_FUNCTION_ARGS) Datum to_ascii_default(PG_FUNCTION_ARGS) { - PG_RETURN_TEXT_P - ( - encode_to_ascii - ( - PG_GETARG_TEXT_P_COPY(0), - GetDatabaseEncoding() - ) + PG_RETURN_TEXT_P + ( + encode_to_ascii + ( + PG_GETARG_TEXT_P_COPY(0), + GetDatabaseEncoding() + ) ); } -#endif /* MULTIBYTE */ +#endif /* MULTIBYTE */ diff --git a/src/backend/utils/adt/bool.c b/src/backend/utils/adt/bool.c index 4f702b24595..dba0fe61492 100644 --- a/src/backend/utils/adt/bool.c +++ b/src/backend/utils/adt/bool.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.24 2001/01/24 19:43:13 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.25 2001/03/22 03:59:49 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -36,8 +36,8 @@ boolin(PG_FUNCTION_ARGS) switch (*b) { - case 't': - case 'T': + case 't': + case 'T': if (strncasecmp(b, "true", strlen(b)) == 0) PG_RETURN_BOOL(true); break; @@ -187,7 +187,7 @@ isfalse(PG_FUNCTION_ARGS) b = PG_GETARG_BOOL(0); - PG_RETURN_BOOL(! b); + PG_RETURN_BOOL(!b); } Datum @@ -200,7 +200,7 @@ isnottrue(PG_FUNCTION_ARGS) b = PG_GETARG_BOOL(0); - PG_RETURN_BOOL(! b); + PG_RETURN_BOOL(!b); } Datum diff --git a/src/backend/utils/adt/cash.c b/src/backend/utils/adt/cash.c index 7a3a5c11be9..dbcf881bf6c 100644 --- a/src/backend/utils/adt/cash.c +++ b/src/backend/utils/adt/cash.c @@ -9,7 +9,7 @@ * workings can be found in the book "Software Solutions in C" by * Dale Schumacher, Academic Press, ISBN: 0-12-632360-7. * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.49 2000/12/03 20:45:35 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.50 2001/03/22 03:59:49 momjian Exp $ */ #include "postgres.h" @@ -82,20 +82,23 @@ cash_in(PG_FUNCTION_ARGS) ssymbol, psymbol, *nsymbol; + #ifdef USE_LOCALE struct lconv *lconvert = PGLC_localeconv(); + #endif #ifdef USE_LOCALE + /* * frac_digits will be CHAR_MAX in some locales, notably C. However, * just testing for == CHAR_MAX is risky, because of compilers like * gcc that "helpfully" let you alter the platform-standard definition * of whether char is signed or not. If we are so unfortunate as to * get compiled with a nonstandard -fsigned-char or -funsigned-char - * switch, then our idea of CHAR_MAX will not agree with libc's. - * The safest course is not to test for CHAR_MAX at all, but to impose - * a range check for plausible frac_digits values. + * switch, then our idea of CHAR_MAX will not agree with libc's. The + * safest course is not to test for CHAR_MAX at all, but to impose a + * range check for plausible frac_digits values. */ fpoint = lconvert->frac_digits; if (fpoint < 0 || fpoint > 10) @@ -238,8 +241,10 @@ cash_out(PG_FUNCTION_ARGS) dsymbol, *nsymbol; char convention; + #ifdef USE_LOCALE struct lconv *lconvert = PGLC_localeconv(); + #endif #ifdef USE_LOCALE @@ -249,8 +254,8 @@ cash_out(PG_FUNCTION_ARGS) points = 2; /* best guess in this case, I think */ /* - * As with frac_digits, must apply a range check to mon_grouping - * to avoid being fooled by variant CHAR_MAX values. + * As with frac_digits, must apply a range check to mon_grouping to + * avoid being fooled by variant CHAR_MAX values. */ mon_group = *lconvert->mon_grouping; if (mon_group <= 0 || mon_group > 6) @@ -680,7 +685,7 @@ cash_words(PG_FUNCTION_ARGS) buf[0] = '\0'; m0 = value % 100; /* cents */ - m1 = (value / 100) % 1000; /* hundreds */ + m1 = (value / 100) % 1000; /* hundreds */ m2 = (value / 100000) % 1000; /* thousands */ m3 = value / 100000000 % 1000; /* millions */ diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c index 35031e81873..5e7d3c92f2e 100644 --- a/src/backend/utils/adt/date.c +++ b/src/backend/utils/adt/date.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.55 2001/01/24 19:43:13 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.56 2001/03/22 03:59:49 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -49,7 +49,7 @@ date_in(PG_FUNCTION_ARGS) char lowstr[MAXDATELEN + 1]; if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0) - || (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp) != 0)) + || (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp) != 0)) elog(ERROR, "Bad date external representation '%s'", str); switch (dtype) @@ -244,15 +244,15 @@ date_timestamp(PG_FUNCTION_ARGS) if (utime == -1) elog(ERROR, "Unable to convert date to tm"); - result = utime + ((date2j(1970,1,1)-date2j(2000,1,1))*86400.0); + result = utime + ((date2j(1970, 1, 1) - date2j(2000, 1, 1)) * 86400.0); #else - result = dateVal*86400.0+CTimeZone; + result = dateVal * 86400.0 + CTimeZone; #endif } else { /* Outside of range for timezone support, so assume UTC */ - result = dateVal*86400.0; + result = dateVal * 86400.0; } PG_RETURN_TIMESTAMP(result); @@ -277,13 +277,9 @@ timestamp_date(PG_FUNCTION_ARGS) elog(ERROR, "Unable to convert timestamp to date"); if (TIMESTAMP_IS_EPOCH(timestamp)) - { timestamp2tm(SetTimestamp(timestamp), NULL, tm, &fsec, NULL); - } else if (TIMESTAMP_IS_CURRENT(timestamp)) - { timestamp2tm(SetTimestamp(timestamp), &tz, tm, &fsec, &tzn); - } else { if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0) @@ -538,8 +534,10 @@ time_smaller(PG_FUNCTION_ARGS) Datum overlaps_time(PG_FUNCTION_ARGS) { - /* The arguments are TimeADT, but we leave them as generic Datums - * to avoid dereferencing nulls (TimeADT is pass-by-reference!) + + /* + * The arguments are TimeADT, but we leave them as generic Datums to + * avoid dereferencing nulls (TimeADT is pass-by-reference!) */ Datum ts1 = PG_GETARG_DATUM(0); Datum te1 = PG_GETARG_DATUM(1); @@ -556,9 +554,9 @@ overlaps_time(PG_FUNCTION_ARGS) (DatumGetTimeADT(t1) < DatumGetTimeADT(t2)) /* - * If both endpoints of interval 1 are null, the result is null (unknown). - * If just one endpoint is null, take ts1 as the non-null one. - * Otherwise, take ts1 as the lesser endpoint. + * If both endpoints of interval 1 are null, the result is null + * (unknown). If just one endpoint is null, take ts1 as the non-null + * one. Otherwise, take ts1 as the lesser endpoint. */ if (ts1IsNull) { @@ -572,7 +570,7 @@ overlaps_time(PG_FUNCTION_ARGS) { if (TIMEADT_GT(ts1, te1)) { - Datum tt = ts1; + Datum tt = ts1; ts1 = te1; te1 = tt; @@ -592,7 +590,7 @@ overlaps_time(PG_FUNCTION_ARGS) { if (TIMEADT_GT(ts2, te2)) { - Datum tt = ts2; + Datum tt = ts2; ts2 = te2; te2 = tt; @@ -605,7 +603,9 @@ overlaps_time(PG_FUNCTION_ARGS) */ if (TIMEADT_GT(ts1, ts2)) { - /* This case is ts1 < te2 OR te1 < te2, which may look redundant + + /* + * This case is ts1 < te2 OR te1 < te2, which may look redundant * but in the presence of nulls it's not quite completely so. */ if (te2IsNull) @@ -614,7 +614,9 @@ overlaps_time(PG_FUNCTION_ARGS) PG_RETURN_BOOL(true); if (te1IsNull) PG_RETURN_NULL(); - /* If te1 is not null then we had ts1 <= te1 above, and we just + + /* + * If te1 is not null then we had ts1 <= te1 above, and we just * found ts1 >= te2, hence te1 >= te2. */ PG_RETURN_BOOL(false); @@ -628,15 +630,20 @@ overlaps_time(PG_FUNCTION_ARGS) PG_RETURN_BOOL(true); if (te2IsNull) PG_RETURN_NULL(); - /* If te2 is not null then we had ts2 <= te2 above, and we just + + /* + * If te2 is not null then we had ts2 <= te2 above, and we just * found ts2 >= te1, hence te2 >= te1. */ PG_RETURN_BOOL(false); } else { - /* For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a - * rather silly way of saying "true if both are nonnull, else null". + + /* + * For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a + * rather silly way of saying "true if both are nonnull, else + * null". */ if (te1IsNull || te2IsNull) PG_RETURN_NULL(); @@ -690,7 +697,7 @@ datetime_timestamp(PG_FUNCTION_ARGS) Timestamp result; result = DatumGetTimestamp(DirectFunctionCall1(date_timestamp, - DateADTGetDatum(date))); + DateADTGetDatum(date))); result += time; PG_RETURN_TIMESTAMP(result); @@ -895,62 +902,62 @@ timetz_out(PG_FUNCTION_ARGS) Datum timetz_eq(PG_FUNCTION_ARGS) { - TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); - TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); + TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); + TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); - PG_RETURN_BOOL(((time1->time+time1->zone) == (time2->time+time2->zone))); + PG_RETURN_BOOL(((time1->time + time1->zone) == (time2->time + time2->zone))); } Datum timetz_ne(PG_FUNCTION_ARGS) { - TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); - TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); + TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); + TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); - PG_RETURN_BOOL(((time1->time+time1->zone) != (time2->time+time2->zone))); + PG_RETURN_BOOL(((time1->time + time1->zone) != (time2->time + time2->zone))); } Datum timetz_lt(PG_FUNCTION_ARGS) { - TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); - TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); + TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); + TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); - PG_RETURN_BOOL(((time1->time+time1->zone) < (time2->time+time2->zone))); + PG_RETURN_BOOL(((time1->time + time1->zone) < (time2->time + time2->zone))); } Datum timetz_le(PG_FUNCTION_ARGS) { - TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); - TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); + TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); + TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); - PG_RETURN_BOOL(((time1->time+time1->zone) <= (time2->time+time2->zone))); + PG_RETURN_BOOL(((time1->time + time1->zone) <= (time2->time + time2->zone))); } Datum timetz_gt(PG_FUNCTION_ARGS) { - TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); - TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); + TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); + TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); - PG_RETURN_BOOL(((time1->time+time1->zone) > (time2->time+time2->zone))); + PG_RETURN_BOOL(((time1->time + time1->zone) > (time2->time + time2->zone))); } Datum timetz_ge(PG_FUNCTION_ARGS) { - TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); - TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); + TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); + TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); - PG_RETURN_BOOL(((time1->time+time1->zone) >= (time2->time+time2->zone))); + PG_RETURN_BOOL(((time1->time + time1->zone) >= (time2->time + time2->zone))); } Datum timetz_cmp(PG_FUNCTION_ARGS) { - TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); - TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); + TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); + TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); if (DatumGetBool(DirectFunctionCall2(timetz_lt, TimeTzADTPGetDatum(time1), @@ -969,7 +976,7 @@ timetz_cmp(PG_FUNCTION_ARGS) Datum timetz_hash(PG_FUNCTION_ARGS) { - TimeTzADT *key = PG_GETARG_TIMETZADT_P(0); + TimeTzADT *key = PG_GETARG_TIMETZADT_P(0); /* * Specify hash length as sizeof(double) + sizeof(int4), not as @@ -982,8 +989,8 @@ timetz_hash(PG_FUNCTION_ARGS) Datum timetz_larger(PG_FUNCTION_ARGS) { - TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); - TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); + TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); + TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); if (DatumGetBool(DirectFunctionCall2(timetz_gt, TimeTzADTPGetDatum(time1), @@ -995,8 +1002,8 @@ timetz_larger(PG_FUNCTION_ARGS) Datum timetz_smaller(PG_FUNCTION_ARGS) { - TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); - TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); + TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); + TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); if (DatumGetBool(DirectFunctionCall2(timetz_lt, TimeTzADTPGetDatum(time1), @@ -1058,7 +1065,9 @@ timetz_mi_interval(PG_FUNCTION_ARGS) Datum overlaps_timetz(PG_FUNCTION_ARGS) { - /* The arguments are TimeTzADT *, but we leave them as generic Datums + + /* + * The arguments are TimeTzADT *, but we leave them as generic Datums * for convenience of notation --- and to avoid dereferencing nulls. */ Datum ts1 = PG_GETARG_DATUM(0); @@ -1076,9 +1085,9 @@ overlaps_timetz(PG_FUNCTION_ARGS) DatumGetBool(DirectFunctionCall2(timetz_lt,t1,t2)) /* - * If both endpoints of interval 1 are null, the result is null (unknown). - * If just one endpoint is null, take ts1 as the non-null one. - * Otherwise, take ts1 as the lesser endpoint. + * If both endpoints of interval 1 are null, the result is null + * (unknown). If just one endpoint is null, take ts1 as the non-null + * one. Otherwise, take ts1 as the lesser endpoint. */ if (ts1IsNull) { @@ -1092,7 +1101,7 @@ overlaps_timetz(PG_FUNCTION_ARGS) { if (TIMETZ_GT(ts1, te1)) { - Datum tt = ts1; + Datum tt = ts1; ts1 = te1; te1 = tt; @@ -1112,7 +1121,7 @@ overlaps_timetz(PG_FUNCTION_ARGS) { if (TIMETZ_GT(ts2, te2)) { - Datum tt = ts2; + Datum tt = ts2; ts2 = te2; te2 = tt; @@ -1125,7 +1134,9 @@ overlaps_timetz(PG_FUNCTION_ARGS) */ if (TIMETZ_GT(ts1, ts2)) { - /* This case is ts1 < te2 OR te1 < te2, which may look redundant + + /* + * This case is ts1 < te2 OR te1 < te2, which may look redundant * but in the presence of nulls it's not quite completely so. */ if (te2IsNull) @@ -1134,7 +1145,9 @@ overlaps_timetz(PG_FUNCTION_ARGS) PG_RETURN_BOOL(true); if (te1IsNull) PG_RETURN_NULL(); - /* If te1 is not null then we had ts1 <= te1 above, and we just + + /* + * If te1 is not null then we had ts1 <= te1 above, and we just * found ts1 >= te2, hence te1 >= te2. */ PG_RETURN_BOOL(false); @@ -1148,15 +1161,20 @@ overlaps_timetz(PG_FUNCTION_ARGS) PG_RETURN_BOOL(true); if (te2IsNull) PG_RETURN_NULL(); - /* If te2 is not null then we had ts2 <= te2 above, and we just + + /* + * If te2 is not null then we had ts2 <= te2 above, and we just * found ts2 >= te1, hence te2 >= te1. */ PG_RETURN_BOOL(false); } else { - /* For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a - * rather silly way of saying "true if both are nonnull, else null". + + /* + * For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a + * rather silly way of saying "true if both are nonnull, else + * null". */ if (te1IsNull || te2IsNull) PG_RETURN_NULL(); @@ -1219,7 +1237,7 @@ datetimetz_timestamp(PG_FUNCTION_ARGS) TimeTzADT *time = PG_GETARG_TIMETZADT_P(1); Timestamp result; - result = date*86400.0 + time->time + time->zone; + result = date * 86400.0 + time->time + time->zone; PG_RETURN_TIMESTAMP(result); } diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index 8e9299643ff..8691fa49b91 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.61 2001/03/14 20:12:10 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.62 2001/03/22 03:59:50 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -25,16 +25,16 @@ #include "utils/datetime.h" static int DecodeNumber(int flen, char *field, - int fmask, int *tmask, - struct tm * tm, double *fsec, int *is2digits); + int fmask, int *tmask, + struct tm * tm, double *fsec, int *is2digits); static int DecodeNumberField(int len, char *str, - int fmask, int *tmask, - struct tm * tm, double *fsec, int *is2digits); + int fmask, int *tmask, + struct tm * tm, double *fsec, int *is2digits); static int DecodeTime(char *str, int fmask, int *tmask, - struct tm * tm, double *fsec); + struct tm * tm, double *fsec); static int DecodeTimezone(char *str, int *tzp); static datetkn *datebsearch(char *key, datetkn *base, unsigned int nel); -static int DecodeDate(char *str, int fmask, int *tmask, struct tm * tm); +static int DecodeDate(char *str, int fmask, int *tmask, struct tm * tm); #define USE_DATE_CACHE 1 #define ROUND_ALL 0 @@ -271,10 +271,13 @@ static datetkn deltatktbl[] = { {"m", UNITS, DTK_MINUTE}, /* "minute" relative time units */ {"microsecon", UNITS, DTK_MICROSEC}, /* "microsecond" relative * time units */ - {"mil", UNITS, DTK_MILLENNIUM}, /* "millennium" relative time units */ - {"mils", UNITS, DTK_MILLENNIUM}, /* "millennia" relative time units */ - {"millennia", UNITS, DTK_MILLENNIUM}, /* "millennia" relative time units */ - {DMILLENNIUM, UNITS, DTK_MILLENNIUM}, /* "millennium" relative time units */ + {"mil", UNITS, DTK_MILLENNIUM}, /* "millennium" relative time + * units */ + {"mils", UNITS, DTK_MILLENNIUM}, /* "millennia" relative time units */ + {"millennia", UNITS, DTK_MILLENNIUM}, /* "millennia" relative + * time units */ + {DMILLENNIUM, UNITS, DTK_MILLENNIUM}, /* "millennium" relative + * time units */ {"millisecon", UNITS, DTK_MILLISEC}, /* relative time units */ {"min", UNITS, DTK_MINUTE}, /* "minute" relative time units */ {"mins", UNITS, DTK_MINUTE},/* "minutes" relative time units */ @@ -876,14 +879,14 @@ DecodeDateTime(char **field, int *ftype, int nf, tm->tm_year += 1900; tm->tm_mon += 1; -# if defined(HAVE_TM_ZONE) +#if defined(HAVE_TM_ZONE) *tzp = -(tm->tm_gmtoff); /* tm_gmtoff is * Sun/DEC-ism */ -# elif defined(HAVE_INT_TIMEZONE) +#elif defined(HAVE_INT_TIMEZONE) *tzp = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL); -# endif /* HAVE_INT_TIMEZONE */ +#endif /* HAVE_INT_TIMEZONE */ -#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ +#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ *tzp = CTimeZone; #endif } @@ -1121,13 +1124,13 @@ DecodeTimeOnly(char **field, int *ftype, int nf, mktime(tmp); tm->tm_isdst = tmp->tm_isdst; -# if defined(HAVE_TM_ZONE) +#if defined(HAVE_TM_ZONE) *tzp = -(tmp->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */ -# elif defined(HAVE_INT_TIMEZONE) +#elif defined(HAVE_INT_TIMEZONE) *tzp = ((tmp->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL); -# endif +#endif -#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ +#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ *tzp = CTimeZone; #endif } @@ -1492,7 +1495,7 @@ DecodeNumberField(int len, char *str, int fmask, return -1; return 0; -} /* DecodeNumberField() */ +} /* DecodeNumberField() */ /* DecodeTimezone() @@ -1674,20 +1677,26 @@ DecodeDateDelta(char **field, int *ftype, int nf, int *dtype, struct tm * tm, do break; case DTK_TZ: + /* * Timezone is a token with a leading sign character and * otherwise the same as a non-signed time field */ Assert((*field[i] == '-') || (*field[i] == '+')); - /* A single signed number ends up here, but will be rejected by DecodeTime(). - * So, work this out to drop through to DTK_NUMBER, which *can* tolerate this. + + /* + * A single signed number ends up here, but will be + * rejected by DecodeTime(). So, work this out to drop + * through to DTK_NUMBER, which *can* tolerate this. */ - cp = field[i]+1; + cp = field[i] + 1; while ((*cp != '\0') && (*cp != ':') && (*cp != '.')) cp++; if ((*cp == ':') - && (DecodeTime((field[i]+1), fmask, &tmask, tm, fsec) == 0)) { - if (*field[i] == '-') { + && (DecodeTime((field[i] + 1), fmask, &tmask, tm, fsec) == 0)) + { + if (*field[i] == '-') + { /* flip the sign on all fields */ tm->tm_hour = -tm->tm_hour; tm->tm_min = -tm->tm_min; @@ -1695,18 +1704,33 @@ DecodeDateDelta(char **field, int *ftype, int nf, int *dtype, struct tm * tm, do *fsec = -(*fsec); } - /* Set the next type to be a day, if units are not specified. - * This handles the case of '1 +02:03' since we are reading right to left. + /* + * Set the next type to be a day, if units are not + * specified. This handles the case of '1 +02:03' + * since we are reading right to left. */ type = DTK_DAY; tmask = DTK_M(TZ); break; - } else if (type == IGNORE) { - if (*cp == '.') { - /* Got a decimal point? Then assume some sort of seconds specification */ + } + else if (type == IGNORE) + { + if (*cp == '.') + { + + /* + * Got a decimal point? Then assume some sort of + * seconds specification + */ type = DTK_SECOND; - } else if (*cp == '\0') { - /* Only a signed integer? Then must assume a timezone-like usage */ + } + else if (*cp == '\0') + { + + /* + * Only a signed integer? Then must assume a + * timezone-like usage + */ type = DTK_HOUR; } } @@ -1921,7 +1945,7 @@ DecodeUnits(int field, char *lowtoken, int *val) * Binary search -- from Knuth (6.2.1) Algorithm B. Special case like this * is WAY faster than the generic bsearch(). */ -static datetkn * +static datetkn * datebsearch(char *key, datetkn *base, unsigned int nel) { datetkn *last = base + nel - 1, @@ -2166,7 +2190,7 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha if ((*tzn != NULL) && (tm->tm_isdst >= 0)) { strcpy((str + 27), " "); - StrNCpy((str + 28), *tzn, MAXTZLEN+1); + StrNCpy((str + 28), *tzn, MAXTZLEN + 1); } } else @@ -2175,7 +2199,7 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha if ((*tzn != NULL) && (tm->tm_isdst >= 0)) { strcpy((str + 24), " "); - StrNCpy((str + 25), *tzn, MAXTZLEN+1); + StrNCpy((str + 25), *tzn, MAXTZLEN + 1); } } @@ -2207,10 +2231,11 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) int is_nonzero = FALSE; char *cp = str; - /* The sign of year and month are guaranteed to match, - * since they are stored internally as "month". - * But we'll need to check for is_before and is_nonzero - * when determining the signs of hour/minute/seconds fields. + /* + * The sign of year and month are guaranteed to match, since they are + * stored internally as "month". But we'll need to check for is_before + * and is_nonzero when determining the signs of hour/minute/seconds + * fields. */ switch (style) { @@ -2247,8 +2272,8 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) if ((!is_nonzero) || (tm->tm_hour != 0) || (tm->tm_min != 0) || (tm->tm_sec != 0) || (fsec != 0)) { - int minus = ((tm->tm_hour < 0) || (tm->tm_min < 0) - || (tm->tm_sec < 0) || (fsec < 0)); + int minus = ((tm->tm_hour < 0) || (tm->tm_min < 0) + || (tm->tm_sec < 0) || (fsec < 0)); sprintf(cp, "%s%s%02d:%02d", (is_nonzero ? " " : ""), (minus ? "-" : (is_before ? "+" : "")), @@ -2283,7 +2308,8 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) if (tm->tm_year != 0) { - int year = tm->tm_year; + int year = tm->tm_year; + if (tm->tm_year < 0) year = -year; @@ -2296,55 +2322,59 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) if (tm->tm_mon != 0) { - int mon = tm->tm_mon; + int mon = tm->tm_mon; + if (is_before || ((!is_nonzero) && (tm->tm_mon < 0))) mon = -mon; sprintf(cp, "%s%d mon%s", (is_nonzero ? " " : ""), mon, ((mon != 1) ? "s" : "")); cp += strlen(cp); - if (! is_nonzero) + if (!is_nonzero) is_before = (tm->tm_mon < 0); is_nonzero = TRUE; } if (tm->tm_mday != 0) { - int day = tm->tm_mday; + int day = tm->tm_mday; + if (is_before || ((!is_nonzero) && (tm->tm_mday < 0))) day = -day; sprintf(cp, "%s%d day%s", (is_nonzero ? " " : ""), day, ((day != 1) ? "s" : "")); cp += strlen(cp); - if (! is_nonzero) + if (!is_nonzero) is_before = (tm->tm_mday < 0); is_nonzero = TRUE; } if (tm->tm_hour != 0) { - int hour = tm->tm_hour; + int hour = tm->tm_hour; + if (is_before || ((!is_nonzero) && (tm->tm_hour < 0))) hour = -hour; sprintf(cp, "%s%d hour%s", (is_nonzero ? " " : ""), hour, ((hour != 1) ? "s" : "")); cp += strlen(cp); - if (! is_nonzero) + if (!is_nonzero) is_before = (tm->tm_hour < 0); is_nonzero = TRUE; } if (tm->tm_min != 0) { - int min = tm->tm_min; + int min = tm->tm_min; + if (is_before || ((!is_nonzero) && (tm->tm_min < 0))) min = -min; sprintf(cp, "%s%d min%s", (is_nonzero ? " " : ""), min, ((min != 1) ? "s" : "")); cp += strlen(cp); - if (! is_nonzero) + if (!is_nonzero) is_before = (tm->tm_min < 0); is_nonzero = TRUE; } @@ -2352,7 +2382,8 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) /* fractional seconds? */ if (fsec != 0) { - double sec; + double sec; + fsec += tm->tm_sec; sec = fsec; if (is_before || ((!is_nonzero) && (fsec < 0))) @@ -2360,7 +2391,7 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) sprintf(cp, "%s%.2f secs", (is_nonzero ? " " : ""), sec); cp += strlen(cp); - if (! is_nonzero) + if (!is_nonzero) is_before = (fsec < 0); is_nonzero = TRUE; @@ -2368,14 +2399,15 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) } else if (tm->tm_sec != 0) { - int sec = tm->tm_sec; + int sec = tm->tm_sec; + if (is_before || ((!is_nonzero) && (tm->tm_sec < 0))) sec = -sec; sprintf(cp, "%s%d sec%s", (is_nonzero ? " " : ""), sec, ((sec != 1) ? "s" : "")); cp += strlen(cp); - if (! is_nonzero) + if (!is_nonzero) is_before = (tm->tm_sec < 0); is_nonzero = TRUE; } @@ -2383,7 +2415,7 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) } /* identically zero? then put in a unitless zero... */ - if (! is_nonzero) + if (!is_nonzero) { strcat(cp, "0"); cp += strlen(cp); diff --git a/src/backend/utils/adt/datum.c b/src/backend/utils/adt/datum.c index 9a1bffb81e4..d0766d15d70 100644 --- a/src/backend/utils/adt/datum.c +++ b/src/backend/utils/adt/datum.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/datum.c,v 1.19 2001/01/24 19:43:13 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/datum.c,v 1.20 2001/03/22 03:59:50 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -153,10 +153,11 @@ datumFree(Datum value, bool typByVal, int typLen) bool datumIsEqual(Datum value1, Datum value2, bool typByVal, int typLen) { - bool res; + bool res; if (typByVal) { + /* * just compare the two datums. NOTE: just comparing "len" bytes * will not do the work, because we do not know how these bytes diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c index b02117d3a78..7a83ee6577e 100644 --- a/src/backend/utils/adt/float.c +++ b/src/backend/utils/adt/float.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.69 2001/01/24 19:43:13 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.70 2001/03/22 03:59:50 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -56,7 +56,7 @@ #include <limits.h> /* for finite() on Solaris */ #ifdef HAVE_IEEEFP_H -# include <ieeefp.h> +#include <ieeefp.h> #endif #include "fmgr.h" @@ -69,6 +69,7 @@ #ifndef atof extern double atof(const char *p); + #endif #ifndef HAVE_CBRT @@ -78,8 +79,9 @@ static double cbrt(double x); #else #if !defined(nextstep) extern double cbrt(double x); + #endif -#endif /* HAVE_CBRT */ +#endif /* HAVE_CBRT */ #ifndef HAVE_RINT #define rint my_rint @@ -87,9 +89,10 @@ static double rint(double x); #else extern double rint(double x); -#endif /* HAVE_RINT */ -#endif /* NeXT check */ +#endif /* HAVE_RINT */ + +#endif /* NeXT check */ static void CheckFloat4Val(double val); @@ -1345,7 +1348,7 @@ setseed(PG_FUNCTION_ARGS) * float8_accum - accumulate for AVG(), STDDEV(), etc * float4_accum - same, but input data is float4 * float8_avg - produce final result for float AVG() - * float8_variance - produce final result for float VARIANCE() + * float8_variance - produce final result for float VARIANCE() * float8_stddev - produce final result for float STDDEV() * * The transition datatype for all these aggregates is a 3-element array @@ -1360,10 +1363,11 @@ setseed(PG_FUNCTION_ARGS) static float8 * check_float8_array(ArrayType *transarray, const char *caller) { + /* - * We expect the input to be a 3-element float array; verify that. - * We don't need to use deconstruct_array() since the array data - * is just going to look like a C array of 3 float8 values. + * We expect the input to be a 3-element float array; verify that. We + * don't need to use deconstruct_array() since the array data is just + * going to look like a C array of 3 float8 values. */ if (ARR_SIZE(transarray) != (ARR_OVERHEAD(1) + 3 * sizeof(float8)) || ARR_NDIM(transarray) != 1 || @@ -1398,7 +1402,7 @@ float8_accum(PG_FUNCTION_ARGS) transdatums[2] = Float8GetDatumFast(sumX2); result = construct_array(transdatums, 3, - false /* float8 byval */, sizeof(float8), 'd'); + false /* float8 byval */ , sizeof(float8), 'd'); PG_RETURN_ARRAYTYPE_P(result); } @@ -1433,7 +1437,7 @@ float4_accum(PG_FUNCTION_ARGS) transdatums[2] = Float8GetDatumFast(sumX2); result = construct_array(transdatums, 3, - false /* float8 byval */, sizeof(float8), 'd'); + false /* float8 byval */ , sizeof(float8), 'd'); PG_RETURN_ARRAYTYPE_P(result); } diff --git a/src/backend/utils/adt/format_type.c b/src/backend/utils/adt/format_type.c index 4cdaaee765f..b4990245500 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 - * $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.9 2001/02/05 17:35:04 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.10 2001/03/22 03:59:50 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -31,10 +31,10 @@ static char *format_type_internal(Oid type_oid, int32 typemod); static char * -psnprintf(size_t len, const char * fmt, ...) +psnprintf(size_t len, const char *fmt,...) { - va_list ap; - char * buf; + va_list ap; + char *buf; buf = palloc(len); @@ -136,7 +136,9 @@ format_type_internal(Oid type_oid, int32 typemod) break; case CHAROID: - /* This char type is the single-byte version. You have to + + /* + * This char type is the single-byte version. You have to * double-quote it to get at it in the parser. */ buf = pstrdup("\"char\""); @@ -252,7 +254,7 @@ type_maximum_size(Oid type_oid, int32 typemod) /* precision (ie, max # of digits) is in upper bits of typmod */ if (typemod > VARHDRSZ) { - int precision = ((typemod - VARHDRSZ) >> 16) & 0xffff; + int precision = ((typemod - VARHDRSZ) >> 16) & 0xffff; /* Numeric stores 2 decimal digits/byte, plus header */ return (precision + 1) / 2 + NUMERIC_HDRSZ; @@ -262,7 +264,7 @@ type_maximum_size(Oid type_oid, int32 typemod) case VARBITOID: case ZPBITOID: /* typemod is the (max) number of bits */ - return (typemod + (BITS_PER_BYTE-1)) / BITS_PER_BYTE + return (typemod + (BITS_PER_BYTE - 1)) / BITS_PER_BYTE + 2 * sizeof(int32); } @@ -300,10 +302,10 @@ oidvectortypes(PG_FUNCTION_ARGS) result = palloc(total); result[0] = '\0'; left = total - 1; - + for (num = 0; num < numargs; num++) { - char * typename = format_type_internal(oidArray[num], -1); + char *typename = format_type_internal(oidArray[num], -1); if (left < strlen(typename) + 2) { diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index bef39d2da53..bebe8240144 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------- * formatting.c * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.33 2001/02/27 08:13:28 ishii Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.34 2001/03/22 03:59:50 momjian Exp $ * * * Portions Copyright (c) 1999-2000, PostgreSQL Global Development Group @@ -47,14 +47,14 @@ * TODO (7.2): * - replace some global values by struct that handle it * - check last used entry in the cache_search - * - better number building (formatting) + * - better number building (formatting) * - add support for abstime * - add support for roman number to standard number conversion * - add support for number spelling * - add support for string to string formatting (we must be better - * than Oracle :-), - * to_char('Hello', 'X X X X X') -> 'H e l l o' - * + * than Oracle :-), + * to_char('Hello', 'X X X X X') -> 'H e l l o' + * * ----------------------------------------------------------------------- */ @@ -116,8 +116,8 @@ * External (defined in PgSQL dt.c (timestamp utils)) * ---------- */ -extern char *months[], /* month abbreviation */ - *days[]; /* full days */ +extern char *months[], /* month abbreviation */ + *days[]; /* full days */ /* ---------- * Format parser structs @@ -125,28 +125,28 @@ extern char *months[], /* month abbreviation */ */ typedef struct { - char *name; /* suffix string */ - int len, /* suffix length */ - id, /* used in node->suffix */ - type; /* prefix / postfix */ + char *name; /* suffix string */ + int len, /* suffix length */ + id, /* used in node->suffix */ + type; /* prefix / postfix */ } KeySuffix; typedef struct { - char *name; /* keyword */ - /* action for keyword */ - int len, /* keyword length */ - (*action) (), - id; /* keyword id */ - bool isitdigit; /* is expected output/input digit */ + char *name; /* keyword */ + /* action for keyword */ + int len, /* keyword length */ + (*action) (), + id; /* keyword id */ + bool isitdigit; /* is expected output/input digit */ } KeyWord; typedef struct { - int type; /* node type */ - KeyWord *key; /* if node type is KEYWORD */ - int character, /* if node type is CHAR */ - suffix; /* keyword suffix */ + int type; /* node type */ + KeyWord *key; /* if node type is KEYWORD */ + int character, /* if node type is CHAR */ + suffix; /* keyword suffix */ } FormatNode; #define NODE_TYPE_END 1 @@ -249,7 +249,7 @@ static char *numth[] = {"st", "nd", "rd", "th", NULL}; * Flags for DCH version * ---------- */ -static int DCH_global_flag = 0; +static int DCH_global_flag = 0; #define DCH_F_FX 0x01 @@ -262,15 +262,15 @@ static int DCH_global_flag = 0; */ typedef struct { - int pre, /* (count) numbers before decimal */ - post, /* (count) numbers after decimal */ - lsign, /* want locales sign */ - flag, /* number parametrs */ - pre_lsign_num, /* tmp value for lsign */ - multi, /* multiplier for 'V' */ - zero_start, /* position of first zero */ - zero_end, /* position of last zero */ - need_locale; /* needs it locale */ + int pre, /* (count) numbers before decimal */ + post, /* (count) numbers after decimal */ + lsign, /* want locales sign */ + flag, /* number parametrs */ + pre_lsign_num, /* tmp value for lsign */ + multi, /* multiplier for 'V' */ + zero_start, /* position of first zero */ + zero_end, /* position of last zero */ + need_locale; /* needs it locale */ } NUMDesc; /* ---------- @@ -280,14 +280,14 @@ typedef struct #define NUM_F_DECIMAL 0x01 #define NUM_F_LDECIMAL 0x02 #define NUM_F_ZERO 0x04 -#define NUM_F_BLANK 0x08 +#define NUM_F_BLANK 0x08 #define NUM_F_FILLMODE 0x10 -#define NUM_F_LSIGN 0x20 +#define NUM_F_LSIGN 0x20 #define NUM_F_BRACKET 0x40 -#define NUM_F_MINUS 0x80 +#define NUM_F_MINUS 0x80 #define NUM_F_PLUS 0x100 -#define NUM_F_ROMAN 0x200 -#define NUM_F_MULTI 0x400 +#define NUM_F_ROMAN 0x200 +#define NUM_F_MULTI 0x400 #define NUM_LSIGN_PRE -1 #define NUM_LSIGN_POST 1 @@ -299,20 +299,20 @@ typedef struct */ #define IS_DECIMAL(_f) ((_f)->flag & NUM_F_DECIMAL) #define IS_LDECIMAL(_f) ((_f)->flag & NUM_F_LDECIMAL) -#define IS_ZERO(_f) ((_f)->flag & NUM_F_ZERO) +#define IS_ZERO(_f) ((_f)->flag & NUM_F_ZERO) #define IS_BLANK(_f) ((_f)->flag & NUM_F_BLANK) #define IS_FILLMODE(_f) ((_f)->flag & NUM_F_FILLMODE) #define IS_BRACKET(_f) ((_f)->flag & NUM_F_BRACKET) #define IS_MINUS(_f) ((_f)->flag & NUM_F_MINUS) #define IS_LSIGN(_f) ((_f)->flag & NUM_F_LSIGN) -#define IS_PLUS(_f) ((_f)->flag & NUM_F_PLUS) +#define IS_PLUS(_f) ((_f)->flag & NUM_F_PLUS) #define IS_ROMAN(_f) ((_f)->flag & NUM_F_ROMAN) #define IS_MULTI(_f) ((_f)->flag & NUM_F_MULTI) /* ---------- * Format picture cache * (cache size: - * Number part = NUM_CACHE_SIZE * NUM_CACHE_FIELDS + * Number part = NUM_CACHE_SIZE * NUM_CACHE_FIELDS * Date-time part = DCH_CACHE_SIZE * DCH_CACHE_FIELDS * ) * ---------- @@ -326,25 +326,25 @@ typedef struct { FormatNode format[DCH_CACHE_SIZE + 1]; char str[DCH_CACHE_SIZE + 1]; - int age; + int age; } DCHCacheEntry; typedef struct { FormatNode format[NUM_CACHE_SIZE + 1]; char str[NUM_CACHE_SIZE + 1]; - int age; + int age; NUMDesc Num; } NUMCacheEntry; /* global cache for --- date/time part */ -static DCHCacheEntry DCHCache[DCH_CACHE_FIELDS + 1]; +static DCHCacheEntry DCHCache[DCH_CACHE_FIELDS + 1]; static int n_DCHCache = 0; /* number of entries */ static int DCHCounter = 0; /* global cache for --- number part */ -static NUMCacheEntry NUMCache[NUM_CACHE_FIELDS + 1]; +static NUMCacheEntry NUMCache[NUM_CACHE_FIELDS + 1]; static NUMCacheEntry *last_NUMCacheEntry; static int n_NUMCache = 0; /* number of entries */ @@ -356,18 +356,38 @@ static int NUMCounter = 0; * For char->date/time conversion * ---------- */ -typedef struct { - int hh, am, pm, mi, ss, ssss, d, dd, ddd, mm, yyyy, yyy, yy, y, - bc, iw, ww, w, cc, q, j; +typedef struct +{ + int hh, + am, + pm, + mi, + ss, + ssss, + d, + dd, + ddd, + mm, + yyyy, + yyy, + yy, + y, + bc, + iw, + ww, + w, + cc, + q, + j; } TmFromChar; -#define ZERO_tmfc( _X ) \ +#define ZERO_tmfc( _X ) \ do { \ (_X)->hh= (_X)->am= (_X)->pm= (_X)->mi= (_X)->ss= (_X)->ssss= \ (_X)->d= (_X)->dd= (_X)->ddd= (_X)->mm= (_X)->yyyy= (_X)->yyy= \ (_X)->yy= (_X)->y= (_X)->bc= (_X)->iw= (_X)->ww= (_X)->w= \ (_X)->cc= (_X)->q= (_X)->j= 0; \ - } while(0) + } while(0) #ifdef DEBUG_TO_FROM_CHAR @@ -396,8 +416,10 @@ typedef struct { * Private global-modul definitions * ---------- */ -static struct tm _tm, *tm = &_tm; -static TmFromChar _tmfc, *tmfc = &_tmfc; +static struct tm _tm, + *tm = &_tm; +static TmFromChar _tmfc, + *tmfc = &_tmfc; static char *tzn; /* ---------- @@ -620,7 +642,7 @@ static KeyWord DCH_keywords[] = { {"AM", 2, dch_time, DCH_AM, FALSE}, {"B.C.", 4, dch_date, DCH_B_C, FALSE}, /* B */ {"BC", 2, dch_date, DCH_BC, FALSE}, - {"CC", 2, dch_date, DCH_CC, TRUE}, /* C */ + {"CC", 2, dch_date, DCH_CC, TRUE}, /* C */ {"DAY", 3, dch_date, DCH_DAY, FALSE}, /* D */ {"DDD", 3, dch_date, DCH_DDD, TRUE}, {"DD", 2, dch_date, DCH_DD, TRUE}, @@ -632,8 +654,8 @@ static 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}, - {"IW", 2, dch_date, DCH_IW, TRUE}, /* I */ - {"J", 1, dch_date, DCH_J, TRUE}, /* J */ + {"IW", 2, dch_date, DCH_IW, TRUE}, /* I */ + {"J", 1, dch_date, DCH_J, TRUE}, /* J */ {"MI", 2, dch_time, DCH_MI, TRUE}, {"MM", 2, dch_date, DCH_MM, TRUE}, {"MONTH", 5, dch_date, DCH_MONTH, FALSE}, @@ -642,12 +664,12 @@ static KeyWord DCH_keywords[] = { {"Mon", 3, dch_date, DCH_Mon, FALSE}, {"P.M.", 4, dch_time, DCH_P_M, FALSE}, /* P */ {"PM", 2, dch_time, DCH_PM, FALSE}, - {"Q", 1, dch_date, DCH_Q, TRUE}, /* Q */ - {"RM", 2, dch_date, DCH_RM, FALSE}, /* R */ - {"SSSS", 4, dch_time, DCH_SSSS, TRUE}, /* S */ + {"Q", 1, dch_date, DCH_Q, TRUE}, /* Q */ + {"RM", 2, dch_date, DCH_RM, FALSE}, /* R */ + {"SSSS", 4, dch_time, DCH_SSSS, TRUE}, /* S */ {"SS", 2, dch_time, DCH_SS, TRUE}, - {"TZ", 2, dch_time, DCH_TZ, FALSE}, /* T */ - {"WW", 2, dch_date, DCH_WW, TRUE}, /* W */ + {"TZ", 2, dch_time, DCH_TZ, FALSE}, /* T */ + {"WW", 2, dch_date, DCH_WW, TRUE}, /* W */ {"W", 1, dch_date, DCH_W, TRUE}, {"Y,YYY", 5, dch_date, DCH_Y_YYY, TRUE}, /* Y */ {"YYYY", 4, dch_date, DCH_YYYY, TRUE}, @@ -660,7 +682,7 @@ static KeyWord DCH_keywords[] = { {"am", 2, dch_time, DCH_am, FALSE}, {"b.c.", 4, dch_date, DCH_b_c, FALSE}, /* b */ {"bc", 2, dch_date, DCH_bc, FALSE}, - {"cc", 2, dch_date, DCH_CC, TRUE}, /* c */ + {"cc", 2, dch_date, DCH_CC, TRUE}, /* c */ {"day", 3, dch_date, DCH_day, FALSE}, /* d */ {"ddd", 3, dch_date, DCH_DDD, TRUE}, {"dd", 2, dch_date, DCH_DD, TRUE}, @@ -670,20 +692,20 @@ static 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}, - {"iw", 2, dch_date, DCH_IW, TRUE}, /* i */ - {"j", 1, dch_time, DCH_J, TRUE}, /* j */ - {"mi", 2, dch_time, DCH_MI, TRUE}, /* m */ + {"iw", 2, dch_date, DCH_IW, TRUE}, /* i */ + {"j", 1, dch_time, DCH_J, TRUE}, /* j */ + {"mi", 2, dch_time, DCH_MI, TRUE}, /* m */ {"mm", 2, dch_date, DCH_MM, TRUE}, {"month", 5, dch_date, DCH_month, FALSE}, {"mon", 3, dch_date, DCH_mon, FALSE}, {"p.m.", 4, dch_time, DCH_p_m, FALSE}, /* p */ {"pm", 2, dch_time, DCH_pm, FALSE}, - {"q", 1, dch_date, DCH_Q, TRUE}, /* q */ - {"rm", 2, dch_date, DCH_rm, FALSE}, /* r */ - {"ssss", 4, dch_time, DCH_SSSS, TRUE}, /* s */ + {"q", 1, dch_date, DCH_Q, TRUE}, /* q */ + {"rm", 2, dch_date, DCH_rm, FALSE}, /* r */ + {"ssss", 4, dch_time, DCH_SSSS, TRUE}, /* s */ {"ss", 2, dch_time, DCH_SS, TRUE}, - {"tz", 2, dch_time, DCH_tz, FALSE}, /* t */ - {"ww", 2, dch_date, DCH_WW, TRUE}, /* w */ + {"tz", 2, dch_time, DCH_tz, FALSE}, /* t */ + {"ww", 2, dch_date, DCH_WW, TRUE}, /* w */ {"w", 1, dch_date, DCH_W, TRUE}, {"y,yyy", 5, dch_date, DCH_Y_YYY, TRUE}, /* y */ {"yyyy", 4, dch_date, DCH_YYYY, TRUE}, @@ -794,32 +816,33 @@ static int NUM_index[KeyWord_INDEX_SIZE] = { */ typedef struct NUMProc { - int type; /* FROM_CHAR (TO_NUMBER) or TO_CHAR */ - - NUMDesc *Num; /* number description */ - - int sign, /* '-' or '+' */ - sign_wrote, /* was sign write */ - sign_pos, /* pre number sign position */ - num_count, /* number of write digits */ - num_in, /* is inside number */ - num_curr, /* current position in number */ - num_pre, /* space before first number */ - - read_dec, /* to_number - was read dec. point */ - read_post; /* to_number - number of dec. digit */ - - char *number, /* string with number */ - *number_p, /* pointer to current number pozition */ - *inout, /* in / out buffer */ - *inout_p, /* pointer to current inout pozition */ - *last_relevant, /* last relevant number after decimal point */ - - *L_negative_sign,/* Locale */ - *L_positive_sign, - *decimal, - *L_thousands_sep, - *L_currency_symbol; + int type; /* FROM_CHAR (TO_NUMBER) or TO_CHAR */ + + NUMDesc *Num; /* number description */ + + int sign, /* '-' or '+' */ + sign_wrote, /* was sign write */ + sign_pos, /* pre number sign position */ + num_count, /* number of write digits */ + num_in, /* is inside number */ + num_curr, /* current position in number */ + num_pre, /* space before first number */ + + read_dec, /* to_number - was read dec. point */ + read_post; /* to_number - number of dec. digit */ + + char *number, /* string with number */ + *number_p, /* pointer to current number pozition */ + *inout, /* in / out buffer */ + *inout_p, /* pointer to current inout pozition */ + *last_relevant, /* last relevant number after decimal + * point */ + + *L_negative_sign,/* Locale */ + *L_positive_sign, + *decimal, + *L_thousands_sep, + *L_currency_symbol; } NUMProc; @@ -1093,11 +1116,11 @@ static void parse_format(FormatNode *node, char *str, KeyWord *kw, KeySuffix *suf, int *index, int ver, NUMDesc *Num) { - KeySuffix *s; - FormatNode *n; - int node_set = 0, - suffix, - last = 0; + KeySuffix *s; + FormatNode *n; + int node_set = 0, + suffix, + last = 0; #ifdef DEBUG_TO_FROM_CHAR elog(DEBUG_elog_output, "to_char/number(): run parser."); @@ -1245,7 +1268,7 @@ DCH_processor(FormatNode *node, char *inout, int flag) { if (n->type == NODE_TYPE_ACTION) { - int len; + int len; /* ---------- * Call node action function @@ -1274,7 +1297,7 @@ DCH_processor(FormatNode *node, char *inout, int flag) * Skip blank space in FROM_CHAR's input * ---------- */ - if (isspace((unsigned char) n->character) && IS_FX == 0) + if (isspace((unsigned char) n->character) && IS_FX == 0) { while (*s != '\0' && isspace((unsigned char) *(s + 1))) ++s; @@ -1341,18 +1364,19 @@ dump_node(FormatNode *node, int max) static char * get_th(char *num, int type) { - int len = strlen(num), - last, seclast; + int len = strlen(num), + last, + seclast; last = *(num + (len - 1)); if (!isdigit((unsigned char) last)) elog(ERROR, "get_th: '%s' is not number.", num); /* - * All "teens" (<x>1[0-9]) get 'TH/th', - * while <x>[02-9][123] still get 'ST/st', 'ND/nd', 'RD/rd', respectively + * All "teens" (<x>1[0-9]) get 'TH/th', while <x>[02-9][123] still get + * 'ST/st', 'ND/nd', 'RD/rd', respectively */ - if ((len > 1) && ((seclast = num[len-2]) == '1')) + if ((len > 1) && ((seclast = num[len - 2]) == '1')) last = 0; switch (last) @@ -1442,11 +1466,11 @@ str_tolower(char *buff) static int seq_search(char *name, char **array, int type, int max, int *len) { - char *p, - *n, - **a; - int last, - i; + char *p, + *n, + **a; + int last, + i; *len = 0; @@ -1522,9 +1546,9 @@ seq_search(char *name, char **array, int type, int max, int *len) static void dump_index(KeyWord *k, int *index) { - int i, - count = 0, - free_i = 0; + int i, + count = 0, + free_i = 0; elog(DEBUG_elog_output, "TO-FROM_CHAR: Dump KeyWord Index:"); @@ -1563,9 +1587,9 @@ dch_global(int arg, char *inout, int suf, int flag, FormatNode *node) { switch (arg) { - case DCH_FX: - DCH_global_flag |= DCH_F_FX; - break; + case DCH_FX: + DCH_global_flag |= DCH_F_FX; + break; } return -1; } @@ -1579,29 +1603,29 @@ is_next_separator(FormatNode *n) { if (n->type == NODE_TYPE_END) return FALSE; - + if (n->type == NODE_TYPE_ACTION && S_THth(n->suffix)) return TRUE; - - /* - * Next node + + /* + * Next node */ - n++; - + n++; + if (n->type == NODE_TYPE_END) return FALSE; - + if (n->type == NODE_TYPE_ACTION) { if (n->key->isitdigit) return FALSE; - - return TRUE; - } + + return TRUE; + } else if (isdigit((unsigned char) n->character)) return FALSE; - - return TRUE; /* some non-digit input (separator) */ + + return TRUE; /* some non-digit input (separator) */ } #define AMPM_ERROR elog(ERROR, "to_timestamp(): bad AM/PM string") @@ -1619,12 +1643,12 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node) switch (arg) { - case DCH_A_M: + case DCH_A_M: case DCH_P_M: if (flag == TO_CHAR) { - strcpy(inout, ((tm->tm_hour > 11 - && tm->tm_hour < 24) ? P_M_STR : A_M_STR)); + strcpy(inout, ((tm->tm_hour > 11 + && tm->tm_hour < 24) ? P_M_STR : A_M_STR)); return 3; } else if (flag == FROM_CHAR) @@ -1632,9 +1656,9 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node) if (strncmp(inout, P_M_STR, 4) == 0) tmfc->pm = TRUE; else if (strncmp(inout, A_M_STR, 4) == 0) - tmfc->am = TRUE; + tmfc->am = TRUE; else - AMPM_ERROR; + AMPM_ERROR; return 3; } break; @@ -1642,8 +1666,8 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node) case DCH_PM: if (flag == TO_CHAR) { - strcpy(inout, ((tm->tm_hour > 11 - && tm->tm_hour < 24) ? PM_STR : AM_STR)); + strcpy(inout, ((tm->tm_hour > 11 + && tm->tm_hour < 24) ? PM_STR : AM_STR)); return 1; } else if (flag == FROM_CHAR) @@ -1653,7 +1677,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node) else if (strncmp(inout, AM_STR, 2) == 0) tmfc->am = TRUE; else - AMPM_ERROR; + AMPM_ERROR; return 1; } break; @@ -1661,8 +1685,8 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node) case DCH_p_m: if (flag == TO_CHAR) { - strcpy(inout, ((tm->tm_hour > 11 - && tm->tm_hour < 24) ? p_m_STR : a_m_STR)); + strcpy(inout, ((tm->tm_hour > 11 + && tm->tm_hour < 24) ? p_m_STR : a_m_STR)); return 3; } else if (flag == FROM_CHAR) @@ -1672,7 +1696,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node) else if (strncmp(inout, a_m_STR, 4) == 0) tmfc->am = TRUE; else - AMPM_ERROR; + AMPM_ERROR; return 3; } break; @@ -1681,7 +1705,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node) if (flag == TO_CHAR) { strcpy(inout, ((tm->tm_hour > 11 - && tm->tm_hour < 24) ? pm_STR : am_STR)); + && tm->tm_hour < 24) ? pm_STR : am_STR)); return 1; } else if (flag == FROM_CHAR) @@ -1691,7 +1715,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node) else if (strncmp(inout, am_STR, 2) == 0) tmfc->am = TRUE; else - AMPM_ERROR; + AMPM_ERROR; return 1; } break; @@ -1812,12 +1836,12 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node) str_numth(p_inout, inout, S_TH_TYPE(suf)); return strlen(p_inout) - 1; } - else if (flag == FROM_CHAR) + else if (flag == FROM_CHAR) { if (is_next_separator(node)) sscanf(inout, "%d", &tmfc->ssss); else - sscanf(inout, "%05d", &tmfc->ssss); + sscanf(inout, "%05d", &tmfc->ssss); return int4len((int4) tmfc->ssss) - 1 + SKIP_THth(suf); } break; @@ -1825,24 +1849,22 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node) case DCH_TZ: if (flag == TO_CHAR && tzn) { - int siz = strlen(tzn); - + int siz = strlen(tzn); + if (arg == DCH_TZ) strcpy(inout, tzn); - else + else { - char *p = palloc(siz); - + char *p = palloc(siz); + strcpy(p, tzn); strcpy(inout, str_tolower(p)); pfree(p); } return siz - 1; - } - else if (flag == FROM_CHAR) - { + } + else if (flag == FROM_CHAR) elog(ERROR, "to_timestamp(): TZ/tz not supported."); - } } return -1; } @@ -1864,10 +1886,10 @@ do { \ static int dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) { - char buff[DCH_CACHE_SIZE], - *p_inout; - int i, - len; + char buff[DCH_CACHE_SIZE], + *p_inout; + int i, + len; p_inout = inout; @@ -1881,7 +1903,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) { if (arg == DCH_MONTH || arg == DCH_Month || arg == DCH_month) { - tmfc->mm = seq_search(inout, months_full, ONE_UPPER, FULL_SIZ, &len) +1; + tmfc->mm = seq_search(inout, months_full, ONE_UPPER, FULL_SIZ, &len) + 1; CHECK_SEQ_SEARCH(len, "MONTH/Month/month"); if (S_FM(suf)) return len - 1; @@ -1891,7 +1913,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) } else if (arg == DCH_MON || arg == DCH_Mon || arg == DCH_mon) { - tmfc->mm = seq_search(inout, months, ONE_UPPER, MAX_MON_LEN, &len) +1; + tmfc->mm = seq_search(inout, months, ONE_UPPER, MAX_MON_LEN, &len) + 1; CHECK_SEQ_SEARCH(len, "MON/Mon/mon"); return 2; } @@ -1983,14 +2005,14 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) return strlen(p_inout) - 1; else return 8; - + case DCH_Month: sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, months_full[tm->tm_mon - 1]); if (S_FM(suf)) return strlen(p_inout) - 1; else return 8; - + case DCH_month: sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, months_full[tm->tm_mon - 1]); *inout = tolower((unsigned char) *inout); @@ -1998,12 +2020,12 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) return strlen(p_inout) - 1; else return 8; - + case DCH_MON: strcpy(inout, months[tm->tm_mon - 1]); inout = str_toupper(inout); return 2; - + case DCH_Mon: strcpy(inout, months[tm->tm_mon - 1]); return 2; @@ -2149,7 +2171,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) if (flag == TO_CHAR) { sprintf(inout, "%0*d", S_FM(suf) ? 0 : 2, - (tm->tm_yday-1) / 7 + 1); + (tm->tm_yday - 1) / 7 + 1); if (S_THth(suf)) str_numth(p_inout, inout, S_TH_TYPE(suf)); if (S_FM(suf) || S_THth(suf)) @@ -2158,7 +2180,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) return 1; } - else if (flag == FROM_CHAR) + else if (flag == FROM_CHAR) { if (S_FM(suf)) { @@ -2176,7 +2198,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) if (flag == TO_CHAR) { sprintf(inout, "%0*d", S_FM(suf) ? 0 : 2, - date2isoweek(tm->tm_year, tm->tm_mon, tm->tm_mday)); + date2isoweek(tm->tm_year, tm->tm_mon, tm->tm_mday)); if (S_THth(suf)) str_numth(p_inout, inout, S_TH_TYPE(suf)); if (S_FM(suf) || S_THth(suf)) @@ -2185,7 +2207,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) return 1; } - else if (flag == FROM_CHAR) + else if (flag == FROM_CHAR) { if (S_FM(suf)) { @@ -2198,7 +2220,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) return 1 + SKIP_THth(suf); } } - break; + break; case DCH_Q: if (flag == TO_CHAR) { @@ -2233,7 +2255,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) else if (flag == FROM_CHAR) { sscanf(inout, "%d", &tmfc->cc); - return int4len((int4) tmfc->cc) + SKIP_THth(suf) -1; + return int4len((int4) tmfc->cc) + SKIP_THth(suf) - 1; } break; case DCH_Y_YYY: @@ -2277,7 +2299,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) sscanf(inout, "%d", &tmfc->yyyy); else sscanf(inout, "%04d", &tmfc->yyyy); - + if (!S_FM(suf) && tmfc->yyyy <= 9999 && tmfc->yyyy >= -9999) len = 4; else @@ -2391,7 +2413,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) case DCH_W: if (flag == TO_CHAR) { - sprintf(inout, "%d", (tm->tm_mday-1) / 7 + 1); + sprintf(inout, "%d", (tm->tm_mday - 1) / 7 + 1); if (S_THth(suf)) { str_numth(p_inout, inout, S_TH_TYPE(suf)); @@ -2416,7 +2438,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) else if (flag == FROM_CHAR) { sscanf(inout, "%d", &tmfc->j); - return int4len((int4) tmfc->j) + SKIP_THth(suf) -1; + return int4len((int4) tmfc->j) + SKIP_THth(suf) - 1; } break; } @@ -2522,24 +2544,24 @@ Datum timestamp_to_char(PG_FUNCTION_ARGS) { Timestamp dt = PG_GETARG_TIMESTAMP(0); - text *fmt = PG_GETARG_TEXT_P(1); - text *result, - *result_tmp; - - FormatNode *format; - char *str; + text *fmt = PG_GETARG_TEXT_P(1); + text *result, + *result_tmp; + + FormatNode *format; + char *str; double fsec; - int len = 0, - tz, - flag = 0, - x = 0; + int len = 0, + tz, + flag = 0, + x = 0; len = VARSIZE(fmt) - VARHDRSZ; if (len <= 0 || TIMESTAMP_NOT_FINITE(dt)) PG_RETURN_NULL(); - ZERO_tm(tm); + ZERO_tm(tm); tzn = NULL; if (TIMESTAMP_IS_EPOCH(dt)) @@ -2613,7 +2635,7 @@ timestamp_to_char(PG_FUNCTION_ARGS) * ---------- */ parse_format(ent->format, str, DCH_keywords, - DCH_suff, DCH_index, DCH_TYPE, NULL); + DCH_suff, DCH_index, DCH_TYPE, NULL); (ent->format + len)->type = NODE_TYPE_END; /* Paranoa? */ @@ -2642,7 +2664,7 @@ timestamp_to_char(PG_FUNCTION_ARGS) pfree(result); PG_RETURN_NULL(); } - + result_tmp = result; result = (text *) palloc(len + 1 + VARHDRSZ); @@ -2664,13 +2686,13 @@ timestamp_to_char(PG_FUNCTION_ARGS) Datum to_timestamp(PG_FUNCTION_ARGS) { - text *date_txt = PG_GETARG_TEXT_P(0); - text *fmt = PG_GETARG_TEXT_P(1); - FormatNode *format; - int flag = 0; + text *date_txt = PG_GETARG_TEXT_P(0); + text *fmt = PG_GETARG_TEXT_P(1); + FormatNode *format; + int flag = 0; Timestamp result; - char *str; - char *date_str; + char *str; + char *date_str; int len, date_len, fsec = 0, @@ -2766,16 +2788,16 @@ to_timestamp(PG_FUNCTION_ARGS) } /* -------------------------------------------------------------- - * Convert values that user define for FROM_CHAR (to_date/to_timestamp) + * Convert values that user define for FROM_CHAR (to_date/to_timestamp) * to standard 'tm' * ---------- - */ + */ #ifdef DEBUG_TO_FROM_CHAR NOTICE_TMFC; -#endif - if (tmfc->ssss) +#endif + if (tmfc->ssss) { - int x = tmfc->ssss; + int x = tmfc->ssss; tm->tm_hour = x / 3600; x %= 3600; @@ -2785,128 +2807,148 @@ to_timestamp(PG_FUNCTION_ARGS) } if (tmfc->cc) - tm->tm_year = (tmfc->cc-1) * 100; + tm->tm_year = (tmfc->cc - 1) * 100; - if (tmfc->ww) + if (tmfc->ww) tmfc->ddd = (tmfc->ww - 1) * 7 + 1; - if (tmfc->w) + if (tmfc->w) tmfc->dd = (tmfc->w - 1) * 7 + 1; - if (tmfc->ss) tm->tm_sec = tmfc->ss; - if (tmfc->mi) tm->tm_min = tmfc->mi; - if (tmfc->hh) tm->tm_hour = tmfc->hh; - - if (tmfc->pm || tmfc->am) - { - if (tm->tm_hour < 1 || tm->tm_hour > 12) - elog(ERROR, "to_timestamp(): AM/PM hour must be between 1 and 12"); - + if (tmfc->ss) + tm->tm_sec = tmfc->ss; + if (tmfc->mi) + tm->tm_min = tmfc->mi; + if (tmfc->hh) + tm->tm_hour = tmfc->hh; + + if (tmfc->pm || tmfc->am) + { + if (tm->tm_hour < 1 || tm->tm_hour > 12) + elog(ERROR, "to_timestamp(): AM/PM hour must be between 1 and 12"); + if (tmfc->pm && tm->tm_hour < 12) tm->tm_hour += 12; - + else if (tmfc->am && tm->tm_hour == 12) - tm->tm_hour = 0; - } + tm->tm_hour = 0; + } - switch (tmfc->q) + switch (tmfc->q) { - case 1: tm->tm_mday = 1; tm->tm_mon = 1; break; - case 2: tm->tm_mday = 1; tm->tm_mon = 4; break; - case 3: tm->tm_mday = 1; tm->tm_mon = 7; break; - case 4: tm->tm_mday = 1; tm->tm_mon = 10; break; + case 1: + tm->tm_mday = 1; + tm->tm_mon = 1; + break; + case 2: + tm->tm_mday = 1; + tm->tm_mon = 4; + break; + case 3: + tm->tm_mday = 1; + tm->tm_mon = 7; + break; + case 4: + tm->tm_mday = 1; + tm->tm_mon = 10; + break; } - - if (tmfc->yyyy) + + if (tmfc->yyyy) tm->tm_year = tmfc->yyyy; else if (tmfc->y) { + /* - * 1-digit year: - * always +2000 + * 1-digit year: always +2000 */ - tm->tm_year = tmfc->y + 2000; - } + tm->tm_year = tmfc->y + 2000; + } else if (tmfc->yy) { + /* - * 2-digit year: - * '00' ... '69' = 2000 ... 2069 - * '70' ... '99' = 1970 ... 1999 - */ + * 2-digit year: '00' ... '69' = 2000 ... 2069 '70' ... '99' = + * 1970 ... 1999 + */ tm->tm_year = tmfc->yy; - + if (tm->tm_year < 70) tm->tm_year += 2000; - else + else tm->tm_year += 1900; } else if (tmfc->yyy) { + /* - * 3-digit year: - * '100' ... '999' = 1100 ... 1999 - * '000' ... '099' = 2000 ... 2099 + * 3-digit year: '100' ... '999' = 1100 ... 1999 '000' ... '099' = + * 2000 ... 2099 */ tm->tm_year = tmfc->yyy; - + if (tm->tm_year >= 100) tm->tm_year += 1000; - else + else tm->tm_year += 2000; } - + if (tmfc->bc) { if (tm->tm_year > 0) tm->tm_year = -(tm->tm_year - 1); else elog(ERROR, "Inconsistant use of year %04d and 'BC'", tm->tm_year); - } - + } + if (tmfc->j) j2date(tmfc->j, &tm->tm_year, &tm->tm_mon, &tm->tm_mday); - + if (tmfc->iw) isoweek2date(tmfc->iw, &tm->tm_year, &tm->tm_mon, &tm->tm_mday); - - if (tmfc->d) tm->tm_wday = tmfc->d; - if (tmfc->dd) tm->tm_mday = tmfc->dd; - if (tmfc->ddd) tm->tm_yday = tmfc->ddd; - if (tmfc->mm) tm->tm_mon = tmfc->mm; + + if (tmfc->d) + tm->tm_wday = tmfc->d; + if (tmfc->dd) + tm->tm_mday = tmfc->dd; + if (tmfc->ddd) + tm->tm_yday = tmfc->ddd; + if (tmfc->mm) + tm->tm_mon = tmfc->mm; /* * we not ignore DDD */ - if (tmfc->ddd && (tm->tm_mon <=1 || tm->tm_mday <=1)) + if (tmfc->ddd && (tm->tm_mon <= 1 || tm->tm_mday <= 1)) { /* count mday and mon from yday */ - int *y, i; - - int ysum[2][13] = { - { 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365, 0 }, - { 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366, 0 }}; - - if (!tm->tm_year) - elog(ERROR, "to_timestamp() cat't convert yday without year information"); - - y = ysum[ isleap(tm->tm_year) ]; - - for (i=0; i <= 11; i++) - { - if (tm->tm_yday < y[i]) + int *y, + i; + + int ysum[2][13] = { + {31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365, 0}, + {31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366, 0}}; + + if (!tm->tm_year) + elog(ERROR, "to_timestamp() cat't convert yday without year information"); + + y = ysum[isleap(tm->tm_year)]; + + for (i = 0; i <= 11; i++) + { + if (tm->tm_yday < y[i]) break; - } - if (tm->tm_mon <=1) - tm->tm_mon = i+1; - - if (tm->tm_mday <=1) - tm->tm_mday = i == 0 ? tm->tm_yday : - tm->tm_yday - y[i-1]; + } + if (tm->tm_mon <= 1) + tm->tm_mon = i + 1; + + if (tm->tm_mday <= 1) + tm->tm_mday = i == 0 ? tm->tm_yday : + tm->tm_yday - y[i - 1]; } - + /* -------------------------------------------------------------- */ #ifdef DEBUG_TO_FROM_CHAR @@ -2920,21 +2962,21 @@ to_timestamp(PG_FUNCTION_ARGS) tm->tm_year -= 1900; tm->tm_mon -= 1; -# ifdef DEBUG_TO_FROM_CHAR +#ifdef DEBUG_TO_FROM_CHAR elog(DEBUG_elog_output, "TO-FROM_CHAR: Call mktime()"); NOTICE_TM; -# endif +#endif mktime(tm); tm->tm_year += 1900; tm->tm_mon += 1; -# if defined(HAVE_TM_ZONE) +#if defined(HAVE_TM_ZONE) tz = -(tm->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */ -# elif defined(HAVE_INT_TIMEZONE) +#elif defined(HAVE_INT_TIMEZONE) tz = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL); -# endif +#endif -#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ +#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ tz = CTimeZone; #endif } @@ -2960,8 +3002,10 @@ to_timestamp(PG_FUNCTION_ARGS) Datum to_date(PG_FUNCTION_ARGS) { - /* Quick hack: since our inputs are just like to_timestamp, - * hand over the whole input info struct... + + /* + * Quick hack: since our inputs are just like to_timestamp, hand over + * the whole input info struct... */ return DirectFunctionCall1(timestamp_date, to_timestamp(fcinfo)); } @@ -2985,7 +3029,7 @@ do { \ (_n)->lsign = 0; \ (_n)->pre = 0; \ (_n)->post = 0; \ - (_n)->pre_lsign_num = 0; \ + (_n)->pre_lsign_num = 0; \ (_n)->need_locale = 0; \ (_n)->multi = 0; \ (_n)->zero_start = 0; \ @@ -3021,10 +3065,11 @@ NUM_cache_getnew(char *str) for (ent = NUMCache; ent <= (NUMCache + NUM_CACHE_FIELDS); ent++) { - /* entry removed via NUM_cache_remove() - * can be used here + + /* + * entry removed via NUM_cache_remove() can be used here */ - if (*ent->str == '\0') + if (*ent->str == '\0') { old = ent; break; @@ -3063,7 +3108,7 @@ NUM_cache_getnew(char *str) static NUMCacheEntry * NUM_cache_search(char *str) { - int i = 0; + int i = 0; NUMCacheEntry *ent; /* counter overload check - paranoa? */ @@ -3196,12 +3241,12 @@ NUM_cache(int len, NUMDesc *Num, char *pars_str, int *flag) static char * int_to_roman(int number) { - int len = 0, - num = 0, - set = 0; - char *p = NULL, - *result, - numstr[5]; + int len = 0, + num = 0, + set = 0; + char *p = NULL, + *result, + numstr[5]; result = (char *) palloc(16); *result = '\0'; @@ -3336,7 +3381,7 @@ static char * get_last_relevant_decnum(char *num) { char *result, - *p = strchr(num, '.'); + *p = strchr(num, '.'); #ifdef DEBUG_TO_FROM_CHAR elog(DEBUG_elog_output, "CALL: get_last_relevant_decnum()"); @@ -3483,7 +3528,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen) } else { - int x = strlen(Np->decimal); + int x = strlen(Np->decimal); #ifdef DEBUG_TO_FROM_CHAR elog(DEBUG_elog_output, "Try read locale point (%c).", *Np->inout_p); @@ -3716,8 +3761,8 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number, int plen, int sign, int type) { FormatNode *n; - NUMProc _Np, - *Np = &_Np; + NUMProc _Np, + *Np = &_Np; Np->Num = Num; Np->type = type; @@ -3802,9 +3847,9 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number, { if (IS_DECIMAL(Np->Num)) Np->last_relevant = get_last_relevant_decnum( - Np->number + - ((Np->Num->zero_end - Np->num_pre > 0) ? - Np->Num->zero_end - Np->num_pre : 0)); + Np->number + + ((Np->Num->zero_end - Np->num_pre > 0) ? + Np->Num->zero_end - Np->num_pre : 0)); } if (!Np->sign_wrote && Np->num_pre == 0) @@ -4168,7 +4213,7 @@ do { \ if (flag) \ pfree(format); \ \ - /* ---------- \ + /* ---------- \ * for result is allocated max memory, which current format-picture\ * needs, now it must be re-allocate to result real size \ * ---------- \ @@ -4194,16 +4239,16 @@ do { \ Datum numeric_to_number(PG_FUNCTION_ARGS) { - text *value = PG_GETARG_TEXT_P(0); - text *fmt = PG_GETARG_TEXT_P(1); - NUMDesc Num; - Datum result; + text *value = PG_GETARG_TEXT_P(0); + text *fmt = PG_GETARG_TEXT_P(1); + NUMDesc Num; + Datum result; FormatNode *format; - char *numstr; - int flag = 0; - int len = 0; - int scale, - precision; + char *numstr; + int flag = 0; + int len = 0; + int scale, + precision; len = VARSIZE(fmt) - VARHDRSZ; @@ -4224,9 +4269,9 @@ numeric_to_number(PG_FUNCTION_ARGS) pfree(format); result = DirectFunctionCall3(numeric_in, - CStringGetDatum(numstr), - ObjectIdGetDatum(InvalidOid), - Int32GetDatum(((precision << 16) | scale) + VARHDRSZ)); + CStringGetDatum(numstr), + ObjectIdGetDatum(InvalidOid), + Int32GetDatum(((precision << 16) | scale) + VARHDRSZ)); pfree(numstr); return result; } @@ -4238,20 +4283,20 @@ numeric_to_number(PG_FUNCTION_ARGS) Datum numeric_to_char(PG_FUNCTION_ARGS) { - Numeric value = PG_GETARG_NUMERIC(0); - text *fmt = PG_GETARG_TEXT_P(1); - NUMDesc Num; + Numeric value = PG_GETARG_NUMERIC(0); + text *fmt = PG_GETARG_TEXT_P(1); + NUMDesc Num; FormatNode *format; - text *result, - *result_tmp; - int flag = 0; - int len = 0, - plen = 0, - sign = 0; - char *numstr, - *orgnum, - *p; - Numeric x; + text *result, + *result_tmp; + int flag = 0; + int len = 0, + plen = 0, + sign = 0; + char *numstr, + *orgnum, + *p; + Numeric x; NUM_TOCHAR_prepare; @@ -4262,11 +4307,11 @@ numeric_to_char(PG_FUNCTION_ARGS) if (IS_ROMAN(&Num)) { x = DatumGetNumeric(DirectFunctionCall2(numeric_round, - NumericGetDatum(value), - Int32GetDatum(0))); + NumericGetDatum(value), + Int32GetDatum(0))); numstr = orgnum = int_to_roman(DatumGetInt32(DirectFunctionCall1(numeric_int4, - NumericGetDatum(x)))); + NumericGetDatum(x)))); pfree(x); } else @@ -4276,16 +4321,16 @@ numeric_to_char(PG_FUNCTION_ARGS) if (IS_MULTI(&Num)) { Numeric a = DatumGetNumeric(DirectFunctionCall1(int4_numeric, - Int32GetDatum(10))); + Int32GetDatum(10))); Numeric b = DatumGetNumeric(DirectFunctionCall1(int4_numeric, - Int32GetDatum(Num.multi))); + Int32GetDatum(Num.multi))); x = DatumGetNumeric(DirectFunctionCall2(numeric_power, NumericGetDatum(a), NumericGetDatum(b))); val = DatumGetNumeric(DirectFunctionCall2(numeric_mul, - NumericGetDatum(value), - NumericGetDatum(x))); + NumericGetDatum(value), + NumericGetDatum(x))); pfree(x); pfree(a); pfree(b); @@ -4293,10 +4338,10 @@ numeric_to_char(PG_FUNCTION_ARGS) } x = DatumGetNumeric(DirectFunctionCall2(numeric_round, - NumericGetDatum(val), - Int32GetDatum(Num.post))); + NumericGetDatum(val), + Int32GetDatum(Num.post))); orgnum = DatumGetCString(DirectFunctionCall1(numeric_out, - NumericGetDatum(x))); + NumericGetDatum(x))); pfree(x); if (*orgnum == '-') @@ -4339,18 +4384,18 @@ numeric_to_char(PG_FUNCTION_ARGS) Datum int4_to_char(PG_FUNCTION_ARGS) { - int32 value = PG_GETARG_INT32(0); - text *fmt = PG_GETARG_TEXT_P(1); - NUMDesc Num; + int32 value = PG_GETARG_INT32(0); + text *fmt = PG_GETARG_TEXT_P(1); + NUMDesc Num; FormatNode *format; - text *result, - *result_tmp; - int flag = 0; - int len = 0, - plen = 0, - sign = 0; - char *numstr, - *orgnum; + text *result, + *result_tmp; + int flag = 0; + int len = 0, + plen = 0, + sign = 0; + char *numstr, + *orgnum; NUM_TOCHAR_prepare; @@ -4359,21 +4404,19 @@ int4_to_char(PG_FUNCTION_ARGS) * ---------- */ if (IS_ROMAN(&Num)) - { numstr = orgnum = int_to_roman(value); - } else { if (IS_MULTI(&Num)) { orgnum = DatumGetCString(DirectFunctionCall1(int4out, - Int32GetDatum(value * ((int32) pow((double) 10, (double) Num.multi))))); + Int32GetDatum(value * ((int32) pow((double) 10, (double) Num.multi))))); Num.pre += Num.multi; } else { orgnum = DatumGetCString(DirectFunctionCall1(int4out, - Int32GetDatum(value))); + Int32GetDatum(value))); } len = strlen(orgnum); @@ -4387,7 +4430,7 @@ int4_to_char(PG_FUNCTION_ARGS) if (Num.post) { - int i; + int i; numstr = (char *) palloc(len + Num.post + 2); strcpy(numstr, orgnum + (*orgnum == '-' ? 1 : 0)); @@ -4423,18 +4466,18 @@ int4_to_char(PG_FUNCTION_ARGS) Datum int8_to_char(PG_FUNCTION_ARGS) { - int64 value = PG_GETARG_INT64(0); - text *fmt = PG_GETARG_TEXT_P(1); - NUMDesc Num; + int64 value = PG_GETARG_INT64(0); + text *fmt = PG_GETARG_TEXT_P(1); + NUMDesc Num; FormatNode *format; - text *result, - *result_tmp; - int flag = 0; - int len = 0, - plen = 0, - sign = 0; - char *numstr, - *orgnum; + text *result, + *result_tmp; + int flag = 0; + int len = 0, + plen = 0, + sign = 0; + char *numstr, + *orgnum; NUM_TOCHAR_prepare; @@ -4446,7 +4489,7 @@ int8_to_char(PG_FUNCTION_ARGS) { /* Currently don't support int8 conversion to roman... */ numstr = orgnum = int_to_roman(DatumGetInt32( - DirectFunctionCall1(int84, Int64GetDatum(value)))); + DirectFunctionCall1(int84, Int64GetDatum(value)))); } else { @@ -4455,14 +4498,14 @@ int8_to_char(PG_FUNCTION_ARGS) double multi = pow((double) 10, (double) Num.multi); value = DatumGetInt64(DirectFunctionCall2(int8mul, - Int64GetDatum(value), - DirectFunctionCall1(dtoi8, - Float8GetDatum(multi)))); + Int64GetDatum(value), + DirectFunctionCall1(dtoi8, + Float8GetDatum(multi)))); Num.pre += Num.multi; } orgnum = DatumGetCString(DirectFunctionCall1(int8out, - Int64GetDatum(value))); + Int64GetDatum(value))); len = strlen(orgnum); if (*orgnum == '-') @@ -4475,7 +4518,7 @@ int8_to_char(PG_FUNCTION_ARGS) if (Num.post) { - int i; + int i; numstr = (char *) palloc(len + Num.post + 2); strcpy(numstr, orgnum + (*orgnum == '-' ? 1 : 0)); @@ -4511,19 +4554,19 @@ int8_to_char(PG_FUNCTION_ARGS) Datum float4_to_char(PG_FUNCTION_ARGS) { - float4 value = PG_GETARG_FLOAT4(0); - text *fmt = PG_GETARG_TEXT_P(1); - NUMDesc Num; + float4 value = PG_GETARG_FLOAT4(0); + text *fmt = PG_GETARG_TEXT_P(1); + NUMDesc Num; FormatNode *format; - text *result, - *result_tmp; - int flag = 0; - int len = 0, - plen = 0, - sign = 0; - char *numstr, - *orgnum, - *p; + text *result, + *result_tmp; + int flag = 0; + int len = 0, + plen = 0, + sign = 0; + char *numstr, + *orgnum, + *p; NUM_TOCHAR_prepare; @@ -4538,7 +4581,7 @@ float4_to_char(PG_FUNCTION_ARGS) if (IS_MULTI(&Num)) { - float multi = pow((double) 10, (double) Num.multi); + float multi = pow((double) 10, (double) Num.multi); val = value * multi; Num.pre += Num.multi; @@ -4591,19 +4634,19 @@ float4_to_char(PG_FUNCTION_ARGS) Datum float8_to_char(PG_FUNCTION_ARGS) { - float8 value = PG_GETARG_FLOAT8(0); - text *fmt = PG_GETARG_TEXT_P(1); - NUMDesc Num; + float8 value = PG_GETARG_FLOAT8(0); + text *fmt = PG_GETARG_TEXT_P(1); + NUMDesc Num; FormatNode *format; - text *result, - *result_tmp; - int flag = 0; - int len = 0, - plen = 0, - sign = 0; - char *numstr, - *orgnum, - *p; + text *result, + *result_tmp; + int flag = 0; + int len = 0, + plen = 0, + sign = 0; + char *numstr, + *orgnum, + *p; NUM_TOCHAR_prepare; @@ -4618,7 +4661,7 @@ float8_to_char(PG_FUNCTION_ARGS) if (IS_MULTI(&Num)) { - double multi = pow((double) 10, (double) Num.multi); + double multi = pow((double) 10, (double) Num.multi); val = value * multi; Num.pre += Num.multi; diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c index ef3e28fc61d..aac191b3778 100644 --- a/src/backend/utils/adt/geo_ops.c +++ b/src/backend/utils/adt/geo_ops.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.57 2001/01/24 19:43:13 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.58 2001/03/22 03:59:50 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -484,11 +484,11 @@ box_ov(BOX *box1, BOX *box2) FPle(box1->low.x, box2->high.x)) || (FPge(box2->high.x, box1->high.x) && FPle(box2->low.x, box1->high.x))) - && - ((FPge(box1->high.y, box2->high.y) && - FPle(box1->low.y, box2->high.y)) || - (FPge(box2->high.y, box1->high.y) && - FPle(box2->low.y, box1->high.y))); + && + ((FPge(box1->high.y, box2->high.y) && + FPle(box1->low.y, box2->high.y)) || + (FPge(box2->high.y, box1->high.y) && + FPle(box2->low.y, box1->high.y))); } /* box_overleft - is the right edge of box1 to the left of @@ -811,8 +811,10 @@ line_in(PG_FUNCTION_ARGS) { #ifdef ENABLE_LINE_TYPE char *str = PG_GETARG_CSTRING(0); + #endif LINE *line; + #ifdef ENABLE_LINE_TYPE LSEG lseg; int isopen; @@ -838,8 +840,10 @@ line_out(PG_FUNCTION_ARGS) { #ifdef ENABLE_LINE_TYPE LINE *line = PG_GETARG_LINE_P(0); + #endif char *result; + #ifdef ENABLE_LINE_TYPE LSEG lseg; @@ -996,9 +1000,9 @@ line_intersect(PG_FUNCTION_ARGS) LINE *l1 = PG_GETARG_LINE_P(0); LINE *l2 = PG_GETARG_LINE_P(1); - PG_RETURN_BOOL(! DatumGetBool(DirectFunctionCall2(line_parallel, - LinePGetDatum(l1), - LinePGetDatum(l2)))); + PG_RETURN_BOOL(!DatumGetBool(DirectFunctionCall2(line_parallel, + LinePGetDatum(l1), + LinePGetDatum(l2)))); } Datum @@ -1089,9 +1093,9 @@ line_distance(PG_FUNCTION_ARGS) float8 result; Point *tmp; - if (! DatumGetBool(DirectFunctionCall2(line_parallel, - LinePGetDatum(l1), - LinePGetDatum(l2)))) + if (!DatumGetBool(DirectFunctionCall2(line_parallel, + LinePGetDatum(l1), + LinePGetDatum(l2)))) PG_RETURN_FLOAT8(0.0); if (FPzero(l1->B)) /* vertical? */ PG_RETURN_FLOAT8(fabs(l1->C - l2->C)); @@ -1131,9 +1135,10 @@ line_interpt_internal(LINE *l1, LINE *l2) y; /* - * NOTE: if the lines are identical then we will find they are parallel - * and report "no intersection". This is a little weird, but since - * there's no *unique* intersection, maybe it's appropriate behavior. + * NOTE: if the lines are identical then we will find they are + * parallel and report "no intersection". This is a little weird, but + * since there's no *unique* intersection, maybe it's appropriate + * behavior. */ if (DatumGetBool(DirectFunctionCall2(line_parallel, LinePGetDatum(l1), @@ -1226,7 +1231,7 @@ path_in(PG_FUNCTION_ARGS) depth++; } - size = offsetof(PATH, p[0]) + sizeof(path->p[0]) * npts; + size = offsetof(PATH, p[0]) +sizeof(path->p[0]) * npts; path = (PATH *) palloc(size); path->size = size; @@ -1321,7 +1326,7 @@ path_isopen(PG_FUNCTION_ARGS) { PATH *path = PG_GETARG_PATH_P(0); - PG_RETURN_BOOL(! path->closed); + PG_RETURN_BOOL(!path->closed); } Datum @@ -1434,7 +1439,7 @@ path_distance(PG_FUNCTION_ARGS) tmp = DatumGetFloat8(DirectFunctionCall2(lseg_distance, LsegPGetDatum(&seg1), - LsegPGetDatum(&seg2))); + LsegPGetDatum(&seg2))); if (!have_min || tmp < min) { min = tmp; @@ -1443,7 +1448,7 @@ path_distance(PG_FUNCTION_ARGS) } } - if (! have_min) + if (!have_min) PG_RETURN_NULL(); PG_RETURN_FLOAT8(min); @@ -1992,9 +1997,10 @@ lseg_interpt(PG_FUNCTION_ARGS) result = line_interpt_internal(&tmp1, &tmp2); if (!PointerIsValid(result)) PG_RETURN_NULL(); + /* - * If the line intersection point isn't within l1 (or equivalently l2), - * there is no valid segment intersection point at all. + * If the line intersection point isn't within l1 (or equivalently + * l2), there is no valid segment intersection point at all. */ if (!on_ps_internal(result, l1) || !on_ps_internal(result, l2)) @@ -2002,10 +2008,11 @@ lseg_interpt(PG_FUNCTION_ARGS) pfree(result); PG_RETURN_NULL(); } + /* * If there is an intersection, then check explicitly for matching - * endpoints since there may be rounding effects with annoying - * lsb residue. - tgl 1997-07-09 + * endpoints since there may be rounding effects with annoying lsb + * residue. - tgl 1997-07-09 */ if ((FPeq(l1->p[0].x, l2->p[0].x) && FPeq(l1->p[0].y, l2->p[0].y)) || (FPeq(l1->p[0].x, l2->p[1].x) && FPeq(l1->p[0].y, l2->p[1].y))) @@ -2014,7 +2021,7 @@ lseg_interpt(PG_FUNCTION_ARGS) result->y = l1->p[0].y; } else if ((FPeq(l1->p[1].x, l2->p[0].x) && FPeq(l1->p[1].y, l2->p[0].y)) || - (FPeq(l1->p[1].x, l2->p[1].x) && FPeq(l1->p[1].y, l2->p[1].y))) + (FPeq(l1->p[1].x, l2->p[1].x) && FPeq(l1->p[1].y, l2->p[1].y))) { result->x = l1->p[1].x; result->y = l1->p[1].y; @@ -2048,7 +2055,7 @@ static double dist_pl_internal(Point *pt, LINE *line) { return (line->A * pt->x + line->B * pt->y + line->C) / - HYPOT(line->A, line->B); + HYPOT(line->A, line->B); } Datum @@ -2080,9 +2087,7 @@ dist_ps_internal(Point *pt, LSEG *lseg) m = (double) DBL_MAX; } else - { m = ((lseg->p[0].y - lseg->p[1].y) / (lseg->p[1].x - lseg->p[0].x)); - } ln = line_construct_pm(pt, m); #ifdef GEODEBUG @@ -2188,9 +2193,7 @@ dist_sl(PG_FUNCTION_ARGS) d2; if (has_interpt_sl(lseg, line)) - { result = 0.0; - } else { result = dist_pl_internal(&lseg->p[0], line); @@ -2230,6 +2233,7 @@ dist_lb(PG_FUNCTION_ARGS) #ifdef NOT_USED LINE *line = PG_GETARG_LINE_P(0); BOX *box = PG_GETARG_BOX_P(1); + #endif /* think about this one for a while */ @@ -2243,7 +2247,7 @@ Datum dist_cpoly(PG_FUNCTION_ARGS) { CIRCLE *circle = PG_GETARG_CIRCLE_P(0); - POLYGON *poly = PG_GETARG_POLYGON_P(1); + POLYGON *poly = PG_GETARG_POLYGON_P(1); float8 result; float8 d; int i; @@ -2430,7 +2434,7 @@ close_ps(PG_FUNCTION_ARGS) xh = lseg->p[0].x < lseg->p[1].x; yh = lseg->p[0].y < lseg->p[1].y; - if (FPeq(lseg->p[0].x, lseg->p[1].x)) /* vertical? */ + if (FPeq(lseg->p[0].x, lseg->p[1].x)) /* vertical? */ { #ifdef GEODEBUG printf("close_ps- segment is vertical\n"); @@ -2450,7 +2454,7 @@ close_ps(PG_FUNCTION_ARGS) result->y = pt->y; PG_RETURN_POINT_P(result); } - else if (FPeq(lseg->p[0].y, lseg->p[1].y)) /* horizontal? */ + else if (FPeq(lseg->p[0].y, lseg->p[1].y)) /* horizontal? */ { #ifdef GEODEBUG printf("close_ps- segment is horizontal\n"); @@ -2484,7 +2488,7 @@ close_ps(PG_FUNCTION_ARGS) * lower end pt */ #ifdef GEODEBUG printf("close_ps below: tmp A %f B %f C %f m %f\n", - tmp->A,tmp->B,tmp->C, tmp->m); + tmp->A, tmp->B, tmp->C, tmp->m); #endif PG_RETURN_POINT_P(result); } @@ -2496,7 +2500,7 @@ close_ps(PG_FUNCTION_ARGS) * higher end pt */ #ifdef GEODEBUG printf("close_ps above: tmp A %f B %f C %f m %f\n", - tmp->A,tmp->B,tmp->C, tmp->m); + tmp->A, tmp->B, tmp->C, tmp->m); #endif PG_RETURN_POINT_P(result); } @@ -2508,7 +2512,7 @@ close_ps(PG_FUNCTION_ARGS) tmp = line_construct_pm(pt, invm); #ifdef GEODEBUG printf("close_ps- tmp A %f B %f C %f m %f\n", - tmp->A,tmp->B,tmp->C, tmp->m); + tmp->A, tmp->B, tmp->C, tmp->m); #endif result = interpt_sl(lseg, tmp); Assert(result != NULL); @@ -2545,12 +2549,12 @@ close_lseg(PG_FUNCTION_ARGS) if ((d = dist_ps_internal(&l2->p[0], l1)) < dist) { result = DatumGetPointP(DirectFunctionCall2(close_ps, - PointPGetDatum(&l2->p[0]), + PointPGetDatum(&l2->p[0]), LsegPGetDatum(l1))); memcpy(&point, result, sizeof(Point)); pfree(result); result = DatumGetPointP(DirectFunctionCall2(close_ps, - PointPGetDatum(&point), + PointPGetDatum(&point), LsegPGetDatum(l2))); } @@ -2560,12 +2564,12 @@ close_lseg(PG_FUNCTION_ARGS) pfree(result); result = DatumGetPointP(DirectFunctionCall2(close_ps, - PointPGetDatum(&l2->p[1]), + PointPGetDatum(&l2->p[1]), LsegPGetDatum(l1))); memcpy(&point, result, sizeof(Point)); pfree(result); result = DatumGetPointP(DirectFunctionCall2(close_ps, - PointPGetDatum(&point), + PointPGetDatum(&point), LsegPGetDatum(l2))); } @@ -2752,6 +2756,7 @@ close_lb(PG_FUNCTION_ARGS) #ifdef NOT_USED LINE *line = PG_GETARG_LINE_P(0); BOX *box = PG_GETARG_BOX_P(1); + #endif /* think about this one for a while */ @@ -2858,11 +2863,11 @@ on_sl(PG_FUNCTION_ARGS) LINE *line = PG_GETARG_LINE_P(1); PG_RETURN_BOOL(DatumGetBool(DirectFunctionCall2(on_pl, - PointPGetDatum(&lseg->p[0]), - LinePGetDatum(line))) && + PointPGetDatum(&lseg->p[0]), + LinePGetDatum(line))) && DatumGetBool(DirectFunctionCall2(on_pl, - PointPGetDatum(&lseg->p[1]), - LinePGetDatum(line)))); + PointPGetDatum(&lseg->p[1]), + LinePGetDatum(line)))); } Datum @@ -2872,11 +2877,11 @@ on_sb(PG_FUNCTION_ARGS) BOX *box = PG_GETARG_BOX_P(1); PG_RETURN_BOOL(DatumGetBool(DirectFunctionCall2(on_pb, - PointPGetDatum(&lseg->p[0]), - BoxPGetDatum(box))) && + PointPGetDatum(&lseg->p[0]), + BoxPGetDatum(box))) && DatumGetBool(DirectFunctionCall2(on_pb, - PointPGetDatum(&lseg->p[1]), - BoxPGetDatum(box)))); + PointPGetDatum(&lseg->p[1]), + BoxPGetDatum(box)))); } /*--------------------------------------------------------------------- @@ -3058,7 +3063,7 @@ poly_in(PG_FUNCTION_ARGS) if ((npts = pair_count(str, ',')) <= 0) elog(ERROR, "Bad polygon external representation '%s'", str); - size = offsetof(POLYGON, p[0]) + sizeof(poly->p[0]) * npts; + size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * npts; poly = (POLYGON *) palloc(size); MemSet((char *) poly, 0, size); /* zero any holes */ @@ -3081,7 +3086,7 @@ poly_in(PG_FUNCTION_ARGS) Datum poly_out(PG_FUNCTION_ARGS) { - POLYGON *poly = PG_GETARG_POLYGON_P(0); + POLYGON *poly = PG_GETARG_POLYGON_P(0); PG_RETURN_CSTRING(path_encode(TRUE, poly->npts, poly->p)); } @@ -3095,13 +3100,16 @@ poly_out(PG_FUNCTION_ARGS) Datum poly_left(PG_FUNCTION_ARGS) { - POLYGON *polya = PG_GETARG_POLYGON_P(0); - POLYGON *polyb = PG_GETARG_POLYGON_P(1); + POLYGON *polya = PG_GETARG_POLYGON_P(0); + POLYGON *polyb = PG_GETARG_POLYGON_P(1); bool result; result = polya->boundbox.high.x < polyb->boundbox.low.x; - /* Avoid leaking memory for toasted inputs ... needed for rtree indexes */ + /* + * Avoid leaking memory for toasted inputs ... needed for rtree + * indexes + */ PG_FREE_IF_COPY(polya, 0); PG_FREE_IF_COPY(polyb, 1); @@ -3116,13 +3124,16 @@ poly_left(PG_FUNCTION_ARGS) Datum poly_overleft(PG_FUNCTION_ARGS) { - POLYGON *polya = PG_GETARG_POLYGON_P(0); - POLYGON *polyb = PG_GETARG_POLYGON_P(1); + POLYGON *polya = PG_GETARG_POLYGON_P(0); + POLYGON *polyb = PG_GETARG_POLYGON_P(1); bool result; result = polya->boundbox.low.x <= polyb->boundbox.high.x; - /* Avoid leaking memory for toasted inputs ... needed for rtree indexes */ + /* + * Avoid leaking memory for toasted inputs ... needed for rtree + * indexes + */ PG_FREE_IF_COPY(polya, 0); PG_FREE_IF_COPY(polyb, 1); @@ -3137,13 +3148,16 @@ poly_overleft(PG_FUNCTION_ARGS) Datum poly_right(PG_FUNCTION_ARGS) { - POLYGON *polya = PG_GETARG_POLYGON_P(0); - POLYGON *polyb = PG_GETARG_POLYGON_P(1); + POLYGON *polya = PG_GETARG_POLYGON_P(0); + POLYGON *polyb = PG_GETARG_POLYGON_P(1); bool result; result = polya->boundbox.low.x > polyb->boundbox.high.x; - /* Avoid leaking memory for toasted inputs ... needed for rtree indexes */ + /* + * Avoid leaking memory for toasted inputs ... needed for rtree + * indexes + */ PG_FREE_IF_COPY(polya, 0); PG_FREE_IF_COPY(polyb, 1); @@ -3158,13 +3172,16 @@ poly_right(PG_FUNCTION_ARGS) Datum poly_overright(PG_FUNCTION_ARGS) { - POLYGON *polya = PG_GETARG_POLYGON_P(0); - POLYGON *polyb = PG_GETARG_POLYGON_P(1); + POLYGON *polya = PG_GETARG_POLYGON_P(0); + POLYGON *polyb = PG_GETARG_POLYGON_P(1); bool result; result = polya->boundbox.high.x > polyb->boundbox.low.x; - /* Avoid leaking memory for toasted inputs ... needed for rtree indexes */ + /* + * Avoid leaking memory for toasted inputs ... needed for rtree + * indexes + */ PG_FREE_IF_COPY(polya, 0); PG_FREE_IF_COPY(polyb, 1); @@ -3181,8 +3198,8 @@ poly_overright(PG_FUNCTION_ARGS) Datum poly_same(PG_FUNCTION_ARGS) { - POLYGON *polya = PG_GETARG_POLYGON_P(0); - POLYGON *polyb = PG_GETARG_POLYGON_P(1); + POLYGON *polya = PG_GETARG_POLYGON_P(0); + POLYGON *polyb = PG_GETARG_POLYGON_P(1); bool result; if (polya->npts != polyb->npts) @@ -3190,7 +3207,10 @@ poly_same(PG_FUNCTION_ARGS) else result = plist_same(polya->npts, polya->p, polyb->p); - /* Avoid leaking memory for toasted inputs ... needed for rtree indexes */ + /* + * Avoid leaking memory for toasted inputs ... needed for rtree + * indexes + */ PG_FREE_IF_COPY(polya, 0); PG_FREE_IF_COPY(polyb, 1); @@ -3206,13 +3226,16 @@ poly_same(PG_FUNCTION_ARGS) Datum poly_overlap(PG_FUNCTION_ARGS) { - POLYGON *polya = PG_GETARG_POLYGON_P(0); - POLYGON *polyb = PG_GETARG_POLYGON_P(1); + POLYGON *polya = PG_GETARG_POLYGON_P(0); + POLYGON *polyb = PG_GETARG_POLYGON_P(1); bool result; result = box_ov(&polya->boundbox, &polyb->boundbox); - /* Avoid leaking memory for toasted inputs ... needed for rtree indexes */ + /* + * Avoid leaking memory for toasted inputs ... needed for rtree + * indexes + */ PG_FREE_IF_COPY(polya, 0); PG_FREE_IF_COPY(polyb, 1); @@ -3226,8 +3249,8 @@ poly_overlap(PG_FUNCTION_ARGS) Datum poly_contain(PG_FUNCTION_ARGS) { - POLYGON *polya = PG_GETARG_POLYGON_P(0); - POLYGON *polyb = PG_GETARG_POLYGON_P(1); + POLYGON *polya = PG_GETARG_POLYGON_P(0); + POLYGON *polyb = PG_GETARG_POLYGON_P(1); bool result; int i; @@ -3275,7 +3298,10 @@ poly_contain(PG_FUNCTION_ARGS) result = false; } - /* Avoid leaking memory for toasted inputs ... needed for rtree indexes */ + /* + * Avoid leaking memory for toasted inputs ... needed for rtree + * indexes + */ PG_FREE_IF_COPY(polya, 0); PG_FREE_IF_COPY(polyb, 1); @@ -3310,7 +3336,7 @@ poly_contained(PG_FUNCTION_ARGS) Datum poly_contain_pt(PG_FUNCTION_ARGS) { - POLYGON *poly = PG_GETARG_POLYGON_P(0); + POLYGON *poly = PG_GETARG_POLYGON_P(0); Point *p = PG_GETARG_POINT_P(1); PG_RETURN_BOOL(point_inside(p, poly->npts, poly->p) != 0); @@ -3320,7 +3346,7 @@ Datum pt_contained_poly(PG_FUNCTION_ARGS) { Point *p = PG_GETARG_POINT_P(0); - POLYGON *poly = PG_GETARG_POLYGON_P(1); + POLYGON *poly = PG_GETARG_POLYGON_P(1); PG_RETURN_BOOL(point_inside(p, poly->npts, poly->p) != 0); } @@ -3330,8 +3356,9 @@ Datum poly_distance(PG_FUNCTION_ARGS) { #ifdef NOT_USED - POLYGON *polya = PG_GETARG_POLYGON_P(0); - POLYGON *polyb = PG_GETARG_POLYGON_P(1); + POLYGON *polya = PG_GETARG_POLYGON_P(0); + POLYGON *polyb = PG_GETARG_POLYGON_P(1); + #endif elog(ERROR, "poly_distance not implemented"); @@ -3531,7 +3558,7 @@ path_add(PG_FUNCTION_ARGS) if (p1->closed || p2->closed) PG_RETURN_NULL(); - size = offsetof(PATH, p[0]) + sizeof(p1->p[0]) * (p1->npts + p2->npts); + size = offsetof(PATH, p[0]) +sizeof(p1->p[0]) * (p1->npts + p2->npts); result = (PATH *) palloc(size); result->size = size; @@ -3601,7 +3628,7 @@ path_mul_pt(PG_FUNCTION_ARGS) for (i = 0; i < path->npts; i++) { p = DatumGetPointP(DirectFunctionCall2(point_mul, - PointPGetDatum(&path->p[i]), + PointPGetDatum(&path->p[i]), PointPGetDatum(point))); path->p[i].x = p->x; path->p[i].y = p->y; @@ -3622,7 +3649,7 @@ path_div_pt(PG_FUNCTION_ARGS) for (i = 0; i < path->npts; i++) { p = DatumGetPointP(DirectFunctionCall2(point_div, - PointPGetDatum(&path->p[i]), + PointPGetDatum(&path->p[i]), PointPGetDatum(point))); path->p[i].x = p->x; path->p[i].y = p->y; @@ -3638,6 +3665,7 @@ path_center(PG_FUNCTION_ARGS) { #ifdef NOT_USED PATH *path = PG_GETARG_PATH_P(0); + #endif elog(ERROR, "path_center not implemented"); @@ -3657,7 +3685,7 @@ path_poly(PG_FUNCTION_ARGS) if (!path->closed) elog(ERROR, "Open path cannot be converted to polygon"); - size = offsetof(POLYGON, p[0]) + sizeof(poly->p[0]) * path->npts; + size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * path->npts; poly = (POLYGON *) palloc(size); poly->size = size; @@ -3684,7 +3712,7 @@ path_poly(PG_FUNCTION_ARGS) Datum poly_npoints(PG_FUNCTION_ARGS) { - POLYGON *poly = PG_GETARG_POLYGON_P(0); + POLYGON *poly = PG_GETARG_POLYGON_P(0); PG_RETURN_INT32(poly->npts); } @@ -3693,7 +3721,7 @@ poly_npoints(PG_FUNCTION_ARGS) Datum poly_center(PG_FUNCTION_ARGS) { - POLYGON *poly = PG_GETARG_POLYGON_P(0); + POLYGON *poly = PG_GETARG_POLYGON_P(0); Datum result; CIRCLE *circle; @@ -3710,7 +3738,7 @@ poly_center(PG_FUNCTION_ARGS) Datum poly_box(PG_FUNCTION_ARGS) { - POLYGON *poly = PG_GETARG_POLYGON_P(0); + POLYGON *poly = PG_GETARG_POLYGON_P(0); BOX *box; if (poly->npts < 1) @@ -3733,7 +3761,7 @@ box_poly(PG_FUNCTION_ARGS) int size; /* map four corners of the box to a polygon */ - size = offsetof(POLYGON, p[0]) + sizeof(poly->p[0]) * 4; + size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * 4; poly = (POLYGON *) palloc(size); poly->size = size; @@ -3758,12 +3786,12 @@ box_poly(PG_FUNCTION_ARGS) Datum poly_path(PG_FUNCTION_ARGS) { - POLYGON *poly = PG_GETARG_POLYGON_P(0); + POLYGON *poly = PG_GETARG_POLYGON_P(0); PATH *path; int size; int i; - size = offsetof(PATH, p[0]) + sizeof(path->p[0]) * poly->npts; + size = offsetof(PATH, p[0]) +sizeof(path->p[0]) * poly->npts; path = (PATH *) palloc(size); path->size = size; @@ -4133,7 +4161,7 @@ circle_mul_pt(PG_FUNCTION_ARGS) result = circle_copy(circle); p = DatumGetPointP(DirectFunctionCall2(point_mul, - PointPGetDatum(&circle->center), + PointPGetDatum(&circle->center), PointPGetDatum(point))); result->center.x = p->x; result->center.y = p->y; @@ -4154,7 +4182,7 @@ circle_div_pt(PG_FUNCTION_ARGS) result = circle_copy(circle); p = DatumGetPointP(DirectFunctionCall2(point_div, - PointPGetDatum(&circle->center), + PointPGetDatum(&circle->center), PointPGetDatum(point))); result->center.x = p->x; result->center.y = p->y; @@ -4381,7 +4409,7 @@ circle_poly(PG_FUNCTION_ARGS) Datum poly_circle(PG_FUNCTION_ARGS) { - POLYGON *poly = PG_GETARG_POLYGON_P(0); + POLYGON *poly = PG_GETARG_POLYGON_P(0); CIRCLE *circle; int i; diff --git a/src/backend/utils/adt/inet_net_ntop.c b/src/backend/utils/adt/inet_net_ntop.c index ecc83cab814..73329300956 100644 --- a/src/backend/utils/adt/inet_net_ntop.c +++ b/src/backend/utils/adt/inet_net_ntop.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.9 2000/11/10 20:13:25 tgl Exp $"; +static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.10 2001/03/22 03:59:51 momjian Exp $"; #endif @@ -56,7 +56,7 @@ inet_cidr_ntop(int af, const void *src, int bits, char *dst, size_t size) { switch (af) { - case AF_INET: + case AF_INET: return (inet_cidr_ntop_ipv4(src, bits, dst, size)); default: errno = EAFNOSUPPORT; @@ -157,7 +157,7 @@ inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size) { switch (af) { - case AF_INET: + case AF_INET: return (inet_net_ntop_ipv4(src, bits, dst, size)); default: errno = EAFNOSUPPORT; diff --git a/src/backend/utils/adt/int.c b/src/backend/utils/adt/int.c index 189cd384162..00c99805c9e 100644 --- a/src/backend/utils/adt/int.c +++ b/src/backend/utils/adt/int.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.45 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.46 2001/03/22 03:59:51 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -63,7 +63,7 @@ Datum int2out(PG_FUNCTION_ARGS) { int16 arg1 = PG_GETARG_INT16(0); - char *result = (char *) palloc(7); /* sign, 5 digits, '\0' */ + char *result = (char *) palloc(7); /* sign, 5 digits, '\0' */ pg_itoa(arg1, result); PG_RETURN_CSTRING(result); @@ -180,7 +180,8 @@ Datum int44out(PG_FUNCTION_ARGS) { int32 *an_array = (int32 *) PG_GETARG_POINTER(0); - char *result = (char *) palloc(16 * 4); /* Allow 14 digits + sign */ + char *result = (char *) palloc(16 * 4); /* Allow 14 digits + + * sign */ int i; char *walk; @@ -219,7 +220,7 @@ Datum int4out(PG_FUNCTION_ARGS) { int32 arg1 = PG_GETARG_INT32(0); - char *result = (char *) palloc(12); /* sign, 10 digits, '\0' */ + char *result = (char *) palloc(12); /* sign, 10 digits, '\0' */ pg_ltoa(arg1, result); PG_RETURN_CSTRING(result); @@ -257,7 +258,7 @@ Datum int2_text(PG_FUNCTION_ARGS) { int16 arg1 = PG_GETARG_INT16(0); - text *result = (text *) palloc(7+VARHDRSZ); /* sign,5 digits, '\0' */ + text *result = (text *) palloc(7 + VARHDRSZ); /* sign,5 digits, '\0' */ pg_itoa(arg1, VARDATA(result)); VARATT_SIZEP(result) = strlen(VARDATA(result)) + VARHDRSZ; @@ -288,7 +289,7 @@ Datum int4_text(PG_FUNCTION_ARGS) { int32 arg1 = PG_GETARG_INT32(0); - text *result = (text *) palloc(12+VARHDRSZ); /* sign,10 digits,'\0' */ + text *result = (text *) palloc(12 + VARHDRSZ); /* sign,10 digits,'\0' */ pg_ltoa(arg1, VARDATA(result)); VARATT_SIZEP(result) = strlen(VARDATA(result)) + VARHDRSZ; @@ -960,4 +961,3 @@ int2shr(PG_FUNCTION_ARGS) PG_RETURN_INT16(arg1 >> arg2); } - diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c index a7df878c65b..3f286069b7d 100644 --- a/src/backend/utils/adt/int8.c +++ b/src/backend/utils/adt/int8.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.28 2001/01/26 22:50:26 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.29 2001/03/22 03:59:51 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -67,15 +67,15 @@ int8in(PG_FUNCTION_ARGS) * Do our own scan, rather than relying on sscanf which might be * broken for long long. */ - while (*ptr && isspace((unsigned char) *ptr)) /* skip leading spaces */ + while (*ptr && isspace((unsigned char) *ptr)) /* skip leading spaces */ ptr++; if (*ptr == '-') /* handle sign */ sign = -1, ptr++; else if (*ptr == '+') ptr++; - if (!isdigit((unsigned char) *ptr)) /* require at least one digit */ + if (!isdigit((unsigned char) *ptr)) /* require at least one digit */ elog(ERROR, "Bad int8 external representation \"%s\"", str); - while (*ptr && isdigit((unsigned char) *ptr)) /* process digits */ + while (*ptr && isdigit((unsigned char) *ptr)) /* process digits */ { int64 newtmp = tmp * 10 + (*ptr++ - '0'); @@ -409,7 +409,7 @@ int8um(PG_FUNCTION_ARGS) { int64 val = PG_GETARG_INT64(0); - PG_RETURN_INT64(- val); + PG_RETURN_INT64(-val); } Datum @@ -702,10 +702,11 @@ dtoi8(PG_FUNCTION_ARGS) /* Round val to nearest integer (but it's still in float form) */ val = rint(val); + /* - * Does it fit in an int64? Avoid assuming that we have handy constants - * defined for the range boundaries, instead test for overflow by - * reverse-conversion. + * Does it fit in an int64? Avoid assuming that we have handy + * constants defined for the range boundaries, instead test for + * overflow by reverse-conversion. */ result = (int64) val; diff --git a/src/backend/utils/adt/like.c b/src/backend/utils/adt/like.c index 7bac7793fba..f27bc067d6a 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 - * $Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.44 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.45 2001/03/22 03:59:51 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -30,10 +30,10 @@ #define LIKE_ABORT (-1) -static int MatchText(unsigned char * t, int tlen, - unsigned char * p, int plen); -static int MatchTextIC(unsigned char * t, int tlen, - unsigned char * p, int plen); +static int MatchText(unsigned char *t, int tlen, + unsigned char *p, int plen); +static int MatchTextIC(unsigned char *t, int tlen, + unsigned char *p, int plen); #ifdef MULTIBYTE @@ -42,19 +42,20 @@ static int MatchTextIC(unsigned char * t, int tlen, * as wide characters. If they match, returns 1 otherwise returns 0. *-------------------- */ -static int wchareq(unsigned char *p1, unsigned char *p2) +static int +wchareq(unsigned char *p1, unsigned char *p2) { - int l; + int l; l = pg_mblen(p1); - if (pg_mblen(p2) != l) { - return(0); - } - while (l--) { + if (pg_mblen(p2) != l) + return (0); + while (l--) + { if (*p1++ != *p2++) - return(0); + return (0); } - return(1); + return (1); } /*-------------------- @@ -65,32 +66,38 @@ static int wchareq(unsigned char *p1, unsigned char *p2) */ #define CHARMAX 0x80 -static int iwchareq(unsigned char *p1, unsigned char *p2) +static int +iwchareq(unsigned char *p1, unsigned char *p2) { - int c1[2], c2[2]; - int l; + int c1[2], + c2[2]; + int l; - /* short cut. if *p1 and *p2 is lower than CHARMAX, then - we could assume they are ASCII */ + /* + * short cut. if *p1 and *p2 is lower than CHARMAX, then we could + * assume they are ASCII + */ if (*p1 < CHARMAX && *p2 < CHARMAX) - return(tolower(*p1) == tolower(*p2)); + return (tolower(*p1) == tolower(*p2)); - /* if one of them is an ASCII while the other is not, then - they must be different characters - */ + /* + * if one of them is an ASCII while the other is not, then they must + * be different characters + */ else if (*p1 < CHARMAX || *p2 < CHARMAX) - return(0); + return (0); - /* ok, p1 and p2 are both > CHARMAX, then they must be multi-byte - characters - */ + /* + * ok, p1 and p2 are both > CHARMAX, then they must be multi-byte + * characters + */ l = pg_mblen(p1); - (void)pg_mb2wchar_with_len(p1, (pg_wchar *)c1, l); + (void) pg_mb2wchar_with_len(p1, (pg_wchar *) c1, l); c1[0] = tolower(c1[0]); l = pg_mblen(p2); - (void)pg_mb2wchar_with_len(p2, (pg_wchar *)c2, l); + (void) pg_mb2wchar_with_len(p2, (pg_wchar *) c2, l); c2[0] = tolower(c2[0]); - return(c1[0] == c2[0]); + return (c1[0] == c2[0]); } #endif @@ -124,13 +131,15 @@ namelike(PG_FUNCTION_ARGS) Name str = PG_GETARG_NAME(0); text *pat = PG_GETARG_TEXT_P(1); bool result; - unsigned char *s, *p; - int slen, plen; + unsigned char *s, + *p; + int slen, + plen; s = NameStr(*str); slen = strlen(s); p = VARDATA(pat); - plen = (VARSIZE(pat)-VARHDRSZ); + plen = (VARSIZE(pat) - VARHDRSZ); result = (MatchText(s, slen, p, plen) == LIKE_TRUE); @@ -143,13 +152,15 @@ namenlike(PG_FUNCTION_ARGS) Name str = PG_GETARG_NAME(0); text *pat = PG_GETARG_TEXT_P(1); bool result; - unsigned char *s, *p; - int slen, plen; + unsigned char *s, + *p; + int slen, + plen; s = NameStr(*str); slen = strlen(s); p = VARDATA(pat); - plen = (VARSIZE(pat)-VARHDRSZ); + plen = (VARSIZE(pat) - VARHDRSZ); result = (MatchText(s, slen, p, plen) != LIKE_TRUE); @@ -162,13 +173,15 @@ textlike(PG_FUNCTION_ARGS) text *str = PG_GETARG_TEXT_P(0); text *pat = PG_GETARG_TEXT_P(1); bool result; - unsigned char *s, *p; - int slen, plen; + unsigned char *s, + *p; + int slen, + plen; s = VARDATA(str); - slen = (VARSIZE(str)-VARHDRSZ); + slen = (VARSIZE(str) - VARHDRSZ); p = VARDATA(pat); - plen = (VARSIZE(pat)-VARHDRSZ); + plen = (VARSIZE(pat) - VARHDRSZ); result = (MatchText(s, slen, p, plen) == LIKE_TRUE); @@ -181,13 +194,15 @@ textnlike(PG_FUNCTION_ARGS) text *str = PG_GETARG_TEXT_P(0); text *pat = PG_GETARG_TEXT_P(1); bool result; - unsigned char *s, *p; - int slen, plen; + unsigned char *s, + *p; + int slen, + plen; s = VARDATA(str); - slen = (VARSIZE(str)-VARHDRSZ); + slen = (VARSIZE(str) - VARHDRSZ); p = VARDATA(pat); - plen = (VARSIZE(pat)-VARHDRSZ); + plen = (VARSIZE(pat) - VARHDRSZ); result = (MatchText(s, slen, p, plen) != LIKE_TRUE); @@ -204,13 +219,15 @@ nameiclike(PG_FUNCTION_ARGS) Name str = PG_GETARG_NAME(0); text *pat = PG_GETARG_TEXT_P(1); bool result; - unsigned char *s, *p; - int slen, plen; + unsigned char *s, + *p; + int slen, + plen; s = NameStr(*str); slen = strlen(s); p = VARDATA(pat); - plen = (VARSIZE(pat)-VARHDRSZ); + plen = (VARSIZE(pat) - VARHDRSZ); result = (MatchTextIC(s, slen, p, plen) == LIKE_TRUE); @@ -223,13 +240,15 @@ nameicnlike(PG_FUNCTION_ARGS) Name str = PG_GETARG_NAME(0); text *pat = PG_GETARG_TEXT_P(1); bool result; - unsigned char *s, *p; - int slen, plen; + unsigned char *s, + *p; + int slen, + plen; s = NameStr(*str); slen = strlen(s); p = VARDATA(pat); - plen = (VARSIZE(pat)-VARHDRSZ); + plen = (VARSIZE(pat) - VARHDRSZ); result = (MatchTextIC(s, slen, p, plen) != LIKE_TRUE); @@ -242,13 +261,15 @@ texticlike(PG_FUNCTION_ARGS) text *str = PG_GETARG_TEXT_P(0); text *pat = PG_GETARG_TEXT_P(1); bool result; - unsigned char *s, *p; - int slen, plen; + unsigned char *s, + *p; + int slen, + plen; s = VARDATA(str); - slen = (VARSIZE(str)-VARHDRSZ); + slen = (VARSIZE(str) - VARHDRSZ); p = VARDATA(pat); - plen = (VARSIZE(pat)-VARHDRSZ); + plen = (VARSIZE(pat) - VARHDRSZ); result = (MatchTextIC(s, slen, p, plen) == LIKE_TRUE); @@ -261,13 +282,15 @@ texticnlike(PG_FUNCTION_ARGS) text *str = PG_GETARG_TEXT_P(0); text *pat = PG_GETARG_TEXT_P(1); bool result; - unsigned char *s, *p; - int slen, plen; + unsigned char *s, + *p; + int slen, + plen; s = VARDATA(str); - slen = (VARSIZE(str)-VARHDRSZ); + slen = (VARSIZE(str) - VARHDRSZ); p = VARDATA(pat); - plen = (VARSIZE(pat)-VARHDRSZ); + plen = (VARSIZE(pat) - VARHDRSZ); result = (MatchTextIC(s, slen, p, plen) != LIKE_TRUE); @@ -284,14 +307,17 @@ like_escape(PG_FUNCTION_ARGS) text *pat = PG_GETARG_TEXT_P(0); text *esc = PG_GETARG_TEXT_P(1); text *result; - unsigned char *p, *e, *r; - int plen, elen; + unsigned char *p, + *e, + *r; + int plen, + elen; bool afterescape; p = VARDATA(pat); - plen = (VARSIZE(pat)-VARHDRSZ); + plen = (VARSIZE(pat) - VARHDRSZ); e = VARDATA(esc); - elen = (VARSIZE(esc)-VARHDRSZ); + elen = (VARSIZE(esc) - VARHDRSZ); /* * Worst-case pattern growth is 2x --- unlikely, but it's hardly worth @@ -302,6 +328,7 @@ like_escape(PG_FUNCTION_ARGS) if (elen == 0) { + /* * No escape character is wanted. Double any backslashes in the * pattern to make them act like ordinary characters. @@ -315,6 +342,7 @@ like_escape(PG_FUNCTION_ARGS) } else { + /* * The specified escape must be only a single character. */ @@ -322,6 +350,7 @@ like_escape(PG_FUNCTION_ARGS) if (elen != 0) elog(ERROR, "ESCAPE string must be empty or one character"); e = VARDATA(esc); + /* * If specified escape is '\', just copy the pattern as-is. */ @@ -330,15 +359,16 @@ like_escape(PG_FUNCTION_ARGS) memcpy(result, pat, VARSIZE(pat)); PG_RETURN_TEXT_P(result); } + /* - * Otherwise, convert occurrences of the specified escape character - * to '\', and double occurrences of '\' --- unless they immediately - * follow an escape character! + * Otherwise, convert occurrences of the specified escape + * character to '\', and double occurrences of '\' --- unless they + * immediately follow an escape character! */ afterescape = false; while (plen > 0) { - if (CHAREQ(p,e) && !afterescape) + if (CHAREQ(p, e) && !afterescape) { *r++ = '\\'; NextChar(p, plen); @@ -347,7 +377,7 @@ like_escape(PG_FUNCTION_ARGS) else if (*p == '\\') { *r++ = '\\'; - if (! afterescape) + if (!afterescape) *r++ = '\\'; NextChar(p, plen); afterescape = false; @@ -413,7 +443,7 @@ like_escape(PG_FUNCTION_ARGS) */ static int -MatchText(unsigned char * t, int tlen, unsigned char * p, int plen) +MatchText(unsigned char *t, int tlen, unsigned char *p, int plen) { /* Fast path for match-everything pattern */ if ((plen == 1) && (*p == '%')) @@ -425,7 +455,7 @@ MatchText(unsigned char * t, int tlen, unsigned char * p, int plen) { /* Next pattern char must match literally, whatever it is */ NextChar(p, plen); - if ((plen <= 0) || !CHAREQ(t,p)) + if ((plen <= 0) || !CHAREQ(t, p)) return LIKE_FALSE; } else if (*p == '%') @@ -439,22 +469,22 @@ MatchText(unsigned char * t, int tlen, unsigned char * p, int plen) return LIKE_TRUE; /* - * Otherwise, scan for a text position at which we can - * match the rest of the pattern. + * Otherwise, scan for a text position at which we can match + * the rest of the pattern. */ while (tlen > 0) { + /* - * Optimization to prevent most recursion: don't - * recurse unless first pattern char might match this - * text char. + * Optimization to prevent most recursion: don't recurse + * unless first pattern char might match this text char. */ - if (CHAREQ(t,p) || (*p == '\\') || (*p == '_')) + if (CHAREQ(t, p) || (*p == '\\') || (*p == '_')) { - int matched = MatchText(t, tlen, p, plen); + int matched = MatchText(t, tlen, p, plen); if (matched != LIKE_FALSE) - return matched; /* TRUE or ABORT */ + return matched; /* TRUE or ABORT */ } NextChar(t, tlen); @@ -466,9 +496,11 @@ MatchText(unsigned char * t, int tlen, unsigned char * p, int plen) */ return LIKE_ABORT; } - else if ((*p != '_') && !CHAREQ(t,p)) + else if ((*p != '_') && !CHAREQ(t, p)) { - /* Not the single-character wildcard and no explicit match? + + /* + * Not the single-character wildcard and no explicit match? * Then time to quit... */ return LIKE_FALSE; @@ -482,7 +514,8 @@ MatchText(unsigned char * t, int tlen, unsigned char * p, int plen) return LIKE_FALSE; /* end of pattern, but not of text */ /* End of input string. Do we have matching pattern remaining? */ - while ((plen > 0) && (*p == '%')) /* allow multiple %'s at end of pattern */ + while ((plen > 0) && (*p == '%')) /* allow multiple %'s at end of + * pattern */ NextChar(p, plen); if (plen <= 0) return LIKE_TRUE; @@ -492,13 +525,13 @@ MatchText(unsigned char * t, int tlen, unsigned char * p, int plen) * start matching this pattern. */ return LIKE_ABORT; -} /* MatchText() */ +} /* MatchText() */ /* * Same as above, but ignore case */ static int -MatchTextIC(unsigned char * t, int tlen, unsigned char * p, int plen) +MatchTextIC(unsigned char *t, int tlen, unsigned char *p, int plen) { /* Fast path for match-everything pattern */ if ((plen == 1) && (*p == '%')) @@ -510,7 +543,7 @@ MatchTextIC(unsigned char * t, int tlen, unsigned char * p, int plen) { /* Next pattern char must match literally, whatever it is */ NextChar(p, plen); - if ((plen <= 0) || !ICHAREQ(t,p)) + if ((plen <= 0) || !ICHAREQ(t, p)) return LIKE_FALSE; } else if (*p == '%') @@ -524,22 +557,22 @@ MatchTextIC(unsigned char * t, int tlen, unsigned char * p, int plen) return LIKE_TRUE; /* - * Otherwise, scan for a text position at which we can - * match the rest of the pattern. + * Otherwise, scan for a text position at which we can match + * the rest of the pattern. */ while (tlen > 0) { + /* - * Optimization to prevent most recursion: don't - * recurse unless first pattern char might match this - * text char. + * Optimization to prevent most recursion: don't recurse + * unless first pattern char might match this text char. */ - if (ICHAREQ(t,p) || (*p == '\\') || (*p == '_')) + if (ICHAREQ(t, p) || (*p == '\\') || (*p == '_')) { - int matched = MatchTextIC(t, tlen, p, plen); + int matched = MatchTextIC(t, tlen, p, plen); if (matched != LIKE_FALSE) - return matched; /* TRUE or ABORT */ + return matched; /* TRUE or ABORT */ } NextChar(t, tlen); @@ -551,9 +584,11 @@ MatchTextIC(unsigned char * t, int tlen, unsigned char * p, int plen) */ return LIKE_ABORT; } - else if ((*p != '_') && !ICHAREQ(t,p)) + else if ((*p != '_') && !ICHAREQ(t, p)) { - /* Not the single-character wildcard and no explicit match? + + /* + * Not the single-character wildcard and no explicit match? * Then time to quit... */ return LIKE_FALSE; @@ -567,7 +602,8 @@ MatchTextIC(unsigned char * t, int tlen, unsigned char * p, int plen) return LIKE_FALSE; /* end of pattern, but not of text */ /* End of input string. Do we have matching pattern remaining? */ - while ((plen > 0) && (*p == '%')) /* allow multiple %'s at end of pattern */ + while ((plen > 0) && (*p == '%')) /* allow multiple %'s at end of + * pattern */ NextChar(p, plen); if (plen <= 0) return LIKE_TRUE; @@ -577,4 +613,4 @@ MatchTextIC(unsigned char * t, int tlen, unsigned char * p, int plen) * start matching this pattern. */ return LIKE_ABORT; -} /* MatchTextIC() */ +} /* MatchTextIC() */ diff --git a/src/backend/utils/adt/mac.c b/src/backend/utils/adt/mac.c index 17754588e97..0724abec5b2 100644 --- a/src/backend/utils/adt/mac.c +++ b/src/backend/utils/adt/mac.c @@ -1,7 +1,7 @@ /* * PostgreSQL type definitions for MAC addresses. * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/mac.c,v 1.19 2000/12/08 23:57:03 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/mac.c,v 1.20 2001/03/22 03:59:51 momjian Exp $ */ #include "postgres.h" @@ -82,7 +82,7 @@ macaddr_in(PG_FUNCTION_ARGS) Datum macaddr_out(PG_FUNCTION_ARGS) { - macaddr *addr = PG_GETARG_MACADDR_P(0); + macaddr *addr = PG_GETARG_MACADDR_P(0); char *result; result = (char *) palloc(32); @@ -139,16 +139,16 @@ text_macaddr(PG_FUNCTION_ARGS) char str[18]; int len; - len = (VARSIZE(addr)-VARHDRSZ); + len = (VARSIZE(addr) - VARHDRSZ); if (len >= 18) elog(ERROR, "Text is too long to convert to MAC address"); memmove(str, VARDATA(addr), len); - *(str+len) = '\0'; + *(str + len) = '\0'; - result = DirectFunctionCall1(macaddr_in, CStringGetDatum(str)); + result = DirectFunctionCall1(macaddr_in, CStringGetDatum(str)); - return(result); + return (result); } /* @@ -173,8 +173,8 @@ macaddr_cmp_internal(macaddr *a1, macaddr *a2) Datum macaddr_cmp(PG_FUNCTION_ARGS) { - macaddr *a1 = PG_GETARG_MACADDR_P(0); - macaddr *a2 = PG_GETARG_MACADDR_P(1); + macaddr *a1 = PG_GETARG_MACADDR_P(0); + macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_INT32(macaddr_cmp_internal(a1, a2)); } @@ -186,8 +186,8 @@ macaddr_cmp(PG_FUNCTION_ARGS) Datum macaddr_lt(PG_FUNCTION_ARGS) { - macaddr *a1 = PG_GETARG_MACADDR_P(0); - macaddr *a2 = PG_GETARG_MACADDR_P(1); + macaddr *a1 = PG_GETARG_MACADDR_P(0); + macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_BOOL(macaddr_cmp_internal(a1, a2) < 0); } @@ -195,8 +195,8 @@ macaddr_lt(PG_FUNCTION_ARGS) Datum macaddr_le(PG_FUNCTION_ARGS) { - macaddr *a1 = PG_GETARG_MACADDR_P(0); - macaddr *a2 = PG_GETARG_MACADDR_P(1); + macaddr *a1 = PG_GETARG_MACADDR_P(0); + macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_BOOL(macaddr_cmp_internal(a1, a2) <= 0); } @@ -204,8 +204,8 @@ macaddr_le(PG_FUNCTION_ARGS) Datum macaddr_eq(PG_FUNCTION_ARGS) { - macaddr *a1 = PG_GETARG_MACADDR_P(0); - macaddr *a2 = PG_GETARG_MACADDR_P(1); + macaddr *a1 = PG_GETARG_MACADDR_P(0); + macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_BOOL(macaddr_cmp_internal(a1, a2) == 0); } @@ -213,8 +213,8 @@ macaddr_eq(PG_FUNCTION_ARGS) Datum macaddr_ge(PG_FUNCTION_ARGS) { - macaddr *a1 = PG_GETARG_MACADDR_P(0); - macaddr *a2 = PG_GETARG_MACADDR_P(1); + macaddr *a1 = PG_GETARG_MACADDR_P(0); + macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_BOOL(macaddr_cmp_internal(a1, a2) >= 0); } @@ -222,8 +222,8 @@ macaddr_ge(PG_FUNCTION_ARGS) Datum macaddr_gt(PG_FUNCTION_ARGS) { - macaddr *a1 = PG_GETARG_MACADDR_P(0); - macaddr *a2 = PG_GETARG_MACADDR_P(1); + macaddr *a1 = PG_GETARG_MACADDR_P(0); + macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_BOOL(macaddr_cmp_internal(a1, a2) > 0); } @@ -231,8 +231,8 @@ macaddr_gt(PG_FUNCTION_ARGS) Datum macaddr_ne(PG_FUNCTION_ARGS) { - macaddr *a1 = PG_GETARG_MACADDR_P(0); - macaddr *a2 = PG_GETARG_MACADDR_P(1); + macaddr *a1 = PG_GETARG_MACADDR_P(0); + macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_BOOL(macaddr_cmp_internal(a1, a2) != 0); } @@ -243,7 +243,7 @@ macaddr_ne(PG_FUNCTION_ARGS) Datum hashmacaddr(PG_FUNCTION_ARGS) { - macaddr *key = PG_GETARG_MACADDR_P(0); + macaddr *key = PG_GETARG_MACADDR_P(0); return hash_any((char *) key, sizeof(macaddr)); } @@ -255,8 +255,8 @@ hashmacaddr(PG_FUNCTION_ARGS) Datum macaddr_trunc(PG_FUNCTION_ARGS) { - macaddr *result; - macaddr *addr = PG_GETARG_MACADDR_P(0); + macaddr *result; + macaddr *addr = PG_GETARG_MACADDR_P(0); result = (macaddr *) palloc(sizeof(macaddr)); diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index d3a82eaf8a1..af08bda8789 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.21 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.22 2001/03/22 03:59:51 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -53,7 +53,7 @@ nonnullvalue(PG_FUNCTION_ARGS) * select * from TEMP where oidrand(TEMP.oid, 10) * will return about 1/10 of the tuples in TEMP * - * NOTE: the OID input is not used at all. It is there just because of + * NOTE: the OID input is not used at all. It is there just because of * an old optimizer bug: a qual expression containing no variables was * mistakenly assumed to be a constant. Pretending to access the row's OID * prevented the optimizer from treating the oidrand() result as constant. @@ -66,6 +66,7 @@ oidrand(PG_FUNCTION_ARGS) { #ifdef NOT_USED Oid o = PG_GETARG_OID(0); + #endif int32 X = PG_GETARG_INT32(1); bool result; diff --git a/src/backend/utils/adt/nabstime.c b/src/backend/utils/adt/nabstime.c index 99dc95d4663..972ca7a67fa 100644 --- a/src/backend/utils/adt/nabstime.c +++ b/src/backend/utils/adt/nabstime.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.82 2001/02/21 22:03:00 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.83 2001/03/22 03:59:52 momjian Exp $ * * NOTES * @@ -162,7 +162,8 @@ GetCurrentAbsoluteTime(void) CDayLight = tm->tm_isdst; CTimeZone = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL); strcpy(CTZName, tzname[tm->tm_isdst]); -#else /* neither HAVE_TM_ZONE nor HAVE_INT_TIMEZONE */ +#else /* neither HAVE_TM_ZONE nor + * HAVE_INT_TIMEZONE */ CTimeZone = tb.timezone * 60; CDayLight = (tb.dstflag != 0); @@ -192,7 +193,8 @@ GetCurrentTime(struct tm * tm) void abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char *tzn) { - time_t time = (time_t) _time; + time_t time = (time_t) _time; + #if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE) struct tm *tx; @@ -207,14 +209,14 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char *tzn) if (tzp != NULL) { tx = localtime((time_t *) &time); -# ifdef NO_MKTIME_BEFORE_1970 +#ifdef NO_MKTIME_BEFORE_1970 if (tx->tm_year < 70 && tx->tm_isdst == 1) { time -= 3600; tx = localtime((time_t *) &time); tx->tm_isdst = 0; } -# endif +#endif } else { @@ -229,7 +231,7 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char *tzn) tm->tm_sec = tx->tm_sec; tm->tm_isdst = tx->tm_isdst; -# if defined(HAVE_TM_ZONE) +#if defined(HAVE_TM_ZONE) tm->tm_gmtoff = tx->tm_gmtoff; tm->tm_zone = tx->tm_zone; @@ -243,11 +245,11 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char *tzn) * Copy no more than MAXTZLEN bytes of timezone to tzn, in case it * contains an error message, which doesn't fit in the buffer */ - StrNCpy(tzn, tm->tm_zone, MAXTZLEN+1); + StrNCpy(tzn, tm->tm_zone, MAXTZLEN + 1); if (strlen(tm->tm_zone) > MAXTZLEN) elog(NOTICE, "Invalid timezone \'%s\'", tm->tm_zone); } -# elif defined(HAVE_INT_TIMEZONE) +#elif defined(HAVE_INT_TIMEZONE) if (tzp != NULL) *tzp = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL); @@ -258,12 +260,12 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char *tzn) * Copy no more than MAXTZLEN bytes of timezone to tzn, in case it * contains an error message, which doesn't fit in the buffer */ - StrNCpy(tzn, tzname[tm->tm_isdst], MAXTZLEN+1); + StrNCpy(tzn, tzname[tm->tm_isdst], MAXTZLEN + 1); if (strlen(tzname[tm->tm_isdst]) > MAXTZLEN) elog(NOTICE, "Invalid timezone \'%s\'", tzname[tm->tm_isdst]); } -# endif -#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ +#endif +#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ if (tzp != NULL) *tzp = tb.timezone * 60; @@ -470,7 +472,7 @@ AbsoluteTimeIsAfter(AbsoluteTime time1, AbsoluteTime time2) Datum abstime_finite(PG_FUNCTION_ARGS) { - AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0); + AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0); PG_RETURN_BOOL((abstime != INVALID_ABSTIME) && (abstime != NOSTART_ABSTIME) && @@ -489,8 +491,8 @@ abstime_finite(PG_FUNCTION_ARGS) Datum abstimeeq(PG_FUNCTION_ARGS) { - AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); - AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); + AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); + AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME) PG_RETURN_BOOL(false); @@ -505,8 +507,8 @@ abstimeeq(PG_FUNCTION_ARGS) Datum abstimene(PG_FUNCTION_ARGS) { - AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); - AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); + AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); + AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME) PG_RETURN_BOOL(false); @@ -521,8 +523,8 @@ abstimene(PG_FUNCTION_ARGS) Datum abstimelt(PG_FUNCTION_ARGS) { - AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); - AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); + AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); + AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME) PG_RETURN_BOOL(false); @@ -537,8 +539,8 @@ abstimelt(PG_FUNCTION_ARGS) Datum abstimegt(PG_FUNCTION_ARGS) { - AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); - AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); + AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); + AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME) PG_RETURN_BOOL(false); @@ -553,8 +555,8 @@ abstimegt(PG_FUNCTION_ARGS) Datum abstimele(PG_FUNCTION_ARGS) { - AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); - AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); + AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); + AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME) PG_RETURN_BOOL(false); @@ -569,8 +571,8 @@ abstimele(PG_FUNCTION_ARGS) Datum abstimege(PG_FUNCTION_ARGS) { - AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); - AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); + AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); + AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME) PG_RETURN_BOOL(false); @@ -596,17 +598,11 @@ timestamp_abstime(PG_FUNCTION_ARGS) *tm = &tt; if (TIMESTAMP_IS_INVALID(timestamp)) - { result = INVALID_ABSTIME; - } else if (TIMESTAMP_IS_NOBEGIN(timestamp)) - { result = NOSTART_ABSTIME; - } else if (TIMESTAMP_IS_NOEND(timestamp)) - { result = NOEND_ABSTIME; - } else { if (TIMESTAMP_IS_RELATIVE(timestamp)) @@ -615,13 +611,9 @@ timestamp_abstime(PG_FUNCTION_ARGS) result = tm2abstime(tm, 0); } else if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) == 0) - { result = tm2abstime(tm, 0); - } else - { result = INVALID_ABSTIME; - } } PG_RETURN_ABSOLUTETIME(result); @@ -633,7 +625,7 @@ timestamp_abstime(PG_FUNCTION_ARGS) Datum abstime_timestamp(PG_FUNCTION_ARGS) { - AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0); + AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0); Timestamp result; switch (abstime) @@ -677,7 +669,7 @@ abstime_timestamp(PG_FUNCTION_ARGS) Datum reltimein(PG_FUNCTION_ARGS) { - char *str = PG_GETARG_CSTRING(0); + char *str = PG_GETARG_CSTRING(0); RelativeTime result; struct tm tt, *tm = &tt; @@ -724,9 +716,7 @@ reltimeout(PG_FUNCTION_ARGS) char buf[MAXDATELEN + 1]; if (time == INVALID_RELTIME) - { strcpy(buf, INVALID_RELTIME_STR); - } else { reltime2tm(time, tm); @@ -840,12 +830,12 @@ tintervalout(PG_FUNCTION_ARGS) else { p = DatumGetCString(DirectFunctionCall1(nabstimeout, - AbsoluteTimeGetDatum(interval->data[0]))); + AbsoluteTimeGetDatum(interval->data[0]))); strcat(i_str, p); pfree(p); strcat(i_str, "\" \""); p = DatumGetCString(DirectFunctionCall1(nabstimeout, - AbsoluteTimeGetDatum(interval->data[1]))); + AbsoluteTimeGetDatum(interval->data[1]))); strcat(i_str, p); pfree(p); } @@ -868,9 +858,7 @@ interval_reltime(PG_FUNCTION_ARGS) double span; if (INTERVAL_IS_INVALID(*interval)) - { time = INVALID_RELTIME; - } else { if (interval->month == 0) @@ -965,8 +953,8 @@ mktinterval(PG_FUNCTION_ARGS) Datum timepl(PG_FUNCTION_ARGS) { - AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); - RelativeTime t2 = PG_GETARG_RELATIVETIME(1); + AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); + RelativeTime t2 = PG_GETARG_RELATIVETIME(1); if (t1 == CURRENT_ABSTIME) t1 = GetCurrentTransactionStartTime(); @@ -987,8 +975,8 @@ timepl(PG_FUNCTION_ARGS) Datum timemi(PG_FUNCTION_ARGS) { - AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); - RelativeTime t2 = PG_GETARG_RELATIVETIME(1); + AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); + RelativeTime t2 = PG_GETARG_RELATIVETIME(1); if (t1 == CURRENT_ABSTIME) t1 = GetCurrentTransactionStartTime(); @@ -1030,17 +1018,17 @@ abstimemi(AbsoluteTime t1, AbsoluteTime t2) Datum intinterval(PG_FUNCTION_ARGS) { - AbsoluteTime t = PG_GETARG_ABSOLUTETIME(0); - TimeInterval interval = PG_GETARG_TIMEINTERVAL(1); + AbsoluteTime t = PG_GETARG_ABSOLUTETIME(0); + TimeInterval interval = PG_GETARG_TIMEINTERVAL(1); if (interval->status == T_INTERVAL_VALID && t != INVALID_ABSTIME) { if (DatumGetBool(DirectFunctionCall2(abstimege, - AbsoluteTimeGetDatum(t), - AbsoluteTimeGetDatum(interval->data[0]))) && + AbsoluteTimeGetDatum(t), + AbsoluteTimeGetDatum(interval->data[0]))) && DatumGetBool(DirectFunctionCall2(abstimele, - AbsoluteTimeGetDatum(t), - AbsoluteTimeGetDatum(interval->data[1])))) + AbsoluteTimeGetDatum(t), + AbsoluteTimeGetDatum(interval->data[1])))) PG_RETURN_BOOL(true); } PG_RETURN_BOOL(false); @@ -1086,8 +1074,8 @@ timenow(PG_FUNCTION_ARGS) Datum reltimeeq(PG_FUNCTION_ARGS) { - RelativeTime t1 = PG_GETARG_RELATIVETIME(0); - RelativeTime t2 = PG_GETARG_RELATIVETIME(1); + RelativeTime t1 = PG_GETARG_RELATIVETIME(0); + RelativeTime t2 = PG_GETARG_RELATIVETIME(1); if (t1 == INVALID_RELTIME || t2 == INVALID_RELTIME) PG_RETURN_BOOL(false); @@ -1097,8 +1085,8 @@ reltimeeq(PG_FUNCTION_ARGS) Datum reltimene(PG_FUNCTION_ARGS) { - RelativeTime t1 = PG_GETARG_RELATIVETIME(0); - RelativeTime t2 = PG_GETARG_RELATIVETIME(1); + RelativeTime t1 = PG_GETARG_RELATIVETIME(0); + RelativeTime t2 = PG_GETARG_RELATIVETIME(1); if (t1 == INVALID_RELTIME || t2 == INVALID_RELTIME) PG_RETURN_BOOL(false); @@ -1108,8 +1096,8 @@ reltimene(PG_FUNCTION_ARGS) Datum reltimelt(PG_FUNCTION_ARGS) { - RelativeTime t1 = PG_GETARG_RELATIVETIME(0); - RelativeTime t2 = PG_GETARG_RELATIVETIME(1); + RelativeTime t1 = PG_GETARG_RELATIVETIME(0); + RelativeTime t2 = PG_GETARG_RELATIVETIME(1); if (t1 == INVALID_RELTIME || t2 == INVALID_RELTIME) PG_RETURN_BOOL(false); @@ -1119,8 +1107,8 @@ reltimelt(PG_FUNCTION_ARGS) Datum reltimegt(PG_FUNCTION_ARGS) { - RelativeTime t1 = PG_GETARG_RELATIVETIME(0); - RelativeTime t2 = PG_GETARG_RELATIVETIME(1); + RelativeTime t1 = PG_GETARG_RELATIVETIME(0); + RelativeTime t2 = PG_GETARG_RELATIVETIME(1); if (t1 == INVALID_RELTIME || t2 == INVALID_RELTIME) PG_RETURN_BOOL(false); @@ -1130,8 +1118,8 @@ reltimegt(PG_FUNCTION_ARGS) Datum reltimele(PG_FUNCTION_ARGS) { - RelativeTime t1 = PG_GETARG_RELATIVETIME(0); - RelativeTime t2 = PG_GETARG_RELATIVETIME(1); + RelativeTime t1 = PG_GETARG_RELATIVETIME(0); + RelativeTime t2 = PG_GETARG_RELATIVETIME(1); if (t1 == INVALID_RELTIME || t2 == INVALID_RELTIME) PG_RETURN_BOOL(false); @@ -1141,8 +1129,8 @@ reltimele(PG_FUNCTION_ARGS) Datum reltimege(PG_FUNCTION_ARGS) { - RelativeTime t1 = PG_GETARG_RELATIVETIME(0); - RelativeTime t2 = PG_GETARG_RELATIVETIME(1); + RelativeTime t1 = PG_GETARG_RELATIVETIME(0); + RelativeTime t2 = PG_GETARG_RELATIVETIME(1); if (t1 == INVALID_RELTIME || t2 == INVALID_RELTIME) PG_RETURN_BOOL(false); @@ -1157,18 +1145,18 @@ reltimege(PG_FUNCTION_ARGS) Datum tintervalsame(PG_FUNCTION_ARGS) { - TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); - TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); + TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL) PG_RETURN_BOOL(false); if (DatumGetBool(DirectFunctionCall2(abstimeeq, - AbsoluteTimeGetDatum(i1->data[0]), - AbsoluteTimeGetDatum(i2->data[0]))) && + AbsoluteTimeGetDatum(i1->data[0]), + AbsoluteTimeGetDatum(i2->data[0]))) && DatumGetBool(DirectFunctionCall2(abstimeeq, - AbsoluteTimeGetDatum(i1->data[1]), - AbsoluteTimeGetDatum(i2->data[1])))) + AbsoluteTimeGetDatum(i1->data[1]), + AbsoluteTimeGetDatum(i2->data[1])))) PG_RETURN_BOOL(true); PG_RETURN_BOOL(false); } @@ -1181,8 +1169,8 @@ tintervalsame(PG_FUNCTION_ARGS) Datum tintervaleq(PG_FUNCTION_ARGS) { - TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); - TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); + TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); AbsoluteTime t10, t11, t20, @@ -1215,8 +1203,8 @@ tintervaleq(PG_FUNCTION_ARGS) Datum tintervalne(PG_FUNCTION_ARGS) { - TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); - TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); + TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); AbsoluteTime t10, t11, t20, @@ -1249,8 +1237,8 @@ tintervalne(PG_FUNCTION_ARGS) Datum tintervallt(PG_FUNCTION_ARGS) { - TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); - TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); + TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); AbsoluteTime t10, t11, t20, @@ -1283,8 +1271,8 @@ tintervallt(PG_FUNCTION_ARGS) Datum tintervalle(PG_FUNCTION_ARGS) { - TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); - TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); + TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); AbsoluteTime t10, t11, t20, @@ -1317,8 +1305,8 @@ tintervalle(PG_FUNCTION_ARGS) Datum tintervalgt(PG_FUNCTION_ARGS) { - TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); - TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); + TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); AbsoluteTime t10, t11, t20, @@ -1351,8 +1339,8 @@ tintervalgt(PG_FUNCTION_ARGS) Datum tintervalge(PG_FUNCTION_ARGS) { - TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); - TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); + TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); AbsoluteTime t10, t11, t20, @@ -1407,7 +1395,7 @@ tintervalleneq(PG_FUNCTION_ARGS) if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME) PG_RETURN_BOOL(false); rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel, - TimeIntervalGetDatum(i))); + TimeIntervalGetDatum(i))); PG_RETURN_BOOL(rt != INVALID_RELTIME && rt == t); } @@ -1421,7 +1409,7 @@ tintervallenne(PG_FUNCTION_ARGS) if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME) PG_RETURN_BOOL(false); rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel, - TimeIntervalGetDatum(i))); + TimeIntervalGetDatum(i))); PG_RETURN_BOOL(rt != INVALID_RELTIME && rt != t); } @@ -1435,7 +1423,7 @@ tintervallenlt(PG_FUNCTION_ARGS) if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME) PG_RETURN_BOOL(false); rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel, - TimeIntervalGetDatum(i))); + TimeIntervalGetDatum(i))); PG_RETURN_BOOL(rt != INVALID_RELTIME && rt < t); } @@ -1449,7 +1437,7 @@ tintervallengt(PG_FUNCTION_ARGS) if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME) PG_RETURN_BOOL(false); rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel, - TimeIntervalGetDatum(i))); + TimeIntervalGetDatum(i))); PG_RETURN_BOOL(rt != INVALID_RELTIME && rt > t); } @@ -1463,7 +1451,7 @@ tintervallenle(PG_FUNCTION_ARGS) if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME) PG_RETURN_BOOL(false); rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel, - TimeIntervalGetDatum(i))); + TimeIntervalGetDatum(i))); PG_RETURN_BOOL(rt != INVALID_RELTIME && rt <= t); } @@ -1477,7 +1465,7 @@ tintervallenge(PG_FUNCTION_ARGS) if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME) PG_RETURN_BOOL(false); rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel, - TimeIntervalGetDatum(i))); + TimeIntervalGetDatum(i))); PG_RETURN_BOOL(rt != INVALID_RELTIME && rt >= t); } @@ -1487,17 +1475,17 @@ tintervallenge(PG_FUNCTION_ARGS) Datum tintervalct(PG_FUNCTION_ARGS) { - TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); - TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); + TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL) PG_RETURN_BOOL(false); if (DatumGetBool(DirectFunctionCall2(abstimele, - AbsoluteTimeGetDatum(i1->data[0]), - AbsoluteTimeGetDatum(i2->data[0]))) && + AbsoluteTimeGetDatum(i1->data[0]), + AbsoluteTimeGetDatum(i2->data[0]))) && DatumGetBool(DirectFunctionCall2(abstimege, - AbsoluteTimeGetDatum(i1->data[1]), - AbsoluteTimeGetDatum(i2->data[1])))) + AbsoluteTimeGetDatum(i1->data[1]), + AbsoluteTimeGetDatum(i2->data[1])))) PG_RETURN_BOOL(true); PG_RETURN_BOOL(false); } @@ -1508,17 +1496,17 @@ tintervalct(PG_FUNCTION_ARGS) Datum tintervalov(PG_FUNCTION_ARGS) { - TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); - TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); + TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL) PG_RETURN_BOOL(false); if (DatumGetBool(DirectFunctionCall2(abstimelt, - AbsoluteTimeGetDatum(i1->data[1]), - AbsoluteTimeGetDatum(i2->data[0]))) || + AbsoluteTimeGetDatum(i1->data[1]), + AbsoluteTimeGetDatum(i2->data[0]))) || DatumGetBool(DirectFunctionCall2(abstimegt, - AbsoluteTimeGetDatum(i1->data[0]), - AbsoluteTimeGetDatum(i2->data[1])))) + AbsoluteTimeGetDatum(i1->data[0]), + AbsoluteTimeGetDatum(i2->data[1])))) PG_RETURN_BOOL(false); PG_RETURN_BOOL(true); } @@ -1529,7 +1517,7 @@ tintervalov(PG_FUNCTION_ARGS) Datum tintervalstart(PG_FUNCTION_ARGS) { - TimeInterval i = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i = PG_GETARG_TIMEINTERVAL(0); if (i->status == T_INTERVAL_INVAL) PG_RETURN_ABSOLUTETIME(INVALID_ABSTIME); @@ -1542,7 +1530,7 @@ tintervalstart(PG_FUNCTION_ARGS) Datum tintervalend(PG_FUNCTION_ARGS) { - TimeInterval i = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i = PG_GETARG_TIMEINTERVAL(0); if (i->status == T_INTERVAL_INVAL) PG_RETURN_ABSOLUTETIME(INVALID_ABSTIME); @@ -1835,7 +1823,7 @@ istinterval(char *i_string, } /* get the first date */ *i_start = DatumGetAbsoluteTime(DirectFunctionCall1(nabstimein, - CStringGetDatum(p))); + CStringGetDatum(p))); /* rechange NULL at the end of the first date to a "'" */ *p1 = '"'; p = ++p1; @@ -1863,7 +1851,7 @@ istinterval(char *i_string, } /* get the second date */ *i_end = DatumGetAbsoluteTime(DirectFunctionCall1(nabstimein, - CStringGetDatum(p))); + CStringGetDatum(p))); /* rechange NULL at the end of the first date to a ''' */ *p1 = '"'; p = ++p1; diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c index 97e0825adf8..56bc534c230 100644 --- a/src/backend/utils/adt/network.c +++ b/src/backend/utils/adt/network.c @@ -3,7 +3,7 @@ * is for IP V4 CIDR notation, but prepared for V6: just * add the necessary bits where the comments indicate. * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/network.c,v 1.28 2000/12/22 18:00:20 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/network.c,v 1.29 2001/03/22 03:59:52 momjian Exp $ * * Jon Postel RIP 16 Oct 1998 */ @@ -21,7 +21,7 @@ static int32 network_cmp_internal(inet *a1, inet *a2); -static int v4bitncmp(unsigned long a1, unsigned long a2, int bits); +static int v4bitncmp(unsigned long a1, unsigned long a2, int bits); static bool v4addressOK(unsigned long a1, int bits); /* @@ -66,12 +66,12 @@ network_in(char *src, int type) } /* - * Error check: CIDR values must not have any bits set beyond the masklen. - * XXX this code is not IPV6 ready. + * Error check: CIDR values must not have any bits set beyond the + * masklen. XXX this code is not IPV6 ready. */ if (type) { - if (! v4addressOK(ip_v4addr(dst), bits)) + if (!v4addressOK(ip_v4addr(dst), bits)) elog(ERROR, "invalid CIDR value '%s': has bits set to right of mask", src); } @@ -116,7 +116,9 @@ inet_out(PG_FUNCTION_ARGS) if (ip_family(src) == AF_INET) { /* It's an IP V4 address: */ - /* Use inet style for both inet and cidr, since we don't want + + /* + * Use inet style for both inet and cidr, since we don't want * abbreviated CIDR style here. */ dst = inet_net_ntop(AF_INET, &ip_v4addr(src), ip_bits(src), @@ -162,7 +164,7 @@ network_cmp_internal(inet *a1, inet *a2) { if (ip_family(a1) == AF_INET && ip_family(a2) == AF_INET) { - int order; + int order; order = v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), Min(ip_bits(a1), ip_bits(a2))); @@ -260,7 +262,7 @@ network_sub(PG_FUNCTION_ARGS) if ((ip_family(a1) == AF_INET) && (ip_family(a2) == AF_INET)) { PG_RETURN_BOOL(ip_bits(a1) > ip_bits(a2) - && v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a2)) == 0); + && v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a2)) == 0); } else { @@ -280,7 +282,7 @@ network_subeq(PG_FUNCTION_ARGS) if ((ip_family(a1) == AF_INET) && (ip_family(a2) == AF_INET)) { PG_RETURN_BOOL(ip_bits(a1) >= ip_bits(a2) - && v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a2)) == 0); + && v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a2)) == 0); } else { @@ -300,7 +302,7 @@ network_sup(PG_FUNCTION_ARGS) if ((ip_family(a1) == AF_INET) && (ip_family(a2) == AF_INET)) { PG_RETURN_BOOL(ip_bits(a1) < ip_bits(a2) - && v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a1)) == 0); + && v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a1)) == 0); } else { @@ -320,7 +322,7 @@ network_supeq(PG_FUNCTION_ARGS) if ((ip_family(a1) == AF_INET) && (ip_family(a2) == AF_INET)) { PG_RETURN_BOOL(ip_bits(a1) <= ip_bits(a2) - && v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a1)) == 0); + && v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a1)) == 0); } else { @@ -456,8 +458,9 @@ network_broadcast(PG_FUNCTION_ARGS) /* It's an IP V4 address: */ unsigned long mask = 0xffffffff; - /* Shifting by 32 or more bits does not yield portable results, - * so don't try it. + /* + * Shifting by 32 or more bits does not yield portable results, so + * don't try it. */ if (ip_bits(ip) < 32) mask >>= ip_bits(ip); @@ -495,8 +498,9 @@ network_network(PG_FUNCTION_ARGS) /* It's an IP V4 address: */ unsigned long mask = 0xffffffff; - /* Shifting by 32 or more bits does not yield portable results, - * so don't try it. + /* + * Shifting by 32 or more bits does not yield portable results, so + * don't try it. */ if (ip_bits(ip) > 0) mask <<= (32 - ip_bits(ip)); @@ -534,8 +538,9 @@ network_netmask(PG_FUNCTION_ARGS) /* It's an IP V4 address: */ unsigned long mask = 0xffffffff; - /* Shifting by 32 or more bits does not yield portable results, - * so don't try it. + /* + * Shifting by 32 or more bits does not yield portable results, so + * don't try it. */ if (ip_bits(ip) > 0) mask <<= (32 - ip_bits(ip)); @@ -568,8 +573,9 @@ v4bitncmp(unsigned long a1, unsigned long a2, int bits) { unsigned long mask; - /* Shifting by 32 or more bits does not yield portable results, - * so don't try it. + /* + * Shifting by 32 or more bits does not yield portable results, so + * don't try it. */ if (bits > 0) mask = (0xFFFFFFFFL << (32 - bits)) & 0xFFFFFFFFL; @@ -592,8 +598,9 @@ v4addressOK(unsigned long a1, int bits) { unsigned long mask; - /* Shifting by 32 or more bits does not yield portable results, - * so don't try it. + /* + * Shifting by 32 or more bits does not yield portable results, so + * don't try it. */ if (bits > 0) mask = (0xFFFFFFFFL << (32 - bits)) & 0xFFFFFFFFL; diff --git a/src/backend/utils/adt/not_in.c b/src/backend/utils/adt/not_in.c index 450cfb2484a..ac596b1f123 100644 --- a/src/backend/utils/adt/not_in.c +++ b/src/backend/utils/adt/not_in.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.25 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.26 2001/03/22 03:59:52 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -55,7 +55,7 @@ int4notin(PG_FUNCTION_ARGS) /* make a null-terminated copy of text */ strlength = VARSIZE(relation_and_attr) - VARHDRSZ; if (strlength >= sizeof(my_copy)) - strlength = sizeof(my_copy)-1; + strlength = sizeof(my_copy) - 1; memcpy(my_copy, VARDATA(relation_and_attr), strlength); my_copy[strlength] = '\0'; @@ -110,8 +110,10 @@ Datum oidnotin(PG_FUNCTION_ARGS) { Oid the_oid = PG_GETARG_OID(0); + #ifdef NOT_USED text *relation_and_attr = PG_GETARG_TEXT_P(1); + #endif if (the_oid == InvalidOid) diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c index d18d3003a08..4a16741bb91 100644 --- a/src/backend/utils/adt/numeric.c +++ b/src/backend/utils/adt/numeric.c @@ -5,7 +5,7 @@ * * 1998 Jan Wieck * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.37 2001/03/14 16:50:37 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.38 2001/03/22 03:59:52 momjian Exp $ * * ---------- */ @@ -192,8 +192,10 @@ Datum numeric_in(PG_FUNCTION_ARGS) { char *str = PG_GETARG_CSTRING(0); + #ifdef NOT_USED Oid typelem = PG_GETARG_OID(1); + #endif int32 typmod = PG_GETARG_INT32(2); NumericVar value; @@ -1865,8 +1867,8 @@ do_numeric_accum(ArrayType *transarray, Numeric newval) NumericGetDatum(newval)); sumX2 = DirectFunctionCall2(numeric_add, sumX2, DirectFunctionCall2(numeric_mul, - NumericGetDatum(newval), - NumericGetDatum(newval))); + NumericGetDatum(newval), + NumericGetDatum(newval))); transdatums[0] = N; transdatums[1] = sumX; @@ -2011,8 +2013,8 @@ numeric_variance(PG_FUNCTION_ARGS) mul_var(&vsumX, &vsumX, &vsumX); /* now vsumX contains sumX * sumX */ mul_var(&vN, &vsumX2, &vsumX2); /* now vsumX2 contains N * sumX2 */ sub_var(&vsumX2, &vsumX, &vsumX2); /* N * sumX2 - sumX * sumX */ - mul_var(&vN, &vNminus1, &vNminus1); /* N * (N - 1) */ - div_var(&vsumX2, &vNminus1, &vsumX); /* variance */ + mul_var(&vN, &vNminus1, &vNminus1); /* N * (N - 1) */ + div_var(&vsumX2, &vNminus1, &vsumX); /* variance */ res = make_result(&vsumX); @@ -2078,9 +2080,9 @@ numeric_stddev(PG_FUNCTION_ARGS) mul_var(&vsumX, &vsumX, &vsumX); /* now vsumX contains sumX * sumX */ mul_var(&vN, &vsumX2, &vsumX2); /* now vsumX2 contains N * sumX2 */ sub_var(&vsumX2, &vsumX, &vsumX2); /* N * sumX2 - sumX * sumX */ - mul_var(&vN, &vNminus1, &vNminus1); /* N * (N - 1) */ - div_var(&vsumX2, &vNminus1, &vsumX); /* variance */ - sqrt_var(&vsumX, &vsumX); /* stddev */ + mul_var(&vN, &vNminus1, &vNminus1); /* N * (N - 1) */ + div_var(&vsumX2, &vNminus1, &vsumX); /* variance */ + sqrt_var(&vsumX, &vsumX); /* stddev */ res = make_result(&vsumX); @@ -2096,9 +2098,9 @@ numeric_stddev(PG_FUNCTION_ARGS) /* * SUM transition functions for integer datatypes. * - * We use a Numeric accumulator to avoid overflow. Because SQL92 defines + * We use a Numeric accumulator to avoid overflow. Because SQL92 defines * the SUM() of no values to be NULL, not zero, the initial condition of - * the transition data value needs to be NULL. This means we can't rely + * the transition data value needs to be NULL. This means we can't rely * on ExecAgg to automatically insert the first non-null data value into * the transition data: it doesn't know how to do the type conversion. * The upshot is that these routines have to be marked non-strict and @@ -3563,7 +3565,7 @@ exp_var(NumericVar *arg, NumericVar *result) set_var_from_var(&const_one, &ifac); set_var_from_var(&const_one, &ni); - for (i = 2; ; i++) + for (i = 2;; i++) { add_var(&ni, &const_one, &ni); mul_var(&xpow, &x, &xpow); @@ -3647,7 +3649,7 @@ ln_var(NumericVar *arg, NumericVar *result) set_var_from_var(&const_one, &ni); - for (i = 2; ; i++) + for (i = 2;; i++) { add_var(&ni, &const_two, &ni); mul_var(&xx, &x, &xx); @@ -3820,6 +3822,7 @@ add_abs(NumericVar *var1, NumericVar *var2, NumericVar *result) i1, i2; int carry = 0; + /* copy these values into local vars for speed in inner loop */ int var1ndigits = var1->ndigits; int var2ndigits = var2->ndigits; @@ -3906,6 +3909,7 @@ sub_abs(NumericVar *var1, NumericVar *var2, NumericVar *result) i1, i2; int borrow = 0; + /* copy these values into local vars for speed in inner loop */ int var1ndigits = var1->ndigits; int var2ndigits = var2->ndigits; diff --git a/src/backend/utils/adt/numutils.c b/src/backend/utils/adt/numutils.c index 11e779d45d6..92af2ab56cf 100644 --- a/src/backend/utils/adt/numutils.c +++ b/src/backend/utils/adt/numutils.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.44 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.45 2001/03/22 03:59:52 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -63,11 +63,11 @@ pg_atoi(char *s, int size, int c) l = (long) 0; else l = strtol(s, &badp, 10); + /* - * strtol() normally only sets ERANGE. On some systems it also - * may set EINVAL, which simply means it couldn't parse the - * input string. This is handled by the second "if" consistent - * across platforms. + * strtol() normally only sets ERANGE. On some systems it also may + * set EINVAL, which simply means it couldn't parse the input string. + * This is handled by the second "if" consistent across platforms. */ if (errno && errno != EINVAL) elog(ERROR, "pg_atoi: error reading \"%s\": %m", s); diff --git a/src/backend/utils/adt/oid.c b/src/backend/utils/adt/oid.c index 0cb4ea1a0a2..91dbf6c54eb 100644 --- a/src/backend/utils/adt/oid.c +++ b/src/backend/utils/adt/oid.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.44 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.45 2001/03/22 03:59:52 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -36,11 +36,11 @@ oidin_subr(const char *funcname, const char *s, char **endloc) cvt = strtoul(s, &endptr, 10); /* - * strtoul() normally only sets ERANGE. On some systems it also - * may set EINVAL, which simply means it couldn't parse the - * input string. This is handled by the second "if" consistent - * across platforms. Note that for historical reasons we accept - * an empty string as meaning 0. + * strtoul() normally only sets ERANGE. On some systems it also may + * set EINVAL, which simply means it couldn't parse the input string. + * This is handled by the second "if" consistent across platforms. + * Note that for historical reasons we accept an empty string as + * meaning 0. */ if (errno && errno != EINVAL) elog(ERROR, "%s: error reading \"%s\": %m", @@ -67,21 +67,20 @@ oidin_subr(const char *funcname, const char *s, char **endloc) result = (Oid) cvt; /* - * Cope with possibility that unsigned long is wider than Oid, - * in which case strtoul will not raise an error for some values - * that are out of the range of Oid. + * Cope with possibility that unsigned long is wider than Oid, in + * which case strtoul will not raise an error for some values that are + * out of the range of Oid. * - * For backwards compatibility, we want to accept inputs that - * are given with a minus sign, so allow the input value if it - * matches after either signed or unsigned extension to long. + * For backwards compatibility, we want to accept inputs that are given + * with a minus sign, so allow the input value if it matches after + * either signed or unsigned extension to long. * - * To ensure consistent results on 32-bit and 64-bit platforms, - * make sure the error message is the same as if strtoul() had - * returned ERANGE. + * To ensure consistent results on 32-bit and 64-bit platforms, make sure + * the error message is the same as if strtoul() had returned ERANGE. */ #if OID_MAX != ULONG_MAX if (cvt != (unsigned long) result && - cvt != (unsigned long) ((int) result)) + cvt != (unsigned long) ((int) result)) elog(ERROR, "%s: error reading \"%s\": %s", funcname, s, strerror(ERANGE)); #endif @@ -235,8 +234,8 @@ oidgt(PG_FUNCTION_ARGS) Datum oidvectoreq(PG_FUNCTION_ARGS) { - Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); - Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); + Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); + Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); PG_RETURN_BOOL(memcmp(arg1, arg2, INDEX_MAX_KEYS * sizeof(Oid)) == 0); } @@ -244,8 +243,8 @@ oidvectoreq(PG_FUNCTION_ARGS) Datum oidvectorne(PG_FUNCTION_ARGS) { - Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); - Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); + Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); + Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); PG_RETURN_BOOL(memcmp(arg1, arg2, INDEX_MAX_KEYS * sizeof(Oid)) != 0); } @@ -253,8 +252,8 @@ oidvectorne(PG_FUNCTION_ARGS) Datum oidvectorlt(PG_FUNCTION_ARGS) { - Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); - Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); + Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); + Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); int i; for (i = 0; i < INDEX_MAX_KEYS; i++) @@ -266,8 +265,8 @@ oidvectorlt(PG_FUNCTION_ARGS) Datum oidvectorle(PG_FUNCTION_ARGS) { - Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); - Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); + Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); + Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); int i; for (i = 0; i < INDEX_MAX_KEYS; i++) @@ -279,8 +278,8 @@ oidvectorle(PG_FUNCTION_ARGS) Datum oidvectorge(PG_FUNCTION_ARGS) { - Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); - Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); + Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); + Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); int i; for (i = 0; i < INDEX_MAX_KEYS; i++) @@ -292,8 +291,8 @@ oidvectorge(PG_FUNCTION_ARGS) Datum oidvectorgt(PG_FUNCTION_ARGS) { - Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); - Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); + Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); + Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); int i; for (i = 0; i < INDEX_MAX_KEYS; i++) diff --git a/src/backend/utils/adt/oracle_compat.c b/src/backend/utils/adt/oracle_compat.c index 5a83c56687f..b91230b1f0a 100644 --- a/src/backend/utils/adt/oracle_compat.c +++ b/src/backend/utils/adt/oracle_compat.c @@ -1,7 +1,7 @@ /* * Edmund Mergl <E.Mergl@bawue.de> * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.30 2000/12/07 23:22:56 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.31 2001/03/22 03:59:52 momjian Exp $ * */ @@ -596,8 +596,8 @@ ascii(PG_FUNCTION_ARGS) Datum chr(PG_FUNCTION_ARGS) { - int32 cvalue = PG_GETARG_INT32(0); - text *result; + int32 cvalue = PG_GETARG_INT32(0); + text *result; result = (text *) palloc(VARHDRSZ + 1); VARATT_SIZEP(result) = VARHDRSZ + 1; @@ -616,20 +616,20 @@ chr(PG_FUNCTION_ARGS) * * Purpose: * - * Repeat string by val. + * Repeat string by val. * ********************************************************************/ Datum repeat(PG_FUNCTION_ARGS) { - text *string = PG_GETARG_TEXT_P(0); - int32 count = PG_GETARG_INT32(1); - text *result; - int slen, - tlen; - int i; - char *cp; + text *string = PG_GETARG_TEXT_P(0); + int32 count = PG_GETARG_INT32(1); + text *result; + int slen, + tlen; + int i; + char *cp; if (count < 0) count = 0; diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index 6d30a53edcb..faa81cd09af 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -4,7 +4,7 @@ * The PostgreSQL locale utils. * * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_locale.c,v 1.8 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_locale.c,v 1.9 2001/03/22 03:59:52 momjian Exp $ * * Portions Copyright (c) 1999-2000, PostgreSQL Global Development Group * @@ -68,7 +68,7 @@ PGLC_debug_lc(PG_LocaleCategories * lc) lc->lc_collate, lc->lc_monetary #ifdef LC_MESSAGES - , lc->lc_messages + ,lc->lc_messages #endif ); } @@ -116,7 +116,7 @@ PGLC_setlocale(PG_LocaleCategories * lc) /*------ * Return the POSIX lconv struct (contains number/money formatting information) - * with locale information for all categories. Note that returned lconv + * with locale information for all categories. Note that returned lconv * does not depend on currently active category settings, but on external * environment variables for locale. * diff --git a/src/backend/utils/adt/pg_lzcompress.c b/src/backend/utils/adt/pg_lzcompress.c index fc93031b521..f548775ad2f 100644 --- a/src/backend/utils/adt/pg_lzcompress.c +++ b/src/backend/utils/adt/pg_lzcompress.c @@ -1,7 +1,7 @@ /* ---------- * pg_lzcompress.c - * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_lzcompress.c,v 1.9 2000/10/03 03:11:20 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_lzcompress.c,v 1.10 2001/03/22 03:59:52 momjian Exp $ * * This is an implementation of LZ compression for PostgreSQL. * It uses a simple history table and generates 2-3 byte tags @@ -120,7 +120,7 @@ * 8 times the size of the input!). * * The compressor creates a table for 8192 lists of positions. - * For each input position (except the last 3), a hash key is + * For each input position (except the last 3), a hash key is * built from the 4 next input bytes and the posiiton remembered * in the appropriate list. Thus, the table points to linked * lists of likely to be at least in the first 4 characters @@ -152,7 +152,7 @@ * * - a match >= good_match is found * - there are no more history entries to look at - * - the next history entry is already too far back + * - the next history entry is already too far back * to be coded into a tag. * * Finally the match algorithm checks that at least a match @@ -286,18 +286,18 @@ static PGLZ_HistEntry hist_entries[PGLZ_HISTORY_SIZE]; #define pglz_hist_add(_hs,_he,_hn,_s,_e) { \ int __hindex = pglz_hist_idx((_s),(_e)); \ if ((_he)[(_hn)].prev == NULL) { \ - (_hs)[__hindex] = (_he)[(_hn)].next; \ + (_hs)[__hindex] = (_he)[(_hn)].next; \ } else { \ - (_he)[(_hn)].prev->next = (_he)[(_hn)].next; \ + (_he)[(_hn)].prev->next = (_he)[(_hn)].next; \ } \ if ((_he)[(_hn)].next != NULL) { \ - (_he)[(_hn)].next->prev = (_he)[(_hn)].prev; \ + (_he)[(_hn)].next->prev = (_he)[(_hn)].prev; \ } \ (_he)[(_hn)].next = (_hs)[__hindex]; \ (_he)[(_hn)].prev = NULL; \ (_he)[(_hn)].pos = (_s); \ if ((_hs)[__hindex] != NULL) { \ - (_hs)[__hindex]->prev = &((_he)[(_hn)]); \ + (_hs)[__hindex]->prev = &((_he)[(_hn)]); \ } \ (_hs)[__hindex] = &((_he)[(_hn)]); \ if (++(_hn) >= PGLZ_HISTORY_SIZE) { \ @@ -476,7 +476,7 @@ pglz_find_match(PGLZ_HistEntry **hstart, char *input, char *end, int pglz_compress(char *source, int32 slen, PGLZ_Header *dest, PGLZ_Strategy *strategy) { - int hist_next = 0; + int hist_next = 0; unsigned char *bp = ((unsigned char *) dest) + sizeof(PGLZ_Header); unsigned char *bstart = bp; diff --git a/src/backend/utils/adt/quote.c b/src/backend/utils/adt/quote.c index 02aaac74134..10999150a21 100644 --- a/src/backend/utils/adt/quote.c +++ b/src/backend/utils/adt/quote.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/quote.c,v 1.3 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/quote.c,v 1.4 2001/03/22 03:59:53 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -35,12 +35,10 @@ quote_ident(PG_FUNCTION_ARGS) text *result; if (quote_ident_required(t)) - { - result = do_quote_ident(t); - } + result = do_quote_ident(t); else { - result = (text *)palloc(VARSIZE(t)); + result = (text *) palloc(VARSIZE(t)); memcpy(result, t, VARSIZE(t)); } @@ -79,23 +77,26 @@ quote_literal(PG_FUNCTION_ARGS) static bool quote_ident_required(text *iptr) { - char *cp; - char *ep; + char *cp; + char *ep; cp = VARDATA(iptr); - ep = VARDATA(iptr) + VARSIZE(iptr) - VARHDRSZ; + ep = VARDATA(iptr) + VARSIZE(iptr) - VARHDRSZ; if (cp >= ep) return true; - if (!(*cp == '_' || (*cp >= 'a' && *cp <= 'z'))) + if (!(*cp == '_' || (*cp >= 'a' && *cp <= 'z'))) return true; - while((++cp) < ep) + while ((++cp) < ep) { - if (*cp >= 'a' && *cp <= 'z') continue; - if (*cp >= '0' && *cp <= '9') continue; - if (*cp == '_') continue; + if (*cp >= 'a' && *cp <= 'z') + continue; + if (*cp >= '0' && *cp <= '9') + continue; + if (*cp == '_') + continue; return true; } @@ -107,29 +108,29 @@ quote_ident_required(text *iptr) static text * do_quote_ident(text *iptr) { - text *result; - char *cp1; - char *cp2; - int len; + text *result; + char *cp1; + char *cp2; + int len; - len = VARSIZE(iptr) - VARHDRSZ; - result = (text *)palloc(len * 2 + VARHDRSZ + 2); + len = VARSIZE(iptr) - VARHDRSZ; + result = (text *) palloc(len * 2 + VARHDRSZ + 2); cp1 = VARDATA(iptr); cp2 = VARDATA(result); *cp2++ = '"'; - while(len-- > 0) + while (len-- > 0) { - if (*cp1 == '"') + if (*cp1 == '"') *cp2++ = '"'; - if (*cp1 == '\\') + if (*cp1 == '\\') *cp2++ = '\\'; - *cp2++ = *cp1++; + *cp2++ = *cp1++; } *cp2++ = '"'; - VARATT_SIZEP(result) = cp2 - ((char *)result); + VARATT_SIZEP(result) = cp2 - ((char *) result); return result; } @@ -138,29 +139,29 @@ do_quote_ident(text *iptr) static text * do_quote_literal(text *lptr) { - text *result; - char *cp1; - char *cp2; - int len; + text *result; + char *cp1; + char *cp2; + int len; - len = VARSIZE(lptr) - VARHDRSZ; - result = (text *)palloc(len * 2 + VARHDRSZ + 2); + len = VARSIZE(lptr) - VARHDRSZ; + result = (text *) palloc(len * 2 + VARHDRSZ + 2); cp1 = VARDATA(lptr); cp2 = VARDATA(result); *cp2++ = '\''; - while(len-- > 0) + while (len-- > 0) { - if (*cp1 == '\'') + if (*cp1 == '\'') *cp2++ = '\''; - if (*cp1 == '\\') + if (*cp1 == '\\') *cp2++ = '\\'; - *cp2++ = *cp1++; + *cp2++ = *cp1++; } *cp2++ = '\''; - VARATT_SIZEP(result) = cp2 - ((char *)result); + VARATT_SIZEP(result) = cp2 - ((char *) result); return result; } @@ -171,28 +172,31 @@ do_quote_literal(text *lptr) static bool quote_ident_required(text *iptr) { - char *cp; - char *ep; + char *cp; + char *ep; cp = VARDATA(iptr); - ep = VARDATA(iptr) + VARSIZE(iptr) - VARHDRSZ; + ep = VARDATA(iptr) + VARSIZE(iptr) - VARHDRSZ; if (cp >= ep) return true; - if(pg_mblen(cp) != 1) + if (pg_mblen(cp) != 1) return true; - if (!(*cp == '_' || (*cp >= 'a' && *cp <= 'z'))) + if (!(*cp == '_' || (*cp >= 'a' && *cp <= 'z'))) return true; - while((++cp) < ep) + while ((++cp) < ep) { if (pg_mblen(cp) != 1) return true; - if (*cp >= 'a' && *cp <= 'z') continue; - if (*cp >= '0' && *cp <= '9') continue; - if (*cp == '_') continue; + if (*cp >= 'a' && *cp <= 'z') + continue; + if (*cp >= '0' && *cp <= '9') + continue; + if (*cp == '_') + continue; return true; } @@ -204,41 +208,41 @@ quote_ident_required(text *iptr) static text * do_quote_ident(text *iptr) { - text *result; - char *cp1; - char *cp2; - int len; - int wl; + text *result; + char *cp1; + char *cp2; + int len; + int wl; - len = VARSIZE(iptr) - VARHDRSZ; - result = (text *)palloc(len * 2 + VARHDRSZ + 2); + len = VARSIZE(iptr) - VARHDRSZ; + result = (text *) palloc(len * 2 + VARHDRSZ + 2); cp1 = VARDATA(iptr); cp2 = VARDATA(result); *cp2++ = '"'; - while(len > 0) + while (len > 0) { if ((wl = pg_mblen(cp1)) != 1) { len -= wl; - while(wl-- > 0) + while (wl-- > 0) *cp2++ = *cp1++; continue; } - if (*cp1 == '"') + if (*cp1 == '"') *cp2++ = '"'; - if (*cp1 == '\\') + if (*cp1 == '\\') *cp2++ = '\\'; - *cp2++ = *cp1++; + *cp2++ = *cp1++; len--; } *cp2++ = '"'; - VARATT_SIZEP(result) = cp2 - ((char *)result); + VARATT_SIZEP(result) = cp2 - ((char *) result); return result; } @@ -247,45 +251,43 @@ do_quote_ident(text *iptr) static text * do_quote_literal(text *lptr) { - text *result; - char *cp1; - char *cp2; - int len; - int wl; + text *result; + char *cp1; + char *cp2; + int len; + int wl; - len = VARSIZE(lptr) - VARHDRSZ; - result = (text *)palloc(len * 2 + VARHDRSZ + 2); + len = VARSIZE(lptr) - VARHDRSZ; + result = (text *) palloc(len * 2 + VARHDRSZ + 2); cp1 = VARDATA(lptr); cp2 = VARDATA(result); *cp2++ = '\''; - while(len > 0) + while (len > 0) { if ((wl = pg_mblen(cp1)) != 1) { len -= wl; - while(wl-- > 0) + while (wl-- > 0) *cp2++ = *cp1++; continue; } - if (*cp1 == '\'') + if (*cp1 == '\'') *cp2++ = '\''; - if (*cp1 == '\\') + if (*cp1 == '\\') *cp2++ = '\\'; - *cp2++ = *cp1++; + *cp2++ = *cp1++; len--; } *cp2++ = '\''; - VARATT_SIZEP(result) = cp2 - ((char *)result); + VARATT_SIZEP(result) = cp2 - ((char *) result); return result; } #endif - - diff --git a/src/backend/utils/adt/regexp.c b/src/backend/utils/adt/regexp.c index b55cb3b42e7..146ae742636 100644 --- a/src/backend/utils/adt/regexp.c +++ b/src/backend/utils/adt/regexp.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.35 2001/03/19 22:27:46 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.36 2001/03/22 03:59:53 momjian Exp $ * * Alistair Crooks added the code for the regex caching * agc - cached the regular expressions used - there's a good chance @@ -121,6 +121,7 @@ RE_compile_and_execute(text *text_re, char *text, int cflags) regcomp_result = pg95_regcomp(&rev[oldest].cre_re, re, cflags); if (regcomp_result == 0) { + /* * use malloc/free for the cre_s field because the storage has to * persist across transactions @@ -197,10 +198,10 @@ nameregexne(PG_FUNCTION_ARGS) Name n = PG_GETARG_NAME(0); text *p = PG_GETARG_TEXT_P(1); - PG_RETURN_BOOL(! fixedlen_regexeq(NameStr(*n), - p, - strlen(NameStr(*n)), - REG_EXTENDED)); + PG_RETURN_BOOL(!fixedlen_regexeq(NameStr(*n), + p, + strlen(NameStr(*n)), + REG_EXTENDED)); } Datum @@ -221,15 +222,15 @@ textregexne(PG_FUNCTION_ARGS) text *s = PG_GETARG_TEXT_P(0); text *p = PG_GETARG_TEXT_P(1); - PG_RETURN_BOOL(! fixedlen_regexeq(VARDATA(s), - p, - VARSIZE(s) - VARHDRSZ, - REG_EXTENDED)); + PG_RETURN_BOOL(!fixedlen_regexeq(VARDATA(s), + p, + VARSIZE(s) - VARHDRSZ, + REG_EXTENDED)); } /* - * routines that use the regexp stuff, but ignore the case. + * routines that use the regexp stuff, but ignore the case. * for this, we use the REG_ICASE flag to pg95_regcomp */ @@ -252,10 +253,10 @@ texticregexne(PG_FUNCTION_ARGS) text *s = PG_GETARG_TEXT_P(0); text *p = PG_GETARG_TEXT_P(1); - PG_RETURN_BOOL(! fixedlen_regexeq(VARDATA(s), - p, - VARSIZE(s) - VARHDRSZ, - REG_ICASE | REG_EXTENDED)); + PG_RETURN_BOOL(!fixedlen_regexeq(VARDATA(s), + p, + VARSIZE(s) - VARHDRSZ, + REG_ICASE | REG_EXTENDED)); } Datum @@ -276,8 +277,8 @@ nameicregexne(PG_FUNCTION_ARGS) Name n = PG_GETARG_NAME(0); text *p = PG_GETARG_TEXT_P(1); - PG_RETURN_BOOL(! fixedlen_regexeq(NameStr(*n), - p, - strlen(NameStr(*n)), - REG_ICASE | REG_EXTENDED)); + PG_RETURN_BOOL(!fixedlen_regexeq(NameStr(*n), + p, + strlen(NameStr(*n)), + REG_ICASE | REG_EXTENDED)); } diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c index 6a772ee1b71..1f3abde5f11 100644 --- a/src/backend/utils/adt/regproc.c +++ b/src/backend/utils/adt/regproc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.60 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.61 2001/03/22 03:59:53 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -58,7 +58,7 @@ regprocin(PG_FUNCTION_ARGS) result = (RegProcedure) GetSysCacheOid(PROCOID, DirectFunctionCall1(oidin, - CStringGetDatum(pro_name_or_oid)), + CStringGetDatum(pro_name_or_oid)), 0, 0, 0); if (!RegProcedureIsValid(result)) elog(ERROR, "No procedure with oid %s", pro_name_or_oid); diff --git a/src/backend/utils/adt/ri_triggers.c b/src/backend/utils/adt/ri_triggers.c index 94d9b7313a1..db7f67ec601 100644 --- a/src/backend/utils/adt/ri_triggers.c +++ b/src/backend/utils/adt/ri_triggers.c @@ -9,7 +9,7 @@ * the backend does. This works because the hashtable structures * themselves are allocated by dynahash.c in its permanent DynaHashCxt, * and the parse/plan node trees they point to are copied into - * TopMemoryContext using SPI_saveplan(). This is pretty ugly, since there + * TopMemoryContext using SPI_saveplan(). This is pretty ugly, since there * is no way to free a no-longer-needed plan tree, but then again we don't * yet have any bookkeeping that would allow us to detect that a plan isn't * needed anymore. Improve it someday. @@ -18,7 +18,7 @@ * Portions Copyright (c) 2000-2001, PostgreSQL Global Development Group * Copyright 1999 Jan Wieck * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.21 2001/02/15 21:57:43 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.22 2001/03/22 03:59:53 momjian Exp $ * * ---------- */ @@ -535,7 +535,7 @@ RI_FKey_noaction_del(PG_FUNCTION_ARGS) char del_nulls[RI_MAX_NUMKEYS + 1]; bool isnull; int i; - Oid save_uid; + Oid save_uid; save_uid = GetUserId(); @@ -750,7 +750,7 @@ RI_FKey_noaction_upd(PG_FUNCTION_ARGS) char upd_nulls[RI_MAX_NUMKEYS + 1]; bool isnull; int i; - Oid save_uid; + Oid save_uid; save_uid = GetUserId(); @@ -1611,7 +1611,7 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS) char upd_nulls[RI_MAX_NUMKEYS + 1]; bool isnull; int i; - Oid save_uid; + Oid save_uid; save_uid = GetUserId(); diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 2dd460a442b..c6db1c5b30f 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -3,7 +3,7 @@ * back to source text * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.73 2001/02/21 18:53:47 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.74 2001/03/22 03:59:53 momjian Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -82,7 +82,7 @@ typedef struct List *rtable; /* List of RangeTblEntry nodes */ List *namespace; /* List of joinlist items (RangeTblRef and * JoinExpr nodes) */ -} deparse_namespace; +} deparse_namespace; /* ---------- @@ -118,15 +118,15 @@ static void get_delete_query_def(Query *query, deparse_context *context); static void get_utility_query_def(Query *query, deparse_context *context); static void get_basic_select_query(Query *query, deparse_context *context); static void get_setop_query(Node *setOp, Query *query, - deparse_context *context, bool toplevel); + deparse_context *context, bool toplevel); static bool simple_distinct(List *distinctClause, List *targetList); static void get_names_for_var(Var *var, deparse_context *context, - char **refname, char **attname); + char **refname, char **attname); static bool get_alias_for_case(CaseExpr *caseexpr, deparse_context *context, - char **refname, char **attname); + char **refname, char **attname); static bool find_alias_in_namespace(Node *nsnode, Node *expr, - List *rangetable, int levelsup, - char **refname, char **attname); + List *rangetable, int levelsup, + char **refname, char **attname); static bool phony_equal(Node *expr1, Node *expr2, int levelsup); static void get_rule_expr(Node *node, deparse_context *context); static void get_func_expr(Expr *expr, deparse_context *context); @@ -135,7 +135,7 @@ static void get_const_expr(Const *constval, deparse_context *context); static void get_sublink_expr(Node *node, deparse_context *context); static void get_from_clause(Query *query, deparse_context *context); static void get_from_clause_item(Node *jtnode, Query *query, - deparse_context *context); + deparse_context *context); static bool tleIsArrayAssign(TargetEntry *tle); static char *quote_identifier(char *ident); static char *get_relation_name(Oid relid); @@ -478,7 +478,7 @@ pg_get_indexdef(PG_FUNCTION_ARGS) * ---------- */ appendStringInfo(&keybuf, "%s", - quote_identifier(get_relid_attribute_name(idxrec->indrelid, + quote_identifier(get_relid_attribute_name(idxrec->indrelid, idxrec->indkey[keyno]))); /* ---------- @@ -767,8 +767,8 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc) quote_identifier(get_relation_name(ev_class))); if (ev_attr > 0) appendStringInfo(buf, ".%s", - quote_identifier(get_relid_attribute_name(ev_class, - ev_attr))); + quote_identifier(get_relid_attribute_name(ev_class, + ev_attr))); /* If the rule has an event qualification, add it */ if (ev_qual == NULL) @@ -1043,9 +1043,7 @@ get_basic_select_query(Query *query, deparse_context *context) if (query->distinctClause != NIL) { if (simple_distinct(query->distinctClause, query->targetList)) - { appendStringInfo(buf, " DISTINCT"); - } else { appendStringInfo(buf, " DISTINCT ON ("); @@ -1146,7 +1144,7 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context, { RangeTblRef *rtr = (RangeTblRef *) setOp; RangeTblEntry *rte = rt_fetch(rtr->rtindex, query->rtable); - Query *subquery = rte->subquery; + Query *subquery = rte->subquery; Assert(subquery != NULL); get_query_def(subquery, buf, context->namespaces); @@ -1155,10 +1153,11 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context, { SetOperationStmt *op = (SetOperationStmt *) setOp; - /* Must suppress parens at top level of a setop tree because - * of grammar limitations... + /* + * Must suppress parens at top level of a setop tree because of + * grammar limitations... */ - if (! toplevel) + if (!toplevel) appendStringInfo(buf, "("); get_setop_query(op->larg, query, context, false); switch (op->op) @@ -1179,7 +1178,7 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context, if (op->all) appendStringInfo(buf, "ALL "); get_setop_query(op->rarg, query, context, false); - if (! toplevel) + if (!toplevel) appendStringInfo(buf, ")"); } else @@ -1201,7 +1200,7 @@ simple_distinct(List *distinctClause, List *targetList) { TargetEntry *tle = (TargetEntry *) lfirst(targetList); - if (! tle->resdom->resjunk) + if (!tle->resdom->resjunk) { if (distinctClause == NIL) return false; @@ -1288,9 +1287,7 @@ get_insert_query_def(Query *query, deparse_context *context) appendStringInfoChar(buf, ')'); } else - { get_query_def(select_rte->subquery, buf, NIL); - } } @@ -1326,12 +1323,13 @@ get_update_query_def(Query *query, deparse_context *context) appendStringInfo(buf, sep); sep = ", "; + /* - * If the update expression is an array assignment, we mustn't - * put out "attname =" here; it will come out of the display - * of the ArrayRef node instead. + * If the update expression is an array assignment, we mustn't put + * out "attname =" here; it will come out of the display of the + * ArrayRef node instead. */ - if (! tleIsArrayAssign(tle)) + if (!tleIsArrayAssign(tle)) appendStringInfo(buf, "%s = ", quote_identifier(tle->resdom->resname)); get_tle_expr(tle, context); @@ -1389,6 +1387,7 @@ get_utility_query_def(Query *query, deparse_context *context) if (query->utilityStmt && IsA(query->utilityStmt, NotifyStmt)) { NotifyStmt *stmt = (NotifyStmt *) query->utilityStmt; + appendStringInfo(buf, "NOTIFY %s", quote_identifier(stmt->relname)); } else @@ -1428,8 +1427,8 @@ get_names_for_var(Var *var, deparse_context *context, /* * Otherwise, fall back on the rangetable entry. This should happen - * only for uses of special RTEs like *NEW* and *OLD*, which won't - * get placed in our namespace. + * only for uses of special RTEs like *NEW* and *OLD*, which won't get + * placed in our namespace. */ rte = rt_fetch(var->varno, dpns->rtable); *refname = rte->eref->relname; @@ -1448,9 +1447,9 @@ get_alias_for_case(CaseExpr *caseexpr, deparse_context *context, int sup; /* - * This could be done more efficiently if we first groveled through the - * CASE to find varlevelsup values, but it's probably not worth the - * trouble. All this code will go away someday anyway ... + * This could be done more efficiently if we first groveled through + * the CASE to find varlevelsup values, but it's probably not worth + * the trouble. All this code will go away someday anyway ... */ sup = 0; @@ -1525,6 +1524,7 @@ find_alias_in_namespace(Node *nsnode, Node *expr, } nlist = lnext(nlist); } + /* * Tables within an aliased join are invisible from outside * the join, according to the scope rules of SQL92 (the join @@ -1579,8 +1579,8 @@ phony_equal(Node *expr1, Node *expr2, int levelsup) return false; if (IsA(expr1, Var)) { - Var *a = (Var *) expr1; - Var *b = (Var *) expr2; + Var *a = (Var *) expr1; + Var *b = (Var *) expr2; if (a->varno != b->varno) return false; @@ -1600,8 +1600,8 @@ phony_equal(Node *expr1, Node *expr2, int levelsup) } if (IsA(expr1, CaseExpr)) { - CaseExpr *a = (CaseExpr *) expr1; - CaseExpr *b = (CaseExpr *) expr2; + CaseExpr *a = (CaseExpr *) expr1; + CaseExpr *b = (CaseExpr *) expr2; if (a->casetype != b->casetype) return false; @@ -1615,8 +1615,8 @@ phony_equal(Node *expr1, Node *expr2, int levelsup) } if (IsA(expr1, CaseWhen)) { - CaseWhen *a = (CaseWhen *) expr1; - CaseWhen *b = (CaseWhen *) expr2; + CaseWhen *a = (CaseWhen *) expr1; + CaseWhen *b = (CaseWhen *) expr2; if (!phony_equal(a->expr, b->expr, levelsup)) return false; @@ -1840,9 +1840,10 @@ get_rule_expr(Node *node, deparse_context *context) /* * If we are doing UPDATE array[n] = expr, we need to - * suppress any prefix on the array name. Currently, - * that is the only context in which we will see a non-null - * refassgnexpr --- but someday a smarter test may be needed. + * suppress any prefix on the array name. Currently, that + * is the only context in which we will see a non-null + * refassgnexpr --- but someday a smarter test may be + * needed. */ if (aref->refassgnexpr) context->varprefix = false; @@ -1880,7 +1881,7 @@ get_rule_expr(Node *node, deparse_context *context) /* we do NOT parenthesize the arg expression, for now */ get_rule_expr(fselect->arg, context); typetup = SearchSysCache(TYPEOID, - ObjectIdGetDatum(exprType(fselect->arg)), + ObjectIdGetDatum(exprType(fselect->arg)), 0, 0, 0); if (!HeapTupleIsValid(typetup)) elog(ERROR, "cache lookup of type %u failed", @@ -2163,9 +2164,9 @@ get_const_expr(Const *constval, deparse_context *context) } extval = DatumGetCString(OidFunctionCall3(typeStruct->typoutput, - constval->constvalue, - ObjectIdGetDatum(typeStruct->typelem), - Int32GetDatum(-1))); + constval->constvalue, + ObjectIdGetDatum(typeStruct->typelem), + Int32GetDatum(-1))); switch (constval->consttype) { @@ -2317,16 +2318,16 @@ get_from_clause(Query *query, deparse_context *context) /* * We use the query's jointree as a guide to what to print. However, - * we must ignore auto-added RTEs that are marked not inFromCl. - * (These can only appear at the top level of the jointree, so it's - * sufficient to check here.) - * Also ignore the rule pseudo-RTEs for NEW and OLD. + * we must ignore auto-added RTEs that are marked not inFromCl. (These + * can only appear at the top level of the jointree, so it's + * sufficient to check here.) Also ignore the rule pseudo-RTEs for NEW + * and OLD. */ sep = " FROM "; foreach(l, query->jointree->fromlist) { - Node *jtnode = (Node *) lfirst(l); + Node *jtnode = (Node *) lfirst(l); if (IsA(jtnode, RangeTblRef)) { @@ -2396,7 +2397,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context) if (col != rte->alias->attrs) appendStringInfo(buf, ", "); appendStringInfo(buf, "%s", - quote_identifier(strVal(lfirst(col)))); + quote_identifier(strVal(lfirst(col)))); } appendStringInfoChar(buf, ')'); } @@ -2435,7 +2436,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context) (int) j->jointype); } get_from_clause_item(j->rarg, query, context); - if (! j->isNatural) + if (!j->isNatural) { if (j->using) { @@ -2447,7 +2448,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context) if (col != j->using) appendStringInfo(buf, ", "); appendStringInfo(buf, "%s", - quote_identifier(strVal(lfirst(col)))); + quote_identifier(strVal(lfirst(col)))); } appendStringInfoChar(buf, ')'); } @@ -2475,7 +2476,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context) if (col != j->alias->attrs) appendStringInfo(buf, ", "); appendStringInfo(buf, "%s", - quote_identifier(strVal(lfirst(col)))); + quote_identifier(strVal(lfirst(col)))); } appendStringInfoChar(buf, ')'); } @@ -2503,6 +2504,7 @@ tleIsArrayAssign(TargetEntry *tle) aref = (ArrayRef *) tle->expr; if (aref->refassgnexpr == NULL) return false; + /* * Currently, it should only be possible to see non-null refassgnexpr * if we are indeed looking at an "UPDATE array[n] = expr" situation. @@ -2563,8 +2565,8 @@ quote_identifier(char *ident) * but the parser doesn't provide any easy way to test for whether * an identifier is safe or not... so be safe not sorry. * - * Note: ScanKeywordLookup() does case-insensitive comparison, - * but that's fine, since we already know we have all-lower-case. + * Note: ScanKeywordLookup() does case-insensitive comparison, but + * that's fine, since we already know we have all-lower-case. */ if (ScanKeywordLookup(ident) != NULL) safe = false; diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index 72be0f04722..b7af8b9ca5e 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.85 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.86 2001/03/22 03:59:54 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -61,18 +61,18 @@ #define NOT_MOST_COMMON_RATIO 0.1 static bool convert_to_scalar(Datum value, Oid valuetypid, double *scaledvalue, - Datum lobound, Datum hibound, Oid boundstypid, - double *scaledlobound, double *scaledhibound); + Datum lobound, Datum hibound, Oid boundstypid, + double *scaledlobound, double *scaledhibound); static double convert_numeric_to_scalar(Datum value, Oid typid); static void convert_string_to_scalar(unsigned char *value, - double *scaledvalue, - unsigned char *lobound, - double *scaledlobound, - unsigned char *hibound, - double *scaledhibound); + double *scaledvalue, + unsigned char *lobound, + double *scaledlobound, + unsigned char *hibound, + double *scaledhibound); static double convert_one_string_to_scalar(unsigned char *value, - int rangelo, int rangehi); -static unsigned char * convert_string_datum(Datum value, Oid typid); + int rangelo, int rangehi); +static unsigned char *convert_string_datum(Datum value, Oid typid); static double convert_timevalue_to_scalar(Datum value, Oid typid); static void getattproperties(Oid relid, AttrNumber attnum, Oid *typid, @@ -87,9 +87,9 @@ static bool getattstatistics(Oid relid, AttrNumber attnum, Datum *loval, Datum *hival); static Selectivity prefix_selectivity(char *prefix, - Oid relid, - AttrNumber attno, - Oid datatype); + Oid relid, + AttrNumber attno, + Oid datatype); static Selectivity pattern_selectivity(char *patt, Pattern_Type ptype); static bool string_lessthan(const char *str1, const char *str2, Oid datatype); @@ -102,7 +102,7 @@ static Datum string_to_datum(const char *str, Oid datatype); * * Note: this routine is also used to estimate selectivity for some * operators that are not "=" but have comparable selectivity behavior, - * such as "~=" (geometric approximate-match). Even for "=", we must + * such as "~=" (geometric approximate-match). Even for "=", we must * keep in mind that the left and right datatypes may differ, so the type * of the given constant "value" may be different from the type of the * attribute. @@ -165,7 +165,7 @@ eqsel(PG_FUNCTION_ARGS) else mostcommon = DatumGetBool(OidFunctionCall2(eqproc, value, - commonval)); + commonval)); if (mostcommon) { @@ -264,15 +264,15 @@ neqsel(PG_FUNCTION_ARGS) float8 result; /* - * We want 1 - eqsel() where the equality operator is the one associated - * with this != operator, that is, its negator. + * We want 1 - eqsel() where the equality operator is the one + * associated with this != operator, that is, its negator. */ eqopid = get_negator(opid); if (eqopid) { result = DatumGetFloat8(DirectFunctionCall5(eqsel, - ObjectIdGetDatum(eqopid), - ObjectIdGetDatum(relid), + ObjectIdGetDatum(eqopid), + ObjectIdGetDatum(relid), Int16GetDatum(attno), value, Int32GetDatum(flag))); @@ -432,16 +432,16 @@ scalargtsel(PG_FUNCTION_ARGS) /* * Compute selectivity of "<", then invert --- but only if we were - * able to produce a non-default estimate. Note that we get the - * negator which strictly speaking means we are looking at "<=" - * for ">" or "<" for ">=". We assume this won't matter. + * able to produce a non-default estimate. Note that we get the + * negator which strictly speaking means we are looking at "<=" for + * ">" or "<" for ">=". We assume this won't matter. */ ltopid = get_negator(opid); if (ltopid) { result = DatumGetFloat8(DirectFunctionCall5(scalarltsel, - ObjectIdGetDatum(ltopid), - ObjectIdGetDatum(relid), + ObjectIdGetDatum(ltopid), + ObjectIdGetDatum(relid), Int16GetDatum(attno), value, Int32GetDatum(flag))); @@ -506,23 +506,28 @@ patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype) if (pstatus == Pattern_Prefix_Exact) { - /* Pattern specifies an exact match, so pretend operator is '=' */ - Oid eqopr = find_operator("=", ltype); - Datum eqcon; + + /* + * Pattern specifies an exact match, so pretend operator is + * '=' + */ + Oid eqopr = find_operator("=", ltype); + Datum eqcon; if (eqopr == InvalidOid) elog(ERROR, "patternsel: no = operator for type %u", ltype); eqcon = string_to_datum(prefix, ltype); result = DatumGetFloat8(DirectFunctionCall5(eqsel, - ObjectIdGetDatum(eqopr), - ObjectIdGetDatum(relid), - Int16GetDatum(attno), - eqcon, - Int32GetDatum(SEL_CONSTANT|SEL_RIGHT))); + ObjectIdGetDatum(eqopr), + ObjectIdGetDatum(relid), + Int16GetDatum(attno), + eqcon, + Int32GetDatum(SEL_CONSTANT | SEL_RIGHT))); pfree(DatumGetPointer(eqcon)); } else { + /* * Not exact-match pattern. We estimate selectivity of the * fixed prefix and remainder of pattern separately, then @@ -648,6 +653,7 @@ eqjoinsel(PG_FUNCTION_ARGS) { #ifdef NOT_USED /* see neqjoinsel() before removing me! */ Oid opid = PG_GETARG_OID(0); + #endif Oid relid1 = PG_GETARG_OID(1); AttrNumber attno1 = PG_GETARG_INT16(2); @@ -701,8 +707,8 @@ neqjoinsel(PG_FUNCTION_ARGS) /* * XXX we skip looking up the negator operator here because we know - * eqjoinsel() won't look at it anyway. If eqjoinsel() ever does look, - * this routine will need to look more like neqsel() does. + * eqjoinsel() won't look at it anyway. If eqjoinsel() ever does + * look, this routine will need to look more like neqsel() does. */ result = DatumGetFloat8(eqjoinsel(fcinfo)); result = 1.0 - result; @@ -845,48 +851,48 @@ convert_to_scalar(Datum value, Oid valuetypid, double *scaledvalue, switch (valuetypid) { - /* - * Built-in numeric types - */ - case BOOLOID: - case INT2OID: - case INT4OID: - case INT8OID: - case FLOAT4OID: - case FLOAT8OID: - case NUMERICOID: - case OIDOID: - case REGPROCOID: + /* + * Built-in numeric types + */ + case BOOLOID: + case INT2OID: + case INT4OID: + case INT8OID: + case FLOAT4OID: + case FLOAT8OID: + case NUMERICOID: + case OIDOID: + case REGPROCOID: *scaledvalue = convert_numeric_to_scalar(value, valuetypid); *scaledlobound = convert_numeric_to_scalar(lobound, boundstypid); *scaledhibound = convert_numeric_to_scalar(hibound, boundstypid); return true; - /* - * Built-in string types - */ + /* + * Built-in string types + */ case CHAROID: case BPCHAROID: case VARCHAROID: case TEXTOID: case NAMEOID: - { - unsigned char *valstr = convert_string_datum(value, valuetypid); - unsigned char *lostr = convert_string_datum(lobound, boundstypid); - unsigned char *histr = convert_string_datum(hibound, boundstypid); - - convert_string_to_scalar(valstr, scaledvalue, - lostr, scaledlobound, - histr, scaledhibound); - pfree(valstr); - pfree(lostr); - pfree(histr); - return true; - } + { + unsigned char *valstr = convert_string_datum(value, valuetypid); + unsigned char *lostr = convert_string_datum(lobound, boundstypid); + unsigned char *histr = convert_string_datum(hibound, boundstypid); + + convert_string_to_scalar(valstr, scaledvalue, + lostr, scaledlobound, + histr, scaledhibound); + pfree(valstr); + pfree(lostr); + pfree(histr); + return true; + } - /* - * Built-in time types - */ + /* + * Built-in time types + */ case TIMESTAMPOID: case ABSTIMEOID: case DATEOID: @@ -911,7 +917,7 @@ convert_numeric_to_scalar(Datum value, Oid typid) { switch (typid) { - case BOOLOID: + case BOOLOID: return (double) DatumGetBool(value); case INT2OID: return (double) DatumGetInt16(value); @@ -931,7 +937,9 @@ convert_numeric_to_scalar(Datum value, Oid typid) /* we can treat OIDs as integers... */ return (double) DatumGetObjectId(value); } - /* Can't get here unless someone tries to use scalarltsel/scalargtsel + + /* + * Can't get here unless someone tries to use scalarltsel/scalargtsel * on an operator with one numeric and one non-numeric operand. */ elog(ERROR, "convert_numeric_to_scalar: unsupported type %u", typid); @@ -1007,7 +1015,9 @@ convert_string_to_scalar(unsigned char *value, if (rangehi < '9') rangehi = '9'; } - /* If range includes less than 10 chars, assume we have not got enough + + /* + * If range includes less than 10 chars, assume we have not got enough * data, and make it include regular ASCII set. */ if (rangehi - rangelo < 9) @@ -1045,7 +1055,10 @@ convert_one_string_to_scalar(unsigned char *value, int rangelo, int rangehi) if (slen <= 0) return 0.0; /* empty string has scalar value 0 */ - /* Since base is at least 10, need not consider more than about 20 chars */ + /* + * Since base is at least 10, need not consider more than about 20 + * chars + */ if (slen > 20) slen = 20; @@ -1055,12 +1068,12 @@ convert_one_string_to_scalar(unsigned char *value, int rangelo, int rangehi) denom = base; while (slen-- > 0) { - int ch = *value++; + int ch = *value++; if (ch < rangelo) - ch = rangelo-1; + ch = rangelo - 1; else if (ch > rangehi) - ch = rangehi+1; + ch = rangehi + 1; num += ((double) (ch - rangelo)) / denom; denom *= base; } @@ -1078,10 +1091,12 @@ static unsigned char * convert_string_datum(Datum value, Oid typid) { char *val; + #ifdef USE_LOCALE char *xfrmstr; size_t xfrmsize; size_t xfrmlen; + #endif switch (typid) @@ -1094,25 +1109,27 @@ convert_string_datum(Datum value, Oid typid) case BPCHAROID: case VARCHAROID: case TEXTOID: - { - char *str = (char *) VARDATA(DatumGetPointer(value)); - int strlength = VARSIZE(DatumGetPointer(value)) - VARHDRSZ; + { + char *str = (char *) VARDATA(DatumGetPointer(value)); + int strlength = VARSIZE(DatumGetPointer(value)) - VARHDRSZ; - val = (char *) palloc(strlength+1); - memcpy(val, str, strlength); - val[strlength] = '\0'; - break; - } + val = (char *) palloc(strlength + 1); + memcpy(val, str, strlength); + val[strlength] = '\0'; + break; + } case NAMEOID: - { - NameData *nm = (NameData *) DatumGetPointer(value); + { + NameData *nm = (NameData *) DatumGetPointer(value); - val = pstrdup(NameStr(*nm)); - break; - } + val = pstrdup(NameStr(*nm)); + break; + } default: - /* Can't get here unless someone tries to use scalarltsel - * on an operator with one string and one non-string operand. + + /* + * Can't get here unless someone tries to use scalarltsel on + * an operator with one string and one non-string operand. */ elog(ERROR, "convert_string_datum: unsupported type %u", typid); return NULL; @@ -1120,7 +1137,7 @@ convert_string_datum(Datum value, Oid typid) #ifdef USE_LOCALE /* Guess that transformed string is not much bigger than original */ - xfrmsize = strlen(val) + 32; /* arbitrary pad value here... */ + xfrmsize = strlen(val) + 32;/* arbitrary pad value here... */ xfrmstr = (char *) palloc(xfrmsize); xfrmlen = strxfrm(xfrmstr, val, xfrmsize); if (xfrmlen >= xfrmsize) @@ -1145,7 +1162,7 @@ convert_timevalue_to_scalar(Datum value, Oid typid) { switch (typid) { - case TIMESTAMPOID: + case TIMESTAMPOID: return DatumGetTimestamp(value); case ABSTIMEOID: return DatumGetTimestamp(DirectFunctionCall1(abstime_timestamp, @@ -1154,31 +1171,33 @@ convert_timevalue_to_scalar(Datum value, Oid typid) return DatumGetTimestamp(DirectFunctionCall1(date_timestamp, value)); case INTERVALOID: - { - Interval *interval = DatumGetIntervalP(value); + { + Interval *interval = DatumGetIntervalP(value); - /* - * Convert the month part of Interval to days using - * assumed average month length of 365.25/12.0 days. Not - * too accurate, but plenty good enough for our purposes. - */ - return interval->time + - interval->month * (365.25 / 12.0 * 24.0 * 60.0 * 60.0); - } + /* + * Convert the month part of Interval to days using + * assumed average month length of 365.25/12.0 days. Not + * too accurate, but plenty good enough for our purposes. + */ + return interval->time + + interval->month * (365.25 / 12.0 * 24.0 * 60.0 * 60.0); + } case RELTIMEOID: return DatumGetRelativeTime(value); case TINTERVALOID: - { - TimeInterval interval = DatumGetTimeInterval(value); + { + TimeInterval interval = DatumGetTimeInterval(value); - if (interval->status != 0) - return interval->data[1] - interval->data[0]; - return 0; /* for lack of a better idea */ - } + if (interval->status != 0) + return interval->data[1] - interval->data[0]; + return 0; /* for lack of a better idea */ + } case TIMEOID: return DatumGetTimeADT(value); } - /* Can't get here unless someone tries to use scalarltsel/scalargtsel + + /* + * Can't get here unless someone tries to use scalarltsel/scalargtsel * on an operator with one timevalue and one non-timevalue operand. */ elog(ERROR, "convert_timevalue_to_scalar: unsupported type %u", typid); @@ -1305,7 +1324,7 @@ getattstatistics(Oid relid, else { char *strval = DatumGetCString(DirectFunctionCall1(textout, - val)); + val)); *commonval = FunctionCall3(&inputproc, CStringGetDatum(strval), @@ -1329,7 +1348,7 @@ getattstatistics(Oid relid, else { char *strval = DatumGetCString(DirectFunctionCall1(textout, - val)); + val)); *loval = FunctionCall3(&inputproc, CStringGetDatum(strval), @@ -1353,7 +1372,7 @@ getattstatistics(Oid relid, else { char *strval = DatumGetCString(DirectFunctionCall1(textout, - val)); + val)); *hival = FunctionCall3(&inputproc, CStringGetDatum(strval), @@ -1417,12 +1436,14 @@ like_fixed_prefix(char *patt, bool case_insensitive, if (patt[pos] == '\0') break; } + /* * XXX I suspect isalpha() is not an adequately locale-sensitive * test for characters that can vary under case folding? */ if (case_insensitive && isalpha((unsigned char) patt[pos])) break; + /* * NOTE: this code used to think that %% meant a literal %, but * textlike() itself does not think that, and the SQL92 spec @@ -1436,7 +1457,8 @@ like_fixed_prefix(char *patt, bool case_insensitive, /* in LIKE, an empty pattern is an exact match! */ if (patt[pos] == '\0') - return Pattern_Prefix_Exact; /* reached end of pattern, so exact */ + return Pattern_Prefix_Exact; /* reached end of pattern, so + * exact */ if (match_pos > 0) return Pattern_Prefix_Partial; @@ -1463,7 +1485,8 @@ regex_fixed_prefix(char *patt, bool case_insensitive, return Pattern_Prefix_None; } - /* If unquoted | is present at paren level 0 in pattern, then there + /* + * If unquoted | is present at paren level 0 in pattern, then there * are multiple alternatives for the start of the string. */ paren_depth = 0; @@ -1495,10 +1518,12 @@ regex_fixed_prefix(char *patt, bool case_insensitive, /* note start at pos 1 to skip leading ^ */ for (pos = 1; patt[pos]; pos++) { + /* - * Check for characters that indicate multiple possible matches here. - * XXX I suspect isalpha() is not an adequately locale-sensitive - * test for characters that can vary under case folding? + * Check for characters that indicate multiple possible matches + * here. XXX I suspect isalpha() is not an adequately + * locale-sensitive test for characters that can vary under case + * folding? */ if (patt[pos] == '.' || patt[pos] == '(' || @@ -1506,9 +1531,11 @@ regex_fixed_prefix(char *patt, bool case_insensitive, patt[pos] == '$' || (case_insensitive && isalpha((unsigned char) patt[pos]))) break; + /* * Check for quantifiers. Except for +, this means the preceding - * character is optional, so we must remove it from the prefix too! + * character is optional, so we must remove it from the prefix + * too! */ if (patt[pos] == '*' || patt[pos] == '?' || @@ -1573,7 +1600,7 @@ pattern_fixed_prefix(char *patt, Pattern_Type ptype, break; default: elog(ERROR, "pattern_fixed_prefix: bogus ptype"); - result = Pattern_Prefix_None; /* keep compiler quiet */ + result = Pattern_Prefix_None; /* keep compiler quiet */ break; } return result; @@ -1596,7 +1623,7 @@ prefix_selectivity(char *prefix, AttrNumber attno, Oid datatype) { - Selectivity prefixsel; + Selectivity prefixsel; Oid cmpopr; Datum prefixcon; char *greaterstr; @@ -1608,21 +1635,21 @@ prefix_selectivity(char *prefix, prefixcon = string_to_datum(prefix, datatype); /* Assume scalargtsel is appropriate for all supported types */ prefixsel = DatumGetFloat8(DirectFunctionCall5(scalargtsel, - ObjectIdGetDatum(cmpopr), - ObjectIdGetDatum(relid), - Int16GetDatum(attno), - prefixcon, - Int32GetDatum(SEL_CONSTANT|SEL_RIGHT))); + ObjectIdGetDatum(cmpopr), + ObjectIdGetDatum(relid), + Int16GetDatum(attno), + prefixcon, + Int32GetDatum(SEL_CONSTANT | SEL_RIGHT))); pfree(DatumGetPointer(prefixcon)); /* - * If we can create a string larger than the prefix, - * say "x < greaterstr". + * If we can create a string larger than the prefix, say "x < + * greaterstr". */ greaterstr = make_greater_string(prefix, datatype); if (greaterstr) { - Selectivity topsel; + Selectivity topsel; cmpopr = find_operator("<", datatype); if (cmpopr == InvalidOid) @@ -1631,28 +1658,28 @@ prefix_selectivity(char *prefix, prefixcon = string_to_datum(greaterstr, datatype); /* Assume scalarltsel is appropriate for all supported types */ topsel = DatumGetFloat8(DirectFunctionCall5(scalarltsel, - ObjectIdGetDatum(cmpopr), - ObjectIdGetDatum(relid), - Int16GetDatum(attno), - prefixcon, - Int32GetDatum(SEL_CONSTANT|SEL_RIGHT))); + ObjectIdGetDatum(cmpopr), + ObjectIdGetDatum(relid), + Int16GetDatum(attno), + prefixcon, + Int32GetDatum(SEL_CONSTANT | SEL_RIGHT))); pfree(DatumGetPointer(prefixcon)); pfree(greaterstr); /* - * Merge the two selectivities in the same way as for - * a range query (see clauselist_selectivity()). + * Merge the two selectivities in the same way as for a range + * query (see clauselist_selectivity()). */ prefixsel = topsel + prefixsel - 1.0; /* - * A zero or slightly negative prefixsel should be converted into a - * small positive value; we probably are dealing with a very + * A zero or slightly negative prefixsel should be converted into + * a small positive value; we probably are dealing with a very * tight range and got a bogus result due to roundoff errors. * However, if prefixsel is very negative, then we probably have * default selectivity estimates on one or both sides of the - * range. In that case, insert a not-so-wildly-optimistic - * default estimate. + * range. In that case, insert a not-so-wildly-optimistic default + * estimate. */ if (prefixsel <= 0.0) { @@ -1660,8 +1687,8 @@ prefix_selectivity(char *prefix, { /* - * No data available --- use a default estimate that - * is small, but not real small. + * No data available --- use a default estimate that is + * small, but not real small. */ prefixsel = 0.01; } @@ -1691,15 +1718,16 @@ prefix_selectivity(char *prefix, #define FIXED_CHAR_SEL 0.04 /* about 1/25 */ #define CHAR_RANGE_SEL 0.25 -#define ANY_CHAR_SEL 0.9 /* not 1, since it won't match end-of-string */ +#define ANY_CHAR_SEL 0.9 /* not 1, since it won't match + * end-of-string */ #define FULL_WILDCARD_SEL 5.0 #define PARTIAL_WILDCARD_SEL 2.0 static Selectivity like_selectivity(char *patt, bool case_insensitive) { - Selectivity sel = 1.0; - int pos; + Selectivity sel = 1.0; + int pos; /* Skip any leading %; it's already factored into initial sel */ pos = (*patt == '%') ? 1 : 0; @@ -1730,17 +1758,17 @@ like_selectivity(char *patt, bool case_insensitive) static Selectivity regex_selectivity_sub(char *patt, int pattlen, bool case_insensitive) { - Selectivity sel = 1.0; - int paren_depth = 0; - int paren_pos = 0; /* dummy init to keep compiler quiet */ - int pos; + Selectivity sel = 1.0; + int paren_depth = 0; + int paren_pos = 0; /* dummy init to keep compiler quiet */ + int pos; for (pos = 0; pos < pattlen; pos++) { if (patt[pos] == '(') { if (paren_depth == 0) - paren_pos = pos; /* remember start of parenthesized item */ + paren_pos = pos;/* remember start of parenthesized item */ paren_depth++; } else if (patt[pos] == ')' && paren_depth > 0) @@ -1753,9 +1781,10 @@ regex_selectivity_sub(char *patt, int pattlen, bool case_insensitive) } else if (patt[pos] == '|' && paren_depth == 0) { + /* - * If unquoted | is present at paren level 0 in pattern, - * we have multiple alternatives; sum their probabilities. + * If unquoted | is present at paren level 0 in pattern, we + * have multiple alternatives; sum their probabilities. */ sel += regex_selectivity_sub(patt + (pos + 1), pattlen - (pos + 1), @@ -1764,19 +1793,20 @@ regex_selectivity_sub(char *patt, int pattlen, bool case_insensitive) } else if (patt[pos] == '[') { - bool negclass = false; + bool negclass = false; if (patt[++pos] == '^') { negclass = true; pos++; } - if (patt[pos] == ']') /* ']' at start of class is not special */ + if (patt[pos] == ']') /* ']' at start of class is not + * special */ pos++; while (pos < pattlen && patt[pos] != ']') pos++; if (paren_depth == 0) - sel *= (negclass ? (1.0-CHAR_RANGE_SEL) : CHAR_RANGE_SEL); + sel *= (negclass ? (1.0 - CHAR_RANGE_SEL) : CHAR_RANGE_SEL); } else if (patt[pos] == '.') { @@ -1822,15 +1852,15 @@ regex_selectivity_sub(char *patt, int pattlen, bool case_insensitive) static Selectivity regex_selectivity(char *patt, bool case_insensitive) { - Selectivity sel; - int pattlen = strlen(patt); + Selectivity sel; + int pattlen = strlen(patt); /* If patt doesn't end with $, consider it to have a trailing wildcard */ - if (pattlen > 0 && patt[pattlen-1] == '$' && - (pattlen == 1 || patt[pattlen-2] != '\\')) + if (pattlen > 0 && patt[pattlen - 1] == '$' && + (pattlen == 1 || patt[pattlen - 2] != '\\')) { /* has trailing $ */ - sel = regex_selectivity_sub(patt, pattlen-1, case_insensitive); + sel = regex_selectivity_sub(patt, pattlen - 1, case_insensitive); } else { @@ -1893,6 +1923,7 @@ locale_is_like_safe(void) localeptr = setlocale(LC_COLLATE, NULL); if (!localeptr) elog(STOP, "Invalid LC_COLLATE setting"); + /* * Currently we accept only "C" and "POSIX" (do any systems still * return "POSIX"?). Which other locales allow safe optimization? @@ -1904,9 +1935,9 @@ locale_is_like_safe(void) else result = false; return (bool) result; -#else /* not USE_LOCALE */ - return true; /* We must be in C locale, which is OK */ -#endif /* USE_LOCALE */ +#else /* not USE_LOCALE */ + return true; /* We must be in C locale, which is OK */ +#endif /* USE_LOCALE */ } /* @@ -2039,6 +2070,7 @@ find_operator(const char *opname, Oid datatype) static Datum string_to_datum(const char *str, Oid datatype) { + /* * We cheat a little by assuming that textin() will do for bpchar and * varchar constants too... diff --git a/src/backend/utils/adt/sets.c b/src/backend/utils/adt/sets.c index 11c5579fc20..c48526a7ba1 100644 --- a/src/backend/utils/adt/sets.c +++ b/src/backend/utils/adt/sets.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.36 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.37 2001/03/22 03:59:54 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -62,8 +62,8 @@ SetDefine(char *querystr, char *typename) false, /* canCache (assume unsafe) */ false, /* isStrict (irrelevant, no args) */ 100, /* byte_pct */ - 0, /* perbyte_cpu */ - 0, /* percall_cpu */ + 0, /* perbyte_cpu */ + 0, /* percall_cpu */ 100, /* outin_ratio */ NIL, /* argList */ whereToSendOutput); @@ -165,8 +165,8 @@ seteval(PG_FUNCTION_ARGS) } /* - * Evaluate the function. NOTE: we need no econtext because there - * are no arguments to evaluate. + * Evaluate the function. NOTE: we need no econtext because there are + * no arguments to evaluate. */ /* ExecMakeFunctionResult assumes these are initialized at call: */ @@ -175,14 +175,14 @@ seteval(PG_FUNCTION_ARGS) result = ExecMakeFunctionResult(fcache, NIL, - NULL, /* no econtext, see above */ + NULL, /* no econtext, see above */ &isNull, &isDone); /* - * If we're done with the results of this set function, get rid of - * its func cache so that we will start from the top next time. - * (Can you say "memory leak"? This feature is a crock anyway...) + * If we're done with the results of this set function, get rid of its + * func cache so that we will start from the top next time. (Can you + * say "memory leak"? This feature is a crock anyway...) */ if (isDone != ExprMultipleResult) { @@ -197,7 +197,7 @@ seteval(PG_FUNCTION_ARGS) if (isDone != ExprSingleResult) { - ReturnSetInfo *rsi = (ReturnSetInfo *) fcinfo->resultinfo; + ReturnSetInfo *rsi = (ReturnSetInfo *) fcinfo->resultinfo; if (rsi && IsA(rsi, ReturnSetInfo)) rsi->isDone = isDone; diff --git a/src/backend/utils/adt/tid.c b/src/backend/utils/adt/tid.c index 18bad89c48b..7e3b4bfc257 100644 --- a/src/backend/utils/adt/tid.c +++ b/src/backend/utils/adt/tid.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.23 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.24 2001/03/22 03:59:54 momjian Exp $ * * NOTES * input routine largely stolen from boxin(). @@ -21,8 +21,8 @@ #include "access/heapam.h" #include "utils/builtins.h" -#define DatumGetItemPointer(X) ((ItemPointer) DatumGetPointer(X)) -#define ItemPointerGetDatum(X) PointerGetDatum(X) +#define DatumGetItemPointer(X) ((ItemPointer) DatumGetPointer(X)) +#define ItemPointerGetDatum(X) PointerGetDatum(X) #define PG_GETARG_ITEMPOINTER(n) DatumGetItemPointer(PG_GETARG_DATUM(n)) #define PG_RETURN_ITEMPOINTER(x) return ItemPointerGetDatum(x) @@ -70,7 +70,7 @@ tidin(PG_FUNCTION_ARGS) Datum tidout(PG_FUNCTION_ARGS) { - ItemPointer itemPtr = PG_GETARG_ITEMPOINTER(0); + ItemPointer itemPtr = PG_GETARG_ITEMPOINTER(0); BlockId blockId; BlockNumber blockNumber; OffsetNumber offsetNumber; @@ -97,8 +97,8 @@ tidout(PG_FUNCTION_ARGS) Datum tideq(PG_FUNCTION_ARGS) { - ItemPointer arg1 = PG_GETARG_ITEMPOINTER(0); - ItemPointer arg2 = PG_GETARG_ITEMPOINTER(1); + ItemPointer arg1 = PG_GETARG_ITEMPOINTER(0); + ItemPointer arg2 = PG_GETARG_ITEMPOINTER(1); PG_RETURN_BOOL(BlockIdGetBlockNumber(&(arg1->ip_blkid)) == BlockIdGetBlockNumber(&(arg2->ip_blkid)) && @@ -109,13 +109,14 @@ tideq(PG_FUNCTION_ARGS) Datum tidne(PG_FUNCTION_ARGS) { - ItemPointer arg1 = PG_GETARG_ITEMPOINTER(0); - ItemPointer arg2 = PG_GETARG_ITEMPOINTER(1); + ItemPointer arg1 = PG_GETARG_ITEMPOINTER(0); + ItemPointer arg2 = PG_GETARG_ITEMPOINTER(1); PG_RETURN_BOOL(BlockIdGetBlockNumber(&(arg1->ip_blkid)) != BlockIdGetBlockNumber(&(arg2->ip_blkid)) || arg1->ip_posid != arg2->ip_posid); } + #endif /* @@ -126,11 +127,11 @@ tidne(PG_FUNCTION_ARGS) Datum currtid_byreloid(PG_FUNCTION_ARGS) { - Oid reloid = PG_GETARG_OID(0); - ItemPointer tid = PG_GETARG_ITEMPOINTER(1); - ItemPointer result, - ret; - Relation rel; + Oid reloid = PG_GETARG_OID(0); + ItemPointer tid = PG_GETARG_ITEMPOINTER(1); + ItemPointer result, + ret; + Relation rel; result = (ItemPointer) palloc(sizeof(ItemPointerData)); ItemPointerSetInvalid(result); @@ -150,12 +151,12 @@ currtid_byreloid(PG_FUNCTION_ARGS) Datum currtid_byrelname(PG_FUNCTION_ARGS) { - text *relname = PG_GETARG_TEXT_P(0); - ItemPointer tid = PG_GETARG_ITEMPOINTER(1); - ItemPointer result, - ret; - char *str; - Relation rel; + text *relname = PG_GETARG_TEXT_P(0); + ItemPointer tid = PG_GETARG_ITEMPOINTER(1); + ItemPointer result, + ret; + char *str; + Relation rel; str = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(relname))); diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index a01a790124f..7a2e6ea8bb0 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.45 2001/02/13 14:32:52 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.46 2001/03/22 03:59:54 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -92,7 +92,7 @@ timestamp_in(PG_FUNCTION_ARGS) default: elog(ERROR, "Internal coding error, can't input timestamp '%s'", str); - TIMESTAMP_INVALID(result); /* keep compiler quiet */ + TIMESTAMP_INVALID(result); /* keep compiler quiet */ } PG_RETURN_TIMESTAMP(result); @@ -315,14 +315,14 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, double *fsec, char **tzn) #if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE) tx = localtime(&utime); -# ifdef NO_MKTIME_BEFORE_1970 +#ifdef NO_MKTIME_BEFORE_1970 if (tx->tm_year < 70 && tx->tm_isdst == 1) { utime -= 3600; tx = localtime(&utime); tx->tm_isdst = 0; } -# endif +#endif tm->tm_year = tx->tm_year + 1900; tm->tm_mon = tx->tm_mon + 1; tm->tm_mday = tx->tm_mday; @@ -341,20 +341,20 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, double *fsec, char **tzn) #endif tm->tm_isdst = tx->tm_isdst; -# if defined(HAVE_TM_ZONE) +#if defined(HAVE_TM_ZONE) tm->tm_gmtoff = tx->tm_gmtoff; tm->tm_zone = tx->tm_zone; *tzp = -(tm->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */ if (tzn != NULL) *tzn = (char *) tm->tm_zone; -# elif defined(HAVE_INT_TIMEZONE) +#elif defined(HAVE_INT_TIMEZONE) *tzp = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL); if (tzn != NULL) *tzn = tzname[(tm->tm_isdst > 0)]; -# endif +#endif -#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ +#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ *tzp = CTimeZone; /* V7 conventions; don't know timezone? */ if (tzn != NULL) *tzn = CTZName; @@ -482,7 +482,7 @@ timestamp_finite(PG_FUNCTION_ARGS) { Timestamp timestamp = PG_GETARG_TIMESTAMP(0); - PG_RETURN_BOOL(! TIMESTAMP_NOT_FINITE(timestamp)); + PG_RETURN_BOOL(!TIMESTAMP_NOT_FINITE(timestamp)); } Datum @@ -490,7 +490,7 @@ interval_finite(PG_FUNCTION_ARGS) { Interval *interval = PG_GETARG_INTERVAL_P(0); - PG_RETURN_BOOL(! INTERVAL_NOT_FINITE(*interval)); + PG_RETURN_BOOL(!INTERVAL_NOT_FINITE(*interval)); } @@ -656,13 +656,9 @@ timestamp_cmp(PG_FUNCTION_ARGS) Timestamp dt2 = PG_GETARG_TIMESTAMP(1); if (TIMESTAMP_IS_INVALID(dt1)) - { PG_RETURN_INT32(TIMESTAMP_IS_INVALID(dt2) ? 0 : 1); - } else if (TIMESTAMP_IS_INVALID(dt2)) - { PG_RETURN_INT32(-1); - } else { if (TIMESTAMP_IS_RELATIVE(dt1)) @@ -839,7 +835,9 @@ interval_hash(PG_FUNCTION_ARGS) Datum overlaps_timestamp(PG_FUNCTION_ARGS) { - /* The arguments are Timestamps, but we leave them as generic Datums + + /* + * The arguments are Timestamps, but we leave them as generic Datums * to avoid unnecessary conversions between value and reference forms * --- not to mention possible dereferences of null pointers. */ @@ -858,9 +856,9 @@ overlaps_timestamp(PG_FUNCTION_ARGS) DatumGetBool(DirectFunctionCall2(timestamp_lt,t1,t2)) /* - * If both endpoints of interval 1 are null, the result is null (unknown). - * If just one endpoint is null, take ts1 as the non-null one. - * Otherwise, take ts1 as the lesser endpoint. + * If both endpoints of interval 1 are null, the result is null + * (unknown). If just one endpoint is null, take ts1 as the non-null + * one. Otherwise, take ts1 as the lesser endpoint. */ if (ts1IsNull) { @@ -874,7 +872,7 @@ overlaps_timestamp(PG_FUNCTION_ARGS) { if (TIMESTAMP_GT(ts1, te1)) { - Datum tt = ts1; + Datum tt = ts1; ts1 = te1; te1 = tt; @@ -894,7 +892,7 @@ overlaps_timestamp(PG_FUNCTION_ARGS) { if (TIMESTAMP_GT(ts2, te2)) { - Datum tt = ts2; + Datum tt = ts2; ts2 = te2; te2 = tt; @@ -907,7 +905,9 @@ overlaps_timestamp(PG_FUNCTION_ARGS) */ if (TIMESTAMP_GT(ts1, ts2)) { - /* This case is ts1 < te2 OR te1 < te2, which may look redundant + + /* + * This case is ts1 < te2 OR te1 < te2, which may look redundant * but in the presence of nulls it's not quite completely so. */ if (te2IsNull) @@ -916,7 +916,9 @@ overlaps_timestamp(PG_FUNCTION_ARGS) PG_RETURN_BOOL(true); if (te1IsNull) PG_RETURN_NULL(); - /* If te1 is not null then we had ts1 <= te1 above, and we just + + /* + * If te1 is not null then we had ts1 <= te1 above, and we just * found ts1 >= te2, hence te1 >= te2. */ PG_RETURN_BOOL(false); @@ -930,15 +932,20 @@ overlaps_timestamp(PG_FUNCTION_ARGS) PG_RETURN_BOOL(true); if (te2IsNull) PG_RETURN_NULL(); - /* If te2 is not null then we had ts2 <= te2 above, and we just + + /* + * If te2 is not null then we had ts2 <= te2 above, and we just * found ts2 >= te1, hence te2 >= te1. */ PG_RETURN_BOOL(false); } else { - /* For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a - * rather silly way of saying "true if both are nonnull, else null". + + /* + * For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a + * rather silly way of saying "true if both are nonnull, else + * null". */ if (te1IsNull || te2IsNull) PG_RETURN_NULL(); @@ -1086,13 +1093,14 @@ timestamp_pl_span(PG_FUNCTION_ARGS) tm->tm_year += 1900; tm->tm_mon += 1; -# if defined(HAVE_TM_ZONE) - tz = -(tm->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */ -# elif defined(HAVE_INT_TIMEZONE) +#if defined(HAVE_TM_ZONE) + tz = -(tm->tm_gmtoff); /* tm_gmtoff is + * Sun/DEC-ism */ +#elif defined(HAVE_INT_TIMEZONE) tz = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL); -# endif +#endif -#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ +#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ tz = CTimeZone; #endif } @@ -1129,8 +1137,8 @@ timestamp_mi_span(PG_FUNCTION_ARGS) Interval *span = PG_GETARG_INTERVAL_P(1); Interval tspan; - tspan.month = - span->month; - tspan.time = - span->time; + tspan.month = -span->month; + tspan.time = -span->time; return DirectFunctionCall2(timestamp_pl_span, TimestampGetDatum(timestamp), @@ -1351,18 +1359,19 @@ interval_accum(PG_FUNCTION_ARGS) &transdatums, &ndatums); if (ndatums != 2) elog(ERROR, "interval_accum: expected 2-element interval array"); + /* * XXX memcpy, instead of just extracting a pointer, to work around * buggy array code: it won't ensure proper alignment of Interval - * objects on machines where double requires 8-byte alignment. - * That should be fixed, but in the meantime... + * objects on machines where double requires 8-byte alignment. That + * should be fixed, but in the meantime... */ memcpy(&sumX, DatumGetIntervalP(transdatums[0]), sizeof(Interval)); memcpy(&N, DatumGetIntervalP(transdatums[1]), sizeof(Interval)); newsum = DatumGetIntervalP(DirectFunctionCall2(interval_pl, - IntervalPGetDatum(&sumX), - IntervalPGetDatum(newval))); + IntervalPGetDatum(&sumX), + IntervalPGetDatum(newval))); N.time += 1; transdatums[0] = IntervalPGetDatum(newsum); @@ -1389,11 +1398,12 @@ interval_avg(PG_FUNCTION_ARGS) &transdatums, &ndatums); if (ndatums != 2) elog(ERROR, "interval_avg: expected 2-element interval array"); + /* * XXX memcpy, instead of just extracting a pointer, to work around * buggy array code: it won't ensure proper alignment of Interval - * objects on machines where double requires 8-byte alignment. - * That should be fixed, but in the meantime... + * objects on machines where double requires 8-byte alignment. That + * should be fixed, but in the meantime... */ memcpy(&sumX, DatumGetIntervalP(transdatums[0]), sizeof(Interval)); memcpy(&N, DatumGetIntervalP(transdatums[1]), sizeof(Interval)); @@ -1439,9 +1449,7 @@ timestamp_age(PG_FUNCTION_ARGS) if (TIMESTAMP_IS_INVALID(dt1) || TIMESTAMP_IS_INVALID(dt2)) - { TIMESTAMP_INVALID(result->time); - } else if ((timestamp2tm(dt1, NULL, tm1, &fsec1, NULL) == 0) && (timestamp2tm(dt2, NULL, tm2, &fsec2, NULL) == 0)) { @@ -1597,7 +1605,7 @@ interval_text(PG_FUNCTION_ARGS) int len; str = DatumGetCString(DirectFunctionCall1(interval_out, - IntervalPGetDatum(interval))); + IntervalPGetDatum(interval))); len = (strlen(str) + VARHDRSZ); @@ -1662,7 +1670,7 @@ timestamp_trunc(PG_FUNCTION_ARGS) if (VARSIZE(units) - VARHDRSZ > MAXDATELEN) elog(ERROR, "Interval units '%s' not recognized", DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(units)))); + PointerGetDatum(units)))); up = VARDATA(units); lp = lowunits; for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++) @@ -1672,9 +1680,7 @@ timestamp_trunc(PG_FUNCTION_ARGS) type = DecodeUnits(0, lowunits, &val); if (TIMESTAMP_NOT_FINITE(timestamp)) - { PG_RETURN_NULL(); - } else { dt = (TIMESTAMP_IS_RELATIVE(timestamp) ? SetTimestamp(timestamp) : timestamp); @@ -1729,13 +1735,13 @@ timestamp_trunc(PG_FUNCTION_ARGS) tm->tm_year += 1900; tm->tm_mon += 1; -# if defined(HAVE_TM_ZONE) +#if defined(HAVE_TM_ZONE) tz = -(tm->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */ -# elif defined(HAVE_INT_TIMEZONE) +#elif defined(HAVE_INT_TIMEZONE) tz = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL); -# endif +#endif -#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ +#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ tz = CTimeZone; #endif } @@ -1789,7 +1795,7 @@ interval_trunc(PG_FUNCTION_ARGS) if (VARSIZE(units) - VARHDRSZ > MAXDATELEN) elog(ERROR, "Interval units '%s' not recognized", DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(units)))); + PointerGetDatum(units)))); up = VARDATA(units); lp = lowunits; for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++) @@ -1872,7 +1878,7 @@ interval_trunc(PG_FUNCTION_ARGS) { elog(ERROR, "Interval units '%s' not recognized", DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(units)))); + PointerGetDatum(units)))); PG_RETURN_NULL(); } @@ -1885,75 +1891,80 @@ interval_trunc(PG_FUNCTION_ARGS) * karel 2000/08/07 */ void -isoweek2date( int woy, int *year, int *mon, int *mday) +isoweek2date(int woy, int *year, int *mon, int *mday) { - int day0, day4, dayn; - + int day0, + day4, + dayn; + if (!*year) elog(ERROR, "isoweek2date(): can't convert without year information"); /* fourth day of current year */ day4 = date2j(*year, 1, 4); - + /* day0 == offset to first day of week (Monday) */ day0 = (j2day(day4 - 1) % 7); dayn = ((woy - 1) * 7) + (day4 - day0); - + j2date(dayn, year, mon, mday); } /* date2isoweek() - * + * * Returns ISO week number of year. */ int -date2isoweek(int year, int mon, int mday) +date2isoweek(int year, int mon, int mday) { - float8 result; - int day0, day4, dayn; - - /* current day */ + float8 result; + int day0, + day4, + dayn; + + /* current day */ dayn = date2j(year, mon, mday); - + /* fourth day of current year */ day4 = date2j(year, 1, 4); - + /* day0 == offset to first day of week (Monday) */ day0 = (j2day(day4 - 1) % 7); - - /* We need the first week containing a Thursday, - * otherwise this day falls into the previous year - * for purposes of counting weeks + + /* + * We need the first week containing a Thursday, otherwise this day + * falls into the previous year for purposes of counting weeks */ if (dayn < (day4 - day0)) { day4 = date2j((year - 1), 1, 4); - + /* day0 == offset to first day of week (Monday) */ day0 = (j2day(day4 - 1) % 7); } - + result = (((dayn - (day4 - day0)) / 7) + 1); - - /* Sometimes the last few days in a year will fall into - * the first week of the next year, so check for this. + + /* + * Sometimes the last few days in a year will fall into the first week + * of the next year, so check for this. */ if (result >= 53) { day4 = date2j((year + 1), 1, 4); - + /* day0 == offset to first day of week (Monday) */ day0 = (j2day(day4 - 1) % 7); - + if (dayn >= (day4 - day0)) result = (((dayn - (day4 - day0)) / 7) + 1); } return (int) result; -} - - +} + + /* timestamp_part() * Extract specified field from timestamp. */ @@ -1980,7 +1991,7 @@ timestamp_part(PG_FUNCTION_ARGS) if (VARSIZE(units) - VARHDRSZ > MAXDATELEN) elog(ERROR, "Interval units '%s' not recognized", DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(units)))); + PointerGetDatum(units)))); up = VARDATA(units); lp = lowunits; for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++) @@ -1992,9 +2003,7 @@ timestamp_part(PG_FUNCTION_ARGS) type = DecodeSpecial(0, lowunits, &val); if (TIMESTAMP_NOT_FINITE(timestamp)) - { PG_RETURN_NULL(); - } else { dt = (TIMESTAMP_IS_RELATIVE(timestamp) ? SetTimestamp(timestamp) : timestamp); @@ -2096,7 +2105,7 @@ timestamp_part(PG_FUNCTION_ARGS) elog(ERROR, "Unable to encode timestamp"); result = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - - date2j(tm->tm_year, 1, 1) + 1); + - date2j(tm->tm_year, 1, 1) + 1); break; default: @@ -2138,7 +2147,7 @@ interval_part(PG_FUNCTION_ARGS) if (VARSIZE(units) - VARHDRSZ > MAXDATELEN) elog(ERROR, "Interval units '%s' not recognized", DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(units)))); + PointerGetDatum(units)))); up = VARDATA(units); lp = lowunits; for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++) @@ -2213,7 +2222,7 @@ interval_part(PG_FUNCTION_ARGS) default: elog(ERROR, "Interval units '%s' not yet supported", DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(units)))); + PointerGetDatum(units)))); result = 0; } @@ -2237,7 +2246,7 @@ interval_part(PG_FUNCTION_ARGS) { elog(ERROR, "Interval units '%s' not recognized", DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(units)))); + PointerGetDatum(units)))); result = 0; } @@ -2283,9 +2292,7 @@ timestamp_zone(PG_FUNCTION_ARGS) type = DecodeSpecial(0, lowzone, &val); if (TIMESTAMP_NOT_FINITE(timestamp)) - { PG_RETURN_NULL(); - } else if ((type == TZ) || (type == DTZ)) { tm->tm_isdst = ((type == DTZ) ? 1 : 0); @@ -2320,7 +2327,7 @@ timestamp_zone(PG_FUNCTION_ARGS) } PG_RETURN_TEXT_P(result); -} /* timestamp_zone() */ +} /* timestamp_zone() */ /* timestamp_izone() * Encode timestamp type with specified time interval as time zone. @@ -2364,4 +2371,4 @@ timestamp_izone(PG_FUNCTION_ARGS) memmove(VARDATA(result), buf, (len - VARHDRSZ)); PG_RETURN_TEXT_P(result); -} /* timestamp_izone() */ +} /* timestamp_izone() */ diff --git a/src/backend/utils/adt/varbit.c b/src/backend/utils/adt/varbit.c index adbdf4f8ca7..775382568bb 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 - * $Header: /cvsroot/pgsql/src/backend/utils/adt/varbit.c,v 1.15 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/varbit.c,v 1.16 2001/03/22 03:59:54 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -51,8 +51,10 @@ Datum zpbit_in(PG_FUNCTION_ARGS) { char *input_string = PG_GETARG_CSTRING(0); + #ifdef NOT_USED Oid typelem = PG_GETARG_OID(1); + #endif int32 atttypmod = PG_GETARG_INT32(2); VarBit *result; /* The resulting bit string */ @@ -79,9 +81,10 @@ zpbit_in(PG_FUNCTION_ARGS) } else { + /* - * Otherwise it's binary. This allows things like cast('1001' - * as bit) to work transparently. + * Otherwise it's binary. This allows things like cast('1001' as + * bit) to work transparently. */ bit_not_hex = true; sp = input_string; @@ -214,8 +217,8 @@ zpbit_out(PG_FUNCTION_ARGS) } /* - * Go back one step if we printed a hex number that was not part - * of the bitstring anymore + * Go back one step if we printed a hex number that was not part of + * the bitstring anymore */ if (i > len) r--; @@ -263,12 +266,13 @@ _zpbit(PG_FUNCTION_ARGS) { ArrayType *v = (ArrayType *) PG_GETARG_VARLENA_P(0); int32 len = PG_GETARG_INT32(1); - FunctionCallInfoData locfcinfo; + FunctionCallInfoData locfcinfo; + /* - * Since zpbit() is a built-in function, we should only need to - * look it up once per run. + * Since zpbit() is a built-in function, we should only need to look + * it up once per run. */ - static FmgrInfo zpbit_finfo; + static FmgrInfo zpbit_finfo; if (zpbit_finfo.fn_oid == InvalidOid) fmgr_info(F_ZPBIT, &zpbit_finfo); @@ -293,8 +297,10 @@ Datum varbit_in(PG_FUNCTION_ARGS) { char *input_string = PG_GETARG_CSTRING(0); + #ifdef NOT_USED Oid typelem = PG_GETARG_OID(1); + #endif int32 atttypmod = PG_GETARG_INT32(2); VarBit *result; /* The resulting bit string */ @@ -490,12 +496,13 @@ _varbit(PG_FUNCTION_ARGS) { ArrayType *v = (ArrayType *) PG_GETARG_VARLENA_P(0); int32 len = PG_GETARG_INT32(1); - FunctionCallInfoData locfcinfo; + FunctionCallInfoData locfcinfo; + /* - * Since varbit() is a built-in function, we should only need to - * look it up once per run. + * Since varbit() is a built-in function, we should only need to look + * it up once per run. */ - static FmgrInfo varbit_finfo; + static FmgrInfo varbit_finfo; if (varbit_finfo.fn_oid == InvalidOid) fmgr_info(F_VARBIT, &varbit_finfo); @@ -765,7 +772,7 @@ bitsubstr(PG_FUNCTION_ARGS) bitlen = VARBITLEN(arg); /* If we do not have an upper bound, set bitlen */ - if (l==-1) + if (l == -1) l = bitlen; e = s + l; s1 = Max(s, 1); @@ -780,6 +787,7 @@ bitsubstr(PG_FUNCTION_ARGS) } else { + /* * OK, we've got a true substring starting at position s1-1 and * ending at position e1-1 @@ -823,7 +831,7 @@ bitsubstr(PG_FUNCTION_ARGS) PG_RETURN_VARBIT_P(result); } -/* bitlength, bitoctetlength +/* bitlength, bitoctetlength * Return the length of a bit string */ Datum @@ -986,7 +994,7 @@ bitnot(PG_FUNCTION_ARGS) p = VARBITS(arg); r = VARBITS(result); for (; p < VARBITEND(arg); p++) - *r++ = ~ *p; + *r++ = ~*p; /* Pad the result */ mask = BITMASK << VARBITPAD(result); @@ -1076,8 +1084,8 @@ bitshiftright(PG_FUNCTION_ARGS) /* Negative shift is a shift to the left */ if (shft < 0) PG_RETURN_DATUM(DirectFunctionCall2(bitshiftleft, - VarBitPGetDatum(arg), - Int32GetDatum(-shft))); + VarBitPGetDatum(arg), + Int32GetDatum(-shft))); result = (VarBit *) palloc(VARSIZE(arg)); VARATT_SIZEP(result) = VARSIZE(arg); @@ -1121,7 +1129,7 @@ bitshiftright(PG_FUNCTION_ARGS) } /* This is not defined in any standard. We retain the natural ordering of - * bits here, as it just seems more intuitive. + * bits here, as it just seems more intuitive. */ Datum bitfromint4(PG_FUNCTION_ARGS) @@ -1130,19 +1138,21 @@ bitfromint4(PG_FUNCTION_ARGS) VarBit *result; bits8 *r; int len; - + /* allocate enough space for the bits in an int4 */ - len = VARBITTOTALLEN(sizeof(int4)*BITS_PER_BYTE); + len = VARBITTOTALLEN(sizeof(int4) * BITS_PER_BYTE); result = (VarBit *) palloc(len); VARATT_SIZEP(result) = len; - VARBITLEN(result) = sizeof(int4)*BITS_PER_BYTE; - /* masks and shifts here are just too painful and we know that an int4 has - * got 4 bytes + VARBITLEN(result) = sizeof(int4) * BITS_PER_BYTE; + + /* + * masks and shifts here are just too painful and we know that an int4 + * has got 4 bytes */ r = VARBITS(result); - r[0] = (bits8) ((a >> (3*BITS_PER_BYTE)) & BITMASK); - r[1] = (bits8) ((a >> (2*BITS_PER_BYTE)) & BITMASK); - r[2] = (bits8) ((a >> (1*BITS_PER_BYTE)) & BITMASK); + r[0] = (bits8) ((a >> (3 * BITS_PER_BYTE)) & BITMASK); + r[1] = (bits8) ((a >> (2 * BITS_PER_BYTE)) & BITMASK); + r[2] = (bits8) ((a >> (1 * BITS_PER_BYTE)) & BITMASK); r[3] = (bits8) (a & BITMASK); PG_RETURN_VARBIT_P(result); @@ -1156,7 +1166,7 @@ bittoint4(PG_FUNCTION_ARGS) bits8 *r; /* Check that the bit string is not too long */ - if (VARBITLEN(arg) > sizeof(int4)*BITS_PER_BYTE) + if (VARBITLEN(arg) > sizeof(int4) * BITS_PER_BYTE) elog(ERROR, "Bit string is too large to fit in an int4"); result = 0; for (r = VARBITS(arg); r < VARBITEND(arg); r++) @@ -1179,18 +1189,18 @@ bittoint4(PG_FUNCTION_ARGS) Datum bitposition(PG_FUNCTION_ARGS) { - VarBit *substr = PG_GETARG_VARBIT_P(1); - VarBit *arg = PG_GETARG_VARBIT_P(0); - int substr_length, + VarBit *substr = PG_GETARG_VARBIT_P(1); + VarBit *arg = PG_GETARG_VARBIT_P(0); + int substr_length, arg_length, i, is; - bits8 *s, /* pointer into substring */ - *p; /* pointer into arg */ - bits8 cmp, /* shifted substring byte to compare */ - mask1, /* mask for substring byte shifted right */ - mask2, /* mask for substring byte shifted left */ - end_mask, /* pad mask for last substring byte */ + bits8 *s, /* pointer into substring */ + *p; /* pointer into arg */ + bits8 cmp, /* shifted substring byte to compare */ + mask1, /* mask for substring byte shifted right */ + mask2, /* mask for substring byte shifted left */ + end_mask, /* pad mask for last substring byte */ arg_mask; /* pad mask for last argument byte */ bool is_match; @@ -1200,8 +1210,8 @@ bitposition(PG_FUNCTION_ARGS) /* Argument has 0 length or substring longer than argument, return 0 */ if (arg_length == 0 || substr_length > arg_length) - PG_RETURN_INT32(0); - + PG_RETURN_INT32(0); + /* 0-length means return 1 */ if (substr_length == 0) PG_RETURN_INT32(1); @@ -1209,23 +1219,26 @@ bitposition(PG_FUNCTION_ARGS) /* Initialise the padding masks */ end_mask = BITMASK << VARBITPAD(substr); arg_mask = BITMASK << VARBITPAD(arg); - for (i = 0; i < VARBITBYTES(arg) - VARBITBYTES(substr) + 1; i++) + for (i = 0; i < VARBITBYTES(arg) - VARBITBYTES(substr) + 1; i++) { - for (is = 0; is < BITS_PER_BYTE; is++) { + for (is = 0; is < BITS_PER_BYTE; is++) + { is_match = true; p = VARBITS(arg) + i; mask1 = BITMASK >> is; mask2 = ~mask1; - for (s = VARBITS(substr); - is_match && s < VARBITEND(substr); s++) + for (s = VARBITS(substr); + is_match && s < VARBITEND(substr); s++) { cmp = *s >> is; - if (s == VARBITEND(substr) - 1) + if (s == VARBITEND(substr) - 1) { mask1 &= end_mask >> is; - if (p == VARBITEND(arg) - 1) { + if (p == VARBITEND(arg) - 1) + { /* Check that there is enough of arg left */ - if (mask1 & ~arg_mask) { + if (mask1 & ~arg_mask) + { is_match = false; break; } @@ -1237,21 +1250,24 @@ bitposition(PG_FUNCTION_ARGS) break; /* Move on to the next byte */ p++; - if (p == VARBITEND(arg)) { + if (p == VARBITEND(arg)) + { mask2 = end_mask << (BITS_PER_BYTE - is); is_match = mask2 == 0; #if 0 - elog(NOTICE,"S. %d %d em=%2x sm=%2x r=%d", - i,is,end_mask,mask2,is_match); + elog(NOTICE, "S. %d %d em=%2x sm=%2x r=%d", + i, is, end_mask, mask2, is_match); #endif break; } cmp = *s << (BITS_PER_BYTE - is); - if (s == VARBITEND(substr) - 1) + if (s == VARBITEND(substr) - 1) { mask2 &= end_mask << (BITS_PER_BYTE - is); - if (p == VARBITEND(arg) - 1) { - if (mask2 & ~arg_mask) { + if (p == VARBITEND(arg) - 1) + { + if (mask2 & ~arg_mask) + { is_match = false; break; } @@ -1262,7 +1278,7 @@ bitposition(PG_FUNCTION_ARGS) } /* Have we found a match */ if (is_match) - PG_RETURN_INT32(i*BITS_PER_BYTE + is + 1); + PG_RETURN_INT32(i * BITS_PER_BYTE + is + 1); } } PG_RETURN_INT32(0); diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c index acec5f0cf24..37eeee4206c 100644 --- a/src/backend/utils/adt/varchar.c +++ b/src/backend/utils/adt/varchar.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.74 2001/02/10 02:31:27 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.75 2001/03/22 03:59:55 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -64,8 +64,10 @@ Datum bpcharin(PG_FUNCTION_ARGS) { char *s = PG_GETARG_CSTRING(0); + #ifdef NOT_USED Oid typelem = PG_GETARG_OID(1); + #endif int32 atttypmod = PG_GETARG_INT32(2); BpChar *result; @@ -82,9 +84,9 @@ bpcharin(PG_FUNCTION_ARGS) else #ifdef MULTIBYTE { + /* - * truncate multi-byte string preserving multi-byte - * boundary + * truncate multi-byte string preserving multi-byte boundary */ len = pg_mbcliplen(s, atttypmod - VARHDRSZ, atttypmod - VARHDRSZ); } @@ -169,6 +171,7 @@ bpchar(PG_FUNCTION_ARGS) r = VARDATA(result); #ifdef MULTIBYTE + /* * truncate multi-byte string in a way not to break multi-byte * boundary @@ -214,18 +217,19 @@ _bpchar(PG_FUNCTION_ARGS) { ArrayType *v = (ArrayType *) PG_GETARG_VARLENA_P(0); int32 len = PG_GETARG_INT32(1); - FunctionCallInfoData locfcinfo; + FunctionCallInfoData locfcinfo; + /* - * Since bpchar() is a built-in function, we should only need to - * look it up once per run. + * Since bpchar() is a built-in function, we should only need to look + * it up once per run. */ - static FmgrInfo bpchar_finfo; + static FmgrInfo bpchar_finfo; if (bpchar_finfo.fn_oid == InvalidOid) fmgr_info(F_BPCHAR, &bpchar_finfo); MemSet(&locfcinfo, 0, sizeof(locfcinfo)); - locfcinfo.flinfo = &bpchar_finfo; + locfcinfo.flinfo = &bpchar_finfo; locfcinfo.nargs = 2; /* We assume we are "strict" and need not worry about null inputs */ locfcinfo.arg[0] = PointerGetDatum(v); @@ -280,7 +284,7 @@ bpchar_name(PG_FUNCTION_ARGS) /* Truncate to max length for a Name */ if (len >= NAMEDATALEN) - len = NAMEDATALEN-1; + len = NAMEDATALEN - 1; /* Remove trailing blanks */ while (len > 0) @@ -335,17 +339,19 @@ Datum varcharin(PG_FUNCTION_ARGS) { char *s = PG_GETARG_CSTRING(0); + #ifdef NOT_USED Oid typelem = PG_GETARG_OID(1); + #endif int32 atttypmod = PG_GETARG_INT32(2); - VarChar *result; + VarChar *result; int len; len = strlen(s) + VARHDRSZ; if (atttypmod >= (int32) VARHDRSZ && len > atttypmod) #ifdef MULTIBYTE - len = pg_mbcliplen(s, len - VARHDRSZ, atttypmod - VARHDRSZ) + VARHDRSZ; + len = pg_mbcliplen(s, len - VARHDRSZ, atttypmod - VARHDRSZ) + VARHDRSZ; #else len = atttypmod; /* clip the string at max length */ #endif @@ -364,7 +370,7 @@ varcharin(PG_FUNCTION_ARGS) Datum varcharout(PG_FUNCTION_ARGS) { - VarChar *s = PG_GETARG_VARCHAR_P(0); + VarChar *s = PG_GETARG_VARCHAR_P(0); char *result; int len; @@ -388,9 +394,9 @@ varcharout(PG_FUNCTION_ARGS) Datum varchar(PG_FUNCTION_ARGS) { - VarChar *s = PG_GETARG_VARCHAR_P(0); + VarChar *s = PG_GETARG_VARCHAR_P(0); int32 slen = PG_GETARG_INT32(1); - VarChar *result; + VarChar *result; int len; len = VARSIZE(s); @@ -402,8 +408,7 @@ varchar(PG_FUNCTION_ARGS) #ifdef MULTIBYTE /* - * truncate multi-byte string preserving multi-byte - * boundary + * truncate multi-byte string preserving multi-byte boundary */ len = pg_mbcliplen(VARDATA(s), slen - VARHDRSZ, slen - VARHDRSZ); slen = len + VARHDRSZ; @@ -427,18 +432,19 @@ _varchar(PG_FUNCTION_ARGS) { ArrayType *v = (ArrayType *) PG_GETARG_VARLENA_P(0); int32 len = PG_GETARG_INT32(1); - FunctionCallInfoData locfcinfo; + FunctionCallInfoData locfcinfo; + /* - * Since varchar() is a built-in function, we should only need to - * look it up once per run. + * Since varchar() is a built-in function, we should only need to look + * it up once per run. */ - static FmgrInfo varchar_finfo; + static FmgrInfo varchar_finfo; if (varchar_finfo.fn_oid == InvalidOid) fmgr_info(F_VARCHAR, &varchar_finfo); MemSet(&locfcinfo, 0, sizeof(locfcinfo)); - locfcinfo.flinfo = &varchar_finfo; + locfcinfo.flinfo = &varchar_finfo; locfcinfo.nargs = 2; /* We assume we are "strict" and need not worry about null inputs */ locfcinfo.arg[0] = PointerGetDatum(v); @@ -468,6 +474,7 @@ Datum bpcharlen(PG_FUNCTION_ARGS) { BpChar *arg = PG_GETARG_BPCHAR_P(0); + #ifdef MULTIBYTE unsigned char *s; int len, @@ -656,7 +663,7 @@ bpcharcmp(PG_FUNCTION_ARGS) /* * bpchar needs a specialized hash function because we want to ignore - * trailing blanks in comparisons. (varchar can use plain hashvarlena.) + * trailing blanks in comparisons. (varchar can use plain hashvarlena.) */ Datum hashbpchar(PG_FUNCTION_ARGS) @@ -685,7 +692,8 @@ hashbpchar(PG_FUNCTION_ARGS) Datum varcharlen(PG_FUNCTION_ARGS) { - VarChar *arg = PG_GETARG_VARCHAR_P(0); + VarChar *arg = PG_GETARG_VARCHAR_P(0); + #ifdef MULTIBYTE unsigned char *s; int len, @@ -711,7 +719,7 @@ varcharlen(PG_FUNCTION_ARGS) Datum varcharoctetlen(PG_FUNCTION_ARGS) { - VarChar *arg = PG_GETARG_VARCHAR_P(0); + VarChar *arg = PG_GETARG_VARCHAR_P(0); PG_RETURN_INT32(VARSIZE(arg) - VARHDRSZ); } @@ -728,8 +736,8 @@ varcharoctetlen(PG_FUNCTION_ARGS) Datum varchareq(PG_FUNCTION_ARGS) { - VarChar *arg1 = PG_GETARG_VARCHAR_P(0); - VarChar *arg2 = PG_GETARG_VARCHAR_P(1); + VarChar *arg1 = PG_GETARG_VARCHAR_P(0); + VarChar *arg2 = PG_GETARG_VARCHAR_P(1); int len1, len2; bool result; @@ -751,8 +759,8 @@ varchareq(PG_FUNCTION_ARGS) Datum varcharne(PG_FUNCTION_ARGS) { - VarChar *arg1 = PG_GETARG_VARCHAR_P(0); - VarChar *arg2 = PG_GETARG_VARCHAR_P(1); + VarChar *arg1 = PG_GETARG_VARCHAR_P(0); + VarChar *arg2 = PG_GETARG_VARCHAR_P(1); int len1, len2; bool result; @@ -774,8 +782,8 @@ varcharne(PG_FUNCTION_ARGS) Datum varcharlt(PG_FUNCTION_ARGS) { - VarChar *arg1 = PG_GETARG_VARCHAR_P(0); - VarChar *arg2 = PG_GETARG_VARCHAR_P(1); + VarChar *arg1 = PG_GETARG_VARCHAR_P(0); + VarChar *arg2 = PG_GETARG_VARCHAR_P(1); int len1, len2; int cmp; @@ -794,8 +802,8 @@ varcharlt(PG_FUNCTION_ARGS) Datum varcharle(PG_FUNCTION_ARGS) { - VarChar *arg1 = PG_GETARG_VARCHAR_P(0); - VarChar *arg2 = PG_GETARG_VARCHAR_P(1); + VarChar *arg1 = PG_GETARG_VARCHAR_P(0); + VarChar *arg2 = PG_GETARG_VARCHAR_P(1); int len1, len2; int cmp; @@ -814,8 +822,8 @@ varcharle(PG_FUNCTION_ARGS) Datum varchargt(PG_FUNCTION_ARGS) { - VarChar *arg1 = PG_GETARG_VARCHAR_P(0); - VarChar *arg2 = PG_GETARG_VARCHAR_P(1); + VarChar *arg1 = PG_GETARG_VARCHAR_P(0); + VarChar *arg2 = PG_GETARG_VARCHAR_P(1); int len1, len2; int cmp; @@ -834,8 +842,8 @@ varchargt(PG_FUNCTION_ARGS) Datum varcharge(PG_FUNCTION_ARGS) { - VarChar *arg1 = PG_GETARG_VARCHAR_P(0); - VarChar *arg2 = PG_GETARG_VARCHAR_P(1); + VarChar *arg1 = PG_GETARG_VARCHAR_P(0); + VarChar *arg2 = PG_GETARG_VARCHAR_P(1); int len1, len2; int cmp; @@ -854,8 +862,8 @@ varcharge(PG_FUNCTION_ARGS) Datum varcharcmp(PG_FUNCTION_ARGS) { - VarChar *arg1 = PG_GETARG_VARCHAR_P(0); - VarChar *arg2 = PG_GETARG_VARCHAR_P(1); + VarChar *arg1 = PG_GETARG_VARCHAR_P(0); + VarChar *arg2 = PG_GETARG_VARCHAR_P(1); int len1, len2; int cmp; diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index ba1ed5350ed..efa6ab65527 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.68 2001/02/10 02:31:27 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.69 2001/03/22 03:59:55 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -202,6 +202,7 @@ Datum textlen(PG_FUNCTION_ARGS) { text *t = PG_GETARG_TEXT_P(0); + #ifdef MULTIBYTE unsigned char *s; int len, @@ -236,10 +237,10 @@ textlen(PG_FUNCTION_ARGS) Datum textoctetlen(PG_FUNCTION_ARGS) { - struct varattrib *t = (struct varattrib *) PG_GETARG_RAW_VARLENA_P(0); + struct varattrib *t = (struct varattrib *) PG_GETARG_RAW_VARLENA_P(0); if (!VARATT_IS_EXTERNAL(t)) - PG_RETURN_INT32(VARATT_SIZE(t) - VARHDRSZ); + PG_RETURN_INT32(VARATT_SIZE(t) - VARHDRSZ); PG_RETURN_INT32(t->va_content.va_external.va_extsize); } @@ -320,9 +321,11 @@ text_substr(PG_FUNCTION_ARGS) int32 n = PG_GETARG_INT32(2); text *ret; int len; + #ifdef MULTIBYTE int i; char *p; + #endif len = VARSIZE(string) - VARHDRSZ; @@ -392,9 +395,11 @@ textpos(PG_FUNCTION_ARGS) len2; pg_wchar *p1, *p2; + #ifdef MULTIBYTE pg_wchar *ps1, *ps2; + #endif if (VARSIZE(t2) <= VARHDRSZ) @@ -843,7 +848,7 @@ text_name(PG_FUNCTION_ARGS) /* Truncate oversize input */ if (len >= NAMEDATALEN) - len = NAMEDATALEN-1; + len = NAMEDATALEN - 1; #ifdef STRINGDEBUG printf("text- convert string length %d (%d) ->%d\n", diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c index 1bedd565d03..f843f2bb166 100644 --- a/src/backend/utils/cache/catcache.c +++ b/src/backend/utils/cache/catcache.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.76 2001/02/22 18:39:19 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.77 2001/03/22 03:59:55 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -31,9 +31,9 @@ static void CatCacheRemoveCTup(CatCache *cache, CatCTup *ct); static Index CatalogCacheComputeHashIndex(CatCache *cache, - ScanKey cur_skey); + ScanKey cur_skey); static Index CatalogCacheComputeTupleHashIndex(CatCache *cache, - HeapTuple tuple); + HeapTuple tuple); static void CatalogCacheInitializeCache(CatCache *cache); static Datum cc_hashname(PG_FUNCTION_ARGS); @@ -88,8 +88,8 @@ GetCCHashFunc(Oid keytype) { switch (keytype) { - case BOOLOID: - case CHAROID: + case BOOLOID: + case CHAROID: return hashchar; case NAMEOID: return cc_hashname; @@ -125,7 +125,7 @@ cc_hashname(PG_FUNCTION_ARGS) */ NameData my_n; - namestrcpy(&my_n, NameStr(* PG_GETARG_NAME(0))); + namestrcpy(&my_n, NameStr(*PG_GETARG_NAME(0))); return DirectFunctionCall1(hashname, NameGetDatum(&my_n)); } @@ -141,15 +141,17 @@ cc_hashname(PG_FUNCTION_ARGS) void CreateCacheMemoryContext(void) { - /* Purely for paranoia, check that context doesn't exist; - * caller probably did so already. + + /* + * Purely for paranoia, check that context doesn't exist; caller + * probably did so already. */ if (!CacheMemoryContext) CacheMemoryContext = AllocSetContextCreate(TopMemoryContext, "CacheMemoryContext", - ALLOCSET_DEFAULT_MINSIZE, - ALLOCSET_DEFAULT_INITSIZE, - ALLOCSET_DEFAULT_MAXSIZE); + ALLOCSET_DEFAULT_MINSIZE, + ALLOCSET_DEFAULT_INITSIZE, + ALLOCSET_DEFAULT_MAXSIZE); } @@ -157,7 +159,7 @@ CreateCacheMemoryContext(void) * CatalogCacheInitializeCache * * This function does final initialization of a catcache: obtain the tuple - * descriptor and set up the hash and equality function links. We assume + * descriptor and set up the hash and equality function links. We assume * that the relcache entry can be opened at this point! * */ @@ -201,8 +203,8 @@ CatalogCacheInitializeCache(CatCache *cache) Assert(RelationIsValid(relation)); /* - * switch to the cache context so our allocations - * do not vanish at the end of a transaction + * switch to the cache context so our allocations do not vanish at the + * end of a transaction * */ if (!CacheMemoryContext) @@ -211,13 +213,13 @@ CatalogCacheInitializeCache(CatCache *cache) oldcxt = MemoryContextSwitchTo(CacheMemoryContext); /* - * copy the relcache's tuple descriptor to permanent cache storage + * copy the relcache's tuple descriptor to permanent cache storage * */ tupdesc = CreateTupleDescCopyConstr(RelationGetDescr(relation)); /* - * return to the caller's memory context and close the rel + * return to the caller's memory context and close the rel * */ MemoryContextSwitchTo(oldcxt); @@ -228,7 +230,7 @@ CatalogCacheInitializeCache(CatCache *cache) cache->cc_relname, cache->cc_nkeys); /* - * initialize cache's key information + * initialize cache's key information * */ for (i = 0; i < cache->cc_nkeys; ++i) @@ -238,9 +240,7 @@ CatalogCacheInitializeCache(CatCache *cache) CatalogCacheInitializeCache_DEBUG2; if (cache->cc_key[i] > 0) - { keytype = tupdesc->attrs[cache->cc_key[i] - 1]->atttypid; - } else { if (cache->cc_key[i] != ObjectIdAttributeNumber) @@ -249,6 +249,7 @@ CatalogCacheInitializeCache(CatCache *cache) } cache->cc_hashfunc[i] = GetCCHashFunc(keytype); + /* * If GetCCHashFunc liked the type, safe to index into eqproc[] */ @@ -268,7 +269,7 @@ CatalogCacheInitializeCache(CatCache *cache) } /* - * mark this cache fully initialized + * mark this cache fully initialized * */ cache->cc_tupdesc = tupdesc; @@ -293,22 +294,22 @@ CatalogCacheComputeHashIndex(CatCache *cache, ScanKey cur_skey) case 4: hashIndex ^= DatumGetUInt32(DirectFunctionCall1(cache->cc_hashfunc[3], - cur_skey[3].sk_argument)) << 9; + cur_skey[3].sk_argument)) << 9; /* FALLTHROUGH */ case 3: hashIndex ^= DatumGetUInt32(DirectFunctionCall1(cache->cc_hashfunc[2], - cur_skey[2].sk_argument)) << 6; + cur_skey[2].sk_argument)) << 6; /* FALLTHROUGH */ case 2: hashIndex ^= DatumGetUInt32(DirectFunctionCall1(cache->cc_hashfunc[1], - cur_skey[1].sk_argument)) << 3; + cur_skey[1].sk_argument)) << 3; /* FALLTHROUGH */ case 1: hashIndex ^= DatumGetUInt32(DirectFunctionCall1(cache->cc_hashfunc[0], - cur_skey[0].sk_argument)); + cur_skey[0].sk_argument)); break; default: elog(FATAL, "CCComputeHashIndex: %d cc_nkeys", cache->cc_nkeys); @@ -422,7 +423,7 @@ CatalogCacheIdInvalidate(int cacheId, CatCache *ccp; /* - * sanity checks + * sanity checks * */ Assert(hashIndex < NCCBUCK); @@ -430,7 +431,7 @@ CatalogCacheIdInvalidate(int cacheId, CACHE1_elog(DEBUG, "CatalogCacheIdInvalidate: called"); /* - * inspect caches to find the proper cache + * inspect caches to find the proper cache * */ for (ccp = Caches; ccp; ccp = ccp->cc_next) @@ -440,8 +441,9 @@ CatalogCacheIdInvalidate(int cacheId, if (cacheId != ccp->id) continue; + /* - * inspect the hash bucket until we find a match or exhaust + * inspect the hash bucket until we find a match or exhaust * */ for (elt = DLGetHead(&ccp->cc_cache[hashIndex]); elt; elt = nextelt) @@ -491,7 +493,7 @@ CatalogCacheIdInvalidate(int cacheId, void AtEOXact_CatCache(bool isCommit) { - CatCache *cache; + CatCache *cache; for (cache = Caches; cache; cache = cache->cc_next) { @@ -530,7 +532,7 @@ AtEOXact_CatCache(bool isCommit) void ResetSystemCache(void) { - CatCache *cache; + CatCache *cache; CACHE1_elog(DEBUG, "ResetSystemCache called"); @@ -617,7 +619,7 @@ do { \ #define InitCatCache_DEBUG1 #endif -CatCache * +CatCache * InitCatCache(int id, char *relname, char *indname, @@ -629,8 +631,8 @@ InitCatCache(int id, int i; /* - * first switch to the cache context so our allocations - * do not vanish at the end of a transaction + * first switch to the cache context so our allocations do not vanish + * at the end of a transaction * */ if (!CacheMemoryContext) @@ -639,15 +641,15 @@ InitCatCache(int id, oldcxt = MemoryContextSwitchTo(CacheMemoryContext); /* - * allocate a new cache structure + * allocate a new cache structure * */ cp = (CatCache *) palloc(sizeof(CatCache)); MemSet((char *) cp, 0, sizeof(CatCache)); /* - * initialize the cache buckets (each bucket is a list header) - * and the LRU tuple list + * initialize the cache buckets (each bucket is a list header) and the + * LRU tuple list * */ DLInitList(&cp->cc_lrulist); @@ -655,17 +657,17 @@ InitCatCache(int id, DLInitList(&cp->cc_cache[i]); /* - * Caches is the pointer to the head of the list of all the - * system caches. here we add the new cache to the top of the list. + * Caches is the pointer to the head of the list of all the system + * caches. here we add the new cache to the top of the list. * */ cp->cc_next = Caches; /* list of caches (single link) */ Caches = cp; /* - * initialize the cache's relation information for the relation - * corresponding to this cache, and initialize some of the new - * cache's other internal fields. But don't open the relation yet. + * initialize the cache's relation information for the relation + * corresponding to this cache, and initialize some of the new cache's + * other internal fields. But don't open the relation yet. * */ cp->cc_relname = relname; @@ -679,14 +681,14 @@ InitCatCache(int id, cp->cc_key[i] = key[i]; /* - * all done. new cache is initialized. print some debugging - * information, if appropriate. + * all done. new cache is initialized. print some debugging + * information, if appropriate. * */ InitCatCache_DEBUG1; /* - * back to the old context before we return... + * back to the old context before we return... * */ MemoryContextSwitchTo(oldcxt); @@ -774,14 +776,14 @@ SearchCatCache(CatCache *cache, MemoryContext oldcxt; /* - * one-time startup overhead + * one-time startup overhead * */ if (cache->cc_tupdesc == NULL) CatalogCacheInitializeCache(cache); /* - * initialize the search key information + * initialize the search key information * */ memcpy(cur_skey, cache->cc_skey, sizeof(cur_skey)); @@ -791,13 +793,13 @@ SearchCatCache(CatCache *cache, cur_skey[3].sk_argument = v4; /* - * find the hash bucket in which to look for the tuple + * find the hash bucket in which to look for the tuple * */ hash = CatalogCacheComputeHashIndex(cache, cur_skey); /* - * scan the hash bucket until we find a match or exhaust our tuples + * scan the hash bucket until we find a match or exhaust our tuples * */ for (elt = DLGetHead(&cache->cc_cache[hash]); @@ -812,8 +814,8 @@ SearchCatCache(CatCache *cache, continue; /* ignore dead entries */ /* - * see if the cached tuple matches our key. - * (should we be worried about time ranges? -cim 10/2/90) + * see if the cached tuple matches our key. (should we be worried + * about time ranges? -cim 10/2/90) * */ HeapKeyTest(&ct->tuple, @@ -821,16 +823,16 @@ SearchCatCache(CatCache *cache, cache->cc_nkeys, cur_skey, res); - if (! res) + if (!res) continue; /* - * we found a tuple in the cache: bump its refcount, move it to - * the front of the LRU list, and return it. We also move it - * to the front of the list for its hashbucket, in order to speed - * subsequent searches. (The most frequently accessed elements - * in any hashbucket will tend to be near the front of the - * hashbucket's list.) + * we found a tuple in the cache: bump its refcount, move it to + * the front of the LRU list, and return it. We also move it to + * the front of the list for its hashbucket, in order to speed + * subsequent searches. (The most frequently accessed elements in + * any hashbucket will tend to be near the front of the + * hashbucket's list.) * */ ct->refcount++; @@ -847,31 +849,30 @@ SearchCatCache(CatCache *cache, } /* - * Tuple was not found in cache, so we have to try and - * retrieve it directly from the relation. If it's found, - * we add it to the cache. + * Tuple was not found in cache, so we have to try and retrieve it + * directly from the relation. If it's found, we add it to the cache. * - * NOTE: it is possible for recursive cache lookups to occur while - * reading the relation --- for example, due to shared-cache-inval - * messages being processed during heap_open(). This is OK. It's - * even possible for one of those lookups to find and enter the - * very same tuple we are trying to fetch here. If that happens, - * we will enter a second copy of the tuple into the cache. The - * first copy will never be referenced again, and will eventually - * age out of the cache, so there's no functional problem. This case - * is rare enough that it's not worth expending extra cycles to detect. + * NOTE: it is possible for recursive cache lookups to occur while + * reading the relation --- for example, due to shared-cache-inval + * messages being processed during heap_open(). This is OK. It's + * even possible for one of those lookups to find and enter the very + * same tuple we are trying to fetch here. If that happens, we will + * enter a second copy of the tuple into the cache. The first copy + * will never be referenced again, and will eventually age out of the + * cache, so there's no functional problem. This case is rare enough + * that it's not worth expending extra cycles to detect. * */ /* - * open the relation associated with the cache + * open the relation associated with the cache * */ relation = heap_openr(cache->cc_relname, AccessShareLock); /* - * Scan the relation to find the tuple. If there's an index, and - * if it's safe to do so, use the index. Else do a heap scan. + * Scan the relation to find the tuple. If there's an index, and if + * it's safe to do so, use the index. Else do a heap scan. * */ ct = NULL; @@ -891,13 +892,13 @@ SearchCatCache(CatCache *cache, cache->cc_relname); /* - * For an index scan, sk_attno has to be set to the index attribute - * number(s), not the heap attribute numbers. We assume that the - * index corresponds exactly to the cache keys (or its first N - * keys do, anyway). + * For an index scan, sk_attno has to be set to the index + * attribute number(s), not the heap attribute numbers. We assume + * that the index corresponds exactly to the cache keys (or its + * first N keys do, anyway). */ for (i = 0; i < cache->cc_nkeys; ++i) - cur_skey[i].sk_attno = i+1; + cur_skey[i].sk_attno = i + 1; idesc = index_openr(cache->cc_indname); isd = index_beginscan(idesc, false, cache->cc_nkeys, cur_skey); @@ -948,21 +949,21 @@ SearchCatCache(CatCache *cache, } /* - * close the relation + * close the relation * */ heap_close(relation, AccessShareLock); /* - * scan is complete. if tup was found, we can add it to the cache. + * scan is complete. if tup was found, we can add it to the cache. * */ if (ct == NULL) return NULL; /* - * Finish initializing the CatCTup header, and add it to the - * linked lists. + * Finish initializing the CatCTup header, and add it to the linked + * lists. * */ CACHE1_elog(DEBUG, "SearchCatCache: found tuple"); @@ -977,8 +978,8 @@ SearchCatCache(CatCache *cache, DLAddHead(&cache->cc_cache[hash], &ct->cache_elem); /* - * If we've exceeded the desired size of this cache, - * try to throw away the least recently used entry. + * If we've exceeded the desired size of this cache, try to throw away + * the least recently used entry. * */ if (++cache->cc_ntup > cache->cc_maxtup) @@ -1022,7 +1023,7 @@ SearchCatCache(CatCache *cache, void ReleaseCatCache(HeapTuple tuple) { - CatCTup *ct = (CatCTup *) (((char *) tuple) - + CatCTup *ct = (CatCTup *) (((char *) tuple) - offsetof(CatCTup, tuple)); /* Safety checks to ensure we were handed a cache entry */ @@ -1038,9 +1039,9 @@ ReleaseCatCache(HeapTuple tuple) ) { /* We can find the associated cache using the dllist pointers */ - Dllist *lru = DLGetListHdr(&ct->lrulist_elem); - CatCache *cache = (CatCache *) (((char *) lru) - - offsetof(CatCache, cc_lrulist)); + Dllist *lru = DLGetListHdr(&ct->lrulist_elem); + CatCache *cache = (CatCache *) (((char *) lru) - + offsetof(CatCache, cc_lrulist)); CatCacheRemoveCTup(cache, ct); } @@ -1061,7 +1062,7 @@ ReleaseCatCache(HeapTuple tuple) * the specified relation, find all catcaches it could be in, compute the * correct hashindex for each such catcache, and call the specified function * to record the cache id, hashindex, and tuple ItemPointer in inval.c's - * lists. CatalogCacheIdInvalidate will be called later, if appropriate, + * lists. CatalogCacheIdInvalidate will be called later, if appropriate, * using the recorded information. * * Note that it is irrelevant whether the given tuple is actually loaded @@ -1082,7 +1083,7 @@ PrepareToInvalidateCacheTuple(Relation relation, CatCache *ccp; /* - * sanity checks + * sanity checks * */ Assert(RelationIsValid(relation)); diff --git a/src/backend/utils/cache/fcache.c b/src/backend/utils/cache/fcache.c index 8c246a1a9fd..91bea5cfc71 100644 --- a/src/backend/utils/cache/fcache.c +++ b/src/backend/utils/cache/fcache.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/fcache.c,v 1.38 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/fcache.c,v 1.39 2001/03/22 03:59:57 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -45,7 +45,10 @@ init_fcache(Oid foid, int nargs, MemoryContext fcacheCxt) if (nargs > FUNC_MAX_ARGS) elog(ERROR, "init_fcache: too many arguments"); - /* If function returns set, prepare a resultinfo node for communication */ + /* + * If function returns set, prepare a resultinfo node for + * communication + */ if (retval->func.fn_retset) { retval->fcinfo.resultinfo = (Node *) &(retval->rsinfo); diff --git a/src/backend/utils/cache/inval.c b/src/backend/utils/cache/inval.c index 8d15188aaf0..bb3c2822232 100644 --- a/src/backend/utils/cache/inval.c +++ b/src/backend/utils/cache/inval.c @@ -25,7 +25,7 @@ * so that they can flush obsolete entries from their caches. * * We do not need to register EVERY tuple operation in this way, just those - * on tuples in relations that have associated catcaches. Also, whenever + * on tuples in relations that have associated catcaches. Also, whenever * we see an operation on a pg_class or pg_attribute tuple, we register * a relcache flush operation for the relation described by that tuple. * @@ -34,7 +34,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.41 2001/02/22 18:39:19 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.42 2001/03/22 03:59:57 momjian Exp $ * * Note - this code is real crufty... badly needs a rewrite to improve * readability and portability. (Shouldn't assume Oid == Index, for example) @@ -136,8 +136,8 @@ static LocalInvalid RollbackStack = EmptyLocalInvalid; static InvalidationEntry InvalidationEntryAllocate(uint16 size); static void LocalInvalidInvalidate(LocalInvalid invalid, - void (*function) (InvalidationMessage), - bool freemember); + void (*function) (InvalidationMessage), + bool freemember); static LocalInvalid LocalInvalidRegister(LocalInvalid invalid, InvalidationEntry entry); static void DiscardInvalidStack(LocalInvalid *invalid); @@ -269,14 +269,14 @@ CacheIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid, InvalidationMessage message; /* - * debugging stuff + * debugging stuff * */ CacheIdRegisterSpecifiedLocalInvalid_DEBUG1; /* - * create a message describing the system catalog tuple - * we wish to invalidate. + * create a message describing the system catalog tuple we wish to + * invalidate. * */ message = (InvalidationMessage) @@ -289,7 +289,7 @@ CacheIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid, ItemPointerCopy(pointer, &message->any.catalog.pointerData); /* - * Add message to linked list of unprocessed messages. + * Add message to linked list of unprocessed messages. * */ invalid = LocalInvalidRegister(invalid, (InvalidationEntry) message); @@ -305,20 +305,22 @@ CacheIdRegisterLocalInvalid(int cacheId, Index hashIndex, ItemPointer pointer) { + /* - * debugging stuff + * debugging stuff * */ CacheIdRegisterLocalInvalid_DEBUG1; /* - * Add message to InvalidForall linked list. + * Add message to InvalidForall linked list. * */ InvalidForall = CacheIdRegisterSpecifiedLocalInvalid(InvalidForall, cacheId, hashIndex, pointer); + /* - * Add message to InvalidLocal linked list. + * Add message to InvalidLocal linked list. * */ InvalidLocal = CacheIdRegisterSpecifiedLocalInvalid(InvalidLocal, @@ -336,13 +338,13 @@ CacheIdRegisterLocalRollback(int cacheId, { /* - * debugging stuff + * debugging stuff * */ CacheIdRegisterLocalRollback_DEBUG1; /* - * Add message to RollbackStack linked list. + * Add message to RollbackStack linked list. * */ RollbackStack = CacheIdRegisterSpecifiedLocalInvalid( @@ -360,7 +362,7 @@ RelationIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid, InvalidationMessage message; /* - * debugging stuff + * debugging stuff * */ #ifdef INVALIDDEBUG @@ -369,8 +371,8 @@ RelationIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid, #endif /* defined(INVALIDDEBUG) */ /* - * create a message describing the relation descriptor - * we wish to invalidate. + * create a message describing the relation descriptor we wish to + * invalidate. * */ message = (InvalidationMessage) @@ -381,7 +383,7 @@ RelationIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid, message->any.relation.objectId = objectId; /* - * Add message to linked list of unprocessed messages. + * Add message to linked list of unprocessed messages. * */ invalid = LocalInvalidRegister(invalid, (InvalidationEntry) message); @@ -395,8 +397,9 @@ RelationIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid, static void RelationIdRegisterLocalInvalid(Oid relationId, Oid objectId) { + /* - * debugging stuff + * debugging stuff * */ #ifdef INVALIDDEBUG @@ -405,13 +408,14 @@ RelationIdRegisterLocalInvalid(Oid relationId, Oid objectId) #endif /* defined(INVALIDDEBUG) */ /* - * Add message to InvalidForall linked list. + * Add message to InvalidForall linked list. * */ InvalidForall = RelationIdRegisterSpecifiedLocalInvalid(InvalidForall, relationId, objectId); + /* - * Add message to InvalidLocal linked list. + * Add message to InvalidLocal linked list. * */ InvalidLocal = RelationIdRegisterSpecifiedLocalInvalid(InvalidLocal, @@ -427,7 +431,7 @@ RelationIdRegisterLocalRollback(Oid relationId, Oid objectId) { /* - * debugging stuff + * debugging stuff * */ #ifdef INVALIDDEBUG @@ -436,7 +440,7 @@ RelationIdRegisterLocalRollback(Oid relationId, Oid objectId) #endif /* defined(INVALIDDEBUG) */ /* - * Add message to RollbackStack linked list. + * Add message to RollbackStack linked list. * */ RollbackStack = RelationIdRegisterSpecifiedLocalInvalid( @@ -464,9 +468,10 @@ CacheIdInvalidate(Index cacheId, Index hashIndex, ItemPointer pointer) { + /* - * assume that if the item pointer is valid, then we are - * invalidating an item in the specified system catalog cache. + * assume that if the item pointer is valid, then we are invalidating + * an item in the specified system catalog cache. * */ if (ItemPointerIsValid(pointer)) @@ -478,8 +483,8 @@ CacheIdInvalidate(Index cacheId, CacheIdInvalidate_DEBUG1; /* - * if the cacheId is the oid of any of the following system relations, - * then assume we are invalidating a relation descriptor + * if the cacheId is the oid of any of the following system relations, + * then assume we are invalidating a relation descriptor * */ if (cacheId == RelOid_pg_class) @@ -495,7 +500,7 @@ CacheIdInvalidate(Index cacheId, } /* - * Yow! the caller asked us to invalidate something else. + * Yow! the caller asked us to invalidate something else. * */ elog(FATAL, "CacheIdInvalidate: cacheId=%d relation id?", cacheId); @@ -630,13 +635,13 @@ PrepareToInvalidateRelationCache(Relation relation, Oid objectId; /* - * get the relation object id + * get the relation object id * */ relationId = RelationGetRelid(relation); /* - * is it one of the ones we need to send an SI message for? + * is it one of the ones we need to send an SI message for? * */ if (relationId == RelOid_pg_class) @@ -647,7 +652,7 @@ PrepareToInvalidateRelationCache(Relation relation, return; /* - * register the relcache-invalidation action in the appropriate list + * register the relcache-invalidation action in the appropriate list * */ Assert(PointerIsValid(function)); @@ -666,8 +671,9 @@ PrepareToInvalidateRelationCache(Relation relation, void DiscardInvalid(void) { + /* - * debugging stuff + * debugging stuff * */ #ifdef INVALIDDEBUG @@ -690,7 +696,7 @@ RegisterInvalid(bool send) LocalInvalid invalid; /* - * debugging stuff + * debugging stuff * */ #ifdef INVALIDDEBUG @@ -698,7 +704,7 @@ RegisterInvalid(bool send) #endif /* defined(INVALIDDEBUG) */ /* - * Process and free the current list of inval messages. + * Process and free the current list of inval messages. * */ @@ -734,7 +740,7 @@ ImmediateLocalInvalidation(bool send) LocalInvalid invalid; /* - * debugging stuff + * debugging stuff * */ #ifdef INVALIDDEBUG @@ -742,7 +748,7 @@ ImmediateLocalInvalidation(bool send) #endif /* defined(INVALIDDEBUG) */ /* - * Process and free the local list of inval messages. + * Process and free the local list of inval messages. * */ @@ -792,8 +798,9 @@ PrepareForTupleInvalidation(Relation relation, HeapTuple tuple, void (*RelationIdRegisterFunc) (Oid, Oid), const char *funcname) { + /* - * sanity checks + * sanity checks * */ Assert(RelationIsValid(relation)); @@ -803,16 +810,16 @@ PrepareForTupleInvalidation(Relation relation, HeapTuple tuple, return; /* - * We only need to worry about invalidation for tuples that are in - * system relations; user-relation tuples are never in catcaches - * and can't affect the relcache either. + * We only need to worry about invalidation for tuples that are in + * system relations; user-relation tuples are never in catcaches and + * can't affect the relcache either. * */ if (!IsSystemRelationName(NameStr(RelationGetForm(relation)->relname))) return; /* - * debugging stuff + * debugging stuff * */ PrepareForTupleInvalidation_DEBUG1; diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 4e04cfea7c4..4882094bee1 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 - * $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.50 2001/01/24 19:43:15 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.51 2001/03/22 03:59:57 momjian Exp $ * * NOTES * Eventually, the index information should go through here, too. @@ -62,7 +62,7 @@ get_attname(Oid relid, AttrNumber attnum) if (HeapTupleIsValid(tp)) { Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp); - char *result; + char *result; result = pstrdup(NameStr(att_tup->attname)); ReleaseSysCache(tp); @@ -118,7 +118,7 @@ get_atttype(Oid relid, AttrNumber attnum) if (HeapTupleIsValid(tp)) { Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp); - Oid result; + Oid result; result = att_tup->atttypid; ReleaseSysCache(tp); @@ -144,7 +144,7 @@ get_attisset(Oid relid, char *attname) if (HeapTupleIsValid(tp)) { Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp); - bool result; + bool result; result = att_tup->attisset; ReleaseSysCache(tp); @@ -172,7 +172,7 @@ get_atttypmod(Oid relid, AttrNumber attnum) if (HeapTupleIsValid(tp)) { Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp); - int32 result; + int32 result; result = att_tup->atttypmod; ReleaseSysCache(tp); @@ -306,7 +306,7 @@ get_opcode(Oid opno) if (HeapTupleIsValid(tp)) { Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp); - RegProcedure result; + RegProcedure result; result = optup->oprcode; ReleaseSysCache(tp); @@ -333,7 +333,7 @@ get_opname(Oid opno) if (HeapTupleIsValid(tp)) { Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp); - char *result; + char *result; result = pstrdup(NameStr(optup->oprname)); ReleaseSysCache(tp); @@ -412,7 +412,7 @@ op_hashjoinable(Oid opno, Oid ltype, Oid rtype) bool op_iscachable(Oid opno) { - RegProcedure funcid = get_opcode(opno); + RegProcedure funcid = get_opcode(opno); if (funcid == (RegProcedure) InvalidOid) elog(ERROR, "Operator OID %u does not exist", opno); @@ -436,7 +436,7 @@ get_commutator(Oid opno) if (HeapTupleIsValid(tp)) { Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp); - Oid result; + Oid result; result = optup->oprcom; ReleaseSysCache(tp); @@ -462,7 +462,7 @@ get_negator(Oid opno) if (HeapTupleIsValid(tp)) { Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp); - Oid result; + Oid result; result = optup->oprnegate; ReleaseSysCache(tp); @@ -488,7 +488,7 @@ get_oprrest(Oid opno) if (HeapTupleIsValid(tp)) { Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp); - RegProcedure result; + RegProcedure result; result = optup->oprrest; ReleaseSysCache(tp); @@ -514,7 +514,7 @@ get_oprjoin(Oid opno) if (HeapTupleIsValid(tp)) { Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp); - RegProcedure result; + RegProcedure result; result = optup->oprjoin; ReleaseSysCache(tp); @@ -587,7 +587,7 @@ get_relnatts(Oid relid) if (HeapTupleIsValid(tp)) { Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); - int result; + int result; result = reltup->relnatts; ReleaseSysCache(tp); @@ -596,6 +596,7 @@ get_relnatts(Oid relid) else return InvalidAttrNumber; } + #endif /* @@ -616,7 +617,7 @@ get_rel_name(Oid relid) if (HeapTupleIsValid(tp)) { Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); - char *result; + char *result; result = pstrdup(NameStr(reltup->relname)); ReleaseSysCache(tp); @@ -644,7 +645,7 @@ get_typlen(Oid typid) if (HeapTupleIsValid(tp)) { Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp); - int16 result; + int16 result; result = typtup->typlen; ReleaseSysCache(tp); @@ -671,7 +672,7 @@ get_typbyval(Oid typid) if (HeapTupleIsValid(tp)) { Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp); - bool result; + bool result; result = typtup->typbyval; ReleaseSysCache(tp); @@ -687,7 +688,7 @@ get_typbyval(Oid typid) * A two-fer: given the type OID, return both typlen and typbyval. * * Since both pieces of info are needed to know how to copy a Datum, - * many places need both. Might as well get them with one cache lookup + * many places need both. Might as well get them with one cache lookup * instead of two. Also, this routine raises an error instead of * returning a bogus value when given a bad type OID. */ @@ -720,7 +721,7 @@ get_typalign(Oid typid) if (HeapTupleIsValid(tp)) { Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp); - char result; + char result; result = typtup->typalign; ReleaseSysCache(tp); @@ -743,7 +744,7 @@ get_typstorage(Oid typid) if (HeapTupleIsValid(tp)) { Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp); - char result; + char result; result = typtup->typstorage; ReleaseSysCache(tp); @@ -864,7 +865,7 @@ get_typtype(Oid typid) if (HeapTupleIsValid(tp)) { Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp); - char result; + char result; result = typtup->typtype; ReleaseSysCache(tp); diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index a2a539f5abf..fc97f46910a 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.128 2001/02/22 18:39:19 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.129 2001/03/22 03:59:57 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -135,7 +135,7 @@ typedef struct relidcacheent typedef struct relnodecacheent { - RelFileNode relnode; + RelFileNode relnode; Relation reldesc; } RelNodeCacheEnt; @@ -250,9 +250,11 @@ do { \ /* non-export function prototypes */ static void RelationClearRelation(Relation relation, bool rebuildIt); + #ifdef ENABLE_REINDEX_NAILED_RELATIONS static void RelationReloadClassinfo(Relation relation); -#endif /* ENABLE_REINDEX_NAILED_RELATIONS */ + +#endif /* ENABLE_REINDEX_NAILED_RELATIONS */ static void RelationFlushRelation(Relation relation); static Relation RelationNameCacheGetRelation(const char *relationName); static void RelationCacheInvalidateWalker(Relation *relationPtr, Datum listp); @@ -326,7 +328,7 @@ scan_pg_rel_seq(RelationBuildDescInfo buildinfo) ScanKeyData key; /* - * form a scan key + * form a scan key * */ switch (buildinfo.infotype) @@ -351,7 +353,7 @@ scan_pg_rel_seq(RelationBuildDescInfo buildinfo) } /* - * open pg_class and fetch a tuple + * open pg_class and fetch a tuple * */ pg_class_desc = heap_openr(RelationRelationName, AccessShareLock); @@ -359,18 +361,19 @@ scan_pg_rel_seq(RelationBuildDescInfo buildinfo) pg_class_tuple = heap_getnext(pg_class_scan, 0); /* - * get set to return tuple + * get set to return tuple * */ if (!HeapTupleIsValid(pg_class_tuple)) return_tuple = pg_class_tuple; else { + /* - * a satanic bug used to live here: pg_class_tuple used to be - * returned here without having the corresponding buffer pinned. - * so when the buffer gets replaced, all hell breaks loose. - * this bug is discovered and killed by wei on 9/27/91. + * a satanic bug used to live here: pg_class_tuple used to be + * returned here without having the corresponding buffer pinned. + * so when the buffer gets replaced, all hell breaks loose. this + * bug is discovered and killed by wei on 9/27/91. * */ return_tuple = heap_copytuple(pg_class_tuple); @@ -390,9 +393,10 @@ scan_pg_rel_ind(RelationBuildDescInfo buildinfo) HeapTuple return_tuple; pg_class_desc = heap_openr(RelationRelationName, AccessShareLock); + /* - * If the indexes of pg_class are deactivated - * we have to call scan_pg_rel_seq() instead. + * If the indexes of pg_class are deactivated we have to call + * scan_pg_rel_seq() instead. */ if (!pg_class_desc->rd_rel->relhasindex) { @@ -404,12 +408,12 @@ scan_pg_rel_ind(RelationBuildDescInfo buildinfo) { case INFO_RELID: return_tuple = ClassOidIndexScan(pg_class_desc, - ObjectIdGetDatum(buildinfo.i.info_id)); + ObjectIdGetDatum(buildinfo.i.info_id)); break; case INFO_RELNAME: return_tuple = ClassNameIndexScan(pg_class_desc, - PointerGetDatum(buildinfo.i.info_name)); + PointerGetDatum(buildinfo.i.info_name)); break; default: @@ -445,14 +449,14 @@ AllocateRelationDesc(Relation relation, Form_pg_class relp) oldcxt = MemoryContextSwitchTo(CacheMemoryContext); /* - * allocate space for new relation descriptor, if needed + * allocate space for new relation descriptor, if needed * */ if (relation == NULL) relation = (Relation) palloc(sizeof(RelationData)); /* - * clear all fields of reldesc + * clear all fields of reldesc * */ MemSet((char *) relation, 0, sizeof(RelationData)); @@ -461,14 +465,14 @@ AllocateRelationDesc(Relation relation, Form_pg_class relp) relation->rd_fd = -1; /* - * Copy the relation tuple form + * Copy the relation tuple form * - * We only allocate space for the fixed fields, ie, CLASS_TUPLE_SIZE. - * relacl is NOT stored in the relcache --- there'd be little point - * in it, since we don't copy the tuple's nullvalues bitmap and hence - * wouldn't know if the value is valid ... bottom line is that relacl - * *cannot* be retrieved from the relcache. Get it from the syscache - * if you need it. + * We only allocate space for the fixed fields, ie, CLASS_TUPLE_SIZE. + * relacl is NOT stored in the relcache --- there'd be little point in + * it, since we don't copy the tuple's nullvalues bitmap and hence + * wouldn't know if the value is valid ... bottom line is that relacl + * *cannot* be retrieved from the relcache. Get it from the syscache + * if you need it. * */ relationForm = (Form_pg_class) palloc(CLASS_TUPLE_SIZE); @@ -538,7 +542,7 @@ SetConstrOfRelation(Relation relation, constr->num_check = relation->rd_rel->relchecks; constr->check = (ConstrCheck *) MemoryContextAlloc(CacheMemoryContext, - constr->num_check * sizeof(ConstrCheck)); + constr->num_check * sizeof(ConstrCheck)); MemSet(constr->check, 0, constr->num_check * sizeof(ConstrCheck)); RelCheckFetch(relation); } @@ -571,7 +575,7 @@ build_tupdesc_seq(RelationBuildDescInfo buildinfo, constr->has_not_null = false; /* - * form a scan key + * form a scan key * */ ScanKeyEntryInitialize(&key, 0, @@ -580,14 +584,14 @@ build_tupdesc_seq(RelationBuildDescInfo buildinfo, ObjectIdGetDatum(RelationGetRelid(relation))); /* - * open pg_attribute and begin a scan + * open pg_attribute and begin a scan * */ pg_attribute_desc = heap_openr(AttributeRelationName, AccessShareLock); pg_attribute_scan = heap_beginscan(pg_attribute_desc, 0, SnapshotNow, 1, &key); /* - * add attribute data to relation->rd_att + * add attribute data to relation->rd_att * */ need = relation->rd_rel->relnatts; @@ -601,7 +605,7 @@ build_tupdesc_seq(RelationBuildDescInfo buildinfo, { relation->rd_att->attrs[attp->attnum - 1] = (Form_pg_attribute) MemoryContextAlloc(CacheMemoryContext, - ATTRIBUTE_TUPLE_SIZE); + ATTRIBUTE_TUPLE_SIZE); memcpy((char *) (relation->rd_att->attrs[attp->attnum - 1]), (char *) attp, @@ -621,7 +625,7 @@ build_tupdesc_seq(RelationBuildDescInfo buildinfo, relation->rd_rel->relnatts * sizeof(AttrDefault)); MemSet(attrdef, 0, - relation->rd_rel->relnatts * sizeof(AttrDefault)); + relation->rd_rel->relnatts * sizeof(AttrDefault)); } attrdef[ndef].adnum = attp->attnum; attrdef[ndef].adbin = NULL; @@ -636,34 +640,32 @@ build_tupdesc_seq(RelationBuildDescInfo buildinfo, need, (need == 1 ? "" : "s"), RelationGetRelid(relation)); /* - * end the scan and close the attribute relation + * end the scan and close the attribute relation * */ heap_endscan(pg_attribute_scan); heap_close(pg_attribute_desc, AccessShareLock); /* - * The attcacheoff values we read from pg_attribute should all be -1 - * ("unknown"). Verify this if assert checking is on. They will be - * computed when and if needed during tuple access. + * The attcacheoff values we read from pg_attribute should all be -1 + * ("unknown"). Verify this if assert checking is on. They will be + * computed when and if needed during tuple access. * */ #ifdef USE_ASSERT_CHECKING { - int i; + int i; for (i = 0; i < relation->rd_rel->relnatts; i++) - { Assert(relation->rd_att->attrs[i]->attcacheoff == -1); - } } #endif /* - * However, we can easily set the attcacheoff value for the first - * attribute: it must be zero. This eliminates the need for special - * cases for attnum=1 that used to exist in fastgetattr() and - * index_getattr(). + * However, we can easily set the attcacheoff value for the first + * attribute: it must be zero. This eliminates the need for special + * cases for attnum=1 that used to exist in fastgetattr() and + * index_getattr(). * */ relation->rd_att->attrs[0]->attcacheoff = 0; @@ -693,18 +695,19 @@ build_tupdesc_ind(RelationBuildDescInfo buildinfo, { #ifdef _DROP_COLUMN_HACK__ bool columnDropped = false; + #endif /* _DROP_COLUMN_HACK__ */ atttup = AttributeRelidNumIndexScan(attrel, - ObjectIdGetDatum(RelationGetRelid(relation)), + ObjectIdGetDatum(RelationGetRelid(relation)), Int32GetDatum(i)); if (!HeapTupleIsValid(atttup)) { #ifdef _DROP_COLUMN_HACK__ atttup = AttributeRelidNumIndexScan(attrel, - ObjectIdGetDatum(RelationGetRelid(relation)), - Int32GetDatum(DROPPED_COLUMN_INDEX(i))); + ObjectIdGetDatum(RelationGetRelid(relation)), + Int32GetDatum(DROPPED_COLUMN_INDEX(i))); if (!HeapTupleIsValid(atttup)) #endif /* _DROP_COLUMN_HACK__ */ elog(ERROR, "cannot find attribute %d of relation %s", i, @@ -754,23 +757,21 @@ build_tupdesc_ind(RelationBuildDescInfo buildinfo, heap_close(attrel, AccessShareLock); /* - * The attcacheoff values we read from pg_attribute should all be -1 - * ("unknown"). Verify this if assert checking is on. They will be - * computed when and if needed during tuple access. + * The attcacheoff values we read from pg_attribute should all be -1 + * ("unknown"). Verify this if assert checking is on. They will be + * computed when and if needed during tuple access. * */ #ifdef USE_ASSERT_CHECKING for (i = 0; i < relation->rd_rel->relnatts; i++) - { Assert(relation->rd_att->attrs[i]->attcacheoff == -1); - } #endif /* - * However, we can easily set the attcacheoff value for the first - * attribute: it must be zero. This eliminates the need for special - * cases for attnum=1 that used to exist in fastgetattr() and - * index_getattr(). + * However, we can easily set the attcacheoff value for the first + * attribute: it must be zero. This eliminates the need for special + * cases for attnum=1 that used to exist in fastgetattr() and + * index_getattr(). * */ relation->rd_att->attrs[0]->attcacheoff = 0; @@ -790,7 +791,7 @@ build_tupdesc_ind(RelationBuildDescInfo buildinfo, * each relcache entry that has associated rules. The context is used * just for rule info, not for any other subsidiary data of the relcache * entry, because that keeps the update logic in RelationClearRelation() - * manageable. The other subsidiary data structures are simple enough + * manageable. The other subsidiary data structures are simple enough * to be easy to free explicitly, anyway. * */ @@ -815,14 +816,14 @@ RelationBuildRuleLock(Relation relation) */ rulescxt = AllocSetContextCreate(CacheMemoryContext, RelationGetRelationName(relation), - 0, /* minsize */ - 1024, /* initsize */ - 1024); /* maxsize */ + 0, /* minsize */ + 1024, /* initsize */ + 1024); /* maxsize */ relation->rd_rulescxt = rulescxt; /* - * form an array to hold the rewrite rules (the array is extended if - * necessary) + * form an array to hold the rewrite rules (the array is extended if + * necessary) * */ maxlocks = 4; @@ -831,7 +832,7 @@ RelationBuildRuleLock(Relation relation) numlocks = 0; /* - * form a scan key + * form a scan key * */ ScanKeyEntryInitialize(&key, 0, @@ -840,7 +841,7 @@ RelationBuildRuleLock(Relation relation) ObjectIdGetDatum(RelationGetRelid(relation))); /* - * open pg_rewrite and begin a scan + * open pg_rewrite and begin a scan * */ pg_rewrite_desc = heap_openr(RewriteRelationName, AccessShareLock); @@ -870,7 +871,7 @@ RelationBuildRuleLock(Relation relation) pg_rewrite_tupdesc, &isnull)); rule->isInstead = DatumGetBool(heap_getattr(pg_rewrite_tuple, - Anum_pg_rewrite_is_instead, + Anum_pg_rewrite_is_instead, pg_rewrite_tupdesc, &isnull)); @@ -878,7 +879,7 @@ RelationBuildRuleLock(Relation relation) Anum_pg_rewrite_ev_action, pg_rewrite_tupdesc, &isnull); - Assert(! isnull); + Assert(!isnull); ruleaction_str = DatumGetCString(DirectFunctionCall1(textout, ruleaction)); oldcxt = MemoryContextSwitchTo(rulescxt); @@ -890,9 +891,9 @@ RelationBuildRuleLock(Relation relation) Anum_pg_rewrite_ev_qual, pg_rewrite_tupdesc, &isnull); - Assert(! isnull); + Assert(!isnull); rule_evqual_str = DatumGetCString(DirectFunctionCall1(textout, - rule_evqual)); + rule_evqual)); oldcxt = MemoryContextSwitchTo(rulescxt); rule->qual = (Node *) stringToNode(rule_evqual_str); MemoryContextSwitchTo(oldcxt); @@ -908,14 +909,14 @@ RelationBuildRuleLock(Relation relation) } /* - * end the scan and close the attribute relation + * end the scan and close the attribute relation * */ heap_endscan(pg_rewrite_scan); heap_close(pg_rewrite_desc, AccessShareLock); /* - * form a RuleLock and insert into relation + * form a RuleLock and insert into relation * */ rulelock = (RuleLock *) MemoryContextAlloc(rulescxt, sizeof(RuleLock)); @@ -1022,58 +1023,58 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo, MemoryContext oldcxt; /* - * find the tuple in pg_class corresponding to the given relation id + * find the tuple in pg_class corresponding to the given relation id * */ pg_class_tuple = ScanPgRelation(buildinfo); /* - * if no such tuple exists, return NULL + * if no such tuple exists, return NULL * */ if (!HeapTupleIsValid(pg_class_tuple)) return NULL; /* - * get information from the pg_class_tuple + * get information from the pg_class_tuple * */ relid = pg_class_tuple->t_data->t_oid; relp = (Form_pg_class) GETSTRUCT(pg_class_tuple); /* - * allocate storage for the relation descriptor, - * and copy pg_class_tuple to relation->rd_rel. + * allocate storage for the relation descriptor, and copy + * pg_class_tuple to relation->rd_rel. * */ relation = AllocateRelationDesc(oldrelation, relp); /* - * now we can free the memory allocated for pg_class_tuple + * now we can free the memory allocated for pg_class_tuple * */ heap_freetuple(pg_class_tuple); /* - * initialize the relation's relation id (relation->rd_id) + * initialize the relation's relation id (relation->rd_id) * */ RelationGetRelid(relation) = relid; /* - * initialize relation->rd_refcnt + * initialize relation->rd_refcnt * */ RelationSetReferenceCount(relation, 1); /* - * normal relations are not nailed into the cache + * normal relations are not nailed into the cache * */ relation->rd_isnailed = false; /* - * initialize the access method information (relation->rd_am) + * initialize the access method information (relation->rd_am) * */ relam = relation->rd_rel->relam; @@ -1082,13 +1083,13 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo, CacheMemoryContext); /* - * initialize the tuple descriptor (relation->rd_att). + * initialize the tuple descriptor (relation->rd_att). * */ RelationBuildTupleDesc(buildinfo, relation); /* - * Fetch rules and triggers that affect this relation + * Fetch rules and triggers that affect this relation * */ if (relation->rd_rel->relhasrules) @@ -1105,14 +1106,14 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo, relation->trigdesc = NULL; /* - * initialize index strategy and support information for this relation + * initialize index strategy and support information for this relation * */ if (OidIsValid(relam)) IndexedAccessMethodInitialize(relation); /* - * initialize the relation lock manager information + * initialize the relation lock manager information * */ RelationInitLockInfo(relation); /* see lmgr.c */ @@ -1124,8 +1125,8 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo, relation->rd_node.relNode = relation->rd_rel->relfilenode; /* - * open the relation and assign the file descriptor returned - * by the storage manager code to rd_fd. + * open the relation and assign the file descriptor returned by the + * storage manager code to rd_fd. * */ if (relation->rd_rel->relkind != RELKIND_VIEW) @@ -1134,8 +1135,8 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo, relation->rd_fd = -1; /* - * insert newly created relation into proper relcaches, - * restore memory context and return the new reldesc. + * insert newly created relation into proper relcaches, restore memory + * context and return the new reldesc. * */ oldcxt = MemoryContextSwitchTo(CacheMemoryContext); @@ -1203,36 +1204,36 @@ formrdesc(char *relationName, int i; /* - * allocate new relation desc + * allocate new relation desc * */ relation = (Relation) palloc(sizeof(RelationData)); MemSet((char *) relation, 0, sizeof(RelationData)); /* - * don't open the unix file yet.. + * don't open the unix file yet.. * */ relation->rd_fd = -1; /* - * initialize reference count + * initialize reference count * */ RelationSetReferenceCount(relation, 1); /* - * all entries built with this routine are nailed-in-cache + * all entries built with this routine are nailed-in-cache * */ relation->rd_isnailed = true; /* - * initialize relation tuple form + * initialize relation tuple form * - * The data we insert here is pretty incomplete/bogus, but it'll - * serve to get us launched. RelationCacheInitializePhase2() will - * read the real data from pg_class and replace what we've done here. + * The data we insert here is pretty incomplete/bogus, but it'll serve to + * get us launched. RelationCacheInitializePhase2() will read the + * real data from pg_class and replace what we've done here. * */ relation->rd_rel = (Form_pg_class) palloc(CLASS_TUPLE_SIZE); @@ -1257,13 +1258,13 @@ formrdesc(char *relationName, relation->rd_rel->relnatts = (int16) natts; /* - * initialize attribute tuple form + * initialize attribute tuple form * */ relation->rd_att = CreateTemplateTupleDesc(natts); /* - * initialize tuple desc info + * initialize tuple desc info * */ for (i = 0; i < natts; i++) @@ -1275,13 +1276,13 @@ formrdesc(char *relationName, } /* - * initialize relation id + * initialize relation id * */ RelationGetRelid(relation) = relation->rd_att->attrs[0]->attrelid; /* - * initialize the relation's lock manager and RelFileNode information + * initialize the relation's lock manager and RelFileNode information * */ RelationInitLockInfo(relation); /* see lmgr.c */ @@ -1290,11 +1291,11 @@ formrdesc(char *relationName, relation->rd_node.tblNode = InvalidOid; else relation->rd_node.tblNode = MyDatabaseId; - relation->rd_node.relNode = + relation->rd_node.relNode = relation->rd_rel->relfilenode = RelationGetRelid(relation); /* - * initialize the rel-has-index flag, using hardwired knowledge + * initialize the rel-has-index flag, using hardwired knowledge * */ relation->rd_rel->relhasindex = false; @@ -1313,7 +1314,7 @@ formrdesc(char *relationName, } /* - * add new reldesc to relcache + * add new reldesc to relcache * */ RelationCacheInsert(relation); @@ -1336,7 +1337,7 @@ fixrdesc(char *relationName) Relation relation; /* - * find the tuple in pg_class corresponding to the given relation name + * find the tuple in pg_class corresponding to the given relation name * */ buildinfo.infotype = INFO_RELNAME; @@ -1350,7 +1351,7 @@ fixrdesc(char *relationName) relp = (Form_pg_class) GETSTRUCT(pg_class_tuple); /* - * find the pre-made relcache entry (better be there!) + * find the pre-made relcache entry (better be there!) * */ relation = RelationNameCacheGetRelation(relationName); @@ -1359,8 +1360,8 @@ fixrdesc(char *relationName) relationName); /* - * and copy pg_class_tuple to relation->rd_rel. - * (See notes in AllocateRelationDesc()) + * and copy pg_class_tuple to relation->rd_rel. (See notes in + * AllocateRelationDesc()) * */ Assert(relation->rd_rel != NULL); @@ -1474,14 +1475,14 @@ RelationIdGetRelation(Oid relationId) RelationBuildDescInfo buildinfo; /* - * increment access statistics + * increment access statistics * */ IncrHeapAccessStat(local_RelationIdGetRelation); IncrHeapAccessStat(global_RelationIdGetRelation); /* - * first try and get a reldesc from the cache + * first try and get a reldesc from the cache * */ rd = RelationIdCacheGetRelation(relationId); @@ -1489,8 +1490,8 @@ RelationIdGetRelation(Oid relationId) return rd; /* - * no reldesc in the cache, so have RelationBuildDesc() - * build one and add it. + * no reldesc in the cache, so have RelationBuildDesc() build one and + * add it. * */ buildinfo.infotype = INFO_RELID; @@ -1514,15 +1515,15 @@ RelationNameGetRelation(const char *relationName) RelationBuildDescInfo buildinfo; /* - * increment access statistics + * increment access statistics * */ IncrHeapAccessStat(local_RelationNameGetRelation); IncrHeapAccessStat(global_RelationNameGetRelation); /* - * if caller is looking for a temp relation, substitute its real name; - * we only index temp rels by their real names. + * if caller is looking for a temp relation, substitute its real name; + * we only index temp rels by their real names. * */ temprelname = get_temp_rel_by_username(relationName); @@ -1530,7 +1531,7 @@ RelationNameGetRelation(const char *relationName) relationName = temprelname; /* - * first try and get a reldesc from the cache + * first try and get a reldesc from the cache * */ rd = RelationNameCacheGetRelation(relationName); @@ -1538,8 +1539,8 @@ RelationNameGetRelation(const char *relationName) return rd; /* - * no reldesc in the cache, so have RelationBuildDesc() - * build one and add it. + * no reldesc in the cache, so have RelationBuildDesc() build one and + * add it. * */ buildinfo.infotype = INFO_RELNAME; @@ -1592,7 +1593,7 @@ RelationReloadClassinfo(Relation relation) { RelationBuildDescInfo buildinfo; HeapTuple pg_class_tuple; - Form_pg_class relp; + Form_pg_class relp; if (!relation->rd_rel) return; @@ -1613,7 +1614,8 @@ RelationReloadClassinfo(Relation relation) return; } -#endif /* ENABLE_REINDEX_NAILED_RELATIONS */ + +#endif /* ENABLE_REINDEX_NAILED_RELATIONS */ /* * RelationClearRelation @@ -1633,7 +1635,7 @@ RelationClearRelation(Relation relation, bool rebuildIt) /* * Make sure smgr and lower levels close the relation's files, if they * weren't closed already. If the relation is not getting deleted, - * the next smgr access should reopen the files automatically. This + * the next smgr access should reopen the files automatically. This * ensures that the low-level file access state is updated after, say, * a vacuum truncation. */ @@ -1648,7 +1650,7 @@ RelationClearRelation(Relation relation, bool rebuildIt) { #ifdef ENABLE_REINDEX_NAILED_RELATIONS RelationReloadClassinfo(relation); -#endif /* ENABLE_REINDEX_NAILED_RELATIONS */ +#endif /* ENABLE_REINDEX_NAILED_RELATIONS */ return; } @@ -1740,9 +1742,7 @@ RelationClearRelation(Relation relation, bool rebuildIt) relation->rd_att = old_att; } else - { FreeTupleDesc(old_att); - } if (equalRuleLocks(old_rules, relation->rd_rules)) { if (relation->rd_rulescxt) @@ -1761,9 +1761,7 @@ RelationClearRelation(Relation relation, bool rebuildIt) relation->trigdesc = old_trigdesc; } else - { FreeTriggerDesc(old_trigdesc); - } relation->rd_nblocks = old_nblocks; /* @@ -1787,6 +1785,7 @@ RelationFlushRelation(Relation relation) if (relation->rd_myxactonly) { + /* * Local rels should always be rebuilt, not flushed; the relcache * entry must live until RelationPurgeLocalRelation(). @@ -1912,7 +1911,7 @@ RelationFlushIndexes(Relation *r, * We do this in two phases: the first pass deletes deletable items, and * the second one rebuilds the rebuildable items. This is essential for * safety, because HashTableWalk only copes with concurrent deletion of - * the element it is currently visiting. If a second SI overflow were to + * the element it is currently visiting. If a second SI overflow were to * occur while we are walking the table, resulting in recursive entry to * this routine, we could crash because the inner invocation blows away * the entry next to be visited by the outer scan. But this way is OK, @@ -1923,8 +1922,8 @@ RelationFlushIndexes(Relation *r, void RelationCacheInvalidate(void) { - List *rebuildList = NIL; - List *l; + List *rebuildList = NIL; + List *l; /* Phase 1 */ HashTableWalk(RelationNameCache, @@ -1932,7 +1931,7 @@ RelationCacheInvalidate(void) PointerGetDatum(&rebuildList)); /* Phase 2: rebuild the items found to need rebuild in phase 1 */ - foreach (l, rebuildList) + foreach(l, rebuildList) { Relation relation = (Relation) lfirst(l); @@ -1945,7 +1944,7 @@ static void RelationCacheInvalidateWalker(Relation *relationPtr, Datum listp) { Relation relation = *relationPtr; - List **rebuildList = (List **) DatumGetPointer(listp); + List **rebuildList = (List **) DatumGetPointer(listp); /* We can ignore xact-local relations, since they are never SI targets */ if (relation->rd_myxactonly) @@ -2070,7 +2069,7 @@ RelationCacheInitialize(void) HASHCTL ctl; /* - * switch to cache memory context + * switch to cache memory context * */ if (!CacheMemoryContext) @@ -2079,7 +2078,7 @@ RelationCacheInitialize(void) oldcxt = MemoryContextSwitchTo(CacheMemoryContext); /* - * create global caches + * create global caches * */ MemSet(&ctl, 0, (int) sizeof(ctl)); @@ -2095,14 +2094,14 @@ RelationCacheInitialize(void) ctl.keysize = sizeof(RelFileNode); ctl.hash = tag_hash; RelationNodeCache = hash_create(INITRELCACHESIZE, &ctl, - HASH_ELEM | HASH_FUNCTION); + HASH_ELEM | HASH_FUNCTION); /* - * initialize the cache with pre-made relation descriptors - * for some of the more important system relations. These - * relations should always be in the cache. + * initialize the cache with pre-made relation descriptors for some of + * the more important system relations. These relations should always + * be in the cache. * - * NB: see also the list in RelationCacheInitializePhase2(). + * NB: see also the list in RelationCacheInitializePhase2(). * */ formrdesc(RelationRelationName, Natts_pg_class, Desc_pg_class); @@ -2113,9 +2112,9 @@ RelationCacheInitialize(void) formrdesc(LogRelationName, Natts_pg_log, Desc_pg_log); /* - * init_irels() used to be called here. It is changed to be called - * in RelationCacheInitializePhase2() now so that transactional - * control could guarantee the consistency. + * init_irels() used to be called here. It is changed to be called in + * RelationCacheInitializePhase2() now so that transactional control + * could guarantee the consistency. */ MemoryContextSwitchTo(oldcxt); @@ -2131,21 +2130,25 @@ RelationCacheInitialize(void) void RelationCacheInitializePhase2(void) { + /* * Get the real pg_class tuple for each nailed-in-cache relcache entry * that was made by RelationCacheInitialize(), and replace the phony - * rd_rel entry made by formrdesc(). This is necessary so that we have, - * for example, the correct toast-table info for tables that have such. + * rd_rel entry made by formrdesc(). This is necessary so that we + * have, for example, the correct toast-table info for tables that + * have such. */ if (!IsBootstrapProcessingMode()) { + /* * Initialize critical system index relation descriptors, first. * They are to make building relation descriptors fast. - * init_irels() used to be called in RelationCacheInitialize(). - * It is changed to be called here to be transaction safe. + * init_irels() used to be called in RelationCacheInitialize(). It + * is changed to be called here to be transaction safe. */ MemoryContext oldcxt = MemoryContextSwitchTo(CacheMemoryContext); + init_irels(); MemoryContextSwitchTo(oldcxt); @@ -2154,19 +2157,23 @@ RelationCacheInitializePhase2(void) fixrdesc(AttributeRelationName); fixrdesc(ProcedureRelationName); fixrdesc(TypeRelationName); - /* We don't bother to update the entries for pg_variable or pg_log. */ + + /* + * We don't bother to update the entries for pg_variable or + * pg_log. + */ } } /* used by XLogInitCache */ -void CreateDummyCaches(void); -void DestroyDummyCaches(void); +void CreateDummyCaches(void); +void DestroyDummyCaches(void); void CreateDummyCaches(void) { - MemoryContext oldcxt; - HASHCTL ctl; + MemoryContext oldcxt; + HASHCTL ctl; if (!CacheMemoryContext) CreateCacheMemoryContext(); @@ -2186,14 +2193,14 @@ CreateDummyCaches(void) ctl.keysize = sizeof(RelFileNode); ctl.hash = tag_hash; RelationNodeCache = hash_create(INITRELCACHESIZE, &ctl, - HASH_ELEM | HASH_FUNCTION); + HASH_ELEM | HASH_FUNCTION); MemoryContextSwitchTo(oldcxt); } void DestroyDummyCaches(void) { - MemoryContext oldcxt; + MemoryContext oldcxt; if (!CacheMemoryContext) return; @@ -2293,8 +2300,8 @@ AttrDefaultFetch(Relation relation) RelationGetRelationName(relation)); else attrdef[i].adbin = MemoryContextStrdup(CacheMemoryContext, - DatumGetCString(DirectFunctionCall1(textout, - val))); + DatumGetCString(DirectFunctionCall1(textout, + val))); break; } if (hasindex) @@ -2399,8 +2406,8 @@ RelCheckFetch(Relation relation) elog(ERROR, "RelCheckFetch: rcbin IS NULL for rel %s", RelationGetRelationName(relation)); check[found].ccbin = MemoryContextStrdup(CacheMemoryContext, - DatumGetCString(DirectFunctionCall1(textout, - val))); + DatumGetCString(DirectFunctionCall1(textout, + val))); found++; if (hasindex) ReleaseBuffer(buffer); @@ -2438,7 +2445,7 @@ RelCheckFetch(Relation relation) * * Since shared cache inval causes the relcache's copy of the list to go away, * we return a copy of the list palloc'd in the caller's context. The caller - * may freeList() the returned list after scanning it. This is necessary + * may freeList() the returned list after scanning it. This is necessary * since the caller will typically be doing syscache lookups on the relevant * indexes, and syscache lookup could cause SI messages to be processed! */ @@ -2468,7 +2475,7 @@ RelationGetIndexList(Relation relation) (bits16) 0x0, (AttrNumber) 1, (RegProcedure) F_OIDEQ, - ObjectIdGetDatum(RelationGetRelid(relation))); + ObjectIdGetDatum(RelationGetRelid(relation))); sd = index_beginscan(irel, false, 1, &skey); } else @@ -2477,18 +2484,18 @@ RelationGetIndexList(Relation relation) (bits16) 0x0, (AttrNumber) Anum_pg_index_indrelid, (RegProcedure) F_OIDEQ, - ObjectIdGetDatum(RelationGetRelid(relation))); + ObjectIdGetDatum(RelationGetRelid(relation))); hscan = heap_beginscan(indrel, false, SnapshotNow, 1, &skey); } /* - * We build the list we intend to return (in the caller's context) while - * doing the scan. After successfully completing the scan, we copy that - * list into the relcache entry. This avoids cache-context memory leakage - * if we get some sort of error partway through. + * We build the list we intend to return (in the caller's context) + * while doing the scan. After successfully completing the scan, we + * copy that list into the relcache entry. This avoids cache-context + * memory leakage if we get some sort of error partway through. */ result = NIL; - + for (;;) { HeapTupleData tuple; @@ -2806,6 +2813,7 @@ write_irels(void) fd = PathNameOpenFile(tempfilename, O_WRONLY | O_CREAT | O_TRUNC | PG_BINARY, 0600); if (fd < 0) { + /* * We used to consider this a fatal error, but we might as well * continue with backend startup ... @@ -2943,7 +2951,5 @@ write_irels(void) * previously-existing init file. */ if (rename(tempfilename, finalfilename) < 0) - { elog(NOTICE, "Cannot rename init file %s to %s: %m\n\tContinuing anyway, but there's something wrong.", tempfilename, finalfilename); - } } diff --git a/src/backend/utils/cache/syscache.c b/src/backend/utils/cache/syscache.c index 4a6a8c00bca..75ef3179202 100644 --- a/src/backend/utils/cache/syscache.c +++ b/src/backend/utils/cache/syscache.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.59 2001/02/22 18:39:20 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.60 2001/03/22 03:59:57 momjian Exp $ * * NOTES * These routines allow the parser/planner/executor to perform @@ -60,7 +60,7 @@ In include/catalog/indexing.h, add a define for the number of indexes on the relation, add define(s) for the index name(s), add an extern array to hold the index names, and use DECLARE_UNIQUE_INDEX to define - the index. Cache lookups return only one row, so the index should be + the index. Cache lookups return only one row, so the index should be unique in most cases. In backend/catalog/indexing.c, initialize the relation array with @@ -89,261 +89,262 @@ struct cachedesc static struct cachedesc cacheinfo[] = { {AggregateRelationName, /* AGGNAME */ - AggregateNameTypeIndex, + AggregateNameTypeIndex, 2, { Anum_pg_aggregate_aggname, Anum_pg_aggregate_aggbasetype, 0, 0 - }}, + }}, {AccessMethodRelationName, /* AMNAME */ - AmNameIndex, + AmNameIndex, 1, { Anum_pg_am_amname, 0, 0, 0 - }}, + }}, {AccessMethodOperatorRelationName, /* AMOPOPID */ - AccessMethodOpidIndex, + AccessMethodOpidIndex, 3, { Anum_pg_amop_amopclaid, Anum_pg_amop_amopopr, Anum_pg_amop_amopid, 0 - }}, + }}, {AccessMethodOperatorRelationName, /* AMOPSTRATEGY */ - AccessMethodStrategyIndex, + AccessMethodStrategyIndex, 3, { Anum_pg_amop_amopid, Anum_pg_amop_amopclaid, Anum_pg_amop_amopstrategy, 0 - }}, + }}, {AttributeRelationName, /* ATTNAME */ - AttributeRelidNameIndex, + AttributeRelidNameIndex, 2, { Anum_pg_attribute_attrelid, Anum_pg_attribute_attname, 0, 0 - }}, + }}, {AttributeRelationName, /* ATTNUM */ - AttributeRelidNumIndex, + AttributeRelidNumIndex, 2, { Anum_pg_attribute_attrelid, Anum_pg_attribute_attnum, 0, 0 - }}, + }}, {OperatorClassRelationName, /* CLADEFTYPE */ - OpclassDeftypeIndex, + OpclassDeftypeIndex, 1, { Anum_pg_opclass_opcdeftype, 0, 0, 0 - }}, + }}, {OperatorClassRelationName, /* CLANAME */ - OpclassNameIndex, + OpclassNameIndex, 1, { Anum_pg_opclass_opcname, 0, 0, 0 - }}, + }}, {GroupRelationName, /* GRONAME */ - GroupNameIndex, + GroupNameIndex, 1, { Anum_pg_group_groname, 0, 0, 0 - }}, + }}, {GroupRelationName, /* GROSYSID */ - GroupSysidIndex, + GroupSysidIndex, 1, { Anum_pg_group_grosysid, 0, 0, 0 - }}, + }}, {IndexRelationName, /* INDEXRELID */ - IndexRelidIndex, + IndexRelidIndex, 1, { Anum_pg_index_indexrelid, 0, 0, 0 - }}, + }}, {InheritsRelationName, /* INHRELID */ - InheritsRelidSeqnoIndex, + InheritsRelidSeqnoIndex, 2, { Anum_pg_inherits_inhrelid, Anum_pg_inherits_inhseqno, 0, 0 - }}, + }}, {LanguageRelationName, /* LANGNAME */ - LanguageNameIndex, + LanguageNameIndex, 1, { Anum_pg_language_lanname, 0, 0, 0 - }}, + }}, {LanguageRelationName, /* LANGOID */ - LanguageOidIndex, + LanguageOidIndex, 1, { ObjectIdAttributeNumber, 0, 0, 0 - }}, + }}, {ListenerRelationName, /* LISTENREL */ - ListenerPidRelnameIndex, + ListenerPidRelnameIndex, 2, { Anum_pg_listener_pid, Anum_pg_listener_relname, 0, 0 - }}, + }}, {OperatorRelationName, /* OPERNAME */ - OperatorNameIndex, + OperatorNameIndex, 4, { Anum_pg_operator_oprname, Anum_pg_operator_oprleft, Anum_pg_operator_oprright, Anum_pg_operator_oprkind - }}, + }}, {OperatorRelationName, /* OPEROID */ - OperatorOidIndex, + OperatorOidIndex, 1, { ObjectIdAttributeNumber, 0, 0, 0 - }}, + }}, {ProcedureRelationName, /* PROCNAME */ - ProcedureNameIndex, + ProcedureNameIndex, 3, { Anum_pg_proc_proname, Anum_pg_proc_pronargs, Anum_pg_proc_proargtypes, 0 - }}, + }}, {ProcedureRelationName, /* PROCOID */ - ProcedureOidIndex, + ProcedureOidIndex, 1, { ObjectIdAttributeNumber, 0, 0, 0 - }}, + }}, {RelationRelationName, /* RELNAME */ - ClassNameIndex, + ClassNameIndex, 1, { Anum_pg_class_relname, 0, 0, 0 - }}, + }}, {RelationRelationName, /* RELOID */ - ClassOidIndex, + ClassOidIndex, 1, { ObjectIdAttributeNumber, 0, 0, 0 - }}, + }}, {RewriteRelationName, /* REWRITENAME */ - RewriteRulenameIndex, + RewriteRulenameIndex, 1, { Anum_pg_rewrite_rulename, 0, 0, 0 - }}, + }}, {RewriteRelationName, /* RULEOID */ - RewriteOidIndex, + RewriteOidIndex, 1, { ObjectIdAttributeNumber, 0, 0, 0 - }}, + }}, {ShadowRelationName, /* SHADOWNAME */ - ShadowNameIndex, + ShadowNameIndex, 1, { Anum_pg_shadow_usename, 0, 0, 0 - }}, + }}, {ShadowRelationName, /* SHADOWSYSID */ - ShadowSysidIndex, + ShadowSysidIndex, 1, { Anum_pg_shadow_usesysid, 0, 0, 0 - }}, + }}, {StatisticRelationName, /* STATRELID */ - StatisticRelidAttnumIndex, + StatisticRelidAttnumIndex, 2, { Anum_pg_statistic_starelid, Anum_pg_statistic_staattnum, 0, 0 - }}, + }}, {TypeRelationName, /* TYPENAME */ - TypeNameIndex, + TypeNameIndex, 1, { Anum_pg_type_typname, 0, 0, 0 - }}, + }}, {TypeRelationName, /* TYPEOID */ - TypeOidIndex, + TypeOidIndex, 1, { ObjectIdAttributeNumber, 0, 0, 0 - }} + }} }; -static CatCache *SysCache[lengthof(cacheinfo)]; -static int SysCacheSize = lengthof(cacheinfo); +static CatCache *SysCache[ + lengthof(cacheinfo)]; +static int SysCacheSize = lengthof(cacheinfo); static bool CacheInitialized = false; @@ -358,7 +359,7 @@ IsCacheInitialized(void) * InitCatalogCache - initialize the caches * * Note that no database access is done here; we only allocate memory - * and initialize the cache structure. Interrogation of the database + * and initialize the cache structure. Interrogation of the database * to complete initialization of a cache happens only upon first use * of that cache. */ @@ -419,8 +420,8 @@ SearchSysCache(int cacheId, /* * If someone tries to look up a relname, translate temp relation - * names to real names. Less obviously, apply the same translation - * to type names, so that the type tuple of a temp table will be found + * names to real names. Less obviously, apply the same translation to + * type names, so that the type tuple of a temp table will be found * when sought. This is a kluge ... temp table substitution should be * happening at a higher level ... */ @@ -522,8 +523,8 @@ SysCacheGetAttr(int cacheId, HeapTuple tup, /* * We just need to get the TupleDesc out of the cache entry, and then * we can apply heap_getattr(). We expect that the cache control data - * is currently valid --- if the caller recently fetched the tuple, then - * it should be. + * is currently valid --- if the caller recently fetched the tuple, + * then it should be. */ if (cacheId < 0 || cacheId >= SysCacheSize) elog(ERROR, "SysCacheGetAttr: Bad cache id %d", cacheId); diff --git a/src/backend/utils/cache/temprel.c b/src/backend/utils/cache/temprel.c index b4ca06bbce6..88dc606cb0e 100644 --- a/src/backend/utils/cache/temprel.c +++ b/src/backend/utils/cache/temprel.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.34 2001/01/24 19:43:15 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.35 2001/03/22 03:59:58 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -19,7 +19,7 @@ * * When a temp table is created, normal entries are made for it in pg_class, * pg_type, etc using a unique "physical" relation name. We also make an - * entry in the temp table list maintained by this module. Subsequently, + * entry in the temp table list maintained by this module. Subsequently, * relname lookups are filtered through the temp table list, and attempts * to look up a temp table name are changed to look up the physical name. * This allows temp table names to mask a regular table of the same name @@ -50,12 +50,13 @@ typedef struct TempTable NameData relname; /* underlying unique name */ Oid relid; /* needed properties of rel */ char relkind; + /* - * If this entry was created during this xact, it should be deleted - * at xact abort. Conversely, if this entry was deleted during this - * xact, it should be removed at xact commit. We leave deleted entries - * in the list until commit so that we can roll back if needed --- - * but we ignore them for purposes of lookup! + * If this entry was created during this xact, it should be deleted at + * xact abort. Conversely, if this entry was deleted during this + * xact, it should be removed at xact commit. We leave deleted + * entries in the list until commit so that we can roll back if needed + * --- but we ignore them for purposes of lookup! */ bool created_in_cur_xact; bool deleted_in_cur_xact; @@ -110,7 +111,11 @@ remove_temp_rel_by_relid(Oid relid) if (temp_rel->relid == relid) temp_rel->deleted_in_cur_xact = true; - /* Keep scanning 'cause there could be multiple matches; see RENAME */ + + /* + * Keep scanning 'cause there could be multiple matches; see + * RENAME + */ } } @@ -161,10 +166,10 @@ rename_temp_relation(const char *oldname, * xact. One of these entries will be deleted at xact end. * * NOTE: the new mapping entry is inserted into the list just after - * the old one. We could alternatively insert it before the old one, - * but that'd take more code. It does need to be in one spot or the - * other, to ensure that deletion of temp rels happens in the right - * order during remove_all_temp_relations(). + * the old one. We could alternatively insert it before the old + * one, but that'd take more code. It does need to be in one spot + * or the other, to ensure that deletion of temp rels happens in + * the right order during remove_all_temp_relations(). */ oldcxt = MemoryContextSwitchTo(CacheMemoryContext); @@ -208,11 +213,11 @@ remove_all_temp_relations(void) StartTransactionCommand(); /* - * Scan the list and delete all entries not already deleted. - * We need not worry about list entries getting deleted from under us, - * because remove_temp_rel_by_relid() doesn't remove entries, only - * mark them dead. Note that entries will be deleted in reverse order - * of creation --- that's critical for cases involving inheritance. + * Scan the list and delete all entries not already deleted. We need + * not worry about list entries getting deleted from under us, because + * remove_temp_rel_by_relid() doesn't remove entries, only mark them + * dead. Note that entries will be deleted in reverse order of + * creation --- that's critical for cases involving inheritance. */ foreach(l, temp_rels) { diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index a8b6215930e..55c7e69c67b 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.82 2001/03/10 04:21:51 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.83 2001/03/22 03:59:58 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -52,24 +52,24 @@ extern CommandDest whereToSendOutput; * 2 = syslog only * ... in theory anyway */ -int Use_syslog = 0; -char *Syslog_facility; -char *Syslog_ident; +int Use_syslog = 0; +char *Syslog_facility; +char *Syslog_ident; static void write_syslog(int level, const char *line); #else -# define Use_syslog 0 +#define Use_syslog 0 #endif -bool Log_timestamp; -bool Log_pid; +bool Log_timestamp; +bool Log_pid; #define TIMESTAMP_SIZE 20 /* format `YYYY-MM-DD HH:MM:SS ' */ #define PID_SIZE 9 /* format `[123456] ' */ -static const char * print_timestamp(void); -static const char * print_pid(void); +static const char *print_timestamp(void); +static const char *print_pid(void); static int Debugfile = -1; static int ElogDebugIndentLevel = 0; @@ -93,9 +93,10 @@ static int ElogDebugIndentLevel = 0; *-------------------- */ void -elog(int lev, const char *fmt, ...) +elog(int lev, const char *fmt,...) { va_list ap; + /* * The expanded format and final output message are dynamically * allocated if necessary, but not if they fit in the "reasonable @@ -108,17 +109,19 @@ elog(int lev, const char *fmt, ...) * Note that we use malloc() not palloc() because we want to retain * control if we run out of memory. palloc() would recursively call * elog(ERROR), which would be all right except if we are working on a - * FATAL or REALLYFATAL error. We'd lose track of the fatal condition + * FATAL or REALLYFATAL error. We'd lose track of the fatal condition * and report a mere ERROR to outer loop, which would be a Bad Thing. - * So, we substitute an appropriate message in-place, without downgrading - * the level if it's above ERROR. + * So, we substitute an appropriate message in-place, without + * downgrading the level if it's above ERROR. */ char fmt_fixedbuf[128]; char msg_fixedbuf[256]; char *fmt_buf = fmt_fixedbuf; char *msg_buf = msg_fixedbuf; + /* this buffer is only used for strange values of lev: */ char prefix_buf[32]; + /* this buffer is only used if errno has a bogus value: */ char errorstr_buf[32]; const char *errorstr; @@ -128,6 +131,7 @@ elog(int lev, const char *fmt, ...) int indent = 0; int space_needed; int len; + /* size of the prefix needed for timestamp and pid, if enabled */ size_t timestamp_size; @@ -136,6 +140,7 @@ elog(int lev, const char *fmt, ...) /* Save error str before calling any function that might change errno */ errorstr = strerror(errno); + /* * Some strerror()s return an empty string for out-of-range errno. * This is ANSI C spec compliant, but not exactly useful. @@ -148,16 +153,18 @@ elog(int lev, const char *fmt, ...) if (lev == ERROR || lev == FATAL) { + /* - * Convert initialization errors into fatal errors. - * This is probably redundant, because Warn_restart_ready won't - * be set anyway... + * Convert initialization errors into fatal errors. This is + * probably redundant, because Warn_restart_ready won't be set + * anyway... */ if (IsInitProcessingMode()) lev = FATAL; + /* - * If we are inside a critical section, all errors become STOP errors. - * See miscadmin.h. + * If we are inside a critical section, all errors become STOP + * errors. See miscadmin.h. */ if (CritSectionCount > 0) lev = STOP; @@ -334,7 +341,7 @@ elog(int lev, const char *fmt, ...) /* Write to syslog, if enabled */ if (Use_syslog >= 1) { - int syslog_level; + int syslog_level; switch (lev) { @@ -360,7 +367,7 @@ elog(int lev, const char *fmt, ...) write_syslog(syslog_level, msg_buf + timestamp_size); } -#endif /* ENABLE_SYSLOG */ +#endif /* ENABLE_SYSLOG */ /* syslog doesn't want a trailing newline, but other destinations do */ strcat(msg_buf, "\n"); @@ -379,10 +386,10 @@ elog(int lev, const char *fmt, ...) char msgtype; /* - * Since backend libpq may call palloc(), switch to a context where - * there's fairly likely to be some free space. After all the - * pushups above, we don't want to drop the ball by running out of - * space now... + * Since backend libpq may call palloc(), switch to a context + * where there's fairly likely to be some free space. After all + * the pushups above, we don't want to drop the ball by running + * out of space now... */ oldcxt = MemoryContextSwitchTo(ErrorContext); @@ -452,17 +459,19 @@ elog(int lev, const char *fmt, ...) * responsibility to see that this doesn't turn into infinite * recursion!) But in the latter case, we exit with nonzero exit * code to indicate that something's pretty wrong. We also want - * to exit with nonzero exit code if not running under the postmaster - * (for example, if we are being run from the initdb script, we'd - * better return an error status). + * to exit with nonzero exit code if not running under the + * postmaster (for example, if we are being run from the initdb + * script, we'd better return an error status). */ if (lev == FATAL || !Warn_restart_ready || proc_exit_inprogress) { + /* * fflush here is just to improve the odds that we get to see - * the error message, in case things are so hosed that proc_exit - * crashes. Any other code you might be tempted to add here - * should probably be in an on_proc_exit callback instead. + * the error message, in case things are so hosed that + * proc_exit crashes. Any other code you might be tempted to + * add here should probably be in an on_proc_exit callback + * instead. */ fflush(stdout); fflush(stderr); @@ -484,6 +493,7 @@ elog(int lev, const char *fmt, ...) if (lev > FATAL) { + /* * Serious crash time. Postmaster will observe nonzero process * exit status and kill the other backends too. @@ -511,6 +521,7 @@ DebugFileOpen(void) if (OutputFileName[0]) { + /* * A debug-output file name was given. * @@ -530,6 +541,7 @@ DebugFileOpen(void) elog(FATAL, "DebugFileOpen: %s reopen as stderr: %m", OutputFileName); Debugfile = fileno(stderr); + /* * If the file is a tty and we're running under the postmaster, * try to send stdout there as well (if it isn't a tty then stderr @@ -565,12 +577,12 @@ DebugFileOpen(void) /* * Return a timestamp string like * - * "2000-06-04 13:12:03 " + * "2000-06-04 13:12:03 " */ static const char * print_timestamp(void) { - time_t curtime; + time_t curtime; static char buf[TIMESTAMP_SIZE + 1]; curtime = time(NULL); @@ -587,7 +599,7 @@ print_timestamp(void) /* * Return a string like * - * "[123456] " + * "[123456] " * * with the current pid. */ @@ -596,7 +608,7 @@ print_pid(void) { static char buf[PID_SIZE + 1]; - snprintf(buf, PID_SIZE + 1, "[%d] ", (int)MyProcPid); + snprintf(buf, PID_SIZE + 1, "[%d] ", (int) MyProcPid); return buf; } @@ -605,7 +617,7 @@ print_pid(void) #ifdef ENABLE_SYSLOG #ifndef PG_SYSLOG_LIMIT -# define PG_SYSLOG_LIMIT 128 +#define PG_SYSLOG_LIMIT 128 #endif /* @@ -619,32 +631,32 @@ print_pid(void) static void write_syslog(int level, const char *line) { - static bool openlog_done = false; + static bool openlog_done = false; static unsigned long seq = 0; static int syslog_fac = LOG_LOCAL0; - int len = strlen(line); + int len = strlen(line); if (Use_syslog == 0) return; if (!openlog_done) { - if (strcasecmp(Syslog_facility,"LOCAL0") == 0) + if (strcasecmp(Syslog_facility, "LOCAL0") == 0) syslog_fac = LOG_LOCAL0; - if (strcasecmp(Syslog_facility,"LOCAL1") == 0) + if (strcasecmp(Syslog_facility, "LOCAL1") == 0) syslog_fac = LOG_LOCAL1; - if (strcasecmp(Syslog_facility,"LOCAL2") == 0) + if (strcasecmp(Syslog_facility, "LOCAL2") == 0) syslog_fac = LOG_LOCAL2; - if (strcasecmp(Syslog_facility,"LOCAL3") == 0) + if (strcasecmp(Syslog_facility, "LOCAL3") == 0) syslog_fac = LOG_LOCAL3; - if (strcasecmp(Syslog_facility,"LOCAL4") == 0) + if (strcasecmp(Syslog_facility, "LOCAL4") == 0) syslog_fac = LOG_LOCAL4; - if (strcasecmp(Syslog_facility,"LOCAL5") == 0) + if (strcasecmp(Syslog_facility, "LOCAL5") == 0) syslog_fac = LOG_LOCAL5; - if (strcasecmp(Syslog_facility,"LOCAL6") == 0) + if (strcasecmp(Syslog_facility, "LOCAL6") == 0) syslog_fac = LOG_LOCAL6; - if (strcasecmp(Syslog_facility,"LOCAL7") == 0) + if (strcasecmp(Syslog_facility, "LOCAL7") == 0) syslog_fac = LOG_LOCAL7; openlog(Syslog_ident, LOG_PID | LOG_NDELAY, syslog_fac); openlog_done = true; @@ -658,16 +670,16 @@ write_syslog(int level, const char *line) /* divide into multiple syslog() calls if message is too long */ /* or if the message contains embedded NewLine(s) '\n' */ - if (len > PG_SYSLOG_LIMIT || strchr(line,'\n') != NULL ) + if (len > PG_SYSLOG_LIMIT || strchr(line, '\n') != NULL) { - int chunk_nr = 0; + int chunk_nr = 0; while (len > 0) { - char buf[PG_SYSLOG_LIMIT+1]; - int buflen; - int l; - int i; + char buf[PG_SYSLOG_LIMIT + 1]; + int buflen; + int l; + int i; /* if we start at a newline, move ahead one char */ if (line[0] == '\n') @@ -679,15 +691,15 @@ write_syslog(int level, const char *line) strncpy(buf, line, PG_SYSLOG_LIMIT); buf[PG_SYSLOG_LIMIT] = '\0'; - if (strchr(buf,'\n') != NULL) - *strchr(buf,'\n') = '\0'; + if (strchr(buf, '\n') != NULL) + *strchr(buf, '\n') = '\0'; l = strlen(buf); #ifdef MULTIBYTE - /* trim to multibyte letter boundary */ + /* trim to multibyte letter boundary */ buflen = pg_mbcliplen(buf, l, l); if (buflen <= 0) - return; + return; buf[buflen] = '\0'; l = strlen(buf); #endif @@ -701,7 +713,7 @@ write_syslog(int level, const char *line) while (i > 0 && !isspace((unsigned char) buf[i])) i--; - if (i <= 0) /* couldn't divide word boundary */ + if (i <= 0) /* couldn't divide word boundary */ buflen = l; else { @@ -724,4 +736,4 @@ write_syslog(int level, const char *line) } } -#endif /* ENABLE_SYSLOG */ +#endif /* ENABLE_SYSLOG */ diff --git a/src/backend/utils/error/exc.c b/src/backend/utils/error/exc.c index f25e01254f5..ee64ecb5f0a 100644 --- a/src/backend/utils/error/exc.c +++ b/src/backend/utils/error/exc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/error/Attic/exc.c,v 1.36 2001/01/24 19:43:15 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/error/Attic/exc.c,v 1.37 2001/03/22 03:59:58 momjian Exp $ * * NOTE * XXX this code needs improvement--check for state violations and @@ -112,6 +112,7 @@ ExcPrint(Exception *excP, /* Save error str before calling any function that might change errno */ errorstr = strerror(errno); + /* * Some strerror()s return an empty string for out-of-range errno. * This is ANSI C spec compliant, but not exactly useful. diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c index c2d25325c7d..49be6b37903 100644 --- a/src/backend/utils/fmgr/dfmgr.c +++ b/src/backend/utils/fmgr/dfmgr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.47 2001/01/24 19:43:15 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.48 2001/03/22 03:59:58 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -32,7 +32,9 @@ typedef struct df_files ino_t inode; /* Inode number of file */ void *handle; /* a handle for pg_dl* functions */ char filename[1]; /* Full pathname of file */ - /* we allocate the block big enough for actual length of pathname. + + /* + * we allocate the block big enough for actual length of pathname. * filename[] must be last item in struct! */ } DynamicFileList; @@ -48,7 +50,7 @@ static DynamicFileList *file_tail = (DynamicFileList *) NULL; * named funcname in it. If the function is not found, we raise an error * if signalNotFound is true, else return (PGFunction) NULL. Note that * errors in loading the library will provoke elog regardless of - * signalNotFound. + * signalNotFound. */ PGFunction load_external_function(char *filename, char *funcname, @@ -64,11 +66,12 @@ load_external_function(char *filename, char *funcname, */ for (file_scanner = file_list; file_scanner != (DynamicFileList *) NULL && - strcmp(filename, file_scanner->filename) != 0; + strcmp(filename, file_scanner->filename) != 0; file_scanner = file_scanner->next) ; if (file_scanner == (DynamicFileList *) NULL) { + /* * Check for same files - different paths (ie, symlink or link) */ @@ -77,13 +80,14 @@ load_external_function(char *filename, char *funcname, for (file_scanner = file_list; file_scanner != (DynamicFileList *) NULL && - !SAME_INODE(stat_buf, *file_scanner); + !SAME_INODE(stat_buf, *file_scanner); file_scanner = file_scanner->next) ; } if (file_scanner == (DynamicFileList *) NULL) { + /* * File not loaded yet. */ @@ -130,7 +134,7 @@ load_external_function(char *filename, char *funcname, /* * This function loads a shlib file without looking up any particular - * function in it. If the same shlib has previously been loaded, + * function in it. If the same shlib has previously been loaded, * unload and reload it. */ void diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c index a0a412cbb6a..08c35327d02 100644 --- a/src/backend/utils/fmgr/fmgr.c +++ b/src/backend/utils/fmgr/fmgr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.50 2001/02/10 02:31:27 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.51 2001/03/22 03:59:59 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -40,8 +40,10 @@ */ #if defined(__mc68000__) && defined(__ELF__) typedef int32 ((*func_ptr) ()); + #else typedef char *((*func_ptr) ()); + #endif /* @@ -50,8 +52,8 @@ typedef char *((*func_ptr) ()); typedef struct { func_ptr func; /* Address of the oldstyle function */ - bool arg_toastable[FUNC_MAX_ARGS]; /* is n'th arg of a toastable - * datatype? */ + bool arg_toastable[FUNC_MAX_ARGS]; /* is n'th arg of a + * toastable datatype? */ } Oldstyle_fnextra; @@ -62,23 +64,24 @@ static Datum fmgr_untrusted(PG_FUNCTION_ARGS); /* - * Lookup routines for builtin-function table. We can search by either Oid + * Lookup routines for builtin-function table. We can search by either Oid * or name, but search by Oid is much faster. */ static const FmgrBuiltin * fmgr_isbuiltin(Oid id) { - int low = 0; - int high = fmgr_nbuiltins - 1; + int low = 0; + int high = fmgr_nbuiltins - 1; - /* Loop invariant: low is the first index that could contain target + /* + * Loop invariant: low is the first index that could contain target * entry, and high is the last index that could contain it. */ while (low <= high) { - int i = (high + low) / 2; - const FmgrBuiltin *ptr = &fmgr_builtins[i]; + int i = (high + low) / 2; + const FmgrBuiltin *ptr = &fmgr_builtins[i]; if (id == ptr->foid) return ptr; @@ -96,15 +99,15 @@ fmgr_isbuiltin(Oid id) * routine. */ static const FmgrBuiltin * -fmgr_lookupByName(const char *name) +fmgr_lookupByName(const char *name) { - int i; + int i; for (i = 0; i < fmgr_nbuiltins; i++) { if (strcmp(name, fmgr_builtins[i].funcName) == 0) return fmgr_builtins + i; - } + } return (const FmgrBuiltin *) NULL; } @@ -126,8 +129,10 @@ fmgr_info(Oid functionId, FmgrInfo *finfo) if ((fbp = fmgr_isbuiltin(functionId)) != NULL) { + /* - * Fast path for builtin functions: don't bother consulting pg_proc + * Fast path for builtin functions: don't bother consulting + * pg_proc */ finfo->fn_nargs = fbp->nargs; finfo->fn_strict = fbp->strict; @@ -160,18 +165,18 @@ fmgr_info(Oid functionId, FmgrInfo *finfo) switch (procedureStruct->prolang) { case INTERNALlanguageId: + /* - * For an ordinary builtin function, we should never get - * here because the isbuiltin() search above will have - * succeeded. However, if the user has done a CREATE - * FUNCTION to create an alias for a builtin function, we - * can end up here. In that case we have to look up the - * function by name. The name of the internal function is - * stored in prosrc (it doesn't have to be the same as the - * name of the alias!) + * For an ordinary builtin function, we should never get here + * because the isbuiltin() search above will have succeeded. + * However, if the user has done a CREATE FUNCTION to create + * an alias for a builtin function, we can end up here. In + * that case we have to look up the function by name. The + * name of the internal function is stored in prosrc (it + * doesn't have to be the same as the name of the alias!) */ prosrc = DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(&procedureStruct->prosrc))); + PointerGetDatum(&procedureStruct->prosrc))); fbp = fmgr_lookupByName(prosrc); if (fbp == NULL) elog(ERROR, "fmgr_info: function %s not in internal table", @@ -240,7 +245,11 @@ fmgr_info_C_lang(FmgrInfo *finfo, HeapTuple procedureTuple) case 0: /* Old style: need to use a handler */ finfo->fn_addr = fmgr_oldstyle; - /* OK to use palloc here because fn_mcxt is CurrentMemoryContext */ + + /* + * OK to use palloc here because fn_mcxt is + * CurrentMemoryContext + */ fnextra = (Oldstyle_fnextra *) palloc(sizeof(Oldstyle_fnextra)); finfo->fn_extra = (void *) fnextra; MemSet(fnextra, 0, sizeof(Oldstyle_fnextra)); @@ -290,10 +299,11 @@ fmgr_info_other_lang(FmgrInfo *finfo, HeapTuple procedureTuple) fmgr_info(languageStruct->lanplcallfoid, &plfinfo); finfo->fn_addr = plfinfo.fn_addr; + /* - * If lookup of the PL handler function produced nonnull - * fn_extra, complain --- it must be an oldstyle function! - * We no longer support oldstyle PL handlers. + * If lookup of the PL handler function produced nonnull fn_extra, + * complain --- it must be an oldstyle function! We no longer + * support oldstyle PL handlers. */ if (plfinfo.fn_extra != NULL) elog(ERROR, "fmgr_info: language %u has old-style handler", @@ -325,7 +335,7 @@ fetch_finfo_record(char *filename, char *funcname) char *infofuncname; PGFInfoFunction infofunc; Pg_finfo_record *inforec; - static Pg_finfo_record default_inforec = { 0 }; + static Pg_finfo_record default_inforec = {0}; /* Compute name of info func */ infofuncname = (char *) palloc(strlen(funcname) + 10); @@ -343,7 +353,7 @@ fetch_finfo_record(char *filename, char *funcname) } /* Found, so call it */ - inforec = (*infofunc)(); + inforec = (*infofunc) (); /* Validate result as best we can */ if (inforec == NULL) @@ -399,10 +409,11 @@ fmgr_oldstyle(PG_FUNCTION_ARGS) fnextra = (Oldstyle_fnextra *) fcinfo->flinfo->fn_extra; /* - * Result is NULL if any argument is NULL, but we still call the function - * (peculiar, but that's the way it worked before, and after all this is - * a backwards-compatibility wrapper). Note, however, that we'll never - * get here with NULL arguments if the function is marked strict. + * Result is NULL if any argument is NULL, but we still call the + * function (peculiar, but that's the way it worked before, and after + * all this is a backwards-compatibility wrapper). Note, however, + * that we'll never get here with NULL arguments if the function is + * marked strict. * * We also need to detoast any TOAST-ed inputs, since it's unlikely that * an old-style function knows about TOASTing. @@ -425,12 +436,13 @@ fmgr_oldstyle(PG_FUNCTION_ARGS) returnValue = (*user_fn) (); break; case 1: + /* * nullvalue() used to use isNull to check if arg is NULL; - * perhaps there are other functions still out there that - * also rely on this undocumented hack? + * perhaps there are other functions still out there that also + * rely on this undocumented hack? */ - returnValue = (*user_fn) (fcinfo->arg[0], & fcinfo->isnull); + returnValue = (*user_fn) (fcinfo->arg[0], &fcinfo->isnull); break; case 2: returnValue = (*user_fn) (fcinfo->arg[0], fcinfo->arg[1]); @@ -534,16 +546,17 @@ fmgr_oldstyle(PG_FUNCTION_ARGS) fcinfo->arg[14], fcinfo->arg[15]); break; default: + /* - * Increasing FUNC_MAX_ARGS doesn't automatically add cases - * to the above code, so mention the actual value in this error + * Increasing FUNC_MAX_ARGS doesn't automatically add cases to + * the above code, so mention the actual value in this error * not FUNC_MAX_ARGS. You could add cases to the above if you * needed to support old-style functions with many arguments, * but making 'em be new-style is probably a better idea. */ elog(ERROR, "fmgr_oldstyle: function %u: too many arguments (%d > %d)", fcinfo->flinfo->fn_oid, n_arguments, 16); - returnValue = NULL; /* keep compiler quiet */ + returnValue = NULL; /* keep compiler quiet */ break; } @@ -557,6 +570,7 @@ fmgr_oldstyle(PG_FUNCTION_ARGS) static Datum fmgr_untrusted(PG_FUNCTION_ARGS) { + /* * Currently these are unsupported. Someday we might do something * like forking a subprocess to execute 'em. @@ -573,20 +587,20 @@ fmgr_untrusted(PG_FUNCTION_ARGS) /* These are for invocation of a specifically named function with a * directly-computed parameter list. Note that neither arguments nor result - * are allowed to be NULL. Also, the function cannot be one that needs to + * are allowed to be NULL. Also, the function cannot be one that needs to * look at FmgrInfo, since there won't be any. */ Datum DirectFunctionCall1(PGFunction func, Datum arg1) { - FunctionCallInfoData fcinfo; - Datum result; + FunctionCallInfoData fcinfo; + Datum result; MemSet(&fcinfo, 0, sizeof(fcinfo)); fcinfo.nargs = 1; fcinfo.arg[0] = arg1; - result = (* func) (&fcinfo); + result = (*func) (&fcinfo); /* Check for null result, since caller is clearly not expecting one */ if (fcinfo.isnull) @@ -599,15 +613,15 @@ DirectFunctionCall1(PGFunction func, Datum arg1) Datum DirectFunctionCall2(PGFunction func, Datum arg1, Datum arg2) { - FunctionCallInfoData fcinfo; - Datum result; + FunctionCallInfoData fcinfo; + Datum result; MemSet(&fcinfo, 0, sizeof(fcinfo)); fcinfo.nargs = 2; fcinfo.arg[0] = arg1; fcinfo.arg[1] = arg2; - result = (* func) (&fcinfo); + result = (*func) (&fcinfo); /* Check for null result, since caller is clearly not expecting one */ if (fcinfo.isnull) @@ -621,8 +635,8 @@ Datum DirectFunctionCall3(PGFunction func, Datum arg1, Datum arg2, Datum arg3) { - FunctionCallInfoData fcinfo; - Datum result; + FunctionCallInfoData fcinfo; + Datum result; MemSet(&fcinfo, 0, sizeof(fcinfo)); fcinfo.nargs = 3; @@ -630,7 +644,7 @@ DirectFunctionCall3(PGFunction func, Datum arg1, Datum arg2, fcinfo.arg[1] = arg2; fcinfo.arg[2] = arg3; - result = (* func) (&fcinfo); + result = (*func) (&fcinfo); /* Check for null result, since caller is clearly not expecting one */ if (fcinfo.isnull) @@ -644,8 +658,8 @@ Datum DirectFunctionCall4(PGFunction func, Datum arg1, Datum arg2, Datum arg3, Datum arg4) { - FunctionCallInfoData fcinfo; - Datum result; + FunctionCallInfoData fcinfo; + Datum result; MemSet(&fcinfo, 0, sizeof(fcinfo)); fcinfo.nargs = 4; @@ -654,7 +668,7 @@ DirectFunctionCall4(PGFunction func, Datum arg1, Datum arg2, fcinfo.arg[2] = arg3; fcinfo.arg[3] = arg4; - result = (* func) (&fcinfo); + result = (*func) (&fcinfo); /* Check for null result, since caller is clearly not expecting one */ if (fcinfo.isnull) @@ -668,8 +682,8 @@ Datum DirectFunctionCall5(PGFunction func, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5) { - FunctionCallInfoData fcinfo; - Datum result; + FunctionCallInfoData fcinfo; + Datum result; MemSet(&fcinfo, 0, sizeof(fcinfo)); fcinfo.nargs = 5; @@ -679,7 +693,7 @@ DirectFunctionCall5(PGFunction func, Datum arg1, Datum arg2, fcinfo.arg[3] = arg4; fcinfo.arg[4] = arg5; - result = (* func) (&fcinfo); + result = (*func) (&fcinfo); /* Check for null result, since caller is clearly not expecting one */ if (fcinfo.isnull) @@ -694,8 +708,8 @@ DirectFunctionCall6(PGFunction func, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6) { - FunctionCallInfoData fcinfo; - Datum result; + FunctionCallInfoData fcinfo; + Datum result; MemSet(&fcinfo, 0, sizeof(fcinfo)); fcinfo.nargs = 6; @@ -706,7 +720,7 @@ DirectFunctionCall6(PGFunction func, Datum arg1, Datum arg2, fcinfo.arg[4] = arg5; fcinfo.arg[5] = arg6; - result = (* func) (&fcinfo); + result = (*func) (&fcinfo); /* Check for null result, since caller is clearly not expecting one */ if (fcinfo.isnull) @@ -721,8 +735,8 @@ DirectFunctionCall7(PGFunction func, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7) { - FunctionCallInfoData fcinfo; - Datum result; + FunctionCallInfoData fcinfo; + Datum result; MemSet(&fcinfo, 0, sizeof(fcinfo)); fcinfo.nargs = 7; @@ -734,7 +748,7 @@ DirectFunctionCall7(PGFunction func, Datum arg1, Datum arg2, fcinfo.arg[5] = arg6; fcinfo.arg[6] = arg7; - result = (* func) (&fcinfo); + result = (*func) (&fcinfo); /* Check for null result, since caller is clearly not expecting one */ if (fcinfo.isnull) @@ -749,8 +763,8 @@ DirectFunctionCall8(PGFunction func, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8) { - FunctionCallInfoData fcinfo; - Datum result; + FunctionCallInfoData fcinfo; + Datum result; MemSet(&fcinfo, 0, sizeof(fcinfo)); fcinfo.nargs = 8; @@ -763,7 +777,7 @@ DirectFunctionCall8(PGFunction func, Datum arg1, Datum arg2, fcinfo.arg[6] = arg7; fcinfo.arg[7] = arg8; - result = (* func) (&fcinfo); + result = (*func) (&fcinfo); /* Check for null result, since caller is clearly not expecting one */ if (fcinfo.isnull) @@ -779,8 +793,8 @@ DirectFunctionCall9(PGFunction func, Datum arg1, Datum arg2, Datum arg6, Datum arg7, Datum arg8, Datum arg9) { - FunctionCallInfoData fcinfo; - Datum result; + FunctionCallInfoData fcinfo; + Datum result; MemSet(&fcinfo, 0, sizeof(fcinfo)); fcinfo.nargs = 9; @@ -794,7 +808,7 @@ DirectFunctionCall9(PGFunction func, Datum arg1, Datum arg2, fcinfo.arg[7] = arg8; fcinfo.arg[8] = arg9; - result = (* func) (&fcinfo); + result = (*func) (&fcinfo); /* Check for null result, since caller is clearly not expecting one */ if (fcinfo.isnull) @@ -812,11 +826,11 @@ DirectFunctionCall9(PGFunction func, Datum arg1, Datum arg2, Datum FunctionCall1(FmgrInfo *flinfo, Datum arg1) { - FunctionCallInfoData fcinfo; - Datum result; + FunctionCallInfoData fcinfo; + Datum result; MemSet(&fcinfo, 0, sizeof(fcinfo)); - fcinfo.flinfo = flinfo; + fcinfo.flinfo = flinfo; fcinfo.nargs = 1; fcinfo.arg[0] = arg1; @@ -833,11 +847,11 @@ FunctionCall1(FmgrInfo *flinfo, Datum arg1) Datum FunctionCall2(FmgrInfo *flinfo, Datum arg1, Datum arg2) { - FunctionCallInfoData fcinfo; - Datum result; + FunctionCallInfoData fcinfo; + Datum result; MemSet(&fcinfo, 0, sizeof(fcinfo)); - fcinfo.flinfo = flinfo; + fcinfo.flinfo = flinfo; fcinfo.nargs = 2; fcinfo.arg[0] = arg1; fcinfo.arg[1] = arg2; @@ -856,11 +870,11 @@ Datum FunctionCall3(FmgrInfo *flinfo, Datum arg1, Datum arg2, Datum arg3) { - FunctionCallInfoData fcinfo; - Datum result; + FunctionCallInfoData fcinfo; + Datum result; MemSet(&fcinfo, 0, sizeof(fcinfo)); - fcinfo.flinfo = flinfo; + fcinfo.flinfo = flinfo; fcinfo.nargs = 3; fcinfo.arg[0] = arg1; fcinfo.arg[1] = arg2; @@ -880,11 +894,11 @@ Datum FunctionCall4(FmgrInfo *flinfo, Datum arg1, Datum arg2, Datum arg3, Datum arg4) { - FunctionCallInfoData fcinfo; - Datum result; + FunctionCallInfoData fcinfo; + Datum result; MemSet(&fcinfo, 0, sizeof(fcinfo)); - fcinfo.flinfo = flinfo; + fcinfo.flinfo = flinfo; fcinfo.nargs = 4; fcinfo.arg[0] = arg1; fcinfo.arg[1] = arg2; @@ -905,11 +919,11 @@ Datum FunctionCall5(FmgrInfo *flinfo, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5) { - FunctionCallInfoData fcinfo; - Datum result; + FunctionCallInfoData fcinfo; + Datum result; MemSet(&fcinfo, 0, sizeof(fcinfo)); - fcinfo.flinfo = flinfo; + fcinfo.flinfo = flinfo; fcinfo.nargs = 5; fcinfo.arg[0] = arg1; fcinfo.arg[1] = arg2; @@ -932,11 +946,11 @@ FunctionCall6(FmgrInfo *flinfo, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6) { - FunctionCallInfoData fcinfo; - Datum result; + FunctionCallInfoData fcinfo; + Datum result; MemSet(&fcinfo, 0, sizeof(fcinfo)); - fcinfo.flinfo = flinfo; + fcinfo.flinfo = flinfo; fcinfo.nargs = 6; fcinfo.arg[0] = arg1; fcinfo.arg[1] = arg2; @@ -960,11 +974,11 @@ FunctionCall7(FmgrInfo *flinfo, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7) { - FunctionCallInfoData fcinfo; - Datum result; + FunctionCallInfoData fcinfo; + Datum result; MemSet(&fcinfo, 0, sizeof(fcinfo)); - fcinfo.flinfo = flinfo; + fcinfo.flinfo = flinfo; fcinfo.nargs = 7; fcinfo.arg[0] = arg1; fcinfo.arg[1] = arg2; @@ -989,11 +1003,11 @@ FunctionCall8(FmgrInfo *flinfo, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8) { - FunctionCallInfoData fcinfo; - Datum result; + FunctionCallInfoData fcinfo; + Datum result; MemSet(&fcinfo, 0, sizeof(fcinfo)); - fcinfo.flinfo = flinfo; + fcinfo.flinfo = flinfo; fcinfo.nargs = 8; fcinfo.arg[0] = arg1; fcinfo.arg[1] = arg2; @@ -1020,11 +1034,11 @@ FunctionCall9(FmgrInfo *flinfo, Datum arg1, Datum arg2, Datum arg6, Datum arg7, Datum arg8, Datum arg9) { - FunctionCallInfoData fcinfo; - Datum result; + FunctionCallInfoData fcinfo; + Datum result; MemSet(&fcinfo, 0, sizeof(fcinfo)); - fcinfo.flinfo = flinfo; + fcinfo.flinfo = flinfo; fcinfo.nargs = 9; fcinfo.arg[0] = arg1; fcinfo.arg[1] = arg2; @@ -1049,21 +1063,21 @@ FunctionCall9(FmgrInfo *flinfo, Datum arg1, Datum arg2, /* These are for invocation of a function identified by OID with a * directly-computed parameter list. Note that neither arguments nor result - * are allowed to be NULL. These are essentially fmgr_info() followed - * by FunctionCallN(). If the same function is to be invoked repeatedly, + * are allowed to be NULL. These are essentially fmgr_info() followed + * by FunctionCallN(). If the same function is to be invoked repeatedly, * do the fmgr_info() once and then use FunctionCallN(). */ Datum OidFunctionCall1(Oid functionId, Datum arg1) { - FmgrInfo flinfo; - FunctionCallInfoData fcinfo; - Datum result; + FmgrInfo flinfo; + FunctionCallInfoData fcinfo; + Datum result; fmgr_info(functionId, &flinfo); MemSet(&fcinfo, 0, sizeof(fcinfo)); - fcinfo.flinfo = &flinfo; + fcinfo.flinfo = &flinfo; fcinfo.nargs = 1; fcinfo.arg[0] = arg1; @@ -1080,14 +1094,14 @@ OidFunctionCall1(Oid functionId, Datum arg1) Datum OidFunctionCall2(Oid functionId, Datum arg1, Datum arg2) { - FmgrInfo flinfo; - FunctionCallInfoData fcinfo; - Datum result; + FmgrInfo flinfo; + FunctionCallInfoData fcinfo; + Datum result; fmgr_info(functionId, &flinfo); MemSet(&fcinfo, 0, sizeof(fcinfo)); - fcinfo.flinfo = &flinfo; + fcinfo.flinfo = &flinfo; fcinfo.nargs = 2; fcinfo.arg[0] = arg1; fcinfo.arg[1] = arg2; @@ -1106,14 +1120,14 @@ Datum OidFunctionCall3(Oid functionId, Datum arg1, Datum arg2, Datum arg3) { - FmgrInfo flinfo; - FunctionCallInfoData fcinfo; - Datum result; + FmgrInfo flinfo; + FunctionCallInfoData fcinfo; + Datum result; fmgr_info(functionId, &flinfo); MemSet(&fcinfo, 0, sizeof(fcinfo)); - fcinfo.flinfo = &flinfo; + fcinfo.flinfo = &flinfo; fcinfo.nargs = 3; fcinfo.arg[0] = arg1; fcinfo.arg[1] = arg2; @@ -1133,14 +1147,14 @@ Datum OidFunctionCall4(Oid functionId, Datum arg1, Datum arg2, Datum arg3, Datum arg4) { - FmgrInfo flinfo; - FunctionCallInfoData fcinfo; - Datum result; + FmgrInfo flinfo; + FunctionCallInfoData fcinfo; + Datum result; fmgr_info(functionId, &flinfo); MemSet(&fcinfo, 0, sizeof(fcinfo)); - fcinfo.flinfo = &flinfo; + fcinfo.flinfo = &flinfo; fcinfo.nargs = 4; fcinfo.arg[0] = arg1; fcinfo.arg[1] = arg2; @@ -1161,14 +1175,14 @@ Datum OidFunctionCall5(Oid functionId, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5) { - FmgrInfo flinfo; - FunctionCallInfoData fcinfo; - Datum result; + FmgrInfo flinfo; + FunctionCallInfoData fcinfo; + Datum result; fmgr_info(functionId, &flinfo); MemSet(&fcinfo, 0, sizeof(fcinfo)); - fcinfo.flinfo = &flinfo; + fcinfo.flinfo = &flinfo; fcinfo.nargs = 5; fcinfo.arg[0] = arg1; fcinfo.arg[1] = arg2; @@ -1191,14 +1205,14 @@ OidFunctionCall6(Oid functionId, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6) { - FmgrInfo flinfo; - FunctionCallInfoData fcinfo; - Datum result; + FmgrInfo flinfo; + FunctionCallInfoData fcinfo; + Datum result; fmgr_info(functionId, &flinfo); MemSet(&fcinfo, 0, sizeof(fcinfo)); - fcinfo.flinfo = &flinfo; + fcinfo.flinfo = &flinfo; fcinfo.nargs = 6; fcinfo.arg[0] = arg1; fcinfo.arg[1] = arg2; @@ -1222,14 +1236,14 @@ OidFunctionCall7(Oid functionId, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7) { - FmgrInfo flinfo; - FunctionCallInfoData fcinfo; - Datum result; + FmgrInfo flinfo; + FunctionCallInfoData fcinfo; + Datum result; fmgr_info(functionId, &flinfo); MemSet(&fcinfo, 0, sizeof(fcinfo)); - fcinfo.flinfo = &flinfo; + fcinfo.flinfo = &flinfo; fcinfo.nargs = 7; fcinfo.arg[0] = arg1; fcinfo.arg[1] = arg2; @@ -1254,14 +1268,14 @@ OidFunctionCall8(Oid functionId, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8) { - FmgrInfo flinfo; - FunctionCallInfoData fcinfo; - Datum result; + FmgrInfo flinfo; + FunctionCallInfoData fcinfo; + Datum result; fmgr_info(functionId, &flinfo); MemSet(&fcinfo, 0, sizeof(fcinfo)); - fcinfo.flinfo = &flinfo; + fcinfo.flinfo = &flinfo; fcinfo.nargs = 8; fcinfo.arg[0] = arg1; fcinfo.arg[1] = arg2; @@ -1288,14 +1302,14 @@ OidFunctionCall9(Oid functionId, Datum arg1, Datum arg2, Datum arg6, Datum arg7, Datum arg8, Datum arg9) { - FmgrInfo flinfo; - FunctionCallInfoData fcinfo; - Datum result; + FmgrInfo flinfo; + FunctionCallInfoData fcinfo; + Datum result; fmgr_info(functionId, &flinfo); MemSet(&fcinfo, 0, sizeof(fcinfo)); - fcinfo.flinfo = &flinfo; + fcinfo.flinfo = &flinfo; fcinfo.nargs = 9; fcinfo.arg[0] = arg1; fcinfo.arg[1] = arg2; @@ -1332,15 +1346,15 @@ OidFunctionCall9(Oid functionId, Datum arg1, Datum arg2, char * fmgr(Oid procedureId,...) { - FmgrInfo flinfo; - FunctionCallInfoData fcinfo; - int n_arguments; - Datum result; + FmgrInfo flinfo; + FunctionCallInfoData fcinfo; + int n_arguments; + Datum result; fmgr_info(procedureId, &flinfo); MemSet(&fcinfo, 0, sizeof(fcinfo)); - fcinfo.flinfo = &flinfo; + fcinfo.flinfo = &flinfo; fcinfo.nargs = flinfo.fn_nargs; n_arguments = fcinfo.nargs; @@ -1430,7 +1444,7 @@ pg_detoast_datum_copy(struct varlena * datum) else { /* Make a modifiable copy of the varlena object */ - Size len = VARSIZE(datum); + Size len = VARSIZE(datum); struct varlena *result = (struct varlena *) palloc(len); memcpy(result, datum, len); diff --git a/src/backend/utils/hash/dynahash.c b/src/backend/utils/hash/dynahash.c index b13bd014490..b3a991fdc52 100644 --- a/src/backend/utils/hash/dynahash.c +++ b/src/backend/utils/hash/dynahash.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/hash/dynahash.c,v 1.34 2001/01/24 19:43:15 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/hash/dynahash.c,v 1.35 2001/03/22 03:59:59 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -719,7 +719,7 @@ hash_seq_search(HASH_SEQ_STATUS *status) curElem = GET_BUCKET(hashp, status->curIndex); status->curIndex = curElem->next; - if (status->curIndex == INVALID_INDEX) /* end of this bucket */ + if (status->curIndex == INVALID_INDEX) /* end of this bucket */ ++status->curBucket; return &(curElem->key); } diff --git a/src/backend/utils/hash/pg_crc.c b/src/backend/utils/hash/pg_crc.c index 96413f3b8b4..22469bf5f5e 100644 --- a/src/backend/utils/hash/pg_crc.c +++ b/src/backend/utils/hash/pg_crc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/hash/pg_crc.c,v 1.1 2001/03/13 01:17:06 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/hash/pg_crc.c,v 1.2 2001/03/22 03:59:59 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -281,7 +281,7 @@ const uint32 crc_table1[256] = { 0xD80C07CD, 0x9AFCE626 }; -#else /* int64 works */ +#else /* int64 works */ const uint64 crc_table[256] = { 0x0000000000000000, 0x42F0E1EBA9EA3693, @@ -414,4 +414,4 @@ const uint64 crc_table[256] = { 0xD80C07CD676F8394, 0x9AFCE626CE85B507 }; -#endif /* INT64_IS_BUSTED */ +#endif /* INT64_IS_BUSTED */ diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c index 43331badc7a..2a1a0aaaae4 100644 --- a/src/backend/utils/init/globals.c +++ b/src/backend/utils/init/globals.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.54 2001/03/13 01:17:06 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.55 2001/03/22 03:59:59 momjian Exp $ * * NOTES * Globals used all over the place should be declared here and not @@ -79,7 +79,7 @@ char DateFormat[20] = "%d-%m-%Y"; /* mjl: sizes! or better * malloc? XXX */ char FloatFormat[20] = "%f"; -bool enableFsync = true; +bool enableFsync = true; bool allowSystemTableMods = false; int SortMem = 512; int NBuffers = DEF_NBUFFERS; diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index f5824327c96..a6dffbee103 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.63 2001/03/18 18:22:08 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.64 2001/03/22 04:00:00 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -109,7 +109,7 @@ SetDatabaseName(const char *name) void SetDataDir(const char *dir) { - char *new; + char *new; AssertArg(dir); if (DataDir) @@ -117,8 +117,8 @@ SetDataDir(const char *dir) if (dir[0] != '/') { - char *buf; - size_t buflen; + char *buf; + size_t buflen; buflen = MAXPGPATH; for (;;) @@ -147,13 +147,11 @@ SetDataDir(const char *dir) free(buf); } else - { new = strdup(dir); - } if (!new) elog(FATAL, "out of memory"); - DataDir = new; + DataDir = new; } @@ -344,7 +342,7 @@ convertstr(unsigned char *buff, int len, int dest) /* ---------------------------------------------------------------- - * User ID things + * User ID things * * The session user is determined at connection start and never * changes. The current user may change when "setuid" functions @@ -415,7 +413,7 @@ SetSessionUserIdFromUserName(const char *username) if (!HeapTupleIsValid(userTup)) elog(FATAL, "user \"%s\" does not exist", username); - SetSessionUserId( ((Form_pg_shadow) GETSTRUCT(userTup))->usesysid ); + SetSessionUserId(((Form_pg_shadow) GETSTRUCT(userTup))->usesysid); ReleaseSysCache(userTup); } @@ -436,7 +434,7 @@ GetUserName(Oid userid) if (!HeapTupleIsValid(tuple)) elog(ERROR, "invalid user id %u", (unsigned) userid); - result = pstrdup( NameStr(((Form_pg_shadow) GETSTRUCT(tuple))->usename) ); + result = pstrdup(NameStr(((Form_pg_shadow) GETSTRUCT(tuple))->usename)); ReleaseSysCache(tuple); return result; @@ -502,12 +500,14 @@ CreateLockFile(const char *filename, bool amPostmaster, */ for (;;) { + /* * Try to create the lock file --- O_EXCL makes this atomic. */ fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600); if (fd >= 0) break; /* Success; exit the retry loop */ + /* * Couldn't create the pid file. Probably it already exists. */ @@ -551,7 +551,7 @@ CreateLockFile(const char *filename, bool amPostmaster, #ifdef __BEOS__ && errno != EINVAL #endif - )) + )) { /* lockfile belongs to a live process */ fprintf(stderr, "Lock file \"%s\" already exists.\n", @@ -571,11 +571,11 @@ CreateLockFile(const char *filename, bool amPostmaster, } /* - * No, the creating process did not exist. However, it could be that - * the postmaster crashed (or more likely was kill -9'd by a clueless - * admin) but has left orphan backends behind. Check for this by - * looking to see if there is an associated shmem segment that is - * still in use. + * No, the creating process did not exist. However, it could be + * that the postmaster crashed (or more likely was kill -9'd by a + * clueless admin) but has left orphan backends behind. Check for + * this by looking to see if there is an associated shmem segment + * that is still in use. */ if (isDDLock) { @@ -585,7 +585,7 @@ CreateLockFile(const char *filename, bool amPostmaster, ptr = strchr(buffer, '\n'); if (ptr != NULL && - (ptr = strchr(ptr+1, '\n')) != NULL) + (ptr = strchr(ptr + 1, '\n')) != NULL) { ptr++; if (sscanf(ptr, "%lu %lu", &shmKey, &shmId) == 2) @@ -607,8 +607,8 @@ CreateLockFile(const char *filename, bool amPostmaster, /* * Looks like nobody's home. Unlink the file and try again to - * create it. Need a loop because of possible race condition against - * other would-be creators. + * create it. Need a loop because of possible race condition + * against other would-be creators. */ if (unlink(filename) < 0) elog(FATAL, "Can't remove old lock file %s: %m" @@ -621,11 +621,11 @@ CreateLockFile(const char *filename, bool amPostmaster, * Successfully created the file, now fill it. */ snprintf(buffer, sizeof(buffer), "%d\n%s\n", - amPostmaster ? (int) my_pid : - ((int) my_pid), + amPostmaster ? (int) my_pid : -((int) my_pid), DataDir); if (write(fd, buffer, strlen(buffer)) != strlen(buffer)) { - int save_errno = errno; + int save_errno = errno; close(fd); unlink(filename); @@ -645,10 +645,10 @@ CreateLockFile(const char *filename, bool amPostmaster, bool CreateDataDirLockFile(const char *datadir, bool amPostmaster) { - char lockfile[MAXPGPATH]; + char lockfile[MAXPGPATH]; snprintf(lockfile, sizeof(lockfile), "%s/postmaster.pid", datadir); - if (! CreateLockFile(lockfile, amPostmaster, true, datadir)) + if (!CreateLockFile(lockfile, amPostmaster, true, datadir)) return false; /* Save name of lockfile for RecordSharedMemoryInLockFile */ strcpy(directoryLockFile, lockfile); @@ -658,10 +658,10 @@ CreateDataDirLockFile(const char *datadir, bool amPostmaster) bool CreateSocketLockFile(const char *socketfile, bool amPostmaster) { - char lockfile[MAXPGPATH]; + char lockfile[MAXPGPATH]; snprintf(lockfile, sizeof(lockfile), "%s.lock", socketfile); - if (! CreateLockFile(lockfile, amPostmaster, false, socketfile)) + if (!CreateLockFile(lockfile, amPostmaster, false, socketfile)) return false; /* Save name of lockfile for TouchSocketLockFile */ strcpy(socketLockFile, lockfile); @@ -698,7 +698,7 @@ TouchSocketLockFile(void) * lock file (if we have created one). * * This may be called multiple times in the life of a postmaster, if we - * delete and recreate shmem due to backend crash. Therefore, be prepared + * delete and recreate shmem due to backend crash. Therefore, be prepared * to overwrite existing information. (As of 7.1, a postmaster only creates * one shm seg anyway; but for the purposes here, if we did have more than * one then any one of them would do anyway.) @@ -712,8 +712,8 @@ RecordSharedMemoryInLockFile(IpcMemoryKey shmKey, IpcMemoryId shmId) char buffer[BLCKSZ]; /* - * Do nothing if we did not create a lockfile (probably because we - * are running standalone). + * Do nothing if we did not create a lockfile (probably because we are + * running standalone). */ if (directoryLockFile[0] == '\0') return; @@ -732,27 +732,30 @@ RecordSharedMemoryInLockFile(IpcMemoryKey shmKey, IpcMemoryId shmId) return; } buffer[len] = '\0'; + /* * Skip over first two lines (PID and path). */ ptr = strchr(buffer, '\n'); if (ptr == NULL || - (ptr = strchr(ptr+1, '\n')) == NULL) + (ptr = strchr(ptr + 1, '\n')) == NULL) { elog(DEBUG, "Bogus data in %s", directoryLockFile); close(fd); return; } ptr++; + /* * Append shm key and ID. Format to try to keep it the same length * always (trailing junk won't hurt, but might confuse humans). */ sprintf(ptr, "%9lu %9lu\n", (unsigned long) shmKey, (unsigned long) shmId); + /* - * And rewrite the data. Since we write in a single kernel call, - * this update should appear atomic to onlookers. + * And rewrite the data. Since we write in a single kernel call, this + * update should appear atomic to onlookers. */ len = strlen(buffer); if (lseek(fd, (off_t) 0, SEEK_SET) != 0 || @@ -781,16 +784,18 @@ void ValidatePgVersion(const char *path) { char full_path[MAXPGPATH]; - FILE *file; + FILE *file; int ret; - long file_major, file_minor; - long my_major = 0, my_minor = 0; - char *endptr; + long file_major, + file_minor; + long my_major = 0, + my_minor = 0; + char *endptr; const char *version_string = PG_VERSION; my_major = strtol(version_string, &endptr, 10); if (*endptr == '.') - my_minor = strtol(endptr+1, NULL, 10); + my_minor = strtol(endptr + 1, NULL, 10); snprintf(full_path, MAXPGPATH, "%s/PG_VERSION", path); diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index 0f9639de02b..ef5f09374af 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.81 2001/02/16 18:50:40 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.82 2001/03/22 04:00:00 momjian Exp $ * * *------------------------------------------------------------------------- @@ -118,7 +118,7 @@ ReverifyMyDatabase(const char *name) * Also check that the database is currently allowing connections. */ dbform = (Form_pg_database) GETSTRUCT(tup); - if (! dbform->datallowconn) + if (!dbform->datallowconn) elog(FATAL, "Database \"%s\" is not currently accepting connections", name); @@ -175,6 +175,7 @@ InitCommunication(void) void BaseInit(void) { + /* * Attach to shared memory and semaphores, and initialize our * input/output/debugging file descriptors. @@ -230,8 +231,8 @@ InitPostgres(const char *dbname, const char *username) ValidatePgVersion(DataDir); /* - * Find oid and path of the database we're about to open. - * Since we're not yet up and running we have to use the hackish + * Find oid and path of the database we're about to open. Since + * we're not yet up and running we have to use the hackish * GetRawDatabaseInfo. */ GetRawDatabaseInfo(dbname, &MyDatabaseId, datpath); @@ -347,8 +348,8 @@ InitPostgres(const char *dbname, const char *username) /* * Unless we are bootstrapping, double-check that InitMyDatabaseInfo() - * got a correct result. We can't do this until all the database-access - * infrastructure is up. + * got a correct result. We can't do this until all the + * database-access infrastructure is up. */ if (!bootstrap) ReverifyMyDatabase(dbname); @@ -359,14 +360,18 @@ InitPostgres(const char *dbname, const char *username) #endif /* - * Set up process-exit callbacks to remove temp relations and then - * do pre-shutdown cleanup. This should be last because we want + * Set up process-exit callbacks to remove temp relations and then do + * pre-shutdown cleanup. This should be last because we want * shmem_exit to call these routines before the exit callbacks that - * are registered by buffer manager, lock manager, etc. We need - * to run this code before we close down database access! + * are registered by buffer manager, lock manager, etc. We need to + * run this code before we close down database access! */ on_shmem_exit(ShutdownPostgres, 0); - /* because callbacks are called in reverse order, this gets done first: */ + + /* + * because callbacks are called in reverse order, this gets done + * first: + */ on_shmem_exit(remove_all_temp_relations, 0); /* close the transaction we started above */ @@ -389,21 +394,24 @@ InitPostgres(const char *dbname, const char *username) static void ShutdownPostgres(void) { + /* - * These operations are really just a minimal subset of AbortTransaction(). - * We don't want to do any inessential cleanup, since that just raises - * the odds of failure --- but there's some stuff we need to do. + * These operations are really just a minimal subset of + * AbortTransaction(). We don't want to do any inessential cleanup, + * since that just raises the odds of failure --- but there's some + * stuff we need to do. * * Release any spinlocks or buffer context locks we might be holding. - * This is a kluge to improve the odds that we won't get into a self-made - * stuck-spinlock scenario while trying to shut down. + * This is a kluge to improve the odds that we won't get into a + * self-made stuck-spinlock scenario while trying to shut down. */ ProcReleaseSpins(NULL); UnlockBuffers(); + /* - * In case a transaction is open, delete any files it created. This + * In case a transaction is open, delete any files it created. This * has to happen before bufmgr shutdown, so having smgr register a * callback for it wouldn't work. */ - smgrDoPendingDeletes(false); /* delete as though aborting xact */ + smgrDoPendingDeletes(false);/* delete as though aborting xact */ } diff --git a/src/backend/utils/mb/conv.c b/src/backend/utils/mb/conv.c index eaef3976b5e..30b1a0d92a6 100644 --- a/src/backend/utils/mb/conv.c +++ b/src/backend/utils/mb/conv.c @@ -6,7 +6,7 @@ * WIN1250 client encoding support contributed by Pavel Behal * SJIS UDC (NEC selection IBM kanji) support contributed by Eiji Tokuya * - * $Id: conv.c,v 1.23 2001/02/11 01:56:58 ishii Exp $ + * $Id: conv.c,v 1.24 2001/03/22 04:00:01 momjian Exp $ * * */ @@ -39,7 +39,7 @@ #include "Unicode/utf8_to_big5.map" #include "Unicode/big5_to_utf8.map" -#endif /* UNICODE_CONVERSION */ +#endif /* UNICODE_CONVERSION */ /* * SJIS alternative code. @@ -86,6 +86,7 @@ sjis2mic(unsigned char *sjis, unsigned char *p, int len) i, k, k2; + /* Eiji Tokuya patched end */ while (len > 0 && (c1 = *sjis++)) { @@ -117,7 +118,7 @@ sjis2mic(unsigned char *sjis, unsigned char *p, int len) { k = ibmkanji[i].sjis; c1 = (k >> 8) & 0xff; - c2 = k & 0xff; + c2 = k & 0xff; } } } @@ -132,7 +133,7 @@ sjis2mic(unsigned char *sjis, unsigned char *p, int len) *p++ = c2 + ((c2 > 0x9e) ? 2 : 0x60) + (c2 < 0x80); } /* Eiji Tokuya patched begin */ - else if ((k >= 0xeb40 && k < 0xf040)||(k >= 0xfc4c && k <= 0xfcfc)) + else if ((k >= 0xeb40 && k < 0xf040) || (k >= 0xfc4c && k <= 0xfcfc)) { /* NEC selection IBM kanji - Other undecided justice */ /* Eiji Tokuya patched end */ @@ -1144,7 +1145,7 @@ mic2win1250(unsigned char *mic, unsigned char *p, int len) static void ascii2utf(unsigned char *ascii, unsigned char *utf, int len) { - ascii2mic(ascii, utf, len); + ascii2mic(ascii, utf, len); } /* @@ -1153,7 +1154,7 @@ ascii2utf(unsigned char *ascii, unsigned char *utf, int len) static void utf2ascii(unsigned char *utf, unsigned char *ascii, int len) { - mic2ascii(utf, ascii, len); + mic2ascii(utf, ascii, len); } /* @@ -1162,14 +1163,12 @@ utf2ascii(unsigned char *utf, unsigned char *ascii, int len) static void latin1_to_utf(unsigned char *iso, unsigned char *utf, int len) { - unsigned short c; + unsigned short c; while (len-- > 0 && (c = *iso++)) { if (c < 0x80) - { *utf++ = c; - } else { *utf++ = (c >> 6) | 0xc0; @@ -1185,7 +1184,9 @@ latin1_to_utf(unsigned char *iso, unsigned char *utf, int len) static void utf_to_latin1(unsigned char *utf, unsigned char *iso, int len) { - unsigned short c, c1, c2; + unsigned short c, + c1, + c2; while (len > 0 && (c = *utf++)) { @@ -1198,9 +1199,7 @@ utf_to_latin1(unsigned char *utf, unsigned char *iso, int len) len -= 2; } else if ((c & 0xe0) == 0xe0) - { elog(ERROR, "Could not convert UTF-8 to ISO8859-1"); - } else { *iso++ = c; @@ -1214,46 +1213,50 @@ utf_to_latin1(unsigned char *utf, unsigned char *iso, int len) * comparison routine for bsearch() * this routine is intended for UTF-8 -> local code */ -static int compare1(const void *p1, const void *p2) +static int +compare1(const void *p1, const void *p2) { - unsigned int v1, v2; + unsigned int v1, + v2; - v1 = *(unsigned int *)p1; - v2 = ((pg_utf_to_local *)p2)->utf; - return(v1 - v2); + v1 = *(unsigned int *) p1; + v2 = ((pg_utf_to_local *) p2)->utf; + return (v1 - v2); } /* * comparison routine for bsearch() * this routine is intended for local code -> UTF-8 */ -static int compare2(const void *p1, const void *p2) +static int +compare2(const void *p1, const void *p2) { - unsigned int v1, v2; + unsigned int v1, + v2; - v1 = *(unsigned int *)p1; - v2 = ((pg_local_to_utf *)p2)->code; - return(v1 - v2); + v1 = *(unsigned int *) p1; + v2 = ((pg_local_to_utf *) p2)->code; + return (v1 - v2); } /* * UTF-8 ---> local code * * utf: input UTF-8 string. Its length is limited by "len" parameter - * or a null terminater. + * or a null terminater. * iso: pointer to the output. * map: the conversion map. * size: the size of the conversion map. */ static void utf_to_local(unsigned char *utf, unsigned char *iso, - pg_utf_to_local *map, int size, int len) + pg_utf_to_local * map, int size, int len) { unsigned int iutf; - int l; + int l; pg_utf_to_local *p; - for (;len > 0 && *utf; len -= l) + for (; len > 0 && *utf; len -= l) { l = pg_utf_mblen(utf); if (l == 1) @@ -1262,7 +1265,7 @@ utf_to_local(unsigned char *utf, unsigned char *iso, continue; } else if (l == 2) - { + { iutf = *utf++ << 8; iutf |= *utf++; } @@ -1297,7 +1300,7 @@ utf_to_local(unsigned char *utf, unsigned char *iso, static void utf_to_latin2(unsigned char *utf, unsigned char *iso, int len) { - utf_to_local(utf, iso, ULmapISO8859_2, sizeof(ULmapISO8859_2)/sizeof(pg_utf_to_local), len); + utf_to_local(utf, iso, ULmapISO8859_2, sizeof(ULmapISO8859_2) / sizeof(pg_utf_to_local), len); } /* @@ -1306,7 +1309,7 @@ utf_to_latin2(unsigned char *utf, unsigned char *iso, int len) static void utf_to_latin3(unsigned char *utf, unsigned char *iso, int len) { - utf_to_local(utf, iso, ULmapISO8859_3, sizeof(ULmapISO8859_3)/sizeof(pg_utf_to_local), len); + utf_to_local(utf, iso, ULmapISO8859_3, sizeof(ULmapISO8859_3) / sizeof(pg_utf_to_local), len); } /* @@ -1315,7 +1318,7 @@ utf_to_latin3(unsigned char *utf, unsigned char *iso, int len) static void utf_to_latin4(unsigned char *utf, unsigned char *iso, int len) { - utf_to_local(utf, iso, ULmapISO8859_4, sizeof(ULmapISO8859_4)/sizeof(pg_utf_to_local), len); + utf_to_local(utf, iso, ULmapISO8859_4, sizeof(ULmapISO8859_4) / sizeof(pg_utf_to_local), len); } /* @@ -1325,7 +1328,7 @@ static void utf_to_latin5(unsigned char *utf, unsigned char *iso, int len) { - utf_to_local(utf, iso, ULmapISO8859_5, sizeof(ULmapISO8859_5)/sizeof(pg_utf_to_local), len); + utf_to_local(utf, iso, ULmapISO8859_5, sizeof(ULmapISO8859_5) / sizeof(pg_utf_to_local), len); } /* @@ -1333,20 +1336,18 @@ utf_to_latin5(unsigned char *utf, unsigned char *iso, int len) */ static void local_to_utf(unsigned char *iso, unsigned char *utf, - pg_local_to_utf *map, int size, int encoding, int len) + pg_local_to_utf * map, int size, int encoding, int len) { unsigned int iiso; - int l; + int l; pg_local_to_utf *p; pg_encoding_conv_tbl *e; e = pg_get_enc_ent(encoding); if (e == 0) - { elog(ERROR, "Invalid encoding number %d", encoding); - } - for (;len > 0 && *iso; len -= l) + for (; len > 0 && *iso; len -= l) { if (*iso < 0x80) { @@ -1358,11 +1359,9 @@ local_to_utf(unsigned char *iso, unsigned char *utf, l = pg_encoding_mblen(encoding, iso); if (l == 1) - { iiso = *iso++; - } else if (l == 2) - { + { iiso = *iso++ << 8; iiso |= *iso++; } @@ -1383,8 +1382,8 @@ local_to_utf(unsigned char *iso, unsigned char *utf, sizeof(pg_local_to_utf), compare2); if (p == NULL) { - elog(NOTICE, "local_to_utf: could not convert (0x%04x) %s to UTF-8. Ignored", - iiso, e->name); + elog(NOTICE, "local_to_utf: could not convert (0x%04x) %s to UTF-8. Ignored", + iiso, e->name); continue; } if (p->utf & 0xff000000) @@ -1405,7 +1404,7 @@ local_to_utf(unsigned char *iso, unsigned char *utf, static void latin2_to_utf(unsigned char *iso, unsigned char *utf, int len) { - local_to_utf(iso, utf, LUmapISO8859_2, sizeof(LUmapISO8859_2)/sizeof(pg_local_to_utf), LATIN2, len); + local_to_utf(iso, utf, LUmapISO8859_2, sizeof(LUmapISO8859_2) / sizeof(pg_local_to_utf), LATIN2, len); } /* @@ -1414,7 +1413,7 @@ latin2_to_utf(unsigned char *iso, unsigned char *utf, int len) static void latin3_to_utf(unsigned char *iso, unsigned char *utf, int len) { - local_to_utf(iso, utf, LUmapISO8859_3, sizeof(LUmapISO8859_3)/sizeof(pg_local_to_utf), LATIN3, len); + local_to_utf(iso, utf, LUmapISO8859_3, sizeof(LUmapISO8859_3) / sizeof(pg_local_to_utf), LATIN3, len); } /* @@ -1423,7 +1422,7 @@ latin3_to_utf(unsigned char *iso, unsigned char *utf, int len) static void latin4_to_utf(unsigned char *iso, unsigned char *utf, int len) { - local_to_utf(iso, utf, LUmapISO8859_4, sizeof(LUmapISO8859_4)/sizeof(pg_local_to_utf), LATIN4, len); + local_to_utf(iso, utf, LUmapISO8859_4, sizeof(LUmapISO8859_4) / sizeof(pg_local_to_utf), LATIN4, len); } /* @@ -1432,7 +1431,7 @@ latin4_to_utf(unsigned char *iso, unsigned char *utf, int len) static void latin5_to_utf(unsigned char *iso, unsigned char *utf, int len) { - local_to_utf(iso, utf, LUmapISO8859_5, sizeof(LUmapISO8859_5)/sizeof(pg_local_to_utf), LATIN5, len); + local_to_utf(iso, utf, LUmapISO8859_5, sizeof(LUmapISO8859_5) / sizeof(pg_local_to_utf), LATIN5, len); } /* @@ -1442,8 +1441,8 @@ static void utf_to_euc_jp(unsigned char *utf, unsigned char *euc, int len) { - utf_to_local(utf, euc, ULmapEUC_JP, - sizeof(ULmapEUC_JP)/sizeof(pg_utf_to_local), len); + utf_to_local(utf, euc, ULmapEUC_JP, + sizeof(ULmapEUC_JP) / sizeof(pg_utf_to_local), len); } /* @@ -1453,7 +1452,7 @@ static void euc_jp_to_utf(unsigned char *euc, unsigned char *utf, int len) { local_to_utf(euc, utf, LUmapEUC_JP, - sizeof(LUmapEUC_JP)/sizeof(pg_local_to_utf), EUC_JP, len); + sizeof(LUmapEUC_JP) / sizeof(pg_local_to_utf), EUC_JP, len); } /* @@ -1463,8 +1462,8 @@ static void utf_to_euc_cn(unsigned char *utf, unsigned char *euc, int len) { - utf_to_local(utf, euc, ULmapEUC_CN, - sizeof(ULmapEUC_CN)/sizeof(pg_utf_to_local), len); + utf_to_local(utf, euc, ULmapEUC_CN, + sizeof(ULmapEUC_CN) / sizeof(pg_utf_to_local), len); } /* @@ -1474,7 +1473,7 @@ static void euc_cn_to_utf(unsigned char *euc, unsigned char *utf, int len) { local_to_utf(euc, utf, LUmapEUC_CN, - sizeof(LUmapEUC_CN)/sizeof(pg_local_to_utf), EUC_CN, len); + sizeof(LUmapEUC_CN) / sizeof(pg_local_to_utf), EUC_CN, len); } /* @@ -1484,8 +1483,8 @@ static void utf_to_euc_kr(unsigned char *utf, unsigned char *euc, int len) { - utf_to_local(utf, euc, ULmapEUC_KR, - sizeof(ULmapEUC_KR)/sizeof(pg_utf_to_local), len); + utf_to_local(utf, euc, ULmapEUC_KR, + sizeof(ULmapEUC_KR) / sizeof(pg_utf_to_local), len); } /* @@ -1495,7 +1494,7 @@ static void euc_kr_to_utf(unsigned char *euc, unsigned char *utf, int len) { local_to_utf(euc, utf, LUmapEUC_KR, - sizeof(LUmapEUC_KR)/sizeof(pg_local_to_utf), EUC_KR, len); + sizeof(LUmapEUC_KR) / sizeof(pg_local_to_utf), EUC_KR, len); } /* @@ -1505,8 +1504,8 @@ static void utf_to_euc_tw(unsigned char *utf, unsigned char *euc, int len) { - utf_to_local(utf, euc, ULmapEUC_TW, - sizeof(ULmapEUC_TW)/sizeof(pg_utf_to_local), len); + utf_to_local(utf, euc, ULmapEUC_TW, + sizeof(ULmapEUC_TW) / sizeof(pg_utf_to_local), len); } /* @@ -1516,7 +1515,7 @@ static void euc_tw_to_utf(unsigned char *euc, unsigned char *utf, int len) { local_to_utf(euc, utf, LUmapEUC_TW, - sizeof(LUmapEUC_TW)/sizeof(pg_local_to_utf), EUC_TW, len); + sizeof(LUmapEUC_TW) / sizeof(pg_local_to_utf), EUC_TW, len); } /* @@ -1526,8 +1525,8 @@ static void utf_to_sjis(unsigned char *utf, unsigned char *euc, int len) { - utf_to_local(utf, euc, ULmapSJIS, - sizeof(ULmapSJIS)/sizeof(pg_utf_to_local), len); + utf_to_local(utf, euc, ULmapSJIS, + sizeof(ULmapSJIS) / sizeof(pg_utf_to_local), len); } /* @@ -1537,7 +1536,7 @@ static void sjis_to_utf(unsigned char *euc, unsigned char *utf, int len) { local_to_utf(euc, utf, LUmapSJIS, - sizeof(LUmapSJIS)/sizeof(pg_local_to_utf), SJIS, len); + sizeof(LUmapSJIS) / sizeof(pg_local_to_utf), SJIS, len); } /* @@ -1547,8 +1546,8 @@ static void utf_to_big5(unsigned char *utf, unsigned char *euc, int len) { - utf_to_local(utf, euc, ULmapBIG5, - sizeof(ULmapBIG5)/sizeof(pg_utf_to_local), len); + utf_to_local(utf, euc, ULmapBIG5, + sizeof(ULmapBIG5) / sizeof(pg_utf_to_local), len); } /* @@ -1558,85 +1557,85 @@ static void big5_to_utf(unsigned char *euc, unsigned char *utf, int len) { local_to_utf(euc, utf, LUmapBIG5, - sizeof(LUmapBIG5)/sizeof(pg_local_to_utf), BIG5, len); + sizeof(LUmapBIG5) / sizeof(pg_local_to_utf), BIG5, len); } /*-----------------------------------------------------------------*/ pg_encoding_conv_tbl pg_conv_tbl[] = { {SQL_ASCII, "SQL_ASCII", 0, ascii2mic, mic2ascii, - ascii2utf, utf2ascii}, /* SQL/ASCII */ + ascii2utf, utf2ascii}, /* SQL/ASCII */ {EUC_JP, "EUC_JP", 0, euc_jp2mic, mic2euc_jp, - euc_jp_to_utf, utf_to_euc_jp}, /* EUC_JP */ + euc_jp_to_utf, utf_to_euc_jp}, /* EUC_JP */ {EUC_CN, "EUC_CN", 0, euc_cn2mic, mic2euc_cn, - euc_cn_to_utf, utf_to_euc_cn}, /* EUC_CN */ + euc_cn_to_utf, utf_to_euc_cn}, /* EUC_CN */ {EUC_KR, "EUC_KR", 0, euc_kr2mic, mic2euc_kr, euc_kr_to_utf, utf_to_euc_kr}, /* EUC_KR */ {EUC_TW, "EUC_TW", 0, euc_tw2mic, mic2euc_tw, - euc_tw_to_utf, utf_to_euc_tw}, /* EUC_TW */ + euc_tw_to_utf, utf_to_euc_tw}, /* EUC_TW */ {UNICODE, "UNICODE", 0, 0, 0}, /* UNICODE */ {MULE_INTERNAL, "MULE_INTERNAL", 0, 0, 0}, /* MULE_INTERNAL */ {LATIN1, "LATIN1", 0, latin12mic, mic2latin1, - latin1_to_utf, utf_to_latin1}, /* ISO 8859 Latin 1 */ + latin1_to_utf, utf_to_latin1}, /* ISO 8859 Latin 1 */ {LATIN2, "LATIN2", 0, latin22mic, mic2latin2, - latin2_to_utf, utf_to_latin2}, /* ISO 8859 Latin 2 */ + latin2_to_utf, utf_to_latin2}, /* ISO 8859 Latin 2 */ {LATIN3, "LATIN3", 0, latin32mic, mic2latin3, - latin3_to_utf, utf_to_latin3}, /* ISO 8859 Latin 3 */ + latin3_to_utf, utf_to_latin3}, /* ISO 8859 Latin 3 */ {LATIN4, "LATIN4", 0, latin42mic, mic2latin4, - latin4_to_utf, utf_to_latin4}, /* ISO 8859 Latin 4 */ + latin4_to_utf, utf_to_latin4}, /* ISO 8859 Latin 4 */ {LATIN5, "LATIN5", 0, iso2mic, mic2iso, - latin5_to_utf, utf_to_latin5}, /* ISO 8859 Latin 5 */ + latin5_to_utf, utf_to_latin5}, /* ISO 8859 Latin 5 */ {KOI8, "KOI8", 0, koi2mic, mic2koi, - 0, 0}, /* KOI8-R */ + 0, 0}, /* KOI8-R */ {WIN, "WIN", 0, win2mic, mic2win, - 0,0}, /* CP1251 */ + 0, 0}, /* CP1251 */ {ALT, "ALT", 0, alt2mic, mic2alt, - 0,0}, /* CP866 */ + 0, 0}, /* CP866 */ {SJIS, "SJIS", 1, sjis2mic, mic2sjis, - sjis_to_utf, utf_to_sjis}, /* SJIS */ + sjis_to_utf, utf_to_sjis}, /* SJIS */ {BIG5, "BIG5", 1, big52mic, mic2big5, - big5_to_utf, utf_to_big5}, /* Big5 */ + big5_to_utf, utf_to_big5}, /* Big5 */ {WIN1250, "WIN1250", 1, win12502mic, mic2win1250, - 0,0}, /* WIN 1250 */ - {-1, "", 0, 0, 0, 0} /* end mark */ + 0, 0}, /* WIN 1250 */ + {-1, "", 0, 0, 0, 0} /* end mark */ }; #else pg_encoding_conv_tbl pg_conv_tbl[] = { {SQL_ASCII, "SQL_ASCII", 0, ascii2mic, mic2ascii, - 0, 0}, /* SQL/ASCII */ + 0, 0}, /* SQL/ASCII */ {EUC_JP, "EUC_JP", 0, euc_jp2mic, mic2euc_jp, - 0, 0}, /* EUC_JP */ + 0, 0}, /* EUC_JP */ {EUC_CN, "EUC_CN", 0, euc_cn2mic, mic2euc_cn, - 0, 0}, /* EUC_CN */ + 0, 0}, /* EUC_CN */ {EUC_KR, "EUC_KR", 0, euc_kr2mic, mic2euc_kr}, /* EUC_KR */ {EUC_TW, "EUC_TW", 0, euc_tw2mic, mic2euc_tw}, /* EUC_TW */ {UNICODE, "UNICODE", 0, 0, 0}, /* UNICODE */ {MULE_INTERNAL, "MULE_INTERNAL", 0, 0, 0}, /* MULE_INTERNAL */ {LATIN1, "LATIN1", 0, latin12mic, mic2latin1, - 0, 0}, /* ISO 8859 Latin 1 */ + 0, 0}, /* ISO 8859 Latin 1 */ {LATIN2, "LATIN2", 0, latin22mic, mic2latin2, - 0, 0}, /* ISO 8859 Latin 2 */ + 0, 0}, /* ISO 8859 Latin 2 */ {LATIN3, "LATIN3", 0, latin32mic, mic2latin3, - 0, 0}, /* ISO 8859 Latin 3 */ + 0, 0}, /* ISO 8859 Latin 3 */ {LATIN4, "LATIN4", 0, latin42mic, mic2latin4, - 0, 0}, /* ISO 8859 Latin 4 */ + 0, 0}, /* ISO 8859 Latin 4 */ {LATIN5, "LATIN5", 0, iso2mic, mic2iso, - 0, 0}, /* ISO 8859 Latin 5 */ + 0, 0}, /* ISO 8859 Latin 5 */ {KOI8, "KOI8", 0, koi2mic, mic2koi, - 0, 0}, /* KOI8-R */ + 0, 0}, /* KOI8-R */ {WIN, "WIN", 0, win2mic, mic2win, - 0,0}, /* CP1251 */ + 0, 0}, /* CP1251 */ {ALT, "ALT", 0, alt2mic, mic2alt, - 0,0}, /* CP866 */ + 0, 0}, /* CP866 */ {SJIS, "SJIS", 1, sjis2mic, mic2sjis, - 0, 0}, /* SJIS */ + 0, 0}, /* SJIS */ {BIG5, "BIG5", 1, big52mic, mic2big5, - 0,0}, /* Big5 */ + 0, 0}, /* Big5 */ {WIN1250, "WIN1250", 1, win12502mic, mic2win1250, - 0,0}, /* WIN 1250 */ - {-1, "", 0, 0, 0, 0} /* end mark */ + 0, 0}, /* WIN 1250 */ + {-1, "", 0, 0, 0, 0} /* end mark */ }; -#endif /* UNICODE_CONVERSION */ +#endif /* UNICODE_CONVERSION */ diff --git a/src/backend/utils/mb/liketest.c b/src/backend/utils/mb/liketest.c index 3c2e9de7507..5cb6860812c 100644 --- a/src/backend/utils/mb/liketest.c +++ b/src/backend/utils/mb/liketest.c @@ -12,37 +12,42 @@ #define UCHARMAX 0xff /*----------------------------------------------------------------*/ -static int wchareq(unsigned char *p1, unsigned char *p2) +static int +wchareq(unsigned char *p1, unsigned char *p2) { - int l; + int l; l = pg_mblen(p1); - if (pg_mblen(p2) != l) { - return(0); - } - while (l--) { + if (pg_mblen(p2) != l) + return (0); + while (l--) + { if (*p1++ != *p2++) - return(0); + return (0); } - return(1); + return (1); } -static int iwchareq(unsigned char *p1, unsigned char *p2) +static int +iwchareq(unsigned char *p1, unsigned char *p2) { - int c1, c2; - int l; + int c1, + c2; + int l; - /* short cut. if *p1 and *p2 is lower than UCHARMAX, then - we assume they are ASCII */ + /* + * short cut. if *p1 and *p2 is lower than UCHARMAX, then we assume + * they are ASCII + */ if (*p1 < UCHARMAX && *p2 < UCHARMAX) - return(tolower(*p1) == tolower(*p2)); + return (tolower(*p1) == tolower(*p2)); if (*p1 < UCHARMAX) c1 = tolower(*p1); else { l = pg_mblen(p1); - (void)pg_mb2wchar_with_len(p1, (pg_wchar *)&c1, l); + (void) pg_mb2wchar_with_len(p1, (pg_wchar *) & c1, l); c1 = tolower(c1); } if (*p2 < UCHARMAX) @@ -50,10 +55,10 @@ static int iwchareq(unsigned char *p1, unsigned char *p2) else { l = pg_mblen(p2); - (void)pg_mb2wchar_with_len(p2, (pg_wchar *)&c2, l); + (void) pg_mb2wchar_with_len(p2, (pg_wchar *) & c2, l); c2 = tolower(c2); } - return(c1 == c2); + return (c1 == c2); } #ifdef MULTIBYTE @@ -69,23 +74,28 @@ static int iwchareq(unsigned char *p1, unsigned char *p2) static int MatchText(PG_CHAR * t, int tlen, PG_CHAR * p, int plen, char *e) { - /* Fast path for match-everything pattern - * Include weird case of escape character as a percent sign or underscore, - * when presumably that wildcard character becomes a literal. + + /* + * Fast path for match-everything pattern Include weird case of escape + * character as a percent sign or underscore, when presumably that + * wildcard character becomes a literal. */ if ((plen == 1) && (*p == '%') - && ! ((e != NULL) && (*e == '%'))) + && !((e != NULL) && (*e == '%'))) return LIKE_TRUE; while ((tlen > 0) && (plen > 0)) { - /* If an escape character was specified and we find it here in the pattern, - * then we'd better have an exact match for the next character. + + /* + * If an escape character was specified and we find it here in the + * pattern, then we'd better have an exact match for the next + * character. */ - if ((e != NULL) && CHAREQ(p,e)) + if ((e != NULL) && CHAREQ(p, e)) { NextChar(p, plen); - if ((plen <= 0) || !CHAREQ(t,p)) + if ((plen <= 0) || !CHAREQ(t, p)) return LIKE_FALSE; } else if (*p == '%') @@ -99,23 +109,23 @@ MatchText(PG_CHAR * t, int tlen, PG_CHAR * p, int plen, char *e) return LIKE_TRUE; /* - * Otherwise, scan for a text position at which we can - * match the rest of the pattern. + * Otherwise, scan for a text position at which we can match + * the rest of the pattern. */ while (tlen > 0) { + /* - * Optimization to prevent most recursion: don't - * recurse unless first pattern char might match this - * text char. + * Optimization to prevent most recursion: don't recurse + * unless first pattern char might match this text char. */ - if (CHAREQ(t,p) || (*p == '_') - || ((e != NULL) && CHAREQ(p,e))) + if (CHAREQ(t, p) || (*p == '_') + || ((e != NULL) && CHAREQ(p, e))) { - int matched = MatchText(t, tlen, p, plen, e); + int matched = MatchText(t, tlen, p, plen, e); if (matched != LIKE_FALSE) - return matched; /* TRUE or ABORT */ + return matched; /* TRUE or ABORT */ } NextChar(t, tlen); @@ -127,9 +137,11 @@ MatchText(PG_CHAR * t, int tlen, PG_CHAR * p, int plen, char *e) */ return LIKE_ABORT; } - else if ((*p != '_') && !CHAREQ(t,p)) + else if ((*p != '_') && !CHAREQ(t, p)) { - /* Not the single-character wildcard and no explicit match? + + /* + * Not the single-character wildcard and no explicit match? * Then time to quit... */ return LIKE_FALSE; @@ -143,7 +155,8 @@ MatchText(PG_CHAR * t, int tlen, PG_CHAR * p, int plen, char *e) return LIKE_FALSE; /* end of pattern, but not of text */ /* End of input string. Do we have matching pattern remaining? */ - while ((plen > 0) && (*p == '%')) /* allow multiple %'s at end of pattern */ + while ((plen > 0) && (*p == '%')) /* allow multiple %'s at end of + * pattern */ NextChar(p, plen); if (plen <= 0) return LIKE_TRUE; @@ -153,28 +166,33 @@ MatchText(PG_CHAR * t, int tlen, PG_CHAR * p, int plen, char *e) * start matching this pattern. */ return LIKE_ABORT; -} /* MatchText() */ +} /* MatchText() */ static int MatchTextLower(PG_CHAR * t, int tlen, PG_CHAR * p, int plen, char *e) { - /* Fast path for match-everything pattern - * Include weird case of escape character as a percent sign or underscore, - * when presumably that wildcard character becomes a literal. + + /* + * Fast path for match-everything pattern Include weird case of escape + * character as a percent sign or underscore, when presumably that + * wildcard character becomes a literal. */ if ((plen == 1) && (*p == '%') - && ! ((e != NULL) && (*e == '%'))) + && !((e != NULL) && (*e == '%'))) return LIKE_TRUE; while ((tlen > 0) && (plen > 0)) { - /* If an escape character was specified and we find it here in the pattern, - * then we'd better have an exact match for the next character. + + /* + * If an escape character was specified and we find it here in the + * pattern, then we'd better have an exact match for the next + * character. */ - if ((e != NULL) && ICHAREQ(p,e)) + if ((e != NULL) && ICHAREQ(p, e)) { NextChar(p, plen); - if ((plen <= 0) || !ICHAREQ(t,p)) + if ((plen <= 0) || !ICHAREQ(t, p)) return LIKE_FALSE; } else if (*p == '%') @@ -188,23 +206,23 @@ MatchTextLower(PG_CHAR * t, int tlen, PG_CHAR * p, int plen, char *e) return LIKE_TRUE; /* - * Otherwise, scan for a text position at which we can - * match the rest of the pattern. + * Otherwise, scan for a text position at which we can match + * the rest of the pattern. */ while (tlen > 0) { + /* - * Optimization to prevent most recursion: don't - * recurse unless first pattern char might match this - * text char. + * Optimization to prevent most recursion: don't recurse + * unless first pattern char might match this text char. */ - if (ICHAREQ(t,p) || (*p == '_') - || ((e != NULL) && ICHAREQ(p,e))) + if (ICHAREQ(t, p) || (*p == '_') + || ((e != NULL) && ICHAREQ(p, e))) { - int matched = MatchText(t, tlen, p, plen, e); + int matched = MatchText(t, tlen, p, plen, e); if (matched != LIKE_FALSE) - return matched; /* TRUE or ABORT */ + return matched; /* TRUE or ABORT */ } NextChar(t, tlen); @@ -216,10 +234,8 @@ MatchTextLower(PG_CHAR * t, int tlen, PG_CHAR * p, int plen, char *e) */ return LIKE_ABORT; } - else if ((*p != '_') && !ICHAREQ(t,p)) - { + else if ((*p != '_') && !ICHAREQ(t, p)) return LIKE_FALSE; - } NextChar(t, tlen); NextChar(p, plen); @@ -229,7 +245,8 @@ MatchTextLower(PG_CHAR * t, int tlen, PG_CHAR * p, int plen, char *e) return LIKE_FALSE; /* end of pattern, but not of text */ /* End of input string. Do we have matching pattern remaining? */ - while ((plen > 0) && (*p == '%')) /* allow multiple %'s at end of pattern */ + while ((plen > 0) && (*p == '%')) /* allow multiple %'s at end of + * pattern */ NextChar(p, plen); if (plen <= 0) return LIKE_TRUE; @@ -239,14 +256,16 @@ MatchTextLower(PG_CHAR * t, int tlen, PG_CHAR * p, int plen, char *e) * start matching this pattern. */ return LIKE_ABORT; -} /* MatchTextLower() */ +} /* MatchTextLower() */ main() { unsigned char *t = "¿ÍZ01²¼"; unsigned char *p = "_Z%"; - int tlen, plen; + int tlen, + plen; + tlen = strlen(t); plen = strlen(p); - printf("%d\n",MatchTextLower(t,tlen,p,plen,"\\")); + printf("%d\n", MatchTextLower(t, tlen, p, plen, "\\")); } diff --git a/src/backend/utils/mb/palloc.c b/src/backend/utils/mb/palloc.c index e547e7a79e5..3e1b70aae9a 100644 --- a/src/backend/utils/mb/palloc.c +++ b/src/backend/utils/mb/palloc.c @@ -4,7 +4,7 @@ void elog(int lev, const char *fmt,...) { - printf(fmt); + printf(fmt); } MemoryContext CurrentMemoryContext; diff --git a/src/backend/utils/mb/utftest.c b/src/backend/utils/mb/utftest.c index 5f0f7f9fb7e..4588e2699c9 100644 --- a/src/backend/utils/mb/utftest.c +++ b/src/backend/utils/mb/utftest.c @@ -1,5 +1,5 @@ /* - * $Id: utftest.c,v 1.4 2000/10/12 06:06:50 ishii Exp $ + * $Id: utftest.c,v 1.5 2001/03/22 04:00:05 momjian Exp $ */ #include "conv.c" #include "wchar.c" @@ -49,5 +49,5 @@ main() } printf("\n"); - return(0); + return (0); } diff --git a/src/backend/utils/mb/wchar.c b/src/backend/utils/mb/wchar.c index 6d10cad020a..f3d91e963f3 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 multi-byte streams. * Tatsuo Ishii - * $Id: wchar.c,v 1.16 2001/03/08 00:24:34 tgl Exp $ + * $Id: wchar.c,v 1.17 2001/03/22 04:00:05 momjian Exp $ * * WIN1250 client encoding updated by Pavel Behal * @@ -22,10 +22,10 @@ /* * SQL/ASCII */ -static int pg_ascii2wchar_with_len +static int pg_ascii2wchar_with_len (const unsigned char *from, pg_wchar * to, int len) { - int cnt = 0; + int cnt = 0; while (len > 0 && *from) { @@ -34,7 +34,7 @@ static int pg_ascii2wchar_with_len cnt++; } *to = 0; - return(cnt); + return (cnt); } static int @@ -47,10 +47,10 @@ pg_ascii_mblen(const unsigned char *s) * EUC */ -static int pg_euc2wchar_with_len +static int pg_euc2wchar_with_len (const unsigned char *from, pg_wchar * to, int len) { - int cnt = 0; + int cnt = 0; while (len > 0 && *from) { @@ -82,7 +82,7 @@ static int pg_euc2wchar_with_len cnt++; } *to = 0; - return(cnt); + return (cnt); } static int @@ -104,10 +104,10 @@ pg_euc_mblen(const unsigned char *s) /* * EUC_JP */ -static int pg_eucjp2wchar_with_len +static int pg_eucjp2wchar_with_len (const unsigned char *from, pg_wchar * to, int len) { - return(pg_euc2wchar_with_len(from, to, len)); + return (pg_euc2wchar_with_len(from, to, len)); } static int @@ -119,10 +119,10 @@ pg_eucjp_mblen(const unsigned char *s) /* * EUC_KR */ -static int pg_euckr2wchar_with_len +static int pg_euckr2wchar_with_len (const unsigned char *from, pg_wchar * to, int len) { - return(pg_euc2wchar_with_len(from, to, len)); + return (pg_euc2wchar_with_len(from, to, len)); } static int @@ -134,10 +134,10 @@ pg_euckr_mblen(const unsigned char *s) /* * EUC_CN */ -static int pg_euccn2wchar_with_len +static int pg_euccn2wchar_with_len (const unsigned char *from, pg_wchar * to, int len) { - int cnt = 0; + int cnt = 0; while (len > 0 && *from) { @@ -170,7 +170,7 @@ static int pg_euccn2wchar_with_len cnt++; } *to = 0; - return(cnt); + return (cnt); } static int @@ -188,10 +188,10 @@ pg_euccn_mblen(const unsigned char *s) /* * EUC_TW */ -static int pg_euctw2wchar_with_len +static int pg_euctw2wchar_with_len (const unsigned char *from, pg_wchar * to, int len) { - int cnt = 0; + int cnt = 0; while (len > 0 && *from) { @@ -225,7 +225,7 @@ static int pg_euctw2wchar_with_len cnt++; } *to = 0; - return(cnt); + return (cnt); } static int @@ -256,7 +256,7 @@ pg_utf2wchar_with_len(const unsigned char *from, pg_wchar * to, int len) unsigned char c1, c2, c3; - int cnt = 0; + int cnt = 0; while (len > 0 && *from) { @@ -292,7 +292,7 @@ pg_utf2wchar_with_len(const unsigned char *from, pg_wchar * to, int len) cnt++; } *to = 0; - return(cnt); + return (cnt); } /* @@ -321,7 +321,7 @@ pg_utf_mblen(const unsigned char *s) static int pg_mule2wchar_with_len(const unsigned char *from, pg_wchar * to, int len) { - int cnt = 0; + int cnt = 0; while (len > 0 && *from) { @@ -362,7 +362,7 @@ pg_mule2wchar_with_len(const unsigned char *from, pg_wchar * to, int len) cnt++; } *to = 0; - return(cnt); + return (cnt); } int @@ -391,7 +391,7 @@ pg_mule_mblen(const unsigned char *s) static int pg_latin12wchar_with_len(const unsigned char *from, pg_wchar * to, int len) { - int cnt = 0; + int cnt = 0; while (len > 0 && *from) { @@ -400,7 +400,7 @@ pg_latin12wchar_with_len(const unsigned char *from, pg_wchar * to, int len) cnt++; } *to = 0; - return(cnt); + return (cnt); } static int @@ -496,7 +496,7 @@ pg_mic_mblen(const unsigned char *mbstr) return (pg_mule_mblen(mbstr)); } -/* +/* * Returns the byte length of a multi-byte word. */ int diff --git a/src/backend/utils/misc/database.c b/src/backend/utils/misc/database.c index 85f16fec347..5e14ef778bd 100644 --- a/src/backend/utils/misc/database.c +++ b/src/backend/utils/misc/database.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/misc/Attic/database.c,v 1.43 2001/01/24 19:43:16 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/misc/Attic/database.c,v 1.44 2001/03/22 04:00:06 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -149,7 +149,8 @@ GetRawDatabaseInfo(const char *name, Oid *db_id, char *path) sprintf(dbfname, "%s/global/%s", DataDir, DatabaseRelationName); #else { - RelFileNode rnode; + RelFileNode rnode; + rnode.tblNode = 0; rnode.relNode = RelOid_pg_database; dbfname = relpath(rnode); @@ -182,8 +183,8 @@ GetRawDatabaseInfo(const char *name, Oid *db_id, char *path) while ((nbytes = read(dbfd, pg, BLCKSZ)) == BLCKSZ) { - OffsetNumber max = PageGetMaxOffsetNumber(pg); - OffsetNumber lineoff; + OffsetNumber max = PageGetMaxOffsetNumber(pg); + OffsetNumber lineoff; /* look at each tuple on the page */ for (lineoff = FirstOffsetNumber; lineoff <= max; lineoff++) @@ -202,7 +203,7 @@ GetRawDatabaseInfo(const char *name, Oid *db_id, char *path) * Check to see if tuple is valid (committed). * * XXX warning, will robinson: violation of transaction semantics - * happens right here. We cannot really determine if the tuple + * happens right here. We cannot really determine if the tuple * is valid without checking transaction commit status, and the * only way to do that at init time is to paw over pg_log by hand, * too. Instead of checking, we assume that the inserting @@ -222,7 +223,7 @@ GetRawDatabaseInfo(const char *name, Oid *db_id, char *path) * handle the password relation? *-------------------- */ - if (! PhonyHeapTupleSatisfiesNow(tup.t_data)) + if (!PhonyHeapTupleSatisfiesNow(tup.t_data)) continue; /* @@ -236,7 +237,7 @@ GetRawDatabaseInfo(const char *name, Oid *db_id, char *path) *db_id = tup.t_data->t_oid; pathlen = VARSIZE(&(tup_db->datpath)) - VARHDRSZ; if (pathlen >= MAXPGPATH) - pathlen = MAXPGPATH-1; /* pure paranoia */ + pathlen = MAXPGPATH - 1; /* pure paranoia */ strncpy(path, VARDATA(&(tup_db->datpath)), pathlen); path[pathlen] = '\0'; goto done; @@ -257,7 +258,7 @@ done: * PhonyHeapTupleSatisfiesNow --- cut-down tuple time qual test * * This is a simplified version of HeapTupleSatisfiesNow() that does not - * depend on having transaction commit info available. Any transaction + * depend on having transaction commit info available. Any transaction * that touched the tuple is assumed committed unless later marked invalid. * (While we could think about more complex rules, this seems appropriate * for examining pg_database, since both CREATE DATABASE and DROP DATABASE diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index d05bb75a294..feceb5d9500 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -4,7 +4,7 @@ * Support for grand unified configuration scheme, including SET * command, configuration file, and command line options. * - * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.33 2001/03/16 05:44:33 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.34 2001/03/22 04:00:06 momjian Exp $ * * Copyright 2000 by PostgreSQL Global Development Group * Written by Peter Eisentraut <peter_e@gmx.net>. @@ -36,39 +36,42 @@ /* XXX these should be in other modules' header files */ extern bool Log_connections; -extern int CheckPointTimeout; -extern int CommitDelay; -extern int CommitSiblings; +extern int CheckPointTimeout; +extern int CommitDelay; +extern int CommitSiblings; extern bool FixBTree; #ifdef ENABLE_SYSLOG extern char *Syslog_facility; extern char *Syslog_ident; static bool check_facility(const char *facility); + #endif /* * Debugging options */ #ifdef USE_ASSERT_CHECKING -bool assert_enabled = true; +bool assert_enabled = true; + #endif -bool Debug_print_query = false; -bool Debug_print_plan = false; -bool Debug_print_parse = false; -bool Debug_print_rewritten = false; -bool Debug_pretty_print = false; +bool Debug_print_query = false; +bool Debug_print_plan = false; +bool Debug_print_parse = false; +bool Debug_print_rewritten = false; +bool Debug_pretty_print = false; -bool Show_parser_stats = false; -bool Show_planner_stats = false; -bool Show_executor_stats = false; -bool Show_query_stats = false; /* this is sort of all three above together */ -bool Show_btree_build_stats = false; +bool Show_parser_stats = false; +bool Show_planner_stats = false; +bool Show_executor_stats = false; +bool Show_query_stats = false; /* this is sort of all three above + * together */ +bool Show_btree_build_stats = false; -bool SQL_inheritance = true; +bool SQL_inheritance = true; #ifndef PG_KRB_SRVTAB -# define PG_KRB_SRVTAB "" +#define PG_KRB_SRVTAB "" #endif @@ -86,39 +89,39 @@ enum config_type struct config_generic { const char *name; - GucContext context; - void *variable; + GucContext context; + void *variable; }; struct config_bool { const char *name; - GucContext context; - bool *variable; - bool default_val; + GucContext context; + bool *variable; + bool default_val; }; struct config_int { const char *name; - GucContext context; - int *variable; - int default_val; - int min; - int max; + GucContext context; + int *variable; + int default_val; + int min; + int max; }; struct config_real { const char *name; - GucContext context; - double *variable; - double default_val; - double min; - double max; + GucContext context; + double *variable; + double default_val; + double min; + double max; }; /* @@ -130,11 +133,11 @@ struct config_real struct config_string { const char *name; - GucContext context; - char **variable; + GucContext context; + char **variable; const char *default_val; - bool (*parse_hook)(const char *proposed); - void (*assign_hook)(const char *newval); + bool (*parse_hook) (const char *proposed); + void (*assign_hook) (const char *newval); }; @@ -164,189 +167,189 @@ struct config_string /******** option names follow ********/ static struct config_bool -ConfigureNamesBool[] = + ConfigureNamesBool[] = { - {"enable_seqscan", PGC_USERSET, &enable_seqscan, true}, - {"enable_indexscan", PGC_USERSET, &enable_indexscan, true}, - {"enable_tidscan", PGC_USERSET, &enable_tidscan, true}, - {"enable_sort", PGC_USERSET, &enable_sort, true}, - {"enable_nestloop", PGC_USERSET, &enable_nestloop, true}, - {"enable_mergejoin", PGC_USERSET, &enable_mergejoin, true}, - {"enable_hashjoin", PGC_USERSET, &enable_hashjoin, true}, - - {"ksqo", PGC_USERSET, &_use_keyset_query_optimizer, false}, - {"geqo", PGC_USERSET, &enable_geqo, true}, - - {"tcpip_socket", PGC_POSTMASTER, &NetServer, false}, - {"ssl", PGC_POSTMASTER, &EnableSSL, false}, - {"fsync", PGC_SIGHUP, &enableFsync, true}, - {"silent_mode", PGC_POSTMASTER, &SilentMode, false}, - - {"log_connections", PGC_SIGHUP, &Log_connections, false}, - {"log_timestamp", PGC_SIGHUP, &Log_timestamp, false}, - {"log_pid", PGC_SIGHUP, &Log_pid, false}, + {"enable_seqscan", PGC_USERSET, &enable_seqscan, true}, + {"enable_indexscan", PGC_USERSET, &enable_indexscan, true}, + {"enable_tidscan", PGC_USERSET, &enable_tidscan, true}, + {"enable_sort", PGC_USERSET, &enable_sort, true}, + {"enable_nestloop", PGC_USERSET, &enable_nestloop, true}, + {"enable_mergejoin", PGC_USERSET, &enable_mergejoin, true}, + {"enable_hashjoin", PGC_USERSET, &enable_hashjoin, true}, + + {"ksqo", PGC_USERSET, &_use_keyset_query_optimizer, false}, + {"geqo", PGC_USERSET, &enable_geqo, true}, + + {"tcpip_socket", PGC_POSTMASTER, &NetServer, false}, + {"ssl", PGC_POSTMASTER, &EnableSSL, false}, + {"fsync", PGC_SIGHUP, &enableFsync, true}, + {"silent_mode", PGC_POSTMASTER, &SilentMode, false}, + + {"log_connections", PGC_SIGHUP, &Log_connections, false}, + {"log_timestamp", PGC_SIGHUP, &Log_timestamp, false}, + {"log_pid", PGC_SIGHUP, &Log_pid, false}, #ifdef USE_ASSERT_CHECKING - {"debug_assertions", PGC_USERSET, &assert_enabled, true}, + {"debug_assertions", PGC_USERSET, &assert_enabled, true}, #endif - {"debug_print_query", PGC_USERSET, &Debug_print_query, false}, - {"debug_print_parse", PGC_USERSET, &Debug_print_parse, false}, - {"debug_print_rewritten", PGC_USERSET, &Debug_print_rewritten, false}, - {"debug_print_plan", PGC_USERSET, &Debug_print_plan, false}, - {"debug_pretty_print", PGC_USERSET, &Debug_pretty_print, false}, + {"debug_print_query", PGC_USERSET, &Debug_print_query, false}, + {"debug_print_parse", PGC_USERSET, &Debug_print_parse, false}, + {"debug_print_rewritten", PGC_USERSET, &Debug_print_rewritten, false}, + {"debug_print_plan", PGC_USERSET, &Debug_print_plan, false}, + {"debug_pretty_print", PGC_USERSET, &Debug_pretty_print, false}, - {"show_parser_stats", PGC_USERSET, &Show_parser_stats, false}, - {"show_planner_stats", PGC_USERSET, &Show_planner_stats, false}, - {"show_executor_stats", PGC_USERSET, &Show_executor_stats, false}, - {"show_query_stats", PGC_USERSET, &Show_query_stats, false}, + {"show_parser_stats", PGC_USERSET, &Show_parser_stats, false}, + {"show_planner_stats", PGC_USERSET, &Show_planner_stats, false}, + {"show_executor_stats", PGC_USERSET, &Show_executor_stats, false}, + {"show_query_stats", PGC_USERSET, &Show_query_stats, false}, #ifdef BTREE_BUILD_STATS - {"show_btree_build_stats", PGC_SUSET, &Show_btree_build_stats, false}, + {"show_btree_build_stats", PGC_SUSET, &Show_btree_build_stats, false}, #endif - {"trace_notify", PGC_USERSET, &Trace_notify, false}, + {"trace_notify", PGC_USERSET, &Trace_notify, false}, #ifdef LOCK_DEBUG - {"trace_locks", PGC_SUSET, &Trace_locks, false}, - {"trace_userlocks", PGC_SUSET, &Trace_userlocks, false}, - {"trace_spinlocks", PGC_SUSET, &Trace_spinlocks, false}, - {"debug_deadlocks", PGC_SUSET, &Debug_deadlocks, false}, + {"trace_locks", PGC_SUSET, &Trace_locks, false}, + {"trace_userlocks", PGC_SUSET, &Trace_userlocks, false}, + {"trace_spinlocks", PGC_SUSET, &Trace_spinlocks, false}, + {"debug_deadlocks", PGC_SUSET, &Debug_deadlocks, false}, #endif - {"hostname_lookup", PGC_SIGHUP, &HostnameLookup, false}, - {"show_source_port", PGC_SIGHUP, &ShowPortNumber, false}, + {"hostname_lookup", PGC_SIGHUP, &HostnameLookup, false}, + {"show_source_port", PGC_SIGHUP, &ShowPortNumber, false}, - {"sql_inheritance", PGC_USERSET, &SQL_inheritance, true}, + {"sql_inheritance", PGC_USERSET, &SQL_inheritance, true}, - {"fixbtree", PGC_POSTMASTER, &FixBTree, true}, + {"fixbtree", PGC_POSTMASTER, &FixBTree, true}, {NULL, 0, NULL, false} }; static struct config_int -ConfigureNamesInt[] = + ConfigureNamesInt[] = { - {"geqo_threshold", PGC_USERSET, &geqo_rels, - DEFAULT_GEQO_RELS, 2, INT_MAX}, - {"geqo_pool_size", PGC_USERSET, &Geqo_pool_size, - DEFAULT_GEQO_POOL_SIZE, 0, MAX_GEQO_POOL_SIZE}, - {"geqo_effort", PGC_USERSET, &Geqo_effort, - 1, 1, INT_MAX}, - {"geqo_generations", PGC_USERSET, &Geqo_generations, - 0, 0, INT_MAX}, - {"geqo_random_seed", PGC_USERSET, &Geqo_random_seed, - -1, INT_MIN, INT_MAX}, - - {"deadlock_timeout", PGC_POSTMASTER, &DeadlockTimeout, - 1000, 0, INT_MAX}, + {"geqo_threshold", PGC_USERSET, &geqo_rels, + DEFAULT_GEQO_RELS, 2, INT_MAX}, + {"geqo_pool_size", PGC_USERSET, &Geqo_pool_size, + DEFAULT_GEQO_POOL_SIZE, 0, MAX_GEQO_POOL_SIZE}, + {"geqo_effort", PGC_USERSET, &Geqo_effort, + 1, 1, INT_MAX}, + {"geqo_generations", PGC_USERSET, &Geqo_generations, + 0, 0, INT_MAX}, + {"geqo_random_seed", PGC_USERSET, &Geqo_random_seed, + -1, INT_MIN, INT_MAX}, + + {"deadlock_timeout", PGC_POSTMASTER, &DeadlockTimeout, + 1000, 0, INT_MAX}, #ifdef ENABLE_SYSLOG - {"syslog", PGC_SIGHUP, &Use_syslog, - 0, 0, 2}, + {"syslog", PGC_SIGHUP, &Use_syslog, + 0, 0, 2}, #endif /* - * Note: There is some postprocessing done in PostmasterMain() to - * make sure the buffers are at least twice the number of - * backends, so the constraints here are partially unused. + * Note: There is some postprocessing done in PostmasterMain() to make + * sure the buffers are at least twice the number of backends, so the + * constraints here are partially unused. */ - {"max_connections", PGC_POSTMASTER, &MaxBackends, - DEF_MAXBACKENDS, 1, MAXBACKENDS}, - {"shared_buffers", PGC_POSTMASTER, &NBuffers, - DEF_NBUFFERS, 16, INT_MAX}, - {"port", PGC_POSTMASTER, &PostPortNumber, - DEF_PGPORT, 1, 65535}, + {"max_connections", PGC_POSTMASTER, &MaxBackends, + DEF_MAXBACKENDS, 1, MAXBACKENDS}, + {"shared_buffers", PGC_POSTMASTER, &NBuffers, + DEF_NBUFFERS, 16, INT_MAX}, + {"port", PGC_POSTMASTER, &PostPortNumber, + DEF_PGPORT, 1, 65535}, - {"sort_mem", PGC_USERSET, &SortMem, - 512, 1, INT_MAX}, + {"sort_mem", PGC_USERSET, &SortMem, + 512, 1, INT_MAX}, - {"debug_level", PGC_USERSET, &DebugLvl, - 0, 0, 16}, + {"debug_level", PGC_USERSET, &DebugLvl, + 0, 0, 16}, #ifdef LOCK_DEBUG - {"trace_lock_oidmin", PGC_SUSET, &Trace_lock_oidmin, - BootstrapObjectIdData, 1, INT_MAX}, - {"trace_lock_table", PGC_SUSET, &Trace_lock_table, - 0, 0, INT_MAX}, + {"trace_lock_oidmin", PGC_SUSET, &Trace_lock_oidmin, + BootstrapObjectIdData, 1, INT_MAX}, + {"trace_lock_table", PGC_SUSET, &Trace_lock_table, + 0, 0, INT_MAX}, #endif - {"max_expr_depth", PGC_USERSET, &max_expr_depth, - DEFAULT_MAX_EXPR_DEPTH, 10, INT_MAX}, + {"max_expr_depth", PGC_USERSET, &max_expr_depth, + DEFAULT_MAX_EXPR_DEPTH, 10, INT_MAX}, - {"unix_socket_permissions", PGC_POSTMASTER, &Unix_socket_permissions, - 0777, 0000, 0777}, + {"unix_socket_permissions", PGC_POSTMASTER, &Unix_socket_permissions, + 0777, 0000, 0777}, - {"checkpoint_segments", PGC_SIGHUP, &CheckPointSegments, - 3, 1, INT_MAX}, + {"checkpoint_segments", PGC_SIGHUP, &CheckPointSegments, + 3, 1, INT_MAX}, - {"checkpoint_timeout", PGC_SIGHUP, &CheckPointTimeout, - 300, 30, 3600}, + {"checkpoint_timeout", PGC_SIGHUP, &CheckPointTimeout, + 300, 30, 3600}, - {"wal_buffers", PGC_POSTMASTER, &XLOGbuffers, - 8, 4, INT_MAX}, + {"wal_buffers", PGC_POSTMASTER, &XLOGbuffers, + 8, 4, INT_MAX}, - {"wal_files", PGC_SIGHUP, &XLOGfiles, - 0, 0, 64}, + {"wal_files", PGC_SIGHUP, &XLOGfiles, + 0, 0, 64}, - {"wal_debug", PGC_SUSET, &XLOG_DEBUG, - 0, 0, 16}, + {"wal_debug", PGC_SUSET, &XLOG_DEBUG, + 0, 0, 16}, - {"commit_delay", PGC_USERSET, &CommitDelay, - 0, 0, 100000}, + {"commit_delay", PGC_USERSET, &CommitDelay, + 0, 0, 100000}, - {"commit_siblings", PGC_USERSET, &CommitSiblings, - 5, 1, 1000}, + {"commit_siblings", PGC_USERSET, &CommitSiblings, + 5, 1, 1000}, {NULL, 0, NULL, 0, 0, 0} }; static struct config_real -ConfigureNamesReal[] = + ConfigureNamesReal[] = { - {"effective_cache_size", PGC_USERSET, &effective_cache_size, - DEFAULT_EFFECTIVE_CACHE_SIZE, 0, DBL_MAX}, - {"random_page_cost", PGC_USERSET, &random_page_cost, - DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX}, - {"cpu_tuple_cost", PGC_USERSET, &cpu_tuple_cost, - DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX}, - {"cpu_index_tuple_cost", PGC_USERSET, &cpu_index_tuple_cost, - DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX}, - {"cpu_operator_cost", PGC_USERSET, &cpu_operator_cost, - DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX}, - - {"geqo_selection_bias", PGC_USERSET, &Geqo_selection_bias, - DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS, MAX_GEQO_SELECTION_BIAS}, + {"effective_cache_size", PGC_USERSET, &effective_cache_size, + DEFAULT_EFFECTIVE_CACHE_SIZE, 0, DBL_MAX}, + {"random_page_cost", PGC_USERSET, &random_page_cost, + DEFAULT_RANDOM_PAGE_COST, 0, DBL_MAX}, + {"cpu_tuple_cost", PGC_USERSET, &cpu_tuple_cost, + DEFAULT_CPU_TUPLE_COST, 0, DBL_MAX}, + {"cpu_index_tuple_cost", PGC_USERSET, &cpu_index_tuple_cost, + DEFAULT_CPU_INDEX_TUPLE_COST, 0, DBL_MAX}, + {"cpu_operator_cost", PGC_USERSET, &cpu_operator_cost, + DEFAULT_CPU_OPERATOR_COST, 0, DBL_MAX}, + + {"geqo_selection_bias", PGC_USERSET, &Geqo_selection_bias, + DEFAULT_GEQO_SELECTION_BIAS, MIN_GEQO_SELECTION_BIAS, MAX_GEQO_SELECTION_BIAS}, {NULL, 0, NULL, 0.0, 0.0, 0.0} }; static struct config_string -ConfigureNamesString[] = + ConfigureNamesString[] = { - {"krb_server_keyfile", PGC_POSTMASTER, &pg_krb_server_keyfile, - PG_KRB_SRVTAB, NULL, NULL}, + {"krb_server_keyfile", PGC_POSTMASTER, &pg_krb_server_keyfile, + PG_KRB_SRVTAB, NULL, NULL}, #ifdef ENABLE_SYSLOG - {"syslog_facility", PGC_POSTMASTER, &Syslog_facility, + {"syslog_facility", PGC_POSTMASTER, &Syslog_facility, "LOCAL0", check_facility, NULL}, - {"syslog_ident", PGC_POSTMASTER, &Syslog_ident, + {"syslog_ident", PGC_POSTMASTER, &Syslog_ident, "postgres", NULL, NULL}, #endif - {"unix_socket_group", PGC_POSTMASTER, &Unix_socket_group, - "", NULL, NULL}, + {"unix_socket_group", PGC_POSTMASTER, &Unix_socket_group, + "", NULL, NULL}, - {"unix_socket_directory", PGC_POSTMASTER, &UnixSocketDir, - "", NULL, NULL}, + {"unix_socket_directory", PGC_POSTMASTER, &UnixSocketDir, + "", NULL, NULL}, - {"virtual_host", PGC_POSTMASTER, &VirtualHost, - "", NULL, NULL}, + {"virtual_host", PGC_POSTMASTER, &VirtualHost, + "", NULL, NULL}, - {"wal_sync_method", PGC_SIGHUP, &XLOG_sync_method, - XLOG_sync_method_default, - check_xlog_sync_method, assign_xlog_sync_method}, + {"wal_sync_method", PGC_SIGHUP, &XLOG_sync_method, + XLOG_sync_method_default, + check_xlog_sync_method, assign_xlog_sync_method}, {NULL, 0, NULL, NULL, NULL, NULL} }; @@ -361,41 +364,41 @@ ConfigureNamesString[] = * the option there. */ static enum config_type -find_option(const char * name, struct config_generic ** record) +find_option(const char *name, struct config_generic ** record) { - int i; + int i; Assert(name); for (i = 0; ConfigureNamesBool[i].name; i++) - if (strcasecmp(ConfigureNamesBool[i].name, name)==0) + if (strcasecmp(ConfigureNamesBool[i].name, name) == 0) { if (record) - *record = (struct config_generic *)&ConfigureNamesBool[i]; + *record = (struct config_generic *) & ConfigureNamesBool[i]; return PGC_BOOL; } for (i = 0; ConfigureNamesInt[i].name; i++) - if (strcasecmp(ConfigureNamesInt[i].name, name)==0) + if (strcasecmp(ConfigureNamesInt[i].name, name) == 0) { if (record) - *record = (struct config_generic *)&ConfigureNamesInt[i]; + *record = (struct config_generic *) & ConfigureNamesInt[i]; return PGC_INT; } for (i = 0; ConfigureNamesReal[i].name; i++) - if (strcasecmp(ConfigureNamesReal[i].name, name)==0) + if (strcasecmp(ConfigureNamesReal[i].name, name) == 0) { if (record) - *record = (struct config_generic *)&ConfigureNamesReal[i]; + *record = (struct config_generic *) & ConfigureNamesReal[i]; return PGC_REAL; } for (i = 0; ConfigureNamesString[i].name; i++) - if (strcasecmp(ConfigureNamesString[i].name, name)==0) + if (strcasecmp(ConfigureNamesString[i].name, name) == 0) { if (record) - *record = (struct config_generic *)&ConfigureNamesString[i]; + *record = (struct config_generic *) & ConfigureNamesString[i]; return PGC_STRING; } @@ -411,7 +414,7 @@ find_option(const char * name, struct config_generic ** record) void ResetAllOptions(void) { - int i; + int i; for (i = 0; ConfigureNamesBool[i].name; i++) *(ConfigureNamesBool[i].variable) = ConfigureNamesBool[i].default_val; @@ -424,7 +427,7 @@ ResetAllOptions(void) for (i = 0; ConfigureNamesString[i].name; i++) { - char * str = NULL; + char *str = NULL; if (ConfigureNamesString[i].default_val) { @@ -448,49 +451,49 @@ ResetAllOptions(void) * there. */ static bool -parse_bool(const char * value, bool * result) +parse_bool(const char *value, bool *result) { - size_t len = strlen(value); + size_t len = strlen(value); - if (strncasecmp(value, "true", len)==0) + if (strncasecmp(value, "true", len) == 0) { if (result) *result = true; } - else if (strncasecmp(value, "false", len)==0) + else if (strncasecmp(value, "false", len) == 0) { if (result) *result = false; } - else if (strncasecmp(value, "yes", len)==0) + else if (strncasecmp(value, "yes", len) == 0) { if (result) *result = true; } - else if (strncasecmp(value, "no", len)==0) + else if (strncasecmp(value, "no", len) == 0) { if (result) *result = false; } - else if (strcasecmp(value, "on")==0) + else if (strcasecmp(value, "on") == 0) { if (result) *result = true; } - else if (strcasecmp(value, "off")==0) + else if (strcasecmp(value, "off") == 0) { if (result) *result = false; } - else if (strcasecmp(value, "1")==0) + else if (strcasecmp(value, "1") == 0) { if (result) *result = true; } - else if (strcasecmp(value, "0")==0) + else if (strcasecmp(value, "0") == 0) { if (result) *result = false; @@ -510,17 +513,17 @@ parse_bool(const char * value, bool * result) * value there. */ static bool -parse_int(const char * value, int * result) +parse_int(const char *value, int *result) { - long val; - char * endptr; + long val; + char *endptr; errno = 0; val = strtol(value, &endptr, 0); if (endptr == value || *endptr != '\0' || errno == ERANGE) return false; if (result) - *result = (int)val; + *result = (int) val; return true; } @@ -528,14 +531,14 @@ parse_int(const char * value, int * result) /* * Try to parse value as a floating point constant in the usual - * format. If the value parsed okay return true, else false. If + * format. If the value parsed okay return true, else false. If * result is not NULL, return the semantic value there. */ static bool -parse_real(const char * value, double * result) +parse_real(const char *value, double *result) { - double val; - char * endptr; + double val; + char *endptr; errno = 0; val = strtod(value, &endptr); @@ -569,12 +572,12 @@ parse_real(const char * value, double * result) * See also SetConfigOption for an external interface. */ bool -set_config_option(const char * name, const char * value, GucContext +set_config_option(const char *name, const char *value, GucContext context, bool DoIt) { - struct config_generic * record; + struct config_generic *record; enum config_type type; - int elevel; + int elevel; elevel = (context == PGC_SIGHUP) ? DEBUG : ERROR; @@ -587,8 +590,8 @@ set_config_option(const char * name, const char * value, GucContext /* * Check if the option can be set at this time. See guc.h for the - * precise rules. Note that we don't want to throw errors if we're - * in the SIGHUP context. In that case we just ignore the attempt. + * precise rules. Note that we don't want to throw errors if we're in + * the SIGHUP context. In that case we just ignore the attempt. */ if (record->context == PGC_POSTMASTER && context != PGC_POSTMASTER) { @@ -601,10 +604,13 @@ set_config_option(const char * name, const char * value, GucContext context != PGC_POSTMASTER) { elog(ERROR, "'%s' cannot be changed now", name); - /* Hmm, the idea of the SIGHUP context is "ought to be global, - * but can be changed after postmaster start". But there's - * nothing that prevents a crafty administrator from sending - * SIGHUP signals to individual backends only. */ + + /* + * Hmm, the idea of the SIGHUP context is "ought to be global, but + * can be changed after postmaster start". But there's nothing + * that prevents a crafty administrator from sending SIGHUP + * signals to individual backends only. + */ } else if (record->context == PGC_BACKEND && context != PGC_BACKEND && context != PGC_POSTMASTER) @@ -616,140 +622,139 @@ set_config_option(const char * name, const char * value, GucContext } else if (record->context == PGC_SUSET && (context == PGC_USERSET || context == PGC_BACKEND)) - { elog(ERROR, "permission denied"); - } /* * Evaluate value and set variable */ - switch(type) + switch (type) { case PGC_BOOL: - { - struct config_bool * conf = (struct config_bool *)record; - - if (value) { - bool boolval; - if (!parse_bool(value, &boolval)) + struct config_bool *conf = (struct config_bool *) record; + + if (value) { - elog(elevel, "option '%s' requires a boolean value", name); - return false; + bool boolval; + + if (!parse_bool(value, &boolval)) + { + elog(elevel, "option '%s' requires a boolean value", name); + return false; + } + if (DoIt) + *conf->variable = boolval; } - if (DoIt) - *conf->variable = boolval; + else if (DoIt) + *conf->variable = conf->default_val; + break; } - else if (DoIt) - *conf->variable = conf->default_val; - break; - } case PGC_INT: - { - struct config_int * conf = (struct config_int *)record; - - if (value) { - int intval; + struct config_int *conf = (struct config_int *) record; - if (!parse_int(value, &intval)) - { - elog(elevel, "option '%s' expects an integer value", name); - return false; - } - if (intval < conf->min || intval > conf->max) + if (value) { - elog(elevel, "option '%s' value %d is outside" - " of permissible range [%d .. %d]", - name, intval, conf->min, conf->max); - return false; + int intval; + + if (!parse_int(value, &intval)) + { + elog(elevel, "option '%s' expects an integer value", name); + return false; + } + if (intval < conf->min || intval > conf->max) + { + elog(elevel, "option '%s' value %d is outside" + " of permissible range [%d .. %d]", + name, intval, conf->min, conf->max); + return false; + } + if (DoIt) + *conf->variable = intval; } - if (DoIt) - *conf->variable = intval; + else if (DoIt) + *conf->variable = conf->default_val; + break; } - else if (DoIt) - *conf->variable = conf->default_val; - break; - } case PGC_REAL: - { - struct config_real * conf = (struct config_real *)record; - - if (value) { - double dval; + struct config_real *conf = (struct config_real *) record; - if (!parse_real(value, &dval)) + if (value) { - elog(elevel, "option '%s' expects a real number", name); - return false; - } - if (dval < conf->min || dval > conf->max) - { - elog(elevel, "option '%s' value %g is outside" - " of permissible range [%g .. %g]", - name, dval, conf->min, conf->max); - return false; + double dval; + + if (!parse_real(value, &dval)) + { + elog(elevel, "option '%s' expects a real number", name); + return false; + } + if (dval < conf->min || dval > conf->max) + { + elog(elevel, "option '%s' value %g is outside" + " of permissible range [%g .. %g]", + name, dval, conf->min, conf->max); + return false; + } + if (DoIt) + *conf->variable = dval; } - if (DoIt) - *conf->variable = dval; + else if (DoIt) + *conf->variable = conf->default_val; + break; } - else if (DoIt) - *conf->variable = conf->default_val; - break; - } case PGC_STRING: - { - struct config_string * conf = (struct config_string *)record; - - if (value) { - if (conf->parse_hook && !(conf->parse_hook)(value)) + struct config_string *conf = (struct config_string *) record; + + if (value) { - elog(elevel, "invalid value for option '%s': '%s'", name, value); - return false; + if (conf->parse_hook && !(conf->parse_hook) (value)) + { + elog(elevel, "invalid value for option '%s': '%s'", name, value); + return false; + } + if (DoIt) + { + char *str; + + str = strdup(value); + if (str == NULL) + { + elog(elevel, "out of memory"); + return false; + } + if (conf->assign_hook) + (conf->assign_hook) (str); + if (*conf->variable) + free(*conf->variable); + *conf->variable = str; + } } - if (DoIt) + else if (DoIt) { - char * str; + char *str; - str = strdup(value); + str = strdup(conf->default_val); if (str == NULL) { elog(elevel, "out of memory"); return false; } if (conf->assign_hook) - (conf->assign_hook)(str); + (conf->assign_hook) (str); if (*conf->variable) free(*conf->variable); *conf->variable = str; } + break; } - else if (DoIt) - { - char * str; - str = strdup(conf->default_val); - if (str == NULL) - { - elog(elevel, "out of memory"); - return false; - } - if (conf->assign_hook) - (conf->assign_hook)(str); - if (*conf->variable) - free(*conf->variable); - *conf->variable = str; - } - break; - } - - default: ; + default:; } return true; } @@ -761,10 +766,10 @@ set_config_option(const char * name, const char * value, GucContext * this is just the wrapper to be called from the outside. */ void -SetConfigOption(const char * name, const char * value, GucContext +SetConfigOption(const char *name, const char *value, GucContext context) { - (void)set_config_option(name, value, context, true); + (void) set_config_option(name, value, context, true); } @@ -780,9 +785,9 @@ SetConfigOption(const char * name, const char * value, GucContext * valid until the next call to configuration related functions. */ const char * -GetConfigOption(const char * name) +GetConfigOption(const char *name) { - struct config_generic * record; + struct config_generic *record; static char buffer[256]; enum config_type opttype; @@ -790,21 +795,21 @@ GetConfigOption(const char * name) if (opttype == PGC_NONE) elog(ERROR, "Option '%s' is not recognized", name); - switch(opttype) + switch (opttype) { case PGC_BOOL: - return *((struct config_bool *)record)->variable ? "on" : "off"; + return *((struct config_bool *) record)->variable ? "on" : "off"; case PGC_INT: - snprintf(buffer, 256, "%d", *((struct config_int *)record)->variable); + snprintf(buffer, 256, "%d", *((struct config_int *) record)->variable); return buffer; case PGC_REAL: - snprintf(buffer, 256, "%g", *((struct config_real *)record)->variable); + snprintf(buffer, 256, "%g", *((struct config_real *) record)->variable); return buffer; case PGC_STRING: - return *((struct config_string *)record)->variable; + return *((struct config_string *) record)->variable; default: ; @@ -822,10 +827,10 @@ GetConfigOption(const char * name) * there is no '=' in the input string then value will be NULL. */ void -ParseLongOption(const char * string, char ** name, char ** value) +ParseLongOption(const char *string, char **name, char **value) { - size_t equal_pos; - char *cp; + size_t equal_pos; + char *cp; AssertArg(string); AssertArg(name); @@ -845,7 +850,8 @@ ParseLongOption(const char * string, char ** name, char ** value) if (!*value) elog(FATAL, "out of memory"); } - else /* no equal sign in string */ + else +/* no equal sign in string */ { *name = strdup(string); if (!*name) @@ -853,7 +859,7 @@ ParseLongOption(const char * string, char ** name, char ** value) *value = NULL; } - for(cp = *name; *cp; cp++) + for (cp = *name; *cp; cp++) if (*cp == '-') *cp = '_'; } @@ -864,14 +870,23 @@ ParseLongOption(const char * string, char ** name, char ** value) static bool check_facility(const char *facility) { - if (strcasecmp(facility,"LOCAL0") == 0) return true; - if (strcasecmp(facility,"LOCAL1") == 0) return true; - if (strcasecmp(facility,"LOCAL2") == 0) return true; - if (strcasecmp(facility,"LOCAL3") == 0) return true; - if (strcasecmp(facility,"LOCAL4") == 0) return true; - if (strcasecmp(facility,"LOCAL5") == 0) return true; - if (strcasecmp(facility,"LOCAL6") == 0) return true; - if (strcasecmp(facility,"LOCAL7") == 0) return true; + if (strcasecmp(facility, "LOCAL0") == 0) + return true; + if (strcasecmp(facility, "LOCAL1") == 0) + return true; + if (strcasecmp(facility, "LOCAL2") == 0) + return true; + if (strcasecmp(facility, "LOCAL3") == 0) + return true; + if (strcasecmp(facility, "LOCAL4") == 0) + return true; + if (strcasecmp(facility, "LOCAL5") == 0) + return true; + if (strcasecmp(facility, "LOCAL6") == 0) + return true; + if (strcasecmp(facility, "LOCAL7") == 0) + return true; return false; } + #endif diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c index a977ee11ed4..4eb49fbeb64 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. Differs wildly across * platforms. * - * $Header: /cvsroot/pgsql/src/backend/utils/misc/ps_status.c,v 1.3 2001/03/20 22:31:54 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/misc/ps_status.c,v 1.4 2001/03/22 04:00:06 momjian Exp $ * * Copyright 2000 by PostgreSQL Global Development Group * various details abducted from various places @@ -18,11 +18,11 @@ #ifdef HAVE_SYS_PSTAT_H -# include <sys/pstat.h> /* for HP-UX */ +#include <sys/pstat.h> /* for HP-UX */ #endif #ifdef HAVE_PS_STRINGS -# include <machine/vmparam.h> /* for old BSD */ -# include <sys/exec.h> +#include <machine/vmparam.h> /* for old BSD */ +#include <sys/exec.h> #endif #include "miscadmin.h" @@ -36,44 +36,44 @@ extern char **environ; * Alternative ways of updating ps display: * * PS_USE_SETPROCTITLE - * use the function setproctitle(const char *, ...) - * (newer BSD systems) + * use the function setproctitle(const char *, ...) + * (newer BSD systems) * PS_USE_PSTAT - * use the pstat(PSTAT_SETCMD, ) - * (HPUX) + * use the pstat(PSTAT_SETCMD, ) + * (HPUX) * PS_USE_PS_STRINGS - * assign PS_STRINGS->ps_argvstr = "string" - * (some BSD systems) + * assign PS_STRINGS->ps_argvstr = "string" + * (some BSD systems) * PS_USE_CHANGE_ARGV - * assign argv[0] = "string" - * (some other BSD systems) + * assign argv[0] = "string" + * (some other BSD systems) * PS_USE_CLOBBER_ARGV - * write over the argv and environment area - * (most SysV-like systems) + * write over the argv and environment area + * (most SysV-like systems) * PS_USE_NONE - * don't update ps display - * (This is the default, as it is safest.) + * don't update ps display + * (This is the default, as it is safest.) */ #if defined(HAVE_SETPROCTITLE) -# define PS_USE_SETPROCTITLE +#define PS_USE_SETPROCTITLE #elif defined(HAVE_PSTAT) && defined(PSTAT_SETCMD) -# define PS_USE_PSTAT +#define PS_USE_PSTAT #elif defined(HAVE_PS_STRINGS) -# define PS_USE_PS_STRINGS +#define PS_USE_PS_STRINGS #elif defined(BSD) || defined(__bsdi__) || defined(__hurd__) -# define PS_USE_CHANGE_ARGV +#define PS_USE_CHANGE_ARGV #elif defined(__linux__) || defined(_AIX4) || defined(_AIX3) || defined(__sgi) || (defined(sun) && !defined(BSD)) || defined(ultrix) || defined(__ksr__) || defined(__osf__) || defined(__QNX__) || defined(__svr4__) || defined(__svr5__) -# define PS_USE_CLOBBER_ARGV +#define PS_USE_CLOBBER_ARGV #else -# define PS_USE_NONE +#define PS_USE_NONE #endif /* Different systems want the buffer padded differently */ #if defined(_AIX3) || defined(__linux__) || defined(__QNX__) || defined(__svr4__) -# define PS_PADDING '\0' +#define PS_PADDING '\0' #else -# define PS_PADDING ' ' +#define PS_PADDING ' ' #endif @@ -83,12 +83,13 @@ extern char **environ; static char ps_buffer[PS_BUFFER_SIZE]; static const size_t ps_buffer_size = PS_BUFFER_SIZE; -#else /* PS_USE_CLOBBER_ARGV */ -static char * ps_buffer; /* will point to argv area */ -static size_t ps_buffer_size; /* space determined at run time */ -#endif /* PS_USE_CLOBBER_ARGV */ +#else /* PS_USE_CLOBBER_ARGV */ +static char *ps_buffer; /* will point to argv area */ +static size_t ps_buffer_size; /* space determined at run time */ -static size_t ps_buffer_fixed_size; /* size of the constant prefix */ +#endif /* PS_USE_CLOBBER_ARGV */ + +static size_t ps_buffer_fixed_size; /* size of the constant prefix */ @@ -97,30 +98,31 @@ static size_t ps_buffer_fixed_size; /* size of the constant prefix */ */ void init_ps_display(int argc, char *argv[], - const char * username, const char * dbname, - const char * host_info) + const char *username, const char *dbname, + const char *host_info) { #ifndef PS_USE_NONE - Assert(username); - Assert(dbname); + Assert(username); + Assert(dbname); /* no ps display for stand-alone backend */ - if (!IsUnderPostmaster) - return; + if (!IsUnderPostmaster) + return; -# ifdef PS_USE_CHANGE_ARGV +#ifdef PS_USE_CHANGE_ARGV argv[0] = ps_buffer; argv[1] = NULL; -# endif /* PS_USE_CHANGE_ARGV */ +#endif /* PS_USE_CHANGE_ARGV */ -# ifdef PS_USE_CLOBBER_ARGV - /* - * If we're going to overwrite the argv area, count the space. - */ +#ifdef PS_USE_CLOBBER_ARGV + + /* + * If we're going to overwrite the argv area, count the space. + */ { - char * end_of_area = NULL; - char **new_environ; - int i; + char *end_of_area = NULL; + char **new_environ; + int i; /* * check for contiguous argv strings @@ -153,31 +155,34 @@ init_ps_display(int argc, char *argv[], */ for (i = 0; environ[i] != NULL; i++) ; - new_environ = malloc(sizeof (char *) * (i + 1)); + new_environ = malloc(sizeof(char *) * (i + 1)); for (i = 0; environ[i] != NULL; i++) - new_environ[i] = strdup(environ[i]); + new_environ[i] = strdup(environ[i]); new_environ[i] = NULL; environ = new_environ; } -# endif /* PS_USE_CLOBBER_ARGV */ +#endif /* PS_USE_CLOBBER_ARGV */ /* * Make fixed prefix */ -# ifdef PS_USE_SETPROCTITLE - /* apparently setproctitle() already adds a `progname:' prefix to - * the ps line */ +#ifdef PS_USE_SETPROCTITLE + + /* + * apparently setproctitle() already adds a `progname:' prefix to the + * ps line + */ snprintf(ps_buffer, ps_buffer_size, "%s %s %s ", username, dbname, host_info); -# else +#else snprintf(ps_buffer, ps_buffer_size, "postgres: %s %s %s ", username, dbname, host_info); -# endif +#endif - ps_buffer_fixed_size = strlen(ps_buffer); -#endif /* not PS_USE_NONE */ + ps_buffer_fixed_size = strlen(ps_buffer); +#endif /* not PS_USE_NONE */ } @@ -187,18 +192,18 @@ init_ps_display(int argc, char *argv[], * indication of what you're currently doing passed in the argument. */ void -set_ps_display(const char * value) +set_ps_display(const char *value) { #ifndef PS_USE_NONE /* no ps display for stand-alone backend */ if (!IsUnderPostmaster) return; -# ifdef PS_USE_CLOBBER_ARGV +#ifdef PS_USE_CLOBBER_ARGV /* If ps_buffer is a pointer, it might still be null */ if (!ps_buffer) return; -# endif +#endif /* Update ps_buffer to contain both fixed part and value */ StrNCpy(ps_buffer + ps_buffer_fixed_size, value, @@ -206,42 +211,43 @@ set_ps_display(const char * value) /* Transmit new setting to kernel, if necessary */ -# ifdef PS_USE_SETPROCTITLE +#ifdef PS_USE_SETPROCTITLE setproctitle("%s", ps_buffer); -# endif +#endif -# ifdef PS_USE_PSTAT - { - union pstun pst; +#ifdef PS_USE_PSTAT + { + union pstun pst; - pst.pst_command = ps_buffer; - pstat(PSTAT_SETCMD, pst, strlen(ps_buffer), 0, 0); - } -# endif /* PS_USE_PSTAT */ + pst.pst_command = ps_buffer; + pstat(PSTAT_SETCMD, pst, strlen(ps_buffer), 0, 0); + } +#endif /* PS_USE_PSTAT */ -# ifdef PS_USE_PS_STRINGS - PS_STRINGS->ps_nargvstr = 1; - PS_STRINGS->ps_argvstr = ps_buffer; -# endif /* PS_USE_PS_STRINGS */ +#ifdef PS_USE_PS_STRINGS + PS_STRINGS->ps_nargvstr = 1; + PS_STRINGS->ps_argvstr = ps_buffer; +#endif /* PS_USE_PS_STRINGS */ -# ifdef PS_USE_CLOBBER_ARGV - { - char * cp; - /* pad unused memory */ - for(cp = ps_buffer + strlen(ps_buffer); - cp < ps_buffer + ps_buffer_size; - cp++) - *cp = PS_PADDING; - } -# endif /* PS_USE_CLOBBER_ARGV */ +#ifdef PS_USE_CLOBBER_ARGV + { + char *cp; + + /* pad unused memory */ + for (cp = ps_buffer + strlen(ps_buffer); + cp < ps_buffer + ps_buffer_size; + cp++) + *cp = PS_PADDING; + } +#endif /* PS_USE_CLOBBER_ARGV */ -#endif /* not PS_USE_NONE */ +#endif /* not PS_USE_NONE */ } /* * Returns what's currently in the ps display, in case someone needs - * it. Note that only the variable part is returned. + * it. Note that only the variable part is returned. */ const char * get_ps_display(void) diff --git a/src/backend/utils/mmgr/aset.c b/src/backend/utils/mmgr/aset.c index 666d8fd83f2..f66e021ad51 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 - * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/aset.c,v 1.40 2001/03/19 22:29:39 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/aset.c,v 1.41 2001/03/22 04:00:07 momjian Exp $ * * NOTE: * This is a new (Feb. 05, 1999) implementation of the allocation set @@ -38,7 +38,7 @@ * request, even if it was much larger than necessary. This led to more * and more wasted space in allocated chunks over time. To fix, get rid * of the midrange behavior: we now handle only "small" power-of-2-size - * chunks as chunks. Anything "large" is passed off to malloc(). Change + * chunks as chunks. Anything "large" is passed off to malloc(). Change * the number of freelists to change the small/large boundary. * * @@ -54,7 +54,7 @@ * Thus, if someone makes the common error of writing past what they've * requested, the problem is likely to go unnoticed ... until the day when * there *isn't* any wasted space, perhaps because of different memory - * alignment on a new platform, or some other effect. To catch this sort + * alignment on a new platform, or some other effect. To catch this sort * of problem, the MEMORY_CONTEXT_CHECKING option stores 0x7E just beyond * the requested space whenever the request is less than the actual chunk * size, and verifies that the byte is undamaged when the chunk is freed. @@ -112,7 +112,7 @@ #define ALLOC_BLOCKHDRSZ MAXALIGN(sizeof(AllocBlockData)) #define ALLOC_CHUNKHDRSZ MAXALIGN(sizeof(AllocChunkData)) -typedef struct AllocBlockData *AllocBlock; /* forward reference */ +typedef struct AllocBlockData *AllocBlock; /* forward reference */ typedef struct AllocChunkData *AllocChunk; /* @@ -126,15 +126,15 @@ typedef void *AllocPointer; */ typedef struct AllocSetContext { - MemoryContextData header; /* Standard memory-context fields */ + MemoryContextData header; /* Standard memory-context fields */ /* Info about storage allocated in this context: */ - AllocBlock blocks; /* head of list of blocks in this set */ - AllocChunk freelist[ALLOCSET_NUM_FREELISTS]; /* free chunk lists */ + AllocBlock blocks; /* head of list of blocks in this set */ + AllocChunk freelist[ALLOCSET_NUM_FREELISTS]; /* free chunk lists */ /* Allocation parameters for this context: */ - Size initBlockSize; /* initial block size */ - Size maxBlockSize; /* maximum block size */ - AllocBlock keeper; /* if not NULL, keep this block - * over resets */ + Size initBlockSize; /* initial block size */ + Size maxBlockSize; /* maximum block size */ + AllocBlock keeper; /* if not NULL, keep this block over + * resets */ } AllocSetContext; typedef AllocSetContext *AllocSet; @@ -204,8 +204,10 @@ static void *AllocSetRealloc(MemoryContext context, void *pointer, Size size); static void AllocSetInit(MemoryContext context); static void AllocSetReset(MemoryContext context); static void AllocSetDelete(MemoryContext context); + #ifdef MEMORY_CONTEXT_CHECKING static void AllocSetCheck(MemoryContext context); + #endif static void AllocSetStats(MemoryContext context); @@ -240,7 +242,7 @@ static MemoryContextMethods AllocSetMethods = { #else #define AllocFreeInfo(_cxt, _chunk) #define AllocAllocInfo(_cxt, _chunk) -#endif +#endif /* ---------- * AllocSetFreeIndex - @@ -300,6 +302,7 @@ AllocSetContextCreate(MemoryContext parent, &AllocSetMethods, parent, name); + /* * Make sure alloc parameters are reasonable, and save them. * @@ -356,9 +359,10 @@ AllocSetContextCreate(MemoryContext parent, static void AllocSetInit(MemoryContext context) { + /* - * Since MemoryContextCreate already zeroed the context node, - * we don't have to do anything here: it's already OK. + * Since MemoryContextCreate already zeroed the context node, we don't + * have to do anything here: it's already OK. */ } @@ -397,7 +401,7 @@ AllocSetReset(MemoryContext context) if (block == set->keeper) { /* Reset the block, but don't return it to malloc */ - char *datastart = ((char *) block) + ALLOC_BLOCKHDRSZ; + char *datastart = ((char *) block) + ALLOC_BLOCKHDRSZ; #ifdef CLOBBER_FREED_MEMORY /* Wipe freed memory for debugging purposes */ @@ -505,8 +509,8 @@ AllocSetAlloc(MemoryContext context, Size size) #endif /* - * Stick the new block underneath the active allocation block, - * so that we don't lose the use of the space remaining therein. + * Stick the new block underneath the active allocation block, so + * that we don't lose the use of the space remaining therein. */ if (set->blocks != NULL) { @@ -518,7 +522,7 @@ AllocSetAlloc(MemoryContext context, Size size) block->next = NULL; set->blocks = block; } - + AllocAllocInfo(set, chunk); return AllocChunkGetPointer(chunk); } @@ -568,8 +572,8 @@ AllocSetAlloc(MemoryContext context, Size size) Assert(chunk_size >= size); /* - * If there is enough room in the active allocation block, - * we will put the chunk into that block. Else must start a new one. + * If there is enough room in the active allocation block, we will put + * the chunk into that block. Else must start a new one. */ if ((block = set->blocks) != NULL) { @@ -577,6 +581,7 @@ AllocSetAlloc(MemoryContext context, Size size) if (availspace < (chunk_size + ALLOC_CHUNKHDRSZ)) { + /* * The existing active (top) block does not have enough room * for the requested allocation, but it might still have a @@ -591,17 +596,18 @@ AllocSetAlloc(MemoryContext context, Size size) */ while (availspace >= ((1 << ALLOC_MINBITS) + ALLOC_CHUNKHDRSZ)) { - Size availchunk = availspace - ALLOC_CHUNKHDRSZ; - int a_fidx = AllocSetFreeIndex(availchunk); + Size availchunk = availspace - ALLOC_CHUNKHDRSZ; + int a_fidx = AllocSetFreeIndex(availchunk); /* - * In most cases, we'll get back the index of the next larger - * freelist than the one we need to put this chunk on. The - * exception is when availchunk is exactly a power of 2. + * In most cases, we'll get back the index of the next + * larger freelist than the one we need to put this chunk + * on. The exception is when availchunk is exactly a + * power of 2. */ if (availchunk != (1 << (a_fidx + ALLOC_MINBITS))) { - a_fidx--; + a_fidx--; Assert(a_fidx >= 0); availchunk = (1 << (a_fidx + ALLOC_MINBITS)); } @@ -613,7 +619,7 @@ AllocSetAlloc(MemoryContext context, Size size) chunk->size = availchunk; #ifdef MEMORY_CONTEXT_CHECKING - chunk->requested_size = 0; /* mark it free */ + chunk->requested_size = 0; /* mark it free */ #endif chunk->aset = (void *) set->freelist[a_fidx]; set->freelist[a_fidx] = chunk; @@ -629,7 +635,7 @@ AllocSetAlloc(MemoryContext context, Size size) */ if (block == NULL) { - Size required_size; + Size required_size; if (set->blocks == NULL) { @@ -687,7 +693,7 @@ AllocSetAlloc(MemoryContext context, Size size) elog(ERROR, "Memory exhausted in AllocSetAlloc(%lu)", (unsigned long) size); } - + block->aset = set; block->freeptr = ((char *) block) + ALLOC_BLOCKHDRSZ; block->endptr = ((char *) block) + blksize; @@ -711,7 +717,7 @@ AllocSetAlloc(MemoryContext context, Size size) /* set mark to catch clobber of "unused" space */ if (size < chunk->size) ((char *) AllocChunkGetPointer(chunk))[size] = 0x7E; -#endif +#endif AllocAllocInfo(set, chunk); return AllocChunkGetPointer(chunk); @@ -735,10 +741,11 @@ AllocSetFree(MemoryContext context, void *pointer) if (((char *) pointer)[chunk->requested_size] != 0x7E) elog(NOTICE, "AllocSetFree: detected write past chunk end in %s %p", set->header.name, chunk); -#endif +#endif if (chunk->size > ALLOC_CHUNK_LIMIT) { + /* * Big chunks are certain to have been allocated as single-chunk * blocks. Find the containing block and return it to malloc(). @@ -786,7 +793,7 @@ AllocSetFree(MemoryContext context, void *pointer) #ifdef MEMORY_CONTEXT_CHECKING /* Reset requested_size to 0 in chunks that are on freelist */ chunk->requested_size = 0; -#endif +#endif set->freelist[fidx] = chunk; } } @@ -804,7 +811,7 @@ AllocSetRealloc(MemoryContext context, void *pointer, Size size) AllocChunk chunk = AllocPointerGetChunk(pointer); Size oldsize = chunk->size; -#ifdef MEMORY_CONTEXT_CHECKING +#ifdef MEMORY_CONTEXT_CHECKING /* Test for someone scribbling on unused space in chunk */ if (chunk->requested_size < oldsize) if (((char *) pointer)[chunk->requested_size] != 0x7E) @@ -819,7 +826,7 @@ AllocSetRealloc(MemoryContext context, void *pointer, Size size) */ if (oldsize >= size) { -#ifdef MEMORY_CONTEXT_CHECKING +#ifdef MEMORY_CONTEXT_CHECKING chunk->requested_size = size; /* set mark to catch clobber of "unused" space */ if (size < oldsize) @@ -830,10 +837,11 @@ AllocSetRealloc(MemoryContext context, void *pointer, Size size) if (oldsize > ALLOC_CHUNK_LIMIT) { + /* - * The chunk must been allocated as a single-chunk block. Find the - * containing block and use realloc() to make it bigger with minimum - * space wastage. + * The chunk must been allocated as a single-chunk block. Find + * the containing block and use realloc() to make it bigger with + * minimum space wastage. */ AllocBlock block = set->blocks; AllocBlock prevblock = NULL; @@ -873,7 +881,7 @@ AllocSetRealloc(MemoryContext context, void *pointer, Size size) else prevblock->next = block; chunk->size = chksize; - + #ifdef MEMORY_CONTEXT_CHECKING chunk->requested_size = size; /* set mark to catch clobber of "unused" space */ @@ -885,14 +893,15 @@ AllocSetRealloc(MemoryContext context, void *pointer, Size size) } else { + /* * Small-chunk case. If the chunk is the last one in its block, * there might be enough free space after it that we can just - * enlarge the chunk in-place. It's relatively painful to find + * enlarge the chunk in-place. It's relatively painful to find * the containing block in the general case, but we can detect - * last-ness quite cheaply for the typical case where the chunk - * is in the active (topmost) allocation block. (At least with - * the regression tests and code as of 1/2001, realloc'ing the last + * last-ness quite cheaply for the typical case where the chunk is + * in the active (topmost) allocation block. (At least with the + * regression tests and code as of 1/2001, realloc'ing the last * chunk of a non-topmost block hardly ever happens, so it's not * worth scanning the block list to catch that case.) * @@ -908,12 +917,12 @@ AllocSetRealloc(MemoryContext context, void *pointer, Size size) chunk_end = (char *) chunk + (oldsize + ALLOC_CHUNKHDRSZ); if (chunk_end == block->freeptr) - { + { /* OK, it's last in block ... is there room? */ - Size freespace = block->endptr - block->freeptr; - int fidx; - Size newsize; - Size delta; + Size freespace = block->endptr - block->freeptr; + int fidx; + Size newsize; + Size delta; fidx = AllocSetFreeIndex(size); newsize = 1 << (fidx + ALLOC_MINBITS); @@ -924,7 +933,7 @@ AllocSetRealloc(MemoryContext context, void *pointer, Size size) /* Yes, so just enlarge the chunk. */ block->freeptr += delta; chunk->size += delta; -#ifdef MEMORY_CONTEXT_CHECKING +#ifdef MEMORY_CONTEXT_CHECKING chunk->requested_size = size; /* set mark to catch clobber of "unused" space */ if (size < chunk->size) @@ -982,7 +991,7 @@ AllocSetStats(MemoryContext context) } } fprintf(stderr, - "%s: %ld total in %ld blocks; %ld free (%ld chunks); %ld used\n", + "%s: %ld total in %ld blocks; %ld free (%ld chunks); %ld used\n", set->header.name, totalspace, nblocks, freespace, nchunks, totalspace - freespace); } @@ -990,7 +999,7 @@ AllocSetStats(MemoryContext context) #ifdef MEMORY_CONTEXT_CHECKING -/* +/* * AllocSetCheck * Walk through chunks and check consistency of memory. * @@ -998,19 +1007,19 @@ AllocSetStats(MemoryContext context) * find yourself in an infinite loop when trouble occurs, because this * routine will be entered again when elog cleanup tries to release memory! */ -static void +static void AllocSetCheck(MemoryContext context) { - AllocSet set = (AllocSet) context; - char *name = set->header.name; + AllocSet set = (AllocSet) context; + char *name = set->header.name; AllocBlock block; for (block = set->blocks; block != NULL; block = block->next) - { - char *bpoz = ((char *) block) + ALLOC_BLOCKHDRSZ; - long blk_used = block->freeptr - bpoz; - long blk_data = 0; - long nchunks = 0; + { + char *bpoz = ((char *) block) + ALLOC_BLOCKHDRSZ; + long blk_used = block->freeptr - bpoz; + long blk_data = 0; + long nchunks = 0; /* * Empty block - empty can be keeper-block only @@ -1018,44 +1027,44 @@ AllocSetCheck(MemoryContext context) if (!blk_used) { if (set->keeper != block) - elog(NOTICE, "AllocSetCheck: %s: empty block %p", + elog(NOTICE, "AllocSetCheck: %s: empty block %p", name, block); - } - + } + /* * Chunk walker - */ + */ while (bpoz < block->freeptr) { AllocChunk chunk = (AllocChunk) bpoz; Size chsize, dsize; char *chdata_end; - - chsize = chunk->size; /* aligned chunk size */ - dsize = chunk->requested_size; /* real data */ + + chsize = chunk->size; /* aligned chunk size */ + dsize = chunk->requested_size; /* real data */ chdata_end = ((char *) chunk) + (ALLOC_CHUNKHDRSZ + dsize); - + /* * Check chunk size */ if (dsize > chsize) elog(NOTICE, "AllocSetCheck: %s: req size > alloc size for chunk %p in block %p", - name, chunk, block); + name, chunk, block); if (chsize < (1 << ALLOC_MINBITS)) elog(NOTICE, "AllocSetCheck: %s: bad size %lu for chunk %p in block %p", name, (unsigned long) chsize, chunk, block); - + /* single-chunk block? */ if (chsize > ALLOC_CHUNK_LIMIT && - chsize + ALLOC_CHUNKHDRSZ != blk_used) + chsize + ALLOC_CHUNKHDRSZ != blk_used) elog(NOTICE, "AllocSetCheck: %s: bad single-chunk %p in block %p", name, chunk, block); /* - * If chunk is allocated, check for correct aset pointer. - * (If it's free, the aset is the freelist pointer, which we - * can't check as easily...) + * If chunk is allocated, check for correct aset pointer. (If + * it's free, the aset is the freelist pointer, which we can't + * check as easily...) */ if (dsize > 0 && chunk->aset != (void *) set) elog(NOTICE, "AllocSetCheck: %s: bogus aset link in block %p, chunk %p", @@ -1063,14 +1072,14 @@ AllocSetCheck(MemoryContext context) /* * Check for overwrite of "unallocated" space in chunk - */ + */ if (dsize > 0 && dsize < chsize && *chdata_end != 0x7E) elog(NOTICE, "AllocSetCheck: %s: detected write past chunk end in block %p, chunk %p", name, block, chunk); - + blk_data += chsize; nchunks++; - + bpoz += ALLOC_CHUNKHDRSZ + chsize; } @@ -1080,4 +1089,4 @@ AllocSetCheck(MemoryContext context) } } -#endif /* MEMORY_CONTEXT_CHECKING */ +#endif /* MEMORY_CONTEXT_CHECKING */ diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c index ab8434a0581..402e4010f76 100644 --- a/src/backend/utils/mmgr/mcxt.c +++ b/src/backend/utils/mmgr/mcxt.c @@ -14,7 +14,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/mcxt.c,v 1.27 2001/02/06 01:53:53 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/mcxt.c,v 1.28 2001/03/22 04:00:08 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -72,9 +72,10 @@ void MemoryContextInit(void) { AssertState(TopMemoryContext == NULL); + /* - * Initialize TopMemoryContext as an AllocSetContext with slow - * growth rate --- we don't really expect much to be allocated in it. + * Initialize TopMemoryContext as an AllocSetContext with slow growth + * rate --- we don't really expect much to be allocated in it. * * (There is special-case code in MemoryContextCreate() for this call.) */ @@ -83,18 +84,20 @@ MemoryContextInit(void) 8 * 1024, 8 * 1024, 8 * 1024); + /* - * Not having any other place to point CurrentMemoryContext, - * make it point to TopMemoryContext. Caller should change this soon! + * Not having any other place to point CurrentMemoryContext, make it + * point to TopMemoryContext. Caller should change this soon! */ CurrentMemoryContext = TopMemoryContext; + /* - * Initialize ErrorContext as an AllocSetContext with slow - * growth rate --- we don't really expect much to be allocated in it. - * More to the point, require it to contain at least 8K at all times. - * This is the only case where retained memory in a context is - * *essential* --- we want to be sure ErrorContext still has some - * memory even if we've run out elsewhere! + * Initialize ErrorContext as an AllocSetContext with slow growth rate + * --- we don't really expect much to be allocated in it. More to the + * point, require it to contain at least 8K at all times. This is the + * only case where retained memory in a context is *essential* --- we + * want to be sure ErrorContext still has some memory even if we've + * run out elsewhere! */ ErrorContext = AllocSetContextCreate(TopMemoryContext, "ErrorContext", @@ -129,14 +132,12 @@ MemoryContextReset(MemoryContext context) void MemoryContextResetChildren(MemoryContext context) { - MemoryContext child; + MemoryContext child; AssertArg(MemoryContextIsValid(context)); for (child = context->firstchild; child != NULL; child = child->nextchild) - { MemoryContextReset(child); - } } /* @@ -146,7 +147,7 @@ MemoryContextResetChildren(MemoryContext context) * * The type-specific delete routine removes all subsidiary storage * for the context, but we have to delete the context node itself, - * as well as recurse to get the children. We must also delink the + * as well as recurse to get the children. We must also delink the * node from its parent, if it has one. */ void @@ -159,23 +160,21 @@ MemoryContextDelete(MemoryContext context) Assert(context != CurrentMemoryContext); MemoryContextDeleteChildren(context); + /* - * We delink the context from its parent before deleting it, - * so that if there's an error we won't have deleted/busted - * contexts still attached to the context tree. Better a leak - * than a crash. + * We delink the context from its parent before deleting it, so that + * if there's an error we won't have deleted/busted contexts still + * attached to the context tree. Better a leak than a crash. */ if (context->parent) { - MemoryContext parent = context->parent; + MemoryContext parent = context->parent; if (context == parent->firstchild) - { parent->firstchild = context->nextchild; - } else { - MemoryContext child; + MemoryContext child; for (child = parent->firstchild; child; child = child->nextchild) { @@ -200,14 +199,13 @@ void MemoryContextDeleteChildren(MemoryContext context) { AssertArg(MemoryContextIsValid(context)); + /* - * MemoryContextDelete will delink the child from me, - * so just iterate as long as there is a child. + * MemoryContextDelete will delink the child from me, so just iterate + * as long as there is a child. */ while (context->firstchild != NULL) - { MemoryContextDelete(context->firstchild); - } } /* @@ -237,15 +235,13 @@ MemoryContextResetAndDeleteChildren(MemoryContext context) void MemoryContextStats(MemoryContext context) { - MemoryContext child; + MemoryContext child; AssertArg(MemoryContextIsValid(context)); (*context->methods->stats) (context); for (child = context->firstchild; child != NULL; child = child->nextchild) - { MemoryContextStats(child); - } } @@ -253,22 +249,21 @@ MemoryContextStats(MemoryContext context) * MemoryContextCheck * Check all chunks in the named context. * - * This is just a debugging utility, so it's not fancy. + * This is just a debugging utility, so it's not fancy. */ #ifdef MEMORY_CONTEXT_CHECKING void MemoryContextCheck(MemoryContext context) { - MemoryContext child; + MemoryContext child; AssertArg(MemoryContextIsValid(context)); (*context->methods->check) (context); for (child = context->firstchild; child != NULL; child = child->nextchild) - { MemoryContextCheck(child); - } } + #endif /* @@ -285,24 +280,26 @@ MemoryContextCheck(MemoryContext context) bool MemoryContextContains(MemoryContext context, void *pointer) { - StandardChunkHeader *header; + StandardChunkHeader *header; /* * Try to detect bogus pointers handed to us, poorly though we can. - * Presumably, a pointer that isn't MAXALIGNED isn't pointing at - * an allocated chunk. + * Presumably, a pointer that isn't MAXALIGNED isn't pointing at an + * allocated chunk. */ if (pointer == NULL || pointer != (void *) MAXALIGN(pointer)) return false; + /* * OK, it's probably safe to look at the chunk header. */ header = (StandardChunkHeader *) ((char *) pointer - STANDARDCHUNKHEADERSIZE); + /* * If the context link doesn't match then we certainly have a - * non-member chunk. Also check for a reasonable-looking size - * as extra guard against being fooled by bogus pointers. + * non-member chunk. Also check for a reasonable-looking size as + * extra guard against being fooled by bogus pointers. */ if (header->context == context && AllocSizeIsValid(header->size)) return true; @@ -347,7 +344,7 @@ MemoryContextContains(MemoryContext context, void *pointer) * * Normally, the context node and the name are allocated from * TopMemoryContext (NOT from the parent context, since the node must - * survive resets of its parent context!). However, this routine is itself + * survive resets of its parent context!). However, this routine is itself * used to create TopMemoryContext! If we see that TopMemoryContext is NULL, * we assume we are creating TopMemoryContext and use malloc() to allocate * the node. @@ -363,8 +360,8 @@ MemoryContextCreate(NodeTag tag, Size size, MemoryContext parent, const char *name) { - MemoryContext node; - Size needed = size + strlen(name) + 1; + MemoryContext node; + Size needed = size + strlen(name) + 1; /* Get space for node and name */ if (TopMemoryContext != NULL) @@ -431,15 +428,16 @@ MemoryContextAlloc(MemoryContext context, Size size) void pfree(void *pointer) { - StandardChunkHeader *header; + StandardChunkHeader *header; /* * Try to detect bogus pointers handed to us, poorly though we can. - * Presumably, a pointer that isn't MAXALIGNED isn't pointing at - * an allocated chunk. + * Presumably, a pointer that isn't MAXALIGNED isn't pointing at an + * allocated chunk. */ Assert(pointer != NULL); Assert(pointer == (void *) MAXALIGN(pointer)); + /* * OK, it's probably safe to look at the chunk header. */ @@ -448,7 +446,7 @@ pfree(void *pointer) AssertArg(MemoryContextIsValid(header->context)); - (*header->context->methods->free_p) (header->context, pointer); + (*header->context->methods->free_p) (header->context, pointer); } /* @@ -458,15 +456,16 @@ pfree(void *pointer) void * repalloc(void *pointer, Size size) { - StandardChunkHeader *header; + StandardChunkHeader *header; /* * Try to detect bogus pointers handed to us, poorly though we can. - * Presumably, a pointer that isn't MAXALIGNED isn't pointing at - * an allocated chunk. + * Presumably, a pointer that isn't MAXALIGNED isn't pointing at an + * allocated chunk. */ Assert(pointer != NULL); Assert(pointer == (void *) MAXALIGN(pointer)); + /* * OK, it's probably safe to look at the chunk header. */ @@ -479,7 +478,7 @@ repalloc(void *pointer, Size size) elog(ERROR, "repalloc: invalid request size %lu", (unsigned long) size); - return (*header->context->methods->realloc) (header->context, + return (*header->context->methods->realloc) (header->context, pointer, size); } diff --git a/src/backend/utils/mmgr/portalmem.c b/src/backend/utils/mmgr/portalmem.c index 63d3ed363cb..a5534dc1cde 100644 --- a/src/backend/utils/mmgr/portalmem.c +++ b/src/backend/utils/mmgr/portalmem.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/portalmem.c,v 1.40 2001/02/27 22:07:34 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/portalmem.c,v 1.41 2001/03/22 04:00:08 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -126,8 +126,8 @@ EnablePortalManager(void) ctl.datasize = sizeof(Portal); /* - * use PORTALS_PER_USER, defined in utils/portal.h as a guess of - * how many hash table entries to create, initially + * use PORTALS_PER_USER, defined in utils/portal.h as a guess of how + * many hash table entries to create, initially */ PortalHashTable = hash_create(PORTALS_PER_USER * 3, &ctl, HASH_ELEM); } diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c index 6dbcc701290..38f4c2fc91e 100644 --- a/src/backend/utils/sort/tuplesort.c +++ b/src/backend/utils/sort/tuplesort.c @@ -78,7 +78,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/sort/tuplesort.c,v 1.13 2001/01/29 00:39:19 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/sort/tuplesort.c,v 1.14 2001/03/22 04:00:09 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -1851,7 +1851,7 @@ comparetup_index(Tuplesortstate *state, const void *a, const void *b) else { compare = DatumGetInt32(FunctionCall2(&entry->sk_func, - attrDatum1, attrDatum2)); + attrDatum1, attrDatum2)); } if (compare != 0) diff --git a/src/backend/utils/sort/tuplestore.c b/src/backend/utils/sort/tuplestore.c index 48a8fbb0716..7621e572978 100644 --- a/src/backend/utils/sort/tuplestore.c +++ b/src/backend/utils/sort/tuplestore.c @@ -11,7 +11,7 @@ * space limit specified by the caller. * * The (approximate) amount of memory allowed to the tuplestore is specified - * in kilobytes by the caller. We absorb tuples and simply store them in an + * in kilobytes by the caller. We absorb tuples and simply store them in an * in-memory array as long as we haven't exceeded maxKBytes. If we reach the * end of the input without exceeding maxKBytes, we just return tuples during * the read phase by scanning the tuple array sequentially. If we do exceed @@ -26,7 +26,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/sort/tuplestore.c,v 1.2 2001/01/24 19:43:18 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/sort/tuplestore.c,v 1.3 2001/03/22 04:00:10 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -38,7 +38,7 @@ #include "utils/tuplestore.h" /* - * Possible states of a Tuplestore object. These denote the states that + * Possible states of a Tuplestore object. These denote the states that * persist between calls of Tuplestore routines. */ typedef enum @@ -66,12 +66,12 @@ struct Tuplestorestate * know it. They are set up by the tuplestore_begin_xxx routines. * * (Although tuplestore.c currently only supports heap tuples, I've - * copied this part of tuplesort.c so that extension to other kinds - * of objects will be easy if it's ever needed.) + * copied this part of tuplesort.c so that extension to other kinds of + * objects will be easy if it's ever needed.) * - * Function to copy a supplied input tuple into palloc'd space. (NB: - * we assume that a single pfree() is enough to release the tuple - * later, so the representation must be "flat" in one palloc chunk.) + * Function to copy a supplied input tuple into palloc'd space. (NB: we + * assume that a single pfree() is enough to release the tuple later, + * so the representation must be "flat" in one palloc chunk.) * state->availMem must be decreased by the amount of space used. */ void *(*copytup) (Tuplestorestate *state, void *tup); @@ -95,7 +95,8 @@ struct Tuplestorestate /* * This array holds pointers to tuples in memory if we are in state - * INITIAL or READMEM. In states WRITEFILE and READFILE it's not used. + * INITIAL or READMEM. In states WRITEFILE and READFILE it's not + * used. */ void **memtuples; /* array of pointers to palloc'd tuples */ int memtupcount; /* number of tuples currently present */ @@ -116,7 +117,7 @@ struct Tuplestorestate }; #define COPYTUP(state,tup) ((*(state)->copytup) (state, tup)) -#define WRITETUP(state,tup) ((*(state)->writetup) (state, tup)) +#define WRITETUP(state,tup) ((*(state)->writetup) (state, tup)) #define READTUP(state,len) ((*(state)->readtup) (state, len)) #define LACKMEM(state) ((state)->availMem < 0) #define USEMEM(state,amt) ((state)->availMem -= (amt)) @@ -145,7 +146,7 @@ struct Tuplestorestate * the back length word (if present). * * The write/read routines can make use of the tuple description data - * stored in the Tuplestorestate record, if needed. They are also expected + * stored in the Tuplestorestate record, if needed. They are also expected * to adjust state->availMem by the amount of memory space (not tape space!) * released or consumed. There is no error return from either writetup * or readtup; they should elog() on failure. @@ -183,7 +184,7 @@ struct Tuplestorestate static Tuplestorestate *tuplestore_begin_common(bool randomAccess, - int maxKBytes); + int maxKBytes); static void dumptuples(Tuplestorestate *state); static unsigned int getlen(Tuplestorestate *state, bool eofOK); static void markrunend(Tuplestorestate *state); @@ -222,7 +223,7 @@ tuplestore_begin_common(bool randomAccess, int maxKBytes) state->memtupcount = 0; if (maxKBytes > 0) - state->memtupsize = 1024; /* initial guess */ + state->memtupsize = 1024; /* initial guess */ else state->memtupsize = 1; /* won't really need any space */ state->memtuples = (void **) palloc(state->memtupsize * sizeof(void *)); @@ -270,14 +271,16 @@ tuplestore_end(Tuplestorestate *state) void tuplestore_puttuple(Tuplestorestate *state, void *tuple) { + /* - * Copy the tuple. (Must do this even in WRITEFILE case.) + * Copy the tuple. (Must do this even in WRITEFILE case.) */ tuple = COPYTUP(state, tuple); switch (state->status) { case TSS_INITIAL: + /* * Stash the tuple in the in-memory array. */ @@ -321,7 +324,8 @@ tuplestore_donestoring(Tuplestorestate *state) { switch (state->status) { - case TSS_INITIAL: + case TSS_INITIAL: + /* * We were able to accumulate all the tuples within the * allowed amount of memory. Just set up to scan them. @@ -333,10 +337,12 @@ tuplestore_donestoring(Tuplestorestate *state) state->status = TSS_READMEM; break; case TSS_WRITEFILE: + /* * Write the EOF marker. */ markrunend(state); + /* * Set up for reading from tape. */ @@ -361,7 +367,7 @@ tuplestore_donestoring(Tuplestorestate *state) */ void * tuplestore_gettuple(Tuplestorestate *state, bool forward, - bool *should_free) + bool *should_free) { unsigned int tuplen; void *tup; @@ -434,7 +440,7 @@ tuplestore_gettuple(Tuplestorestate *state, bool forward, * empty file. */ if (BufFileSeek(state->myfile, 0, - - (long) (2 * sizeof(unsigned int)), + -(long) (2 * sizeof(unsigned int)), SEEK_CUR) != 0) return NULL; state->eof_reached = false; @@ -448,7 +454,7 @@ tuplestore_gettuple(Tuplestorestate *state, bool forward, * file. */ if (BufFileSeek(state->myfile, 0, - - (long) sizeof(unsigned int), + -(long) sizeof(unsigned int), SEEK_CUR) != 0) return NULL; tuplen = getlen(state, false); @@ -457,7 +463,7 @@ tuplestore_gettuple(Tuplestorestate *state, bool forward, * Back up to get ending length word of tuple before it. */ if (BufFileSeek(state->myfile, 0, - - (long) (tuplen + 2 * sizeof(unsigned int)), + -(long) (tuplen + 2 * sizeof(unsigned int)), SEEK_CUR) != 0) { @@ -468,7 +474,7 @@ tuplestore_gettuple(Tuplestorestate *state, bool forward, * but that is what in-memory case does). */ if (BufFileSeek(state->myfile, 0, - - (long) (tuplen + sizeof(unsigned int)), + -(long) (tuplen + sizeof(unsigned int)), SEEK_CUR) != 0) elog(ERROR, "tuplestore_gettuple: bogus tuple len in backward scan"); return NULL; @@ -483,7 +489,7 @@ tuplestore_gettuple(Tuplestorestate *state, bool forward, * initial length word of the tuple, so back up to that point. */ if (BufFileSeek(state->myfile, 0, - - (long) tuplen, + -(long) tuplen, SEEK_CUR) != 0) elog(ERROR, "tuplestore_gettuple: bogus tuple len in backward scan"); tup = READTUP(state, tuplen); @@ -504,9 +510,7 @@ dumptuples(Tuplestorestate *state) int i; for (i = 0; i < state->memtupcount; i++) - { WRITETUP(state, state->memtuples[i]); - } state->memtupcount = 0; } |