From e6c6146eb8129f1ea1e1f68ef739c13824357225 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Wed, 7 Jan 1998 18:47:07 +0000 Subject: [PATCH] Allow varchar() to only store needed bytes. Remove PALLOC,PALLOCTYPE,PFREE. Clean up use of VARDATA. --- contrib/datetime/datetime_functions.c | 10 +- contrib/int8/int8.c | 36 ++---- src/backend/access/rtree/rtproc.c | 6 +- src/backend/commands/variable.c | 14 +-- src/backend/utils/adt/cash.c | 32 +++--- src/backend/utils/adt/date.c | 6 +- src/backend/utils/adt/datetime.c | 14 +-- src/backend/utils/adt/dt.c | 50 ++++----- src/backend/utils/adt/geo_ops.c | 204 +++++++++++++++++----------------- src/backend/utils/adt/int.c | 18 +-- src/backend/utils/adt/nabstime.c | 6 +- src/backend/utils/adt/oid.c | 10 +- src/backend/utils/adt/varchar.c | 118 ++++++++------------ src/backend/utils/adt/varlena.c | 6 +- src/include/utils/geo_decls.h | 14 +-- src/test/regress/regress.c | 12 +- 16 files changed, 253 insertions(+), 303 deletions(-) diff --git a/contrib/datetime/datetime_functions.c b/contrib/datetime/datetime_functions.c index b96761bc8f..4c8d11794c 100644 --- a/contrib/datetime/datetime_functions.c +++ b/contrib/datetime/datetime_functions.c @@ -66,7 +66,7 @@ hhmm_in(char *str) elog(ERROR,"Second must be limited to values 0 through < 60 in '%s'", str); - time = PALLOCTYPE(TimeADT); + time = palloc(sizeof(TimeADT)); *time = ((((tm->tm_hour*60)+tm->tm_min)*60)); @@ -99,7 +99,7 @@ hhmm_out(TimeADT *time) sprintf(buf, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec); } - result = PALLOC(strlen(buf)+1); + result = palloc(strlen(buf)+1); strcpy( result, buf); @@ -109,7 +109,7 @@ hhmm_out(TimeADT *time) TimeADT * hhmm(TimeADT *time) { - TimeADT *result = PALLOCTYPE(TimeADT); + TimeADT *result = palloc(sizeof(TimeADT)); *result = (((int) *time) / 60 * 60); @@ -119,7 +119,7 @@ hhmm(TimeADT *time) TimeADT * time_difference(TimeADT *time1, TimeADT *time2) { - TimeADT *time = PALLOCTYPE(TimeADT); + TimeADT *time = palloc(sizeof(TimeADT)); *time = (*time1 - *time2); return(time); @@ -188,7 +188,7 @@ date_year(DateADT val) TimeADT * currenttime() { - TimeADT *result = PALLOCTYPE(TimeADT); + TimeADT *result = palloc(sizeof(TimeADT)); struct tm *tm; time_t current_time; diff --git a/contrib/int8/int8.c b/contrib/int8/int8.c index afb3b6a93e..f8945ccd5d 100644 --- a/contrib/int8/int8.c +++ b/contrib/int8/int8.c @@ -19,8 +19,6 @@ #define MAXINT8LEN 25 -#define USE_LOCAL_CODE 1 - #if defined(__alpha) || defined(__GNUC__) #define HAVE_64BIT_INTS 1 #endif @@ -79,18 +77,6 @@ int16 int82(int64 * val); float64 i8tod(int64 * val); int64 *dtoi8(float64 val); -#if USE_LOCAL_CODE - -#ifndef PALLOC -#define PALLOC(p) palloc(p) -#endif - -#ifndef PALLOCTYPE -#define PALLOCTYPE(p) palloc(sizeof(p)) -#endif - -#endif - /*********************************************************************** ** ** Routines for 64-bit integers. @@ -106,7 +92,7 @@ int64 *dtoi8(float64 val); int64 * int8in(char *str) { - int64 *result = PALLOCTYPE(int64); + int64 *result = palloc(sizeof(int64)); #if HAVE_64BIT_INTS if (!PointerIsValid(str)) @@ -141,7 +127,7 @@ int8out(int64 * val) if ((len = snprintf(buf, MAXINT8LEN, INT64_FORMAT, *val)) < 0) elog(ERROR, "Unable to format int8", NULL); - result = PALLOC(len + 1); + result = palloc(len + 1); strcpy(result, buf); @@ -245,7 +231,7 @@ int84ge(int64 * val1, int32 val2) int64 * int8um(int64 * val) { - int64 *result = PALLOCTYPE(int64); + int64 *result = palloc(sizeof(int64)); if (!PointerIsValid(val)) return NULL; @@ -258,7 +244,7 @@ int8um(int64 * val) int64 * int8pl(int64 * val1, int64 * val2) { - int64 *result = PALLOCTYPE(int64); + int64 *result = palloc(sizeof(int64)); if ((!PointerIsValid(val1)) || (!PointerIsValid(val2))) return NULL; @@ -271,7 +257,7 @@ int8pl(int64 * val1, int64 * val2) int64 * int8mi(int64 * val1, int64 * val2) { - int64 *result = PALLOCTYPE(int64); + int64 *result = palloc(sizeof(int64)); if ((!PointerIsValid(val1)) || (!PointerIsValid(val2))) return NULL; @@ -284,7 +270,7 @@ int8mi(int64 * val1, int64 * val2) int64 * int8mul(int64 * val1, int64 * val2) { - int64 *result = PALLOCTYPE(int64); + int64 *result = palloc(sizeof(int64)); if ((!PointerIsValid(val1)) || (!PointerIsValid(val2))) return NULL; @@ -297,7 +283,7 @@ int8mul(int64 * val1, int64 * val2) int64 * int8div(int64 * val1, int64 * val2) { - int64 *result = PALLOCTYPE(int64); + int64 *result = palloc(sizeof(int64)); if ((!PointerIsValid(val1)) || (!PointerIsValid(val2))) return NULL; @@ -315,7 +301,7 @@ int8div(int64 * val1, int64 * val2) int64 * int48(int32 val) { - int64 *result = PALLOCTYPE(int64); + int64 *result = palloc(sizeof(int64)); *result = val; @@ -344,7 +330,7 @@ int28 (int16 val) { int64 *result; - if (!PointerIsValid(result = PALLOCTYPE(int64))) + if (!PointerIsValid(result = palloc(sizeof(int64)))) elog(ERROR, "Memory allocation failed, can't convert int8 to int2", NULL); *result = val; @@ -370,7 +356,7 @@ int82(int64 * val) float64 i8tod(int64 * val) { - float64 result = PALLOCTYPE(float64data); + float64 result = palloc(sizeof(float64data)); *result = *val; @@ -380,7 +366,7 @@ i8tod(int64 * val) int64 * dtoi8(float64 val) { - int64 *result = PALLOCTYPE(int64); + int64 *result = palloc(sizeof(int64)); if ((*val < (-pow(2, 64) + 1)) || (*val > (pow(2, 64) - 1))) elog(ERROR, "Floating point conversion to int64 is out of range", NULL); diff --git a/src/backend/access/rtree/rtproc.c b/src/backend/access/rtree/rtproc.c index a78ea22892..dda0fc4263 100644 --- a/src/backend/access/rtree/rtproc.c +++ b/src/backend/access/rtree/rtproc.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtproc.c,v 1.13 1998/01/05 03:29:59 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtproc.c,v 1.14 1998/01/07 18:46:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -91,7 +91,7 @@ rt_poly_union(POLYGON *a, POLYGON *b) { POLYGON *p; - p = (POLYGON *) PALLOCTYPE(POLYGON); + p = (POLYGON *) palloc(sizeof(POLYGON)); if (!PointerIsValid(p)) elog(ABORT, "Cannot allocate polygon for union"); @@ -133,7 +133,7 @@ rt_poly_inter(POLYGON *a, POLYGON *b) { POLYGON *p; - p = (POLYGON *) PALLOCTYPE(POLYGON); + p = (POLYGON *) palloc(sizeof(POLYGON)); if (!PointerIsValid(p)) elog(ABORT, "Cannot allocate polygon for intersection"); diff --git a/src/backend/commands/variable.c b/src/backend/commands/variable.c index 8ee7e777af..8193b6cb91 100644 --- a/src/backend/commands/variable.c +++ b/src/backend/commands/variable.c @@ -2,7 +2,7 @@ * Routines for handling of 'SET var TO', * 'SHOW var' and 'RESET var' statements. * - * $Id: variable.c,v 1.1 1998/01/05 18:42:50 momjian Exp $ + * $Id: variable.c,v 1.2 1998/01/07 18:46:26 momjian Exp $ * */ @@ -73,7 +73,7 @@ get_token(char **tok, char **val, const char *str) len++; } - *tok = (char *) PALLOC(len + 1); + *tok = (char *) palloc(len + 1); StrNCpy(*tok, start, len+1); /* skip white spaces */ @@ -119,7 +119,7 @@ get_token(char **tok, char **val, const char *str) len++; } - *val = (char *) PALLOC(len + 1); + *val = (char *) palloc(len + 1); StrNCpy(*val, start, len+1); /* skip white spaces */ @@ -186,7 +186,7 @@ parse_geqo(const char *value) geqo_rels = pg_atoi(val, sizeof(int32), '\0'); if (geqo_rels <= 1) elog(ERROR, "Bad value for # of relations (%s)", val); - PFREE(val); + pfree(val); } _use_geqo_ = true; _use_geqo_rels_ = geqo_rels; @@ -200,7 +200,7 @@ parse_geqo(const char *value) else elog(ERROR, "Bad value for GEQO (%s)", value); - PFREE(tok); + pfree(tok); return TRUE; } @@ -394,7 +394,7 @@ parse_date(const char *value) { elog(ERROR, "Bad value for date style (%s)", tok); } - PFREE(tok); + pfree(tok); } if (dcnt > 1 || ecnt > 1) @@ -493,7 +493,7 @@ parse_timezone(const char *value) elog(ERROR, "Unable to set TZ environment variable to %s", tok); tzset(); - PFREE(tok); + pfree(tok); } return TRUE; diff --git a/src/backend/utils/adt/cash.c b/src/backend/utils/adt/cash.c index dbe34a30a8..7d2f7b937c 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.20 1998/01/05 16:39:45 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.21 1998/01/07 18:46:34 momjian Exp $ */ #include @@ -158,7 +158,7 @@ printf( "cashin- precision %d; decimal %c; thousands %c; currency %c; positive % if (*s != '\0') elog(ERROR, "Bad money external representation %s", str); - if (!PointerIsValid(result = PALLOCTYPE(Cash))) + if (!PointerIsValid(result = palloc(sizeof(Cash)))) elog(ERROR, "Memory allocation failed, can't input cash '%s'", str); *result = (value * sgn); @@ -256,7 +256,7 @@ cash_out(Cash *in_value) /* see if we need to signify negative amount */ if (minus) { - if (!PointerIsValid(result = PALLOC(CASH_BUFSZ + 2 - count + strlen(nsymbol)))) + if (!PointerIsValid(result = palloc(CASH_BUFSZ + 2 - count + strlen(nsymbol)))) elog(ERROR, "Memory allocation failed, can't output cash", NULL); /* Position code of 0 means use parens */ @@ -269,7 +269,7 @@ cash_out(Cash *in_value) } else { - if (!PointerIsValid(result = PALLOC(CASH_BUFSZ + 2 - count))) + if (!PointerIsValid(result = palloc(CASH_BUFSZ + 2 - count))) elog(ERROR, "Memory allocation failed, can't output cash", NULL); strcpy(result, buf + count); @@ -345,7 +345,7 @@ cash_pl(Cash *c1, Cash *c2) if (!PointerIsValid(c1) || !PointerIsValid(c2)) return (NULL); - if (!PointerIsValid(result = PALLOCTYPE(Cash))) + if (!PointerIsValid(result = palloc(sizeof(Cash)))) elog(ERROR, "Memory allocation failed, can't add cash", NULL); *result = (*c1 + *c2); @@ -365,7 +365,7 @@ cash_mi(Cash *c1, Cash *c2) if (!PointerIsValid(c1) || !PointerIsValid(c2)) return (NULL); - if (!PointerIsValid(result = PALLOCTYPE(Cash))) + if (!PointerIsValid(result = palloc(sizeof(Cash)))) elog(ERROR, "Memory allocation failed, can't subtract cash", NULL); *result = (*c1 - *c2); @@ -385,7 +385,7 @@ cash_mul_flt8(Cash *c, float8 *f) if (!PointerIsValid(f) || !PointerIsValid(c)) return (NULL); - if (!PointerIsValid(result = PALLOCTYPE(Cash))) + if (!PointerIsValid(result = palloc(sizeof(Cash)))) elog(ERROR, "Memory allocation failed, can't multiply cash", NULL); *result = ((*f) * (*c)); @@ -418,7 +418,7 @@ cash_div_flt8(Cash *c, float8 *f) if (!PointerIsValid(f) || !PointerIsValid(c)) return (NULL); - if (!PointerIsValid(result = PALLOCTYPE(Cash))) + if (!PointerIsValid(result = palloc(sizeof(Cash)))) elog(ERROR, "Memory allocation failed, can't divide cash", NULL); if (*f == 0.0) @@ -440,7 +440,7 @@ cash_mul_flt4(Cash *c, float4 *f) if (!PointerIsValid(f) || !PointerIsValid(c)) return (NULL); - if (!PointerIsValid(result = PALLOCTYPE(Cash))) + if (!PointerIsValid(result = palloc(sizeof(Cash)))) elog(ERROR, "Memory allocation failed, can't multiply cash", NULL); *result = ((*f) * (*c)); @@ -473,7 +473,7 @@ cash_div_flt4(Cash *c, float4 *f) if (!PointerIsValid(f) || !PointerIsValid(c)) return (NULL); - if (!PointerIsValid(result = PALLOCTYPE(Cash))) + if (!PointerIsValid(result = palloc(sizeof(Cash)))) elog(ERROR, "Memory allocation failed, can't divide cash", NULL); if (*f == 0.0) @@ -496,7 +496,7 @@ cash_mul_int4(Cash *c, int4 i) if (!PointerIsValid(c)) return (NULL); - if (!PointerIsValid(result = PALLOCTYPE(Cash))) + if (!PointerIsValid(result = palloc(sizeof(Cash)))) elog(ERROR, "Memory allocation failed, can't multiply cash", NULL); *result = ((i) * (*c)); @@ -529,7 +529,7 @@ cash_div_int4(Cash *c, int4 i) if (!PointerIsValid(c)) return (NULL); - if (!PointerIsValid(result = PALLOCTYPE(Cash))) + if (!PointerIsValid(result = palloc(sizeof(Cash)))) elog(ERROR, "Memory allocation failed, can't divide cash", NULL); if (i == 0) @@ -552,7 +552,7 @@ cash_mul_int2(Cash *c, int2 s) if (!PointerIsValid(c)) return (NULL); - if (!PointerIsValid(result = PALLOCTYPE(Cash))) + if (!PointerIsValid(result = palloc(sizeof(Cash)))) elog(ERROR, "Memory allocation failed, can't multiply cash", NULL); *result = ((s) * (*c)); @@ -585,7 +585,7 @@ cash_div_int2(Cash *c, int2 s) if (!PointerIsValid(c)) return (NULL); - if (!PointerIsValid(result = PALLOCTYPE(Cash))) + if (!PointerIsValid(result = palloc(sizeof(Cash)))) elog(ERROR, "Memory allocation failed, can't divide cash", NULL); if (s == 0) @@ -608,7 +608,7 @@ cashlarger(Cash *c1, Cash *c2) if (!PointerIsValid(c1) || !PointerIsValid(c2)) return (NULL); - if (!PointerIsValid(result = PALLOCTYPE(Cash))) + if (!PointerIsValid(result = palloc(sizeof(Cash)))) elog(ERROR, "Memory allocation failed, can't return larger cash", NULL); *result = ((*c1 > *c2) ? *c1 : *c2); @@ -628,7 +628,7 @@ cashsmaller(Cash *c1, Cash *c2) if (!PointerIsValid(c1) || !PointerIsValid(c2)) return (NULL); - if (!PointerIsValid(result = PALLOCTYPE(Cash))) + if (!PointerIsValid(result = palloc(sizeof(Cash)))) elog(ERROR, "Memory allocation failed, can't return smaller cash", NULL); *result = ((*c1 < *c2) ? *c1 : *c2); diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c index c42b9d0963..4959ea4e72 100644 --- a/src/backend/utils/adt/date.c +++ b/src/backend/utils/adt/date.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.21 1998/01/05 16:39:48 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.22 1998/01/07 18:46:37 momjian Exp $ * * NOTES * This code is actually (almost) unused. @@ -180,7 +180,7 @@ reltimeout(int32 time) EncodeTimeSpan(tm, 0, DateStyle, buf); } - result = PALLOC(strlen(buf) + 1); + result = palloc(strlen(buf) + 1); strcpy(result, buf); return (result); @@ -360,7 +360,7 @@ reltime_timespan(RelativeTime reltime) int year, month; - if (!PointerIsValid(result = PALLOCTYPE(TimeSpan))) + if (!PointerIsValid(result = palloc(sizeof(TimeSpan)))) elog(ERROR, "Memory allocation failed, can't convert reltime to timespan", NULL); switch (reltime) diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index 50c72c179f..4e6cea8db5 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.20 1998/01/05 16:39:50 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.21 1998/01/07 18:46:41 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -128,7 +128,7 @@ date_out(DateADT date) EncodeDateOnly(tm, DateStyle, buf); - result = PALLOC(strlen(buf) + 1); + result = palloc(strlen(buf) + 1); strcpy(result, buf); @@ -236,7 +236,7 @@ date_datetime(DateADT dateVal) double fsec = 0; char *tzn; - result = PALLOCTYPE(DateTime); + result = palloc(sizeof(DateTime)); if (date2tm(dateVal, &tz, tm, &fsec, &tzn) != 0) elog(ERROR, "Unable to convert date to datetime", NULL); @@ -453,7 +453,7 @@ time_in(char *str) if ((tm->tm_sec < 0) || ((tm->tm_sec + fsec) >= 60)) elog(ERROR, "Second must be limited to values 0 through < 60 in '%s'", str); - time = PALLOCTYPE(TimeADT); + time = palloc(sizeof(TimeADT)); *time = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec); @@ -482,7 +482,7 @@ time_out(TimeADT *time) EncodeTimeOnly(tm, fsec, DateStyle, buf); - result = PALLOC(strlen(buf) + 1); + result = palloc(strlen(buf) + 1); strcpy(result, buf); @@ -586,7 +586,7 @@ datetime_time(DateTime *datetime) elog(ERROR, "Unable to convert datetime to date", NULL); } - result = PALLOCTYPE(TimeADT); + result = palloc(sizeof(TimeADT)); *result = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec); @@ -604,7 +604,7 @@ datetime_datetime(DateADT date, TimeADT *time) if (!PointerIsValid(time)) { - result = PALLOCTYPE(DateTime); + result = palloc(sizeof(DateTime)); DATETIME_INVALID(*result); } else { result = date_datetime(date); diff --git a/src/backend/utils/adt/dt.c b/src/backend/utils/adt/dt.c index fec9b04b8f..6265d08490 100644 --- a/src/backend/utils/adt/dt.c +++ b/src/backend/utils/adt/dt.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.49 1998/01/05 16:39:55 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.50 1998/01/07 18:46:45 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -115,7 +115,7 @@ datetime_in(char *str) || (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0)) elog(ERROR, "Bad datetime external representation '%s'", str); - result = PALLOCTYPE(DateTime); + result = palloc(sizeof(DateTime)); switch (dtype) { @@ -188,7 +188,7 @@ datetime_out(DateTime *dt) EncodeSpecialDateTime(DT_INVALID, buf); } - result = PALLOC(strlen(buf) + 1); + result = palloc(strlen(buf) + 1); strcpy(result, buf); @@ -231,7 +231,7 @@ timespan_in(char *str) || (DecodeDateDelta(field, ftype, nf, &dtype, tm, &fsec) != 0)) elog(ERROR, "Bad timespan external representation '%s'", str); - span = PALLOCTYPE(TimeSpan); + span = palloc(sizeof(TimeSpan)); switch (dtype) { @@ -274,7 +274,7 @@ timespan_out(TimeSpan *span) if (EncodeTimeSpan(tm, fsec, DateStyle, buf) != 0) elog(ERROR, "Unable to format timespan", NULL); - result = PALLOC(strlen(buf) + 1); + result = palloc(strlen(buf) + 1); strcpy(result, buf); return (result); @@ -715,7 +715,7 @@ datetime_smaller(DateTime *datetime1, DateTime *datetime2) dt1 = *datetime1; dt2 = *datetime2; - result = PALLOCTYPE(DateTime); + result = palloc(sizeof(DateTime)); if (DATETIME_IS_RELATIVE(dt1)) dt1 = SetDateTime(dt1); @@ -752,7 +752,7 @@ datetime_larger(DateTime *datetime1, DateTime *datetime2) dt1 = *datetime1; dt2 = *datetime2; - result = PALLOCTYPE(DateTime); + result = palloc(sizeof(DateTime)); if (DATETIME_IS_RELATIVE(dt1)) dt1 = SetDateTime(dt1); @@ -790,7 +790,7 @@ datetime_mi(DateTime *datetime1, DateTime *datetime2) dt1 = *datetime1; dt2 = *datetime2; - result = PALLOCTYPE(TimeSpan); + result = palloc(sizeof(TimeSpan)); if (DATETIME_IS_RELATIVE(dt1)) dt1 = SetDateTime(dt1); @@ -836,7 +836,7 @@ datetime_pl_span(DateTime *datetime, TimeSpan *span) if ((!PointerIsValid(datetime)) || (!PointerIsValid(span))) return NULL; - result = PALLOCTYPE(DateTime); + result = palloc(sizeof(DateTime)); #ifdef DATEDEBUG printf("datetime_pl_span- add %f to %d %f\n", *datetime, span->month, span->time); @@ -945,7 +945,7 @@ timespan_um(TimeSpan *timespan) if (!PointerIsValid(timespan)) return NULL; - result = PALLOCTYPE(TimeSpan); + result = palloc(sizeof(TimeSpan)); result->time = -(timespan->time); result->month = -(timespan->month); @@ -965,7 +965,7 @@ timespan_smaller(TimeSpan *timespan1, TimeSpan *timespan2) if (!PointerIsValid(timespan1) || !PointerIsValid(timespan2)) return NULL; - result = PALLOCTYPE(TimeSpan); + result = palloc(sizeof(TimeSpan)); if (TIMESPAN_IS_INVALID(*timespan1)) { @@ -1020,7 +1020,7 @@ timespan_larger(TimeSpan *timespan1, TimeSpan *timespan2) if (!PointerIsValid(timespan1) || !PointerIsValid(timespan2)) return NULL; - result = PALLOCTYPE(TimeSpan); + result = palloc(sizeof(TimeSpan)); if (TIMESPAN_IS_INVALID(*timespan1)) { @@ -1073,7 +1073,7 @@ timespan_pl(TimeSpan *span1, TimeSpan *span2) if ((!PointerIsValid(span1)) || (!PointerIsValid(span2))) return NULL; - result = PALLOCTYPE(TimeSpan); + result = palloc(sizeof(TimeSpan)); result->month = (span1->month + span2->month); result->time = JROUND(span1->time + span2->time); @@ -1089,7 +1089,7 @@ timespan_mi(TimeSpan *span1, TimeSpan *span2) if ((!PointerIsValid(span1)) || (!PointerIsValid(span2))) return NULL; - result = PALLOCTYPE(TimeSpan); + result = palloc(sizeof(TimeSpan)); result->month = (span1->month - span2->month); result->time = JROUND(span1->time - span2->time); @@ -1105,7 +1105,7 @@ timespan_div(TimeSpan *span1, float8 *arg2) if ((!PointerIsValid(span1)) || (!PointerIsValid(arg2))) return NULL; - if (!PointerIsValid(result = PALLOCTYPE(TimeSpan))) + if (!PointerIsValid(result = palloc(sizeof(TimeSpan)))) elog(ERROR, "Memory allocation failed, can't subtract timespans", NULL); if (*arg2 == 0.0) @@ -1143,7 +1143,7 @@ datetime_age(DateTime *datetime1, DateTime *datetime2) if (!PointerIsValid(datetime1) || !PointerIsValid(datetime2)) return NULL; - result = PALLOCTYPE(TimeSpan); + result = palloc(sizeof(TimeSpan)); dt1 = *datetime1; dt2 = *datetime2; @@ -1287,12 +1287,12 @@ datetime_text(DateTime *datetime) len = (strlen(str) + VARHDRSZ); - result = PALLOC(len); + result = palloc(len); VARSIZE(result) = len; memmove(VARDATA(result), str, (len - VARHDRSZ)); - PFREE(str); + pfree(str); return (result); } /* datetime_text() */ @@ -1347,12 +1347,12 @@ timespan_text(TimeSpan *timespan) len = (strlen(str) + VARHDRSZ); - result = PALLOC(len); + result = palloc(len); VARSIZE(result) = len; memmove(VARDATA(result), str, (len - VARHDRSZ)); - PFREE(str); + pfree(str); return (result); } /* timespan_text() */ @@ -1410,7 +1410,7 @@ datetime_trunc(text *units, DateTime *datetime) if ((!PointerIsValid(units)) || (!PointerIsValid(datetime))) return NULL; - result = PALLOCTYPE(DateTime); + result = palloc(sizeof(DateTime)); up = VARDATA(units); lp = lowunits; @@ -1555,7 +1555,7 @@ timespan_trunc(text *units, TimeSpan *timespan) if ((!PointerIsValid(units)) || (!PointerIsValid(timespan))) return NULL; - result = PALLOCTYPE(TimeSpan); + result = palloc(sizeof(TimeSpan)); up = VARDATA(units); lp = lowunits; @@ -1684,7 +1684,7 @@ datetime_part(text *units, DateTime *datetime) if ((!PointerIsValid(units)) || (!PointerIsValid(datetime))) return NULL; - result = PALLOCTYPE(float64data); + result = palloc(sizeof(float64data)); up = VARDATA(units); lp = lowunits; @@ -1841,7 +1841,7 @@ timespan_part(text *units, TimeSpan *timespan) if ((!PointerIsValid(units)) || (!PointerIsValid(timespan))) return NULL; - result = PALLOCTYPE(float64data); + result = palloc(sizeof(float64data)); up = VARDATA(units); lp = lowunits; @@ -2031,7 +2031,7 @@ datetime_zone(text *zone, DateTime *datetime) len = (strlen(buf) + VARHDRSZ); - result = PALLOC(len); + result = palloc(len); VARSIZE(result) = len; memmove(VARDATA(result), buf, (len - VARHDRSZ)); diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c index 50f87bd497..0978970313 100644 --- a/src/backend/utils/adt/geo_ops.c +++ b/src/backend/utils/adt/geo_ops.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.28 1998/01/05 16:40:02 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.29 1998/01/07 18:46:47 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -272,7 +272,7 @@ path_decode(int opentype, int npts, char *str, int *isopen, char **ss, Point *p) static char * path_encode(bool closed, int npts, Point *pt) { - char *result = PALLOC(npts * (P_MAXLEN + 3) + 2); + char *result = palloc(npts * (P_MAXLEN + 3) + 2); char *cp; int i; @@ -356,7 +356,7 @@ pair_count(char *s, char delim) BOX * box_in(char *str) { - BOX *box = PALLOCTYPE(BOX); + BOX *box = palloc(sizeof(BOX)); int isopen; char *s; @@ -404,7 +404,7 @@ box_out(BOX *box) static BOX * box_construct(double x1, double x2, double y1, double y2) { - BOX *result = PALLOCTYPE(BOX); + BOX *result = palloc(sizeof(BOX)); return (box_fill(result, x1, x2, y1, y2)); } @@ -445,7 +445,7 @@ box_fill(BOX *result, double x1, double x2, double y1, double y2) static BOX * box_copy(BOX *box) { - BOX *result = PALLOCTYPE(BOX); + BOX *result = palloc(sizeof(BOX)); memmove((char *) result, (char *) box, sizeof(BOX)); @@ -601,7 +601,7 @@ box_ge(BOX *box1, BOX *box2) double * box_area(BOX *box) { - double *result = PALLOCTYPE(double); + double *result = palloc(sizeof(double)); *result = box_wd(box) * box_ht(box); @@ -615,7 +615,7 @@ box_area(BOX *box) double * box_width(BOX *box) { - double *result = PALLOCTYPE(double); + double *result = palloc(sizeof(double)); *result = box->high.x - box->low.x; @@ -629,7 +629,7 @@ box_width(BOX *box) double * box_height(BOX *box) { - double *result = PALLOCTYPE(double); + double *result = palloc(sizeof(double)); *result = box->high.y - box->low.y; @@ -643,7 +643,7 @@ box_height(BOX *box) double * box_distance(BOX *box1, BOX *box2) { - double *result = PALLOCTYPE(double); + double *result = palloc(sizeof(double)); Point *a, *b; @@ -651,8 +651,8 @@ box_distance(BOX *box1, BOX *box2) b = box_center(box2); *result = HYPOT(a->x - b->x, a->y - b->y); - PFREE(a); - PFREE(b); + pfree(a); + pfree(b); return (result); } @@ -662,7 +662,7 @@ box_distance(BOX *box1, BOX *box2) Point * box_center(BOX *box) { - Point *result = PALLOCTYPE(Point); + Point *result = palloc(sizeof(Point)); result->x = (box->high.x + box->low.x) / 2.0; result->y = (box->high.y + box->low.y) / 2.0; @@ -715,8 +715,8 @@ box_dt(BOX *box1, BOX *box2) b = box_center(box2); result = HYPOT(a->x - b->x, a->y - b->y); - PFREE(a); - PFREE(b); + pfree(a); + pfree(b); return (result); } @@ -738,7 +738,7 @@ box_intersect(BOX *box1, BOX *box2) if (!box_overlap(box1, box2)) return (NULL); - result = PALLOCTYPE(BOX); + result = palloc(sizeof(BOX)); result->high.x = Min(box1->high.x, box2->high.x); result->low.x = Max(box1->low.x, box2->low.x); @@ -785,7 +785,7 @@ box_diagonal(BOX *box) static LINE * /* point-slope */ line_construct_pm(Point *pt, double m) { - LINE *result = PALLOCTYPE(LINE); + LINE *result = palloc(sizeof(LINE)); /* use "mx - y + yinter = 0" */ result->A = m; @@ -801,7 +801,7 @@ line_construct_pm(Point *pt, double m) static LINE * /* two points */ line_construct_pp(Point *pt1, Point *pt2) { - LINE *result = PALLOCTYPE(LINE); + LINE *result = palloc(sizeof(LINE)); if (FPeq(pt1->x, pt2->x)) { /* vertical */ @@ -941,7 +941,7 @@ line_eq(LINE *l1, LINE *l2) double * /* distance between l1, l2 */ line_distance(LINE *l1, LINE *l2) { - double *result = PALLOCTYPE(double); + double *result = palloc(sizeof(double)); Point *tmp; if (line_intersect(l1, l2)) @@ -955,7 +955,7 @@ line_distance(LINE *l1, LINE *l2) { tmp = point_construct(0.0, l1->C); result = dist_pl(tmp, l2); - PFREE(tmp); + pfree(tmp); } return (result); } @@ -1075,7 +1075,7 @@ path_in(char *str) } size = offsetof(PATH, p[0]) +(sizeof(path->p[0]) * npts); - path = PALLOC(size); + path = palloc(size); path->size = size; path->npts = npts; @@ -1208,7 +1208,7 @@ path_copy(PATH *path) int size; size = offsetof(PATH, p[0]) +(sizeof(path->p[0]) * path->npts); - result = PALLOC(size); + result = palloc(size); memmove((char *) result, (char *) path, size); return (result); @@ -1295,12 +1295,12 @@ path_distance(PATH *p1, PATH *p2) if ((min == NULL) || (*min < *tmp)) { if (min != NULL) - PFREE(min); + pfree(min); min = tmp; } else { - PFREE(tmp); + pfree(tmp); } } @@ -1318,7 +1318,7 @@ path_length(PATH *path) double *result; int i; - result = PALLOCTYPE(double); + result = palloc(sizeof(double)); *result = 0; for (i = 0; i < (path->npts - 1); i++) @@ -1372,7 +1372,7 @@ point_in(char *str) if (!pair_decode(str, &x, &y, &s) || (strlen(s) > 0)) elog(ERROR, "Bad point external representation '%s'", str); - point = PALLOCTYPE(Point); + point = palloc(sizeof(Point)); point->x = x; point->y = y; @@ -1393,7 +1393,7 @@ point_out(Point *pt) static Point * point_construct(double x, double y) { - Point *result = PALLOCTYPE(Point); + Point *result = palloc(sizeof(Point)); result->x = x; result->y = y; @@ -1409,7 +1409,7 @@ point_copy(Point *pt) if (!PointerIsValid(pt)) return (NULL); - result = PALLOCTYPE(Point); + result = palloc(sizeof(Point)); result->x = pt->x; result->y = pt->y; @@ -1490,7 +1490,7 @@ pointdist(Point *p1, Point *p2) double * point_distance(Point *pt1, Point *pt2) { - double *result = PALLOCTYPE(double); + double *result = palloc(sizeof(double)); *result = HYPOT(pt1->x - pt2->x, pt1->y - pt2->y); return (result); @@ -1506,7 +1506,7 @@ point_dt(Point *pt1, Point *pt2) double * point_slope(Point *pt1, Point *pt2) { - double *result = PALLOCTYPE(double); + double *result = palloc(sizeof(double)); if (point_vert(pt1, pt2)) *result = (double) DBL_MAX; @@ -1551,7 +1551,7 @@ lseg_in(char *str) if (!PointerIsValid(str)) elog(ERROR, " Bad (null) lseg external representation", NULL); - lseg = PALLOCTYPE(LSEG); + lseg = palloc(sizeof(LSEG)); if ((!path_decode(TRUE, 2, str, &isopen, &s, &(lseg->p[0]))) || (*s != '\0')) @@ -1579,7 +1579,7 @@ lseg_out(LSEG *ls) LSEG * lseg_construct(Point *pt1, Point *pt2) { - LSEG *result = PALLOCTYPE(LSEG); + LSEG *result = palloc(sizeof(LSEG)); result->p[0].x = pt1->x; result->p[0].y = pt1->y; @@ -1626,8 +1626,8 @@ lseg_intersect(LSEG *l1, LSEG *l2) else retval = FALSE; if (interpt != NULL) - PFREE(interpt); - PFREE(ln); + pfree(interpt); + pfree(ln); return (retval); } @@ -1692,7 +1692,7 @@ lseg_eq(LSEG *l1, LSEG *l2) double * lseg_distance(LSEG *l1, LSEG *l2) { - double *result = PALLOCTYPE(double); + double *result = palloc(sizeof(double)); *result = lseg_dt(l1, l2); @@ -1711,20 +1711,20 @@ lseg_dt(LSEG *l1, LSEG *l2) d = dist_ps(&l1->p[0], l2); result = *d; - PFREE(d); + pfree(d); d = dist_ps(&l1->p[1], l2); result = Min(result, *d); - PFREE(d); + pfree(d); #if FALSE /* XXX Why are we checking distances from all endpoints to the other segment? * One set of endpoints should be sufficient - tgl 97/07/03 */ d = dist_ps(&l2->p[0], l1); result = Min(result, *d); - PFREE(d); + pfree(d); d = dist_ps(&l2->p[1], l1); result = Min(result, *d); - PFREE(d); + pfree(d); #endif return (result); @@ -1739,7 +1739,7 @@ lseg_center(LSEG *lseg) if (!PointerIsValid(lseg)) return (NULL); - result = PALLOCTYPE(Point); + result = palloc(sizeof(Point)); result->x = (lseg->p[0].x - lseg->p[1].x) / 2; result->y = (lseg->p[0].y - lseg->p[1].y) / 2; @@ -1790,12 +1790,12 @@ lseg_interpt(LSEG *l1, LSEG *l2) } else { - PFREE(result); + pfree(result); result = NULL; } } - PFREE(tmp1); - PFREE(tmp2); + pfree(tmp1); + pfree(tmp2); return (result); } /* lseg_interpt() */ @@ -1820,7 +1820,7 @@ lseg_interpt(LSEG *l1, LSEG *l2) double * dist_pl(Point *pt, LINE *line) { - double *result = PALLOCTYPE(double); + double *result = palloc(sizeof(double)); *result = (line->A * pt->x + line->B * pt->y + line->C) / HYPOT(line->A, line->B); @@ -1886,12 +1886,12 @@ dist_ps(Point *pt, LSEG *lseg) tmpdist = point_distance(pt, &lseg->p[1]); if (*tmpdist < *result) *result = *tmpdist; - PFREE(tmpdist); + pfree(tmpdist); } if (ip != NULL) - PFREE(ip); - PFREE(ln); + pfree(ip); + pfree(ln); return (result); } @@ -1925,14 +1925,14 @@ dist_ppath(Point *pt, PATH *path) * the distance from a point to a path is the smallest * distance from the point to any of its constituent segments. */ - result = PALLOCTYPE(double); + result = palloc(sizeof(double)); for (i = 0; i < path->npts - 1; i++) { statlseg_construct(&lseg, &path->p[i], &path->p[i + 1]); tmp = dist_ps(pt, &lseg); if (i == 0 || *tmp < *result) *result = *tmp; - PFREE(tmp); + pfree(tmp); } break; } @@ -1947,7 +1947,7 @@ dist_pb(Point *pt, BOX *box) tmp = close_pb(pt, box); result = point_distance(tmp, pt); - PFREE(tmp); + pfree(tmp); return (result); } @@ -1961,7 +1961,7 @@ dist_sl(LSEG *lseg, LINE *line) if (inter_sl(lseg, line)) { - result = PALLOCTYPE(double); + result = palloc(sizeof(double)); *result = 0.0; } @@ -1971,12 +1971,12 @@ dist_sl(LSEG *lseg, LINE *line) d2 = dist_pl(&lseg->p[1], line); if (*d2 > *result) { - PFREE(result); + pfree(result); result = d2; } else { - PFREE(d2); + pfree(d2); } } @@ -1993,13 +1993,13 @@ dist_sb(LSEG *lseg, BOX *box) tmp = close_sb(lseg, box); if (tmp == NULL) { - result = PALLOCTYPE(double); + result = palloc(sizeof(double)); *result = 0.0; } else { result = dist_pb(tmp, box); - PFREE(tmp); + pfree(tmp); } return (result); @@ -2015,13 +2015,13 @@ dist_lb(LINE *line, BOX *box) tmp = close_lb(line, box); if (tmp == NULL) { - result = PALLOCTYPE(double); + result = palloc(sizeof(double)); *result = 0.0; } else { result = dist_pb(tmp, box); - PFREE(tmp); + pfree(tmp); } return (result); @@ -2044,7 +2044,7 @@ dist_cpoly(CIRCLE *circle, POLYGON *poly) #ifdef GEODEBUG printf("dist_cpoly- center inside of polygon\n"); #endif - result = PALLOCTYPE(double); + result = palloc(sizeof(double)); *result = 0; return (result); @@ -2073,7 +2073,7 @@ dist_cpoly(CIRCLE *circle, POLYGON *poly) #endif if (*d < *result) *result = *d; - PFREE(d); + pfree(d); } *result -= circle->radius; @@ -2119,12 +2119,12 @@ interpt_sl(LSEG *lseg, LINE *line) } else { - PFREE(p); + pfree(p); p = NULL; } } - PFREE(tmp); + pfree(tmp); return (p); } @@ -2145,7 +2145,7 @@ close_pl(Point *pt, LINE *line) LINE *tmp; double invm; - result = PALLOCTYPE(Point); + result = palloc(sizeof(Point)); #if FALSE if (FPeq(line->A, -1.0) && FPzero(line->B)) { /* vertical */ @@ -2264,8 +2264,8 @@ close_sl(LSEG *lseg, LINE *line) else result = point_copy(&lseg->p[1]); - PFREE(d1); - PFREE(d2); + pfree(d1); + pfree(d2); return (result); } @@ -2469,7 +2469,7 @@ inter_sl(LSEG *lseg, LINE *line) tmp = interpt_sl(lseg, line); if (tmp) { - PFREE(tmp); + pfree(tmp); return (1); } return (0); @@ -2559,7 +2559,7 @@ poly_in(char *str) elog(ERROR, "Bad polygon external representation '%s'", str); size = offsetof(POLYGON, p[0]) +(sizeof(poly->p[0]) * npts); - poly = PALLOC(size); + poly = palloc(size); MemSet((char *) poly, 0, size); /* zero any holes */ poly->size = size; @@ -2784,7 +2784,7 @@ poly_distance(POLYGON *polya, POLYGON *polyb) if (!PointerIsValid(polya) || !PointerIsValid(polyb)) return (NULL); - result = PALLOCTYPE(double); + result = palloc(sizeof(double)); *result = 0; @@ -2816,7 +2816,7 @@ point_add(Point *p1, Point *p2) if (!(PointerIsValid(p1) && PointerIsValid(p2))) return (NULL); - result = PALLOCTYPE(Point); + result = palloc(sizeof(Point)); result->x = (p1->x + p2->x); result->y = (p1->y + p2->y); @@ -2832,7 +2832,7 @@ point_sub(Point *p1, Point *p2) if (!(PointerIsValid(p1) && PointerIsValid(p2))) return (NULL); - result = PALLOCTYPE(Point); + result = palloc(sizeof(Point)); result->x = (p1->x - p2->x); result->y = (p1->y - p2->y); @@ -2848,7 +2848,7 @@ point_mul(Point *p1, Point *p2) if (!(PointerIsValid(p1) && PointerIsValid(p2))) return (NULL); - result = PALLOCTYPE(Point); + result = palloc(sizeof(Point)); result->x = (p1->x * p2->x) - (p1->y * p2->y); result->y = (p1->x * p2->y) + (p1->y * p2->x); @@ -2865,7 +2865,7 @@ point_div(Point *p1, Point *p2) if (!(PointerIsValid(p1) && PointerIsValid(p2))) return (NULL); - result = PALLOCTYPE(Point); + result = palloc(sizeof(Point)); div = (p2->x * p2->x) + (p2->y * p2->y); @@ -2940,8 +2940,8 @@ box_mul(BOX *box, Point *p) low = point_mul(&box->low, p); result = box_construct(high->x, low->x, high->y, low->y); - PFREE(high); - PFREE(low); + pfree(high); + pfree(low); return (result); } /* box_mul() */ @@ -2960,8 +2960,8 @@ box_div(BOX *box, Point *p) low = point_div(&box->low, p); result = box_construct(high->x, low->x, high->y, low->y); - PFREE(high); - PFREE(low); + pfree(high); + pfree(low); return (result); } /* box_div() */ @@ -2998,7 +2998,7 @@ path_add(PATH *p1, PATH *p2) return (NULL); size = offsetof(PATH, p[0]) +(sizeof(p1->p[0]) * (p1->npts + p2->npts)); - result = PALLOC(size); + result = palloc(size); result->size = size; result->npts = (p1->npts + p2->npts); @@ -3082,7 +3082,7 @@ path_mul_pt(PATH *path, Point *point) p = point_mul(&path->p[i], point); result->p[i].x = p->x; result->p[i].y = p->y; - PFREE(p); + pfree(p); } return (result); @@ -3105,7 +3105,7 @@ path_div_pt(PATH *path, Point *point) p = point_div(&path->p[i], point); result->p[i].x = p->x; result->p[i].y = p->y; - PFREE(p); + pfree(p); } return (result); @@ -3141,7 +3141,7 @@ path_center(PATH *path) elog(ERROR, "path_center not implemented", NULL); - result = PALLOCTYPE(Point); + result = palloc(sizeof(Point)); result = NULL; return (result); @@ -3161,7 +3161,7 @@ path_poly(PATH *path) elog(ERROR, "Open path cannot be converted to polygon", NULL); size = offsetof(POLYGON, p[0]) +(sizeof(poly->p[0]) * path->npts); - poly = PALLOC(size); + poly = palloc(size); poly->size = size; poly->npts = path->npts; @@ -3201,7 +3201,7 @@ upgradepath(PATH *path) npts = (path->npts - 1); size = offsetof(PATH, p[0]) +(sizeof(path->p[0]) * npts); - result = PALLOC(size); + result = palloc(size); MemSet((char *) result, 0, size); result->size = size; @@ -3255,7 +3255,7 @@ poly_center(POLYGON *poly) if (PointerIsValid(circle = poly_circle(poly))) { result = circle_center(circle); - PFREE(circle); + pfree(circle); } else @@ -3295,7 +3295,7 @@ box_poly(BOX *box) /* map four corners of the box to a polygon */ size = offsetof(POLYGON, p[0]) +(sizeof(poly->p[0]) * 4); - poly = PALLOC(size); + poly = palloc(size); poly->size = size; poly->npts = 4; @@ -3326,7 +3326,7 @@ poly_path(POLYGON *poly) return (NULL); size = offsetof(PATH, p[0]) +(sizeof(path->p[0]) * poly->npts); - path = PALLOC(size); + path = palloc(size); path->size = size; path->npts = poly->npts; @@ -3360,7 +3360,7 @@ upgradepoly(POLYGON *poly) return (NULL); size = offsetof(POLYGON, p[0]) +(sizeof(poly->p[0]) * poly->npts); - result = PALLOC(size); + result = palloc(size); MemSet((char *) result, 0, size); result->size = size; @@ -3406,7 +3406,7 @@ revertpoly(POLYGON *poly) return (NULL); size = offsetof(POLYGON, p[0]) +(sizeof(poly->p[0]) * poly->npts); - result = PALLOC(size); + result = palloc(size); MemSet((char *) result, 0, size); result->size = size; @@ -3465,7 +3465,7 @@ circle_in(char *str) if (!PointerIsValid(str)) elog(ERROR, " Bad (null) circle external representation", NULL); - circle = PALLOCTYPE(CIRCLE); + circle = palloc(sizeof(CIRCLE)); s = str; while (isspace(*s)) @@ -3526,7 +3526,7 @@ circle_out(CIRCLE *circle) if (!PointerIsValid(circle)) return (NULL); - result = PALLOC(3 * (P_MAXLEN + 1) + 3); + result = palloc(3 * (P_MAXLEN + 1) + 3); cp = result; *cp++ = LDELIM_C; @@ -3694,7 +3694,7 @@ circle_copy(CIRCLE *circle) if (!PointerIsValid(circle)) return NULL; - result = PALLOCTYPE(CIRCLE); + result = palloc(sizeof(CIRCLE)); memmove((char *) result, (char *) circle, sizeof(CIRCLE)); return (result); @@ -3754,7 +3754,7 @@ circle_mul_pt(CIRCLE *circle, Point *point) p = point_mul(&circle->center, point); result->center.x = p->x; result->center.y = p->y; - PFREE(p); + pfree(p); result->radius *= HYPOT(point->x, point->y); return (result); @@ -3774,7 +3774,7 @@ circle_div_pt(CIRCLE *circle, Point *point) p = point_div(&circle->center, point); result->center.x = p->x; result->center.y = p->y; - PFREE(p); + pfree(p); result->radius /= HYPOT(point->x, point->y); return (result); @@ -3788,7 +3788,7 @@ circle_area(CIRCLE *circle) { double *result; - result = PALLOCTYPE(double); + result = palloc(sizeof(double)); *result = circle_ar(circle); return (result); @@ -3802,7 +3802,7 @@ circle_diameter(CIRCLE *circle) { double *result; - result = PALLOCTYPE(double); + result = palloc(sizeof(double)); *result = (2 * circle->radius); return (result); @@ -3816,7 +3816,7 @@ circle_radius(CIRCLE *circle) { double *result; - result = PALLOCTYPE(double); + result = palloc(sizeof(double)); *result = circle->radius; return (result); @@ -3831,7 +3831,7 @@ circle_distance(CIRCLE *circle1, CIRCLE *circle2) { double *result; - result = PALLOCTYPE(double); + result = palloc(sizeof(double)); *result = (point_dt(&circle1->center, &circle2->center) - (circle1->radius + circle2->radius)); if (*result < 0) @@ -3852,7 +3852,7 @@ circle_contain_pt(CIRCLE *circle, Point *point) d = point_distance(&(circle->center), point); within = (*d <= circle->radius); - PFREE(d); + pfree(d); return (within); } /* circle_contain_pt() */ @@ -3873,7 +3873,7 @@ dist_pc(Point *point, CIRCLE *circle) { double *result; - result = PALLOCTYPE(double); + result = palloc(sizeof(double)); *result = (point_dt(point, &circle->center) - circle->radius); if (*result < 0) @@ -3890,7 +3890,7 @@ circle_center(CIRCLE *circle) { Point *result; - result = PALLOCTYPE(Point); + result = palloc(sizeof(Point)); result->x = circle->center.x; result->y = circle->center.y; @@ -3935,7 +3935,7 @@ circle(Point *center, float8 *radius) if (!(PointerIsValid(center) && PointerIsValid(radius))) return (NULL); - result = PALLOCTYPE(CIRCLE); + result = palloc(sizeof(CIRCLE)); result->center.x = center->x; result->center.y = center->y; @@ -3954,7 +3954,7 @@ circle_box(CIRCLE *circle) if (!PointerIsValid(circle)) return (NULL); - box = PALLOCTYPE(BOX); + box = palloc(sizeof(BOX)); delta = circle->radius / sqrt(2.0e0); @@ -3977,7 +3977,7 @@ box_circle(BOX *box) if (!PointerIsValid(box)) return (NULL); - circle = PALLOCTYPE(CIRCLE); + circle = palloc(sizeof(CIRCLE)); circle->center.x = (box->high.x + box->low.x) / 2; circle->center.y = (box->high.y + box->low.y) / 2; @@ -4003,7 +4003,7 @@ circle_poly(int npts, CIRCLE *circle) elog(ERROR, "Unable to convert circle to polygon", NULL); size = offsetof(POLYGON, p[0]) +(sizeof(poly->p[0]) * npts); - poly = PALLOC(size); + poly = palloc(size); MemSet((char *) poly, 0, size); /* zero any holes */ poly->size = size; @@ -4038,7 +4038,7 @@ poly_circle(POLYGON *poly) if (poly->npts < 2) elog(ERROR, "Unable to convert polygon to circle", NULL); - circle = PALLOCTYPE(CIRCLE); + circle = palloc(sizeof(CIRCLE)); circle->center.x = 0; circle->center.y = 0; diff --git a/src/backend/utils/adt/int.c b/src/backend/utils/adt/int.c index c33920e851..43d0d372be 100644 --- a/src/backend/utils/adt/int.c +++ b/src/backend/utils/adt/int.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.12 1998/01/05 16:40:06 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.13 1998/01/07 18:46:49 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -250,12 +250,12 @@ int2_text(int16 arg1) str = int2out(arg1); len = (strlen(str) + VARHDRSZ); - result = PALLOC(len); + result = palloc(len); VARSIZE(result) = len; memmove(VARDATA(result), str, (len - VARHDRSZ)); - PFREE(str); + pfree(str); return(result); } /* int2_text() */ @@ -270,12 +270,12 @@ text_int2(text *string) len = (VARSIZE(string) - VARHDRSZ); - str = PALLOC(len+1); + str = palloc(len+1); memmove(str, VARDATA(string), len); *(str+len) = '\0'; result = int2in(str); - PFREE(str); + pfree(str); return(result); } /* text_int2() */ @@ -291,12 +291,12 @@ int4_text(int32 arg1) str = int4out(arg1); len = (strlen(str) + VARHDRSZ); - result = PALLOC(len); + result = palloc(len); VARSIZE(result) = len; memmove(VARDATA(result), str, (len - VARHDRSZ)); - PFREE(str); + pfree(str); return(result); } /* int4_text() */ @@ -311,12 +311,12 @@ text_int4(text *string) len = (VARSIZE(string) - VARHDRSZ); - str = PALLOC(len+1); + str = palloc(len+1); memmove(str, VARDATA(string), len); *(str+len) = '\0'; result = int4in(str); - PFREE(str); + pfree(str); return(result); } /* text_int4() */ diff --git a/src/backend/utils/adt/nabstime.c b/src/backend/utils/adt/nabstime.c index f35940c4fb..85e8381471 100644 --- a/src/backend/utils/adt/nabstime.c +++ b/src/backend/utils/adt/nabstime.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.38 1998/01/05 16:40:07 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.39 1998/01/07 18:46:50 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -345,7 +345,7 @@ nabstimeout(AbsoluteTime time) break; } - result = PALLOC(strlen(buf) + 1); + result = palloc(strlen(buf) + 1); strcpy(result, buf); return (result); @@ -546,7 +546,7 @@ abstime_datetime(AbsoluteTime abstime) { DateTime *result; - if (!PointerIsValid(result = PALLOCTYPE(DateTime))) + if (!PointerIsValid(result = palloc(sizeof(DateTime)))) elog(ERROR, "Unable to allocate space to convert abstime to datetime", NULL); switch (abstime) diff --git a/src/backend/utils/adt/oid.c b/src/backend/utils/adt/oid.c index 5ab41769b7..27f4a83885 100644 --- a/src/backend/utils/adt/oid.c +++ b/src/backend/utils/adt/oid.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.12 1997/10/25 05:21:54 thomas Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.13 1998/01/07 18:46:50 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -150,11 +150,11 @@ oid_text(Oid oid) str = oidout(oid); len = (strlen(str) + VARHDRSZ); - result = PALLOC(len); + result = palloc(len); VARSIZE(result) = len; memmove(VARDATA(result), str, (len-VARHDRSZ)); - PFREE(str); + pfree(str); return(result); } /* oid_text() */ @@ -169,12 +169,12 @@ text_oid(text *string) len = (VARSIZE(string) - VARHDRSZ); - str = PALLOC(len+1); + str = palloc(len+1); memmove(str, VARDATA(string), len); *(str+len) = '\0'; result = oidin(str); - PFREE(str); + pfree(str); return(result); } /* oid_text() */ diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c index 78cae3f1f8..c5a9bb8232 100644 --- a/src/backend/utils/adt/varchar.c +++ b/src/backend/utils/adt/varchar.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.16 1998/01/05 16:40:18 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.17 1998/01/07 18:46:52 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -70,16 +70,14 @@ bpcharin(char *s, int dummy, int typlen) typlen = len + VARHDRSZ; } else - { len = typlen - VARHDRSZ; - } if (len > 4096) elog(ERROR, "bpcharin: length of char() must be less than 4096"); result = (char *) palloc(typlen); - *(int32 *) result = typlen; - r = result + VARHDRSZ; + VARSIZE(result) = typlen; + r = VARDATA(result); for (i = 0; i < len; i++, r++, s++) { *r = *s; @@ -108,9 +106,9 @@ bpcharout(char *s) } else { - len = *(int32 *) s - VARHDRSZ; + len = VARSIZE(s) - VARHDRSZ; result = (char *) palloc(len + 1); - StrNCpy(result, s + VARHDRSZ, len+1); /* these are blank-padded */ + StrNCpy(result, VARDATA(s), len+1); /* these are blank-padded */ } return (result); } @@ -129,27 +127,21 @@ char * varcharin(char *s, int dummy, int typlen) { char *result; - int len = typlen - VARHDRSZ; + int len; if (s == NULL) return ((char *) NULL); - if (typlen == -1) - { - - /* - * this is here because some functions can't supply the typlen - */ - len = strlen(s); - typlen = len + VARHDRSZ; - } + len = strlen(s) + VARHDRSZ; + if (typlen != -1 && len > typlen) + len = typlen; /* clip the string at max length */ if (len > 4096) elog(ERROR, "varcharin: length of char() must be less than 4096"); - result = (char *) palloc(typlen); - *(int32 *) result = typlen; - strncpy(result + VARHDRSZ, s, len+1); + result = (char *) palloc(len); + VARSIZE(result) = len; + memmove(VARDATA(result), s, len - VARHDRSZ); return (result); } @@ -168,9 +160,9 @@ varcharout(char *s) } else { - len = *(int32 *) s - VARHDRSZ; + len = VARSIZE(s) - VARHDRSZ; result = (char *) palloc(len + 1); - StrNCpy(result, s + VARHDRSZ, len+1); + StrNCpy(result, VARDATA(s), len+1); } return (result); } @@ -182,11 +174,11 @@ varcharout(char *s) static int bcTruelen(char *arg) { - char *s = arg + VARHDRSZ; + char *s = VARDATA(arg); int i; int len; - len = *(int32 *) arg - VARHDRSZ; + len = VARSIZE(arg) - VARHDRSZ; for (i = len - 1; i >= 0; i--) { if (s[i] != ' ') @@ -218,7 +210,7 @@ bpchareq(char *arg1, char *arg2) if (len1 != len2) return 0; - return (strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, len1) == 0); + return (strncmp(VARDATA(arg1), VARDATA(arg2), len1) == 0); } bool @@ -235,7 +227,7 @@ bpcharne(char *arg1, char *arg2) if (len1 != len2) return 1; - return (strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, len1) != 0); + return (strncmp(VARDATA(arg1), VARDATA(arg2), len1) != 0); } bool @@ -250,7 +242,7 @@ bpcharlt(char *arg1, char *arg2) len1 = bcTruelen(arg1); len2 = bcTruelen(arg2); - cmp = strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, Min(len1, len2)); + cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); if (cmp == 0) return (len1 < len2); else @@ -269,7 +261,7 @@ bpcharle(char *arg1, char *arg2) len1 = bcTruelen(arg1); len2 = bcTruelen(arg2); - cmp = strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, Min(len1, len2)); + cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); if (0 == cmp) return (bool) (len1 <= len2 ? 1 : 0); else @@ -288,7 +280,7 @@ bpchargt(char *arg1, char *arg2) len1 = bcTruelen(arg1); len2 = bcTruelen(arg2); - cmp = strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, Min(len1, len2)); + cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); if (cmp == 0) return (len1 > len2); else @@ -307,7 +299,7 @@ bpcharge(char *arg1, char *arg2) len1 = bcTruelen(arg1); len2 = bcTruelen(arg2); - cmp = strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, Min(len1, len2)); + cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); if (0 == cmp) return (bool) (len1 >= len2 ? 1 : 0); else @@ -324,7 +316,7 @@ bpcharcmp(char *arg1, char *arg2) len1 = bcTruelen(arg1); len2 = bcTruelen(arg2); - cmp = strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, Min(len1, len2)); + cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); if ((0 == cmp) && (len1 != len2)) return (int32) (len1 < len2 ? -1 : 1); else @@ -335,30 +327,14 @@ bpcharcmp(char *arg1, char *arg2) * Comparison Functions used for varchar *****************************************************************************/ -static int -vcTruelen(char *arg) -{ - char *s = arg + VARHDRSZ; - int i; - int len; - - len = *(int32 *) arg - VARHDRSZ; - for (i = 0; i < len; i++) - { - if (*s++ == '\0') - break; - } - return i; -} - int32 varcharlen(char *arg) { if (!PointerIsValid(arg)) elog(ERROR, "Bad (null) varchar() external representation", NULL); - return(vcTruelen(arg)); -} /* vclen() */ + return VARSIZE(arg); +} bool varchareq(char *arg1, char *arg2) @@ -368,13 +344,13 @@ varchareq(char *arg1, char *arg2) if (arg1 == NULL || arg2 == NULL) return ((bool) 0); - len1 = vcTruelen(arg1); - len2 = vcTruelen(arg2); + len1 = VARSIZE(arg1); + len2 = VARSIZE(arg2); if (len1 != len2) return 0; - return (strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, len1) == 0); + return (strncmp(VARDATA(arg1), VARDATA(arg2), len1) == 0); } bool @@ -385,13 +361,13 @@ varcharne(char *arg1, char *arg2) if (arg1 == NULL || arg2 == NULL) return ((bool) 0); - len1 = vcTruelen(arg1); - len2 = vcTruelen(arg2); + len1 = VARSIZE(arg1); + len2 = VARSIZE(arg2); if (len1 != len2) return 1; - return (strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, len1) != 0); + return (strncmp(VARDATA(arg1), VARDATA(arg2), len1) != 0); } bool @@ -403,10 +379,10 @@ varcharlt(char *arg1, char *arg2) if (arg1 == NULL || arg2 == NULL) return ((bool) 0); - len1 = vcTruelen(arg1); - len2 = vcTruelen(arg2); + len1 = VARSIZE(arg1); + len2 = VARSIZE(arg2); - cmp = strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, Min(len1, len2)); + cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); if (cmp == 0) return (len1 < len2); else @@ -422,10 +398,10 @@ varcharle(char *arg1, char *arg2) if (arg1 == NULL || arg2 == NULL) return ((bool) 0); - len1 = vcTruelen(arg1); - len2 = vcTruelen(arg2); + len1 = VARSIZE(arg1); + len2 = VARSIZE(arg2); - cmp = strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, Min(len1, len2)); + cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); if (0 == cmp) return (bool) (len1 <= len2 ? 1 : 0); else @@ -441,10 +417,10 @@ varchargt(char *arg1, char *arg2) if (arg1 == NULL || arg2 == NULL) return ((bool) 0); - len1 = vcTruelen(arg1); - len2 = vcTruelen(arg2); + len1 = VARSIZE(arg1); + len2 = VARSIZE(arg2); - cmp = strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, Min(len1, len2)); + cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); if (cmp == 0) return (len1 > len2); else @@ -460,10 +436,10 @@ varcharge(char *arg1, char *arg2) if (arg1 == NULL || arg2 == NULL) return ((bool) 0); - len1 = vcTruelen(arg1); - len2 = vcTruelen(arg2); + len1 = VARSIZE(arg1); + len2 = VARSIZE(arg2); - cmp = strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, Min(len1, len2)); + cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); if (0 == cmp) return (bool) (len1 >= len2 ? 1 : 0); else @@ -478,9 +454,9 @@ varcharcmp(char *arg1, char *arg2) len2; int cmp; - len1 = vcTruelen(arg1); - len2 = vcTruelen(arg2); - cmp = (strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, Min(len1, len2))); + len1 = VARSIZE(arg1); + len2 = VARSIZE(arg2); + cmp = (strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2))); if ((0 == cmp) && (len1 != len2)) return (int32) (len1 < len2 ? -1 : 1); else @@ -544,7 +520,7 @@ hashvarchar(struct varlena * key) int loop; keydata = VARDATA(key); - keylen = vcTruelen((char *) key); + keylen = VARSIZE((char *) key); #define HASHC n = *keydata++ + 65599 * n diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index 092dee702a..1fc611286c 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.28 1998/01/05 16:40:20 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.29 1998/01/07 18:46:54 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -236,7 +236,7 @@ textcat(text *t1, text *t2) while (len2 > 0 && VARDATA(t2)[len2 - 1] == '\0') len2--; - result = PALLOC(len = len1 + len2 + VARHDRSZ); + result = palloc(len = len1 + len2 + VARHDRSZ); /* Fill data field of result string... */ ptr = VARDATA(result); @@ -293,7 +293,7 @@ text_substr(text *string, int32 m, int32 n) n = (len-m); } - ret = (text *) PALLOC(VARHDRSZ + n); + ret = (text *) palloc(VARHDRSZ + n); VARSIZE(ret) = VARHDRSZ + n; memcpy(VARDATA(ret), VARDATA(string)+m, n); diff --git a/src/include/utils/geo_decls.h b/src/include/utils/geo_decls.h index 45ef116bfe..4df0cddd43 100644 --- a/src/include/utils/geo_decls.h +++ b/src/include/utils/geo_decls.h @@ -5,7 +5,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: geo_decls.h,v 1.15 1997/09/25 16:52:23 momjian Exp $ + * $Id: geo_decls.h,v 1.16 1998/01/07 18:46:59 momjian Exp $ * * NOTE * These routines do *not* use the float types from adt/. @@ -21,8 +21,6 @@ #include "access/attnum.h" -/*#ifndef FmgrIncluded -- seems like always included. (it's FMgrIncluded) AY */ - /*-------------------------------------------------------------------- * Useful floating point utilities and constants. *-------------------------------------------------------------------*/ @@ -50,16 +48,6 @@ #define HYPOT(A, B) sqrt((A) * (A) + (B) * (B)) -/*-------------------------------------------------------------------- - * Memory management. - *-------------------------------------------------------------------*/ - -#define PALLOC(SIZE) palloc(SIZE) -#define PFREE(P) pfree(P) -#define PALLOCTYPE(TYPE) (TYPE *) PALLOC(sizeof(TYPE)) - -/*#endif !FmgrIncluded */ - /*--------------------------------------------------------------------- * Point - (x,y) *-------------------------------------------------------------------*/ diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c index 0ba658f800..656b023afc 100644 --- a/src/test/regress/regress.c +++ b/src/test/regress/regress.c @@ -1,5 +1,5 @@ /* - * $Header: /cvsroot/pgsql/src/test/regress/regress.c,v 1.20 1998/01/06 19:24:52 momjian Exp $ + * $Header: /cvsroot/pgsql/src/test/regress/regress.c,v 1.21 1998/01/07 18:47:07 momjian Exp $ */ #include /* faked on sunos */ @@ -43,7 +43,7 @@ PATH *path; switch (path->npts) { case 0: - result = PALLOCTYPE(double); + result = palloc(sizeof(double)); *result = Abs((double) DBL_MAX); /* +infinity */ break; case 1: @@ -56,14 +56,14 @@ PATH *path; * distance from the point to any of its constituent segments. */ Assert(path->npts > 1); - result = PALLOCTYPE(double); + result = palloc(sizeof(double)); for (i = 0; i < path->npts - 1; ++i) { regress_lseg_construct(&lseg, &path->p[i], &path->p[i + 1]); tmp = dist_ps(pt, &lseg); if (i == 0 || *tmp < *result) *result = *tmp; - PFREE(tmp); + pfree(tmp); } break; @@ -97,7 +97,7 @@ PATH *p2; if (*min < *(tmp = lseg_distance(&seg1, &seg2))) *min = *tmp; - PFREE(tmp); + pfree(tmp); } return (min); @@ -108,7 +108,7 @@ poly2path(poly) POLYGON *poly; { int i; - char *output = (char *) PALLOC(2 * (P_MAXDIG + 1) * poly->npts + 64); + char *output = (char *) palloc(2 * (P_MAXDIG + 1) * poly->npts + 64); char buf[2 * (P_MAXDIG) + 20]; sprintf(output, "(1, %*d", P_MAXDIG, poly->npts); -- 2.11.0