diff options
author | Bruce Momjian <bruce@momjian.us> | 1997-09-07 05:04:48 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 1997-09-07 05:04:48 +0000 |
commit | 1ccd423235a48739d6f7a4d7889705b5f9ecc69b (patch) | |
tree | 8001c4e839dfad8f29ceda7f8c5f5dbb8759b564 /src/backend/utils/adt/datum.c | |
parent | 8fecd4febf8357f3cc20383ed29ced484877d5ac (diff) | |
download | postgresql-1ccd423235a48739d6f7a4d7889705b5f9ecc69b.tar.gz postgresql-1ccd423235a48739d6f7a4d7889705b5f9ecc69b.zip |
Massive commit to run PGINDENT on all *.c and *.h files.
Diffstat (limited to 'src/backend/utils/adt/datum.c')
-rw-r--r-- | src/backend/utils/adt/datum.c | 221 |
1 files changed, 123 insertions, 98 deletions
diff --git a/src/backend/utils/adt/datum.c b/src/backend/utils/adt/datum.c index 493843071cd..eb314176bab 100644 --- a/src/backend/utils/adt/datum.c +++ b/src/backend/utils/adt/datum.c @@ -6,7 +6,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/datum.c,v 1.5 1997/08/19 21:34:33 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/datum.c,v 1.6 1997/09/07 04:50:09 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -49,39 +49,51 @@ Size datumGetSize(Datum value, Oid type, bool byVal, Size len) { - - struct varlena *s; - Size size = 0; - - if (byVal) { - if (len <= sizeof(Datum)) { - size = len; - } else { - elog(WARN, - "datumGetSize: Error: type=%ld, byVaL with len=%d", - (long) type, len); + + struct varlena *s; + Size size = 0; + + if (byVal) + { + if (len <= sizeof(Datum)) + { + size = len; + } + else + { + elog(WARN, + "datumGetSize: Error: type=%ld, byVaL with len=%d", + (long) type, len); + } } - } else { /* not byValue */ - if (len == -1) { - /* - * variable length type - * Look at the varlena struct for its real length... - */ - s = (struct varlena *) DatumGetPointer(value); - if (!PointerIsValid(s)) { - elog(WARN, - "datumGetSize: Invalid Datum Pointer"); - } - size = (Size) VARSIZE(s); - } else { - /* - * fixed length type - */ - size = len; + else + { /* not byValue */ + if (len == -1) + { + + /* + * variable length type Look at the varlena struct for its + * real length... + */ + s = (struct varlena *) DatumGetPointer(value); + if (!PointerIsValid(s)) + { + elog(WARN, + "datumGetSize: Invalid Datum Pointer"); + } + size = (Size) VARSIZE(s); + } + else + { + + /* + * fixed length type + */ + size = len; + } } - } - - return(size); + + return (size); } /*------------------------------------------------------------------------- @@ -97,29 +109,35 @@ datumGetSize(Datum value, Oid type, bool byVal, Size len) Datum datumCopy(Datum value, Oid type, bool byVal, Size len) { - - Size realSize; - Datum res; - char *s; - - - if (byVal) { - res = value; - } else { - if (value == 0) return((Datum)NULL); - realSize = datumGetSize(value, type, byVal, len); - /* - * the value is a pointer. Allocate enough space - * and copy the pointed data. - */ - s = (char *) palloc(realSize); - if (s == NULL) { - elog(WARN,"datumCopy: out of memory\n"); + + Size realSize; + Datum res; + char *s; + + + if (byVal) + { + res = value; } - memmove(s, DatumGetPointer(value), realSize); - res = (Datum)s; - } - return(res); + else + { + if (value == 0) + return ((Datum) NULL); + realSize = datumGetSize(value, type, byVal, len); + + /* + * the value is a pointer. Allocate enough space and copy the + * pointed data. + */ + s = (char *) palloc(realSize); + if (s == NULL) + { + elog(WARN, "datumCopy: out of memory\n"); + } + memmove(s, DatumGetPointer(value), realSize); + res = (Datum) s; + } + return (res); } /*------------------------------------------------------------------------- @@ -135,20 +153,23 @@ datumCopy(Datum value, Oid type, bool byVal, Size len) void datumFree(Datum value, Oid type, bool byVal, Size len) { - - Size realSize; - Pointer s; - - realSize = datumGetSize(value, type, byVal, len); - - if (!byVal) { - /* - * free the space palloced by "datumCopy()" - */ - s = DatumGetPointer(value); - pfree(s); - } + + Size realSize; + Pointer s; + + realSize = datumGetSize(value, type, byVal, len); + + if (!byVal) + { + + /* + * free the space palloced by "datumCopy()" + */ + s = DatumGetPointer(value); + pfree(s); + } } + #endif /*------------------------------------------------------------------------- @@ -167,36 +188,40 @@ datumFree(Datum value, Oid type, bool byVal, Size len) bool datumIsEqual(Datum value1, Datum value2, Oid type, bool byVal, Size len) { - Size size1, size2; - char *s1, *s2; - - if (byVal) { - /* - * just compare the two datums. - * NOTE: just comparing "len" bytes will not do the - * work, because we do not know how these bytes - * are aligned inside the "Datum". - */ - if (value1 == value2) - return(true); - else - return(false); - } else { - /* - * byVal = false - * Compare the bytes pointed by the pointers stored in the - * datums. - */ - size1 = datumGetSize(value1, type, byVal, len); - size2 = datumGetSize(value2, type, byVal, len); - if (size1 != size2) - return(false); - s1 = (char *) DatumGetPointer(value1); - s2 = (char *) DatumGetPointer(value2); - if (!memcmp(s1, s2, size1)) - return(true); + Size size1, + size2; + char *s1, + *s2; + + if (byVal) + { + + /* + * just compare the two datums. NOTE: just comparing "len" bytes + * will not do the work, because we do not know how these bytes + * are aligned inside the "Datum". + */ + if (value1 == value2) + return (true); + else + return (false); + } else - return(false); - } -} + { + /* + * byVal = false Compare the bytes pointed by the pointers stored + * in the datums. + */ + size1 = datumGetSize(value1, type, byVal, len); + size2 = datumGetSize(value2, type, byVal, len); + if (size1 != size2) + return (false); + s1 = (char *) DatumGetPointer(value1); + s2 = (char *) DatumGetPointer(value2); + if (!memcmp(s1, s2, size1)) + return (true); + else + return (false); + } +} |