1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

More timezone patches by Thomas:

Here are patches which should help fix timezone problems in the
datetime and abstime code. Also, I repatched varlena.c to add in
some comments and a little error checking on top of Vadim's earlier
repairs. There are slight mods to the circle data type to have the
distance operator between circles measure the distance between
closest points rather than between centers.
This commit is contained in:
Marc G. Fournier
1997-04-25 18:40:50 +00:00
parent b8e376ceb9
commit 094ec2d3f3
8 changed files with 252 additions and 222 deletions

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.14 1997/04/21 04:31:53 vadim Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.15 1997/04/25 18:40:39 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@ -288,19 +288,23 @@ textne(struct varlena *arg1, struct varlena *arg2)
/* text_lt()
* Comparison function for text strings.
* Includes locale support, but must copy strings to temporary memory
* to allow null-termination for inputs to strcoll().
* to allow null-termination for inputs to strcoll().
* XXX HACK code for textlen() indicates that there can be embedded nulls
* but it appears that most routines (incl. this one) assume not! - tgl 97/04/07
*/
bool
text_lt(struct varlena *arg1, struct varlena *arg2)
{
bool result;
#ifdef USE_LOCALE
int cval;
#endif
int len;
#ifdef UNSIGNED_CHAR_TEXT
unsigned
#endif
char *a1p, *a2p;
#ifdef USE_LOCALE
int cval;
#endif
if (arg1 == NULL || arg2 == NULL)
return((bool) FALSE);
@ -308,9 +312,11 @@ text_lt(struct varlena *arg1, struct varlena *arg2)
len = (((VARSIZE(arg1) <= VARSIZE(arg2))? VARSIZE(arg1): VARSIZE(arg2))-VARHDRSZ);
#ifdef USE_LOCALE
a1p = palloc (len+1);
a2p = palloc (len+1);
if (!PointerIsValid(a1p = PALLOC(len+1))
|| !PointerIsValid(a2p = PALLOC(len+1))) {
elog(WARN,"Unable to allocate memory for text comparison",NULL);
return(FALSE);
};
memcpy(a1p, VARDATA(arg1), len);
*(a1p+len) = '\0';
@ -318,15 +324,11 @@ text_lt(struct varlena *arg1, struct varlena *arg2)
*(a2p+len) = '\0';
cval = strcoll(a1p,a2p);
pfree (a1p);
pfree (a2p);
return((bool) ( (cval < 0) ||
( (cval == 0) && (VARSIZE(arg1) < VARSIZE(arg2)) ) ) );
result = ((cval < 0) || ((cval == 0) && (VARSIZE(arg1) < VARSIZE(arg2))));
PFREE(a1p);
PFREE(a2p);
#else
a1p = (unsigned char *)VARDATA(arg1);
a2p = (unsigned char *)VARDATA(arg2);
@ -335,28 +337,33 @@ text_lt(struct varlena *arg1, struct varlena *arg2)
a2p++;
len--;
};
return((bool) (len? (*a1p < *a2p): (VARSIZE(arg1) < VARSIZE(arg2))));
result = (len? (*a1p < *a2p): (VARSIZE(arg1) < VARSIZE(arg2)));
#endif
return(result);
} /* text_lt() */
/* text_le()
* Comparison function for text strings.
* Includes locale support, but must copy strings to temporary memory
* to allow null-termination for inputs to strcoll().
* to allow null-termination for inputs to strcoll().
* XXX HACK code for textlen() indicates that there can be embedded nulls
* but it appears that most routines (incl. this one) assume not! - tgl 97/04/07
*/
bool
text_le(struct varlena *arg1, struct varlena *arg2)
{
bool result;
#ifdef USE_LOCALE
int cval;
#endif
int len;
#ifdef UNSIGNED_CHAR_TEXT
unsigned
#endif
char *a1p, *a2p;
#ifdef USE_LOCALE
int cval;
#endif
if (arg1 == NULL || arg2 == NULL)
return((bool) 0);
@ -364,9 +371,11 @@ text_le(struct varlena *arg1, struct varlena *arg2)
len = (((VARSIZE(arg1) <= VARSIZE(arg2))? VARSIZE(arg1): VARSIZE(arg2))-VARHDRSZ);
#ifdef USE_LOCALE
a1p = palloc (len+1);
a2p = palloc (len+1);
if (!PointerIsValid(a1p = PALLOC(len+1))
|| !PointerIsValid(a2p = PALLOC(len+1))) {
elog(WARN,"Unable to allocate memory for text comparison",NULL);
return(FALSE);
};
memcpy(a1p, VARDATA(arg1), len);
*(a1p+len) = '\0';
@ -374,15 +383,11 @@ text_le(struct varlena *arg1, struct varlena *arg2)
*(a2p+len) = '\0';
cval = strcoll(a1p,a2p);
pfree (a1p);
pfree (a2p);
return ((bool) ( (cval < 0) ||
( (cval == 0) && (VARSIZE(arg1) <= VARSIZE(arg2)) ) ) );
result = ((cval < 0) || ((cval == 0) && (VARSIZE(arg1) <= VARSIZE(arg2))));
PFREE(a1p);
PFREE(a2p);
#else
a1p = (unsigned char *)VARDATA(arg1);
a2p = (unsigned char *)VARDATA(arg2);
@ -392,10 +397,10 @@ text_le(struct varlena *arg1, struct varlena *arg2)
len--;
};
return((bool) (len? (*a1p <= *a2p): (VARSIZE(arg1) <= VARSIZE(arg2))));
result = (len? (*a1p <= *a2p): (VARSIZE(arg1) <= VARSIZE(arg2)));
#endif
return(result);
} /* text_le() */
bool