1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-25 21:42:33 +03:00

Clean up redundant tests for valid pointers in geometric types.

Fix up decoder field masks for timespan and reltime.
This commit is contained in:
Thomas G. Lockhart 1997-05-23 05:24:53 +00:00
parent 0828204538
commit ac534bee01
2 changed files with 44 additions and 42 deletions

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.21 1997/05/13 04:26:07 thomas Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.22 1997/05/23 05:24:47 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -2640,7 +2640,7 @@ DecodeDateDelta( char *field[], int ftype[], int nf, int *dtype, struct tm *tm,
*dtype = DTK_DELTA; *dtype = DTK_DELTA;
type = DTK_SECOND; type = SECOND;
tm->tm_year = 0; tm->tm_year = 0;
tm->tm_mon = 0; tm->tm_mon = 0;
tm->tm_mday = 0; tm->tm_mday = 0;
@ -2691,7 +2691,7 @@ printf( "DecodeDateDelta- field[%d] is %s (type %d)\n", i, field[i], ftype[i]);
if (val < 0) *fsec = - (*fsec); if (val < 0) *fsec = - (*fsec);
}; };
flen = strlen(field[i]); flen = strlen(field[i]);
tmask = DTK_M(type); tmask = 0; /* DTK_M(type); */
switch (type) { switch (type) {
case DTK_MICROSEC: case DTK_MICROSEC:
@ -2704,42 +2704,52 @@ printf( "DecodeDateDelta- field[%d] is %s (type %d)\n", i, field[i], ftype[i]);
case DTK_SECOND: case DTK_SECOND:
tm->tm_sec += val; tm->tm_sec += val;
tmask = DTK_M(SECOND);
break; break;
case DTK_MINUTE: case DTK_MINUTE:
tm->tm_min += val; tm->tm_min += val;
tmask = DTK_M(MINUTE);
break; break;
case DTK_HOUR: case DTK_HOUR:
tm->tm_hour += val; tm->tm_hour += val;
tmask = DTK_M(HOUR);
break; break;
case DTK_DAY: case DTK_DAY:
tm->tm_mday += val; tm->tm_mday += val;
tmask = ((fmask & DTK_M(DAY))? 0: DTK_M(DAY));
break; break;
case DTK_WEEK: case DTK_WEEK:
tm->tm_mday += val*7; tm->tm_mday += val*7;
tmask = ((fmask & DTK_M(DAY))? 0: DTK_M(DAY));
break; break;
case DTK_MONTH: case DTK_MONTH:
tm->tm_mon += val; tm->tm_mon += val;
tmask = DTK_M(MONTH);
break; break;
case DTK_YEAR: case DTK_YEAR:
tm->tm_year += val; tm->tm_year += val;
tmask = ((fmask & DTK_M(YEAR))? 0: DTK_M(YEAR));
break; break;
case DTK_DECADE: case DTK_DECADE:
tm->tm_year += val*10; tm->tm_year += val*10;
tmask = ((fmask & DTK_M(YEAR))? 0: DTK_M(YEAR));
break; break;
case DTK_CENTURY: case DTK_CENTURY:
tm->tm_year += val*100; tm->tm_year += val*100;
tmask = ((fmask & DTK_M(YEAR))? 0: DTK_M(YEAR));
break; break;
case DTK_MILLENIUM: case DTK_MILLENIUM:
tm->tm_year += val*1000; tm->tm_year += val*1000;
tmask = ((fmask & DTK_M(YEAR))? 0: DTK_M(YEAR));
break; break;
default: default:
@ -2770,7 +2780,7 @@ printf( "DecodeDateDelta- UNITS field %s value is %d\n", field[i], val);
break; break;
case RESERV: case RESERV:
type = (DTK_DATE_M || DTK_TIME_M); tmask = (DTK_DATE_M || DTK_TIME_M);
*dtype = val; *dtype = val;
break; break;

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.8 1997/05/22 00:07:21 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.9 1997/05/23 05:24:53 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -95,7 +95,7 @@ int pair_decode(char *str, float8 *x, float8 *y, char **s)
int has_delim; int has_delim;
char *cp; char *cp;
if (!PointerIsValid((char *)str)) if (!PointerIsValid(str))
return(FALSE); return(FALSE);
while (isspace( *str)) str++; while (isspace( *str)) str++;
@ -264,7 +264,7 @@ BOX *box_in(char *str)
char *s; char *s;
double x, y; double x, y;
if (!PointerIsValid((char *)str)) if (!PointerIsValid(str))
elog (WARN," Bad (null) box external representation",NULL); elog (WARN," Bad (null) box external representation",NULL);
if ((! path_decode(FALSE, 2, str, &isopen, &s, &(box->high))) if ((! path_decode(FALSE, 2, str, &isopen, &s, &(box->high)))
@ -296,7 +296,7 @@ char *box_out(BOX *box)
char *cp; char *cp;
#endif #endif
if (!PointerIsValid((char *)box)) if (!PointerIsValid(box))
return(NULL); return(NULL);
#if OLD_FORMAT_OUT #if OLD_FORMAT_OUT
@ -826,7 +826,7 @@ PATH *path_in(char *str)
double x, y; double x, y;
#endif #endif
if (!PointerIsValid((char *)str)) if (!PointerIsValid(str))
elog(WARN, "Bad (null) path external representation"); elog(WARN, "Bad (null) path external representation");
if ((npts = pair_count(str, ',')) <= 0) if ((npts = pair_count(str, ',')) <= 0)
@ -886,7 +886,7 @@ char *path_out(PATH *path)
char *result, *cp; char *result, *cp;
#endif #endif
if (!PointerIsValid((char *)path)) if (!PointerIsValid(path))
return NULL; return NULL;
#if OLD_FORMAT_OUT #if OLD_FORMAT_OUT
@ -956,7 +956,7 @@ PATH *path_copy(PATH *path);
bool bool
path_isclosed( PATH *path) path_isclosed( PATH *path)
{ {
if (!PointerIsValid((char *)path)) if (!PointerIsValid(path))
return FALSE; return FALSE;
return(path->closed); return(path->closed);
@ -965,7 +965,7 @@ path_isclosed( PATH *path)
bool bool
path_isopen( PATH *path) path_isopen( PATH *path)
{ {
if (!PointerIsValid((char *)path)) if (!PointerIsValid(path))
return FALSE; return FALSE;
return(! path->closed); return(! path->closed);
@ -975,7 +975,7 @@ path_isopen( PATH *path)
int4 int4
path_npoints( PATH *path) path_npoints( PATH *path)
{ {
if (!PointerIsValid((char *)path)) if (!PointerIsValid(path))
return 0; return 0;
return(path->npts); return(path->npts);
@ -987,7 +987,7 @@ path_close(PATH *path)
PATH *result; PATH *result;
result = path_copy(path); result = path_copy(path);
if (PointerIsValid((char *)result)) if (PointerIsValid(result))
result->closed = TRUE; result->closed = TRUE;
return(result); return(result);
@ -999,7 +999,7 @@ path_open(PATH *path)
PATH *result; PATH *result;
result = path_copy(path); result = path_copy(path);
if (PointerIsValid((char *)result)) if (PointerIsValid(result))
result->closed = FALSE; result->closed = FALSE;
return(result); return(result);
@ -1012,7 +1012,7 @@ path_copy(PATH *path)
PATH *result; PATH *result;
int size; int size;
if (!PointerIsValid((char *)path)) if (!PointerIsValid(path))
return NULL; return NULL;
size = offsetof(PATH, p[0]) + (sizeof(path->p[0]) * path->npts); size = offsetof(PATH, p[0]) + (sizeof(path->p[0]) * path->npts);
@ -1169,7 +1169,7 @@ point_in(char *str)
char * char *
point_out(Point *pt) point_out(Point *pt)
{ {
if (!PointerIsValid((char *)pt)) if (!PointerIsValid(pt))
return(NULL); return(NULL);
return( path_encode( -1, 1, pt)); return( path_encode( -1, 1, pt));
@ -1308,7 +1308,7 @@ LSEG *lseg_in(char *str)
int isopen; int isopen;
char *s; char *s;
if (!PointerIsValid((char *)str)) if (!PointerIsValid(str))
elog (WARN," Bad (null) lseg external representation",NULL); elog (WARN," Bad (null) lseg external representation",NULL);
lseg = PALLOCTYPE(LSEG); lseg = PALLOCTYPE(LSEG);
@ -1325,7 +1325,7 @@ LSEG *lseg_in(char *str)
char *lseg_out(LSEG *ls) char *lseg_out(LSEG *ls)
{ {
if (!PointerIsValid((char *)ls)) if (!PointerIsValid(ls))
return(NULL); return(NULL);
return( path_encode( FALSE, 2, (Point *) &(ls->p[0]))); return( path_encode( FALSE, 2, (Point *) &(ls->p[0])));
@ -2005,7 +2005,7 @@ POLYGON *poly_in(char *str)
double x1, x2; double x1, x2;
#endif #endif
if (!PointerIsValid((char *)str)) if (!PointerIsValid(str))
elog (WARN," Bad (null) polygon external representation"); elog (WARN," Bad (null) polygon external representation");
if ((npts = pair_count(str, ',')) <= 0) if ((npts = pair_count(str, ',')) <= 0)
@ -2091,7 +2091,7 @@ char *poly_out(POLYGON *poly)
char *result, *cp; char *result, *cp;
#endif #endif
if (!PointerIsValid((char *)poly)) if (!PointerIsValid(poly))
return NULL; return NULL;
#if OLD_FORMAT_OUT #if OLD_FORMAT_OUT
@ -2434,8 +2434,7 @@ path_add_pt(PATH *path, Point *point)
if (! (PointerIsValid(path) && PointerIsValid(point))) if (! (PointerIsValid(path) && PointerIsValid(point)))
return(NULL); return(NULL);
if (! PointerIsValid(result = path_copy(path))) result = path_copy(path);
elog(WARN, "Memory allocation failed, can't add path",NULL);
for (i=0; i<path->npts; i++) { for (i=0; i<path->npts; i++) {
result->p[i].x += point->x; result->p[i].x += point->x;
@ -2454,8 +2453,7 @@ path_sub_pt(PATH *path, Point *point)
if (! (PointerIsValid(path) && PointerIsValid(point))) if (! (PointerIsValid(path) && PointerIsValid(point)))
return(NULL); return(NULL);
if (! PointerIsValid(result = path_copy(path))) result = path_copy(path);
elog(WARN, "Memory allocation failed, can't subtract path",NULL);
for (i=0; i<path->npts; i++) { for (i=0; i<path->npts; i++) {
result->p[i].x -= point->x; result->p[i].x -= point->x;
@ -2479,8 +2477,7 @@ path_mul_pt(PATH *path, Point *point)
if (! (PointerIsValid(path) && PointerIsValid(point))) if (! (PointerIsValid(path) && PointerIsValid(point)))
return(NULL); return(NULL);
if (! PointerIsValid(result = path_copy(path))) result = path_copy(path);
elog(WARN, "Memory allocation failed, can't multiply path",NULL);
for (i=0; i<path->npts; i++) { for (i=0; i<path->npts; i++) {
p = point_mul( &path->p[i], point); p = point_mul( &path->p[i], point);
@ -2502,8 +2499,7 @@ path_div_pt(PATH *path, Point *point)
if (! (PointerIsValid(path) && PointerIsValid(point))) if (! (PointerIsValid(path) && PointerIsValid(point)))
return(NULL); return(NULL);
if (! PointerIsValid(result = path_copy(path))) result = path_copy(path);
elog(WARN, "Memory allocation failed, can't divide path",NULL);
for (i=0; i<path->npts; i++) { for (i=0; i<path->npts; i++) {
p = point_div( &path->p[i], point); p = point_div( &path->p[i], point);
@ -2641,7 +2637,7 @@ poly_path(POLYGON *poly)
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.8 1997/05/22 00:07:21 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.9 1997/05/23 05:24:53 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -2923,11 +2919,10 @@ circle_add_pt(CIRCLE *circle, Point *point)
{ {
CIRCLE *result; CIRCLE *result;
if (!PointerIsValid(circle) && !PointerIsValid(point)) if (!PointerIsValid(circle) || !PointerIsValid(point))
return(NULL); return(NULL);
if (! PointerIsValid(result = circle_copy(circle))) result = circle_copy(circle);
elog(WARN, "Memory allocation failed, can't add circle",NULL);
result->center.x += point->x; result->center.x += point->x;
result->center.y += point->y; result->center.y += point->y;
@ -2940,11 +2935,10 @@ circle_sub_pt(CIRCLE *circle, Point *point)
{ {
CIRCLE *result; CIRCLE *result;
if (!PointerIsValid(circle) && !PointerIsValid(point)) if (!PointerIsValid(circle) || !PointerIsValid(point))
return(NULL); return(NULL);
if (! PointerIsValid(result = circle_copy(circle))) result = circle_copy(circle);
elog(WARN, "Memory allocation failed, can't subtract circle",NULL);
result->center.x -= point->x; result->center.x -= point->x;
result->center.y -= point->y; result->center.y -= point->y;
@ -2962,11 +2956,10 @@ circle_mul_pt(CIRCLE *circle, Point *point)
CIRCLE *result; CIRCLE *result;
Point *p; Point *p;
if (!PointerIsValid(circle) && !PointerIsValid(point)) if (!PointerIsValid(circle) || !PointerIsValid(point))
return(NULL); return(NULL);
if (! PointerIsValid(result = circle_copy(circle))) result = circle_copy(circle);
elog(WARN, "Memory allocation failed, can't multiply circle",NULL);
p = point_mul( &circle->center, point); p = point_mul( &circle->center, point);
result->center.x = p->x; result->center.x = p->x;
@ -2983,11 +2976,10 @@ circle_div_pt(CIRCLE *circle, Point *point)
CIRCLE *result; CIRCLE *result;
Point *p; Point *p;
if (!PointerIsValid(circle) && !PointerIsValid(point)) if (!PointerIsValid(circle) || !PointerIsValid(point))
return(NULL); return(NULL);
if (! PointerIsValid(result = circle_copy(circle))) result = circle_copy(circle);
elog(WARN, "Memory allocation failed, can't add circle",NULL);
p = point_div( &circle->center, point); p = point_div( &circle->center, point);
result->center.x = p->x; result->center.x = p->x;