Commit e6c6146e authored by Bruce Momjian's avatar Bruce Momjian

Allow varchar() to only store needed bytes. Remove PALLOC,PALLOCTYPE,PFREE. ...

Allow varchar() to only store needed bytes.  Remove PALLOC,PALLOCTYPE,PFREE.  Clean up use of VARDATA.
parent 7a2a7d43
......@@ -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;
......
......@@ -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);
......
......@@ -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");
......
......@@ -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;
......
......@@ -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 <stdio.h>
......@@ -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);
......
......@@ -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)
......
......@@ -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);
......
......@@ -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));
......
This diff is collapsed.
......@@ -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() */
......
......@@ -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)
......
......@@ -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() */
......@@ -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
......
......@@ -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);
......
......@@ -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)
*-------------------------------------------------------------------*/
......
/*
* $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 <float.h> /* 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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment