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) ...@@ -66,7 +66,7 @@ hhmm_in(char *str)
elog(ERROR,"Second must be limited to values 0 through < 60 in '%s'", elog(ERROR,"Second must be limited to values 0 through < 60 in '%s'",
str); str);
time = PALLOCTYPE(TimeADT); time = palloc(sizeof(TimeADT));
*time = ((((tm->tm_hour*60)+tm->tm_min)*60)); *time = ((((tm->tm_hour*60)+tm->tm_min)*60));
...@@ -99,7 +99,7 @@ hhmm_out(TimeADT *time) ...@@ -99,7 +99,7 @@ hhmm_out(TimeADT *time)
sprintf(buf, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec); 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); strcpy( result, buf);
...@@ -109,7 +109,7 @@ hhmm_out(TimeADT *time) ...@@ -109,7 +109,7 @@ hhmm_out(TimeADT *time)
TimeADT * TimeADT *
hhmm(TimeADT *time) hhmm(TimeADT *time)
{ {
TimeADT *result = PALLOCTYPE(TimeADT); TimeADT *result = palloc(sizeof(TimeADT));
*result = (((int) *time) / 60 * 60); *result = (((int) *time) / 60 * 60);
...@@ -119,7 +119,7 @@ hhmm(TimeADT *time) ...@@ -119,7 +119,7 @@ hhmm(TimeADT *time)
TimeADT * TimeADT *
time_difference(TimeADT *time1, TimeADT *time2) time_difference(TimeADT *time1, TimeADT *time2)
{ {
TimeADT *time = PALLOCTYPE(TimeADT); TimeADT *time = palloc(sizeof(TimeADT));
*time = (*time1 - *time2); *time = (*time1 - *time2);
return(time); return(time);
...@@ -188,7 +188,7 @@ date_year(DateADT val) ...@@ -188,7 +188,7 @@ date_year(DateADT val)
TimeADT * TimeADT *
currenttime() currenttime()
{ {
TimeADT *result = PALLOCTYPE(TimeADT); TimeADT *result = palloc(sizeof(TimeADT));
struct tm *tm; struct tm *tm;
time_t current_time; time_t current_time;
......
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
#define MAXINT8LEN 25 #define MAXINT8LEN 25
#define USE_LOCAL_CODE 1
#if defined(__alpha) || defined(__GNUC__) #if defined(__alpha) || defined(__GNUC__)
#define HAVE_64BIT_INTS 1 #define HAVE_64BIT_INTS 1
#endif #endif
...@@ -79,18 +77,6 @@ int16 int82(int64 * val); ...@@ -79,18 +77,6 @@ int16 int82(int64 * val);
float64 i8tod(int64 * val); float64 i8tod(int64 * val);
int64 *dtoi8(float64 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. ** Routines for 64-bit integers.
...@@ -106,7 +92,7 @@ int64 *dtoi8(float64 val); ...@@ -106,7 +92,7 @@ int64 *dtoi8(float64 val);
int64 * int64 *
int8in(char *str) int8in(char *str)
{ {
int64 *result = PALLOCTYPE(int64); int64 *result = palloc(sizeof(int64));
#if HAVE_64BIT_INTS #if HAVE_64BIT_INTS
if (!PointerIsValid(str)) if (!PointerIsValid(str))
...@@ -141,7 +127,7 @@ int8out(int64 * val) ...@@ -141,7 +127,7 @@ int8out(int64 * val)
if ((len = snprintf(buf, MAXINT8LEN, INT64_FORMAT, *val)) < 0) if ((len = snprintf(buf, MAXINT8LEN, INT64_FORMAT, *val)) < 0)
elog(ERROR, "Unable to format int8", NULL); elog(ERROR, "Unable to format int8", NULL);
result = PALLOC(len + 1); result = palloc(len + 1);
strcpy(result, buf); strcpy(result, buf);
...@@ -245,7 +231,7 @@ int84ge(int64 * val1, int32 val2) ...@@ -245,7 +231,7 @@ int84ge(int64 * val1, int32 val2)
int64 * int64 *
int8um(int64 * val) int8um(int64 * val)
{ {
int64 *result = PALLOCTYPE(int64); int64 *result = palloc(sizeof(int64));
if (!PointerIsValid(val)) if (!PointerIsValid(val))
return NULL; return NULL;
...@@ -258,7 +244,7 @@ int8um(int64 * val) ...@@ -258,7 +244,7 @@ int8um(int64 * val)
int64 * int64 *
int8pl(int64 * val1, int64 * val2) int8pl(int64 * val1, int64 * val2)
{ {
int64 *result = PALLOCTYPE(int64); int64 *result = palloc(sizeof(int64));
if ((!PointerIsValid(val1)) || (!PointerIsValid(val2))) if ((!PointerIsValid(val1)) || (!PointerIsValid(val2)))
return NULL; return NULL;
...@@ -271,7 +257,7 @@ int8pl(int64 * val1, int64 * val2) ...@@ -271,7 +257,7 @@ int8pl(int64 * val1, int64 * val2)
int64 * int64 *
int8mi(int64 * val1, int64 * val2) int8mi(int64 * val1, int64 * val2)
{ {
int64 *result = PALLOCTYPE(int64); int64 *result = palloc(sizeof(int64));
if ((!PointerIsValid(val1)) || (!PointerIsValid(val2))) if ((!PointerIsValid(val1)) || (!PointerIsValid(val2)))
return NULL; return NULL;
...@@ -284,7 +270,7 @@ int8mi(int64 * val1, int64 * val2) ...@@ -284,7 +270,7 @@ int8mi(int64 * val1, int64 * val2)
int64 * int64 *
int8mul(int64 * val1, int64 * val2) int8mul(int64 * val1, int64 * val2)
{ {
int64 *result = PALLOCTYPE(int64); int64 *result = palloc(sizeof(int64));
if ((!PointerIsValid(val1)) || (!PointerIsValid(val2))) if ((!PointerIsValid(val1)) || (!PointerIsValid(val2)))
return NULL; return NULL;
...@@ -297,7 +283,7 @@ int8mul(int64 * val1, int64 * val2) ...@@ -297,7 +283,7 @@ int8mul(int64 * val1, int64 * val2)
int64 * int64 *
int8div(int64 * val1, int64 * val2) int8div(int64 * val1, int64 * val2)
{ {
int64 *result = PALLOCTYPE(int64); int64 *result = palloc(sizeof(int64));
if ((!PointerIsValid(val1)) || (!PointerIsValid(val2))) if ((!PointerIsValid(val1)) || (!PointerIsValid(val2)))
return NULL; return NULL;
...@@ -315,7 +301,7 @@ int8div(int64 * val1, int64 * val2) ...@@ -315,7 +301,7 @@ int8div(int64 * val1, int64 * val2)
int64 * int64 *
int48(int32 val) int48(int32 val)
{ {
int64 *result = PALLOCTYPE(int64); int64 *result = palloc(sizeof(int64));
*result = val; *result = val;
...@@ -344,7 +330,7 @@ int28 (int16 val) ...@@ -344,7 +330,7 @@ int28 (int16 val)
{ {
int64 *result; 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); elog(ERROR, "Memory allocation failed, can't convert int8 to int2", NULL);
*result = val; *result = val;
...@@ -370,7 +356,7 @@ int82(int64 * val) ...@@ -370,7 +356,7 @@ int82(int64 * val)
float64 float64
i8tod(int64 * val) i8tod(int64 * val)
{ {
float64 result = PALLOCTYPE(float64data); float64 result = palloc(sizeof(float64data));
*result = *val; *result = *val;
...@@ -380,7 +366,7 @@ i8tod(int64 * val) ...@@ -380,7 +366,7 @@ i8tod(int64 * val)
int64 * int64 *
dtoi8(float64 val) dtoi8(float64 val)
{ {
int64 *result = PALLOCTYPE(int64); int64 *result = palloc(sizeof(int64));
if ((*val < (-pow(2, 64) + 1)) || (*val > (pow(2, 64) - 1))) if ((*val < (-pow(2, 64) + 1)) || (*val > (pow(2, 64) - 1)))
elog(ERROR, "Floating point conversion to int64 is out of range", NULL); elog(ERROR, "Floating point conversion to int64 is out of range", NULL);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -91,7 +91,7 @@ rt_poly_union(POLYGON *a, POLYGON *b)
{ {
POLYGON *p; POLYGON *p;
p = (POLYGON *) PALLOCTYPE(POLYGON); p = (POLYGON *) palloc(sizeof(POLYGON));
if (!PointerIsValid(p)) if (!PointerIsValid(p))
elog(ABORT, "Cannot allocate polygon for union"); elog(ABORT, "Cannot allocate polygon for union");
...@@ -133,7 +133,7 @@ rt_poly_inter(POLYGON *a, POLYGON *b) ...@@ -133,7 +133,7 @@ rt_poly_inter(POLYGON *a, POLYGON *b)
{ {
POLYGON *p; POLYGON *p;
p = (POLYGON *) PALLOCTYPE(POLYGON); p = (POLYGON *) palloc(sizeof(POLYGON));
if (!PointerIsValid(p)) if (!PointerIsValid(p))
elog(ABORT, "Cannot allocate polygon for intersection"); elog(ABORT, "Cannot allocate polygon for intersection");
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Routines for handling of 'SET var TO', * Routines for handling of 'SET var TO',
* 'SHOW var' and 'RESET var' statements. * '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) ...@@ -73,7 +73,7 @@ get_token(char **tok, char **val, const char *str)
len++; len++;
} }
*tok = (char *) PALLOC(len + 1); *tok = (char *) palloc(len + 1);
StrNCpy(*tok, start, len+1); StrNCpy(*tok, start, len+1);
/* skip white spaces */ /* skip white spaces */
...@@ -119,7 +119,7 @@ get_token(char **tok, char **val, const char *str) ...@@ -119,7 +119,7 @@ get_token(char **tok, char **val, const char *str)
len++; len++;
} }
*val = (char *) PALLOC(len + 1); *val = (char *) palloc(len + 1);
StrNCpy(*val, start, len+1); StrNCpy(*val, start, len+1);
/* skip white spaces */ /* skip white spaces */
...@@ -186,7 +186,7 @@ parse_geqo(const char *value) ...@@ -186,7 +186,7 @@ parse_geqo(const char *value)
geqo_rels = pg_atoi(val, sizeof(int32), '\0'); geqo_rels = pg_atoi(val, sizeof(int32), '\0');
if (geqo_rels <= 1) if (geqo_rels <= 1)
elog(ERROR, "Bad value for # of relations (%s)", val); elog(ERROR, "Bad value for # of relations (%s)", val);
PFREE(val); pfree(val);
} }
_use_geqo_ = true; _use_geqo_ = true;
_use_geqo_rels_ = geqo_rels; _use_geqo_rels_ = geqo_rels;
...@@ -200,7 +200,7 @@ parse_geqo(const char *value) ...@@ -200,7 +200,7 @@ parse_geqo(const char *value)
else else
elog(ERROR, "Bad value for GEQO (%s)", value); elog(ERROR, "Bad value for GEQO (%s)", value);
PFREE(tok); pfree(tok);
return TRUE; return TRUE;
} }
...@@ -394,7 +394,7 @@ parse_date(const char *value) ...@@ -394,7 +394,7 @@ parse_date(const char *value)
{ {
elog(ERROR, "Bad value for date style (%s)", tok); elog(ERROR, "Bad value for date style (%s)", tok);
} }
PFREE(tok); pfree(tok);
} }
if (dcnt > 1 || ecnt > 1) if (dcnt > 1 || ecnt > 1)
...@@ -493,7 +493,7 @@ parse_timezone(const char *value) ...@@ -493,7 +493,7 @@ parse_timezone(const char *value)
elog(ERROR, "Unable to set TZ environment variable to %s", tok); elog(ERROR, "Unable to set TZ environment variable to %s", tok);
tzset(); tzset();
PFREE(tok); pfree(tok);
} }
return TRUE; return TRUE;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* workings can be found in the book "Software Solutions in C" by * workings can be found in the book "Software Solutions in C" by
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7. * 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> #include <stdio.h>
...@@ -158,7 +158,7 @@ printf( "cashin- precision %d; decimal %c; thousands %c; currency %c; positive % ...@@ -158,7 +158,7 @@ printf( "cashin- precision %d; decimal %c; thousands %c; currency %c; positive %
if (*s != '\0') if (*s != '\0')
elog(ERROR, "Bad money external representation %s", str); 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); elog(ERROR, "Memory allocation failed, can't input cash '%s'", str);
*result = (value * sgn); *result = (value * sgn);
...@@ -256,7 +256,7 @@ cash_out(Cash *in_value) ...@@ -256,7 +256,7 @@ cash_out(Cash *in_value)
/* see if we need to signify negative amount */ /* see if we need to signify negative amount */
if (minus) 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); elog(ERROR, "Memory allocation failed, can't output cash", NULL);
/* Position code of 0 means use parens */ /* Position code of 0 means use parens */
...@@ -269,7 +269,7 @@ cash_out(Cash *in_value) ...@@ -269,7 +269,7 @@ cash_out(Cash *in_value)
} }
else 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); elog(ERROR, "Memory allocation failed, can't output cash", NULL);
strcpy(result, buf + count); strcpy(result, buf + count);
...@@ -345,7 +345,7 @@ cash_pl(Cash *c1, Cash *c2) ...@@ -345,7 +345,7 @@ cash_pl(Cash *c1, Cash *c2)
if (!PointerIsValid(c1) || !PointerIsValid(c2)) if (!PointerIsValid(c1) || !PointerIsValid(c2))
return (NULL); return (NULL);
if (!PointerIsValid(result = PALLOCTYPE(Cash))) if (!PointerIsValid(result = palloc(sizeof(Cash))))
elog(ERROR, "Memory allocation failed, can't add cash", NULL); elog(ERROR, "Memory allocation failed, can't add cash", NULL);
*result = (*c1 + *c2); *result = (*c1 + *c2);
...@@ -365,7 +365,7 @@ cash_mi(Cash *c1, Cash *c2) ...@@ -365,7 +365,7 @@ cash_mi(Cash *c1, Cash *c2)
if (!PointerIsValid(c1) || !PointerIsValid(c2)) if (!PointerIsValid(c1) || !PointerIsValid(c2))
return (NULL); return (NULL);
if (!PointerIsValid(result = PALLOCTYPE(Cash))) if (!PointerIsValid(result = palloc(sizeof(Cash))))
elog(ERROR, "Memory allocation failed, can't subtract cash", NULL); elog(ERROR, "Memory allocation failed, can't subtract cash", NULL);
*result = (*c1 - *c2); *result = (*c1 - *c2);
...@@ -385,7 +385,7 @@ cash_mul_flt8(Cash *c, float8 *f) ...@@ -385,7 +385,7 @@ cash_mul_flt8(Cash *c, float8 *f)
if (!PointerIsValid(f) || !PointerIsValid(c)) if (!PointerIsValid(f) || !PointerIsValid(c))
return (NULL); return (NULL);
if (!PointerIsValid(result = PALLOCTYPE(Cash))) if (!PointerIsValid(result = palloc(sizeof(Cash))))
elog(ERROR, "Memory allocation failed, can't multiply cash", NULL); elog(ERROR, "Memory allocation failed, can't multiply cash", NULL);
*result = ((*f) * (*c)); *result = ((*f) * (*c));
...@@ -418,7 +418,7 @@ cash_div_flt8(Cash *c, float8 *f) ...@@ -418,7 +418,7 @@ cash_div_flt8(Cash *c, float8 *f)
if (!PointerIsValid(f) || !PointerIsValid(c)) if (!PointerIsValid(f) || !PointerIsValid(c))
return (NULL); return (NULL);
if (!PointerIsValid(result = PALLOCTYPE(Cash))) if (!PointerIsValid(result = palloc(sizeof(Cash))))
elog(ERROR, "Memory allocation failed, can't divide cash", NULL); elog(ERROR, "Memory allocation failed, can't divide cash", NULL);
if (*f == 0.0) if (*f == 0.0)
...@@ -440,7 +440,7 @@ cash_mul_flt4(Cash *c, float4 *f) ...@@ -440,7 +440,7 @@ cash_mul_flt4(Cash *c, float4 *f)
if (!PointerIsValid(f) || !PointerIsValid(c)) if (!PointerIsValid(f) || !PointerIsValid(c))
return (NULL); return (NULL);
if (!PointerIsValid(result = PALLOCTYPE(Cash))) if (!PointerIsValid(result = palloc(sizeof(Cash))))
elog(ERROR, "Memory allocation failed, can't multiply cash", NULL); elog(ERROR, "Memory allocation failed, can't multiply cash", NULL);
*result = ((*f) * (*c)); *result = ((*f) * (*c));
...@@ -473,7 +473,7 @@ cash_div_flt4(Cash *c, float4 *f) ...@@ -473,7 +473,7 @@ cash_div_flt4(Cash *c, float4 *f)
if (!PointerIsValid(f) || !PointerIsValid(c)) if (!PointerIsValid(f) || !PointerIsValid(c))
return (NULL); return (NULL);
if (!PointerIsValid(result = PALLOCTYPE(Cash))) if (!PointerIsValid(result = palloc(sizeof(Cash))))
elog(ERROR, "Memory allocation failed, can't divide cash", NULL); elog(ERROR, "Memory allocation failed, can't divide cash", NULL);
if (*f == 0.0) if (*f == 0.0)
...@@ -496,7 +496,7 @@ cash_mul_int4(Cash *c, int4 i) ...@@ -496,7 +496,7 @@ cash_mul_int4(Cash *c, int4 i)
if (!PointerIsValid(c)) if (!PointerIsValid(c))
return (NULL); return (NULL);
if (!PointerIsValid(result = PALLOCTYPE(Cash))) if (!PointerIsValid(result = palloc(sizeof(Cash))))
elog(ERROR, "Memory allocation failed, can't multiply cash", NULL); elog(ERROR, "Memory allocation failed, can't multiply cash", NULL);
*result = ((i) * (*c)); *result = ((i) * (*c));
...@@ -529,7 +529,7 @@ cash_div_int4(Cash *c, int4 i) ...@@ -529,7 +529,7 @@ cash_div_int4(Cash *c, int4 i)
if (!PointerIsValid(c)) if (!PointerIsValid(c))
return (NULL); return (NULL);
if (!PointerIsValid(result = PALLOCTYPE(Cash))) if (!PointerIsValid(result = palloc(sizeof(Cash))))
elog(ERROR, "Memory allocation failed, can't divide cash", NULL); elog(ERROR, "Memory allocation failed, can't divide cash", NULL);
if (i == 0) if (i == 0)
...@@ -552,7 +552,7 @@ cash_mul_int2(Cash *c, int2 s) ...@@ -552,7 +552,7 @@ cash_mul_int2(Cash *c, int2 s)
if (!PointerIsValid(c)) if (!PointerIsValid(c))
return (NULL); return (NULL);
if (!PointerIsValid(result = PALLOCTYPE(Cash))) if (!PointerIsValid(result = palloc(sizeof(Cash))))
elog(ERROR, "Memory allocation failed, can't multiply cash", NULL); elog(ERROR, "Memory allocation failed, can't multiply cash", NULL);
*result = ((s) * (*c)); *result = ((s) * (*c));
...@@ -585,7 +585,7 @@ cash_div_int2(Cash *c, int2 s) ...@@ -585,7 +585,7 @@ cash_div_int2(Cash *c, int2 s)
if (!PointerIsValid(c)) if (!PointerIsValid(c))
return (NULL); return (NULL);
if (!PointerIsValid(result = PALLOCTYPE(Cash))) if (!PointerIsValid(result = palloc(sizeof(Cash))))
elog(ERROR, "Memory allocation failed, can't divide cash", NULL); elog(ERROR, "Memory allocation failed, can't divide cash", NULL);
if (s == 0) if (s == 0)
...@@ -608,7 +608,7 @@ cashlarger(Cash *c1, Cash *c2) ...@@ -608,7 +608,7 @@ cashlarger(Cash *c1, Cash *c2)
if (!PointerIsValid(c1) || !PointerIsValid(c2)) if (!PointerIsValid(c1) || !PointerIsValid(c2))
return (NULL); return (NULL);
if (!PointerIsValid(result = PALLOCTYPE(Cash))) if (!PointerIsValid(result = palloc(sizeof(Cash))))
elog(ERROR, "Memory allocation failed, can't return larger cash", NULL); elog(ERROR, "Memory allocation failed, can't return larger cash", NULL);
*result = ((*c1 > *c2) ? *c1 : *c2); *result = ((*c1 > *c2) ? *c1 : *c2);
...@@ -628,7 +628,7 @@ cashsmaller(Cash *c1, Cash *c2) ...@@ -628,7 +628,7 @@ cashsmaller(Cash *c1, Cash *c2)
if (!PointerIsValid(c1) || !PointerIsValid(c2)) if (!PointerIsValid(c1) || !PointerIsValid(c2))
return (NULL); return (NULL);
if (!PointerIsValid(result = PALLOCTYPE(Cash))) if (!PointerIsValid(result = palloc(sizeof(Cash))))
elog(ERROR, "Memory allocation failed, can't return smaller cash", NULL); elog(ERROR, "Memory allocation failed, can't return smaller cash", NULL);
*result = ((*c1 < *c2) ? *c1 : *c2); *result = ((*c1 < *c2) ? *c1 : *c2);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * 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 * NOTES
* This code is actually (almost) unused. * This code is actually (almost) unused.
...@@ -180,7 +180,7 @@ reltimeout(int32 time) ...@@ -180,7 +180,7 @@ reltimeout(int32 time)
EncodeTimeSpan(tm, 0, DateStyle, buf); EncodeTimeSpan(tm, 0, DateStyle, buf);
} }
result = PALLOC(strlen(buf) + 1); result = palloc(strlen(buf) + 1);
strcpy(result, buf); strcpy(result, buf);
return (result); return (result);
...@@ -360,7 +360,7 @@ reltime_timespan(RelativeTime reltime) ...@@ -360,7 +360,7 @@ reltime_timespan(RelativeTime reltime)
int year, int year,
month; month;
if (!PointerIsValid(result = PALLOCTYPE(TimeSpan))) if (!PointerIsValid(result = palloc(sizeof(TimeSpan))))
elog(ERROR, "Memory allocation failed, can't convert reltime to timespan", NULL); elog(ERROR, "Memory allocation failed, can't convert reltime to timespan", NULL);
switch (reltime) switch (reltime)
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -128,7 +128,7 @@ date_out(DateADT date)
EncodeDateOnly(tm, DateStyle, buf); EncodeDateOnly(tm, DateStyle, buf);
result = PALLOC(strlen(buf) + 1); result = palloc(strlen(buf) + 1);
strcpy(result, buf); strcpy(result, buf);
...@@ -236,7 +236,7 @@ date_datetime(DateADT dateVal) ...@@ -236,7 +236,7 @@ date_datetime(DateADT dateVal)
double fsec = 0; double fsec = 0;
char *tzn; char *tzn;
result = PALLOCTYPE(DateTime); result = palloc(sizeof(DateTime));
if (date2tm(dateVal, &tz, tm, &fsec, &tzn) != 0) if (date2tm(dateVal, &tz, tm, &fsec, &tzn) != 0)
elog(ERROR, "Unable to convert date to datetime", NULL); elog(ERROR, "Unable to convert date to datetime", NULL);
...@@ -453,7 +453,7 @@ time_in(char *str) ...@@ -453,7 +453,7 @@ time_in(char *str)
if ((tm->tm_sec < 0) || ((tm->tm_sec + fsec) >= 60)) if ((tm->tm_sec < 0) || ((tm->tm_sec + fsec) >= 60))
elog(ERROR, "Second must be limited to values 0 through < 60 in '%s'", 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) + tm->tm_sec + fsec); *time = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
...@@ -482,7 +482,7 @@ time_out(TimeADT *time) ...@@ -482,7 +482,7 @@ time_out(TimeADT *time)
EncodeTimeOnly(tm, fsec, DateStyle, buf); EncodeTimeOnly(tm, fsec, DateStyle, buf);
result = PALLOC(strlen(buf) + 1); result = palloc(strlen(buf) + 1);
strcpy(result, buf); strcpy(result, buf);
...@@ -586,7 +586,7 @@ datetime_time(DateTime *datetime) ...@@ -586,7 +586,7 @@ datetime_time(DateTime *datetime)
elog(ERROR, "Unable to convert datetime to date", NULL); 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); *result = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
...@@ -604,7 +604,7 @@ datetime_datetime(DateADT date, TimeADT *time) ...@@ -604,7 +604,7 @@ datetime_datetime(DateADT date, TimeADT *time)
if (!PointerIsValid(time)) if (!PointerIsValid(time))
{ {
result = PALLOCTYPE(DateTime); result = palloc(sizeof(DateTime));
DATETIME_INVALID(*result); DATETIME_INVALID(*result);
} else { } else {
result = date_datetime(date); result = date_datetime(date);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -115,7 +115,7 @@ datetime_in(char *str)
|| (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0)) || (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0))
elog(ERROR, "Bad datetime external representation '%s'", str); elog(ERROR, "Bad datetime external representation '%s'", str);
result = PALLOCTYPE(DateTime); result = palloc(sizeof(DateTime));
switch (dtype) switch (dtype)
{ {
...@@ -188,7 +188,7 @@ datetime_out(DateTime *dt) ...@@ -188,7 +188,7 @@ datetime_out(DateTime *dt)
EncodeSpecialDateTime(DT_INVALID, buf); EncodeSpecialDateTime(DT_INVALID, buf);
} }
result = PALLOC(strlen(buf) + 1); result = palloc(strlen(buf) + 1);
strcpy(result, buf); strcpy(result, buf);
...@@ -231,7 +231,7 @@ timespan_in(char *str) ...@@ -231,7 +231,7 @@ timespan_in(char *str)
|| (DecodeDateDelta(field, ftype, nf, &dtype, tm, &fsec) != 0)) || (DecodeDateDelta(field, ftype, nf, &dtype, tm, &fsec) != 0))
elog(ERROR, "Bad timespan external representation '%s'", str); elog(ERROR, "Bad timespan external representation '%s'", str);
span = PALLOCTYPE(TimeSpan); span = palloc(sizeof(TimeSpan));
switch (dtype) switch (dtype)
{ {
...@@ -274,7 +274,7 @@ timespan_out(TimeSpan *span) ...@@ -274,7 +274,7 @@ timespan_out(TimeSpan *span)
if (EncodeTimeSpan(tm, fsec, DateStyle, buf) != 0) if (EncodeTimeSpan(tm, fsec, DateStyle, buf) != 0)
elog(ERROR, "Unable to format timespan", NULL); elog(ERROR, "Unable to format timespan", NULL);
result = PALLOC(strlen(buf) + 1); result = palloc(strlen(buf) + 1);
strcpy(result, buf); strcpy(result, buf);
return (result); return (result);
...@@ -715,7 +715,7 @@ datetime_smaller(DateTime *datetime1, DateTime *datetime2) ...@@ -715,7 +715,7 @@ datetime_smaller(DateTime *datetime1, DateTime *datetime2)
dt1 = *datetime1; dt1 = *datetime1;
dt2 = *datetime2; dt2 = *datetime2;
result = PALLOCTYPE(DateTime); result = palloc(sizeof(DateTime));
if (DATETIME_IS_RELATIVE(dt1)) if (DATETIME_IS_RELATIVE(dt1))
dt1 = SetDateTime(dt1); dt1 = SetDateTime(dt1);
...@@ -752,7 +752,7 @@ datetime_larger(DateTime *datetime1, DateTime *datetime2) ...@@ -752,7 +752,7 @@ datetime_larger(DateTime *datetime1, DateTime *datetime2)
dt1 = *datetime1; dt1 = *datetime1;
dt2 = *datetime2; dt2 = *datetime2;
result = PALLOCTYPE(DateTime); result = palloc(sizeof(DateTime));
if (DATETIME_IS_RELATIVE(dt1)) if (DATETIME_IS_RELATIVE(dt1))
dt1 = SetDateTime(dt1); dt1 = SetDateTime(dt1);
...@@ -790,7 +790,7 @@ datetime_mi(DateTime *datetime1, DateTime *datetime2) ...@@ -790,7 +790,7 @@ datetime_mi(DateTime *datetime1, DateTime *datetime2)
dt1 = *datetime1; dt1 = *datetime1;
dt2 = *datetime2; dt2 = *datetime2;
result = PALLOCTYPE(TimeSpan); result = palloc(sizeof(TimeSpan));
if (DATETIME_IS_RELATIVE(dt1)) if (DATETIME_IS_RELATIVE(dt1))
dt1 = SetDateTime(dt1); dt1 = SetDateTime(dt1);
...@@ -836,7 +836,7 @@ datetime_pl_span(DateTime *datetime, TimeSpan *span) ...@@ -836,7 +836,7 @@ datetime_pl_span(DateTime *datetime, TimeSpan *span)
if ((!PointerIsValid(datetime)) || (!PointerIsValid(span))) if ((!PointerIsValid(datetime)) || (!PointerIsValid(span)))
return NULL; return NULL;
result = PALLOCTYPE(DateTime); result = palloc(sizeof(DateTime));
#ifdef DATEDEBUG #ifdef DATEDEBUG
printf("datetime_pl_span- add %f to %d %f\n", *datetime, span->month, span->time); printf("datetime_pl_span- add %f to %d %f\n", *datetime, span->month, span->time);
...@@ -945,7 +945,7 @@ timespan_um(TimeSpan *timespan) ...@@ -945,7 +945,7 @@ timespan_um(TimeSpan *timespan)
if (!PointerIsValid(timespan)) if (!PointerIsValid(timespan))
return NULL; return NULL;
result = PALLOCTYPE(TimeSpan); result = palloc(sizeof(TimeSpan));
result->time = -(timespan->time); result->time = -(timespan->time);
result->month = -(timespan->month); result->month = -(timespan->month);
...@@ -965,7 +965,7 @@ timespan_smaller(TimeSpan *timespan1, TimeSpan *timespan2) ...@@ -965,7 +965,7 @@ timespan_smaller(TimeSpan *timespan1, TimeSpan *timespan2)
if (!PointerIsValid(timespan1) || !PointerIsValid(timespan2)) if (!PointerIsValid(timespan1) || !PointerIsValid(timespan2))
return NULL; return NULL;
result = PALLOCTYPE(TimeSpan); result = palloc(sizeof(TimeSpan));
if (TIMESPAN_IS_INVALID(*timespan1)) if (TIMESPAN_IS_INVALID(*timespan1))
{ {
...@@ -1020,7 +1020,7 @@ timespan_larger(TimeSpan *timespan1, TimeSpan *timespan2) ...@@ -1020,7 +1020,7 @@ timespan_larger(TimeSpan *timespan1, TimeSpan *timespan2)
if (!PointerIsValid(timespan1) || !PointerIsValid(timespan2)) if (!PointerIsValid(timespan1) || !PointerIsValid(timespan2))
return NULL; return NULL;
result = PALLOCTYPE(TimeSpan); result = palloc(sizeof(TimeSpan));
if (TIMESPAN_IS_INVALID(*timespan1)) if (TIMESPAN_IS_INVALID(*timespan1))
{ {
...@@ -1073,7 +1073,7 @@ timespan_pl(TimeSpan *span1, TimeSpan *span2) ...@@ -1073,7 +1073,7 @@ timespan_pl(TimeSpan *span1, TimeSpan *span2)
if ((!PointerIsValid(span1)) || (!PointerIsValid(span2))) if ((!PointerIsValid(span1)) || (!PointerIsValid(span2)))
return NULL; return NULL;
result = PALLOCTYPE(TimeSpan); result = palloc(sizeof(TimeSpan));
result->month = (span1->month + span2->month); result->month = (span1->month + span2->month);
result->time = JROUND(span1->time + span2->time); result->time = JROUND(span1->time + span2->time);
...@@ -1089,7 +1089,7 @@ timespan_mi(TimeSpan *span1, TimeSpan *span2) ...@@ -1089,7 +1089,7 @@ timespan_mi(TimeSpan *span1, TimeSpan *span2)
if ((!PointerIsValid(span1)) || (!PointerIsValid(span2))) if ((!PointerIsValid(span1)) || (!PointerIsValid(span2)))
return NULL; return NULL;
result = PALLOCTYPE(TimeSpan); result = palloc(sizeof(TimeSpan));
result->month = (span1->month - span2->month); result->month = (span1->month - span2->month);
result->time = JROUND(span1->time - span2->time); result->time = JROUND(span1->time - span2->time);
...@@ -1105,7 +1105,7 @@ timespan_div(TimeSpan *span1, float8 *arg2) ...@@ -1105,7 +1105,7 @@ timespan_div(TimeSpan *span1, float8 *arg2)
if ((!PointerIsValid(span1)) || (!PointerIsValid(arg2))) if ((!PointerIsValid(span1)) || (!PointerIsValid(arg2)))
return NULL; return NULL;
if (!PointerIsValid(result = PALLOCTYPE(TimeSpan))) if (!PointerIsValid(result = palloc(sizeof(TimeSpan))))
elog(ERROR, "Memory allocation failed, can't subtract timespans", NULL); elog(ERROR, "Memory allocation failed, can't subtract timespans", NULL);
if (*arg2 == 0.0) if (*arg2 == 0.0)
...@@ -1143,7 +1143,7 @@ datetime_age(DateTime *datetime1, DateTime *datetime2) ...@@ -1143,7 +1143,7 @@ datetime_age(DateTime *datetime1, DateTime *datetime2)
if (!PointerIsValid(datetime1) || !PointerIsValid(datetime2)) if (!PointerIsValid(datetime1) || !PointerIsValid(datetime2))
return NULL; return NULL;
result = PALLOCTYPE(TimeSpan); result = palloc(sizeof(TimeSpan));
dt1 = *datetime1; dt1 = *datetime1;
dt2 = *datetime2; dt2 = *datetime2;
...@@ -1287,12 +1287,12 @@ datetime_text(DateTime *datetime) ...@@ -1287,12 +1287,12 @@ datetime_text(DateTime *datetime)
len = (strlen(str) + VARHDRSZ); len = (strlen(str) + VARHDRSZ);
result = PALLOC(len); result = palloc(len);
VARSIZE(result) = len; VARSIZE(result) = len;
memmove(VARDATA(result), str, (len - VARHDRSZ)); memmove(VARDATA(result), str, (len - VARHDRSZ));
PFREE(str); pfree(str);
return (result); return (result);
} /* datetime_text() */ } /* datetime_text() */
...@@ -1347,12 +1347,12 @@ timespan_text(TimeSpan *timespan) ...@@ -1347,12 +1347,12 @@ timespan_text(TimeSpan *timespan)
len = (strlen(str) + VARHDRSZ); len = (strlen(str) + VARHDRSZ);
result = PALLOC(len); result = palloc(len);
VARSIZE(result) = len; VARSIZE(result) = len;
memmove(VARDATA(result), str, (len - VARHDRSZ)); memmove(VARDATA(result), str, (len - VARHDRSZ));
PFREE(str); pfree(str);
return (result); return (result);
} /* timespan_text() */ } /* timespan_text() */
...@@ -1410,7 +1410,7 @@ datetime_trunc(text *units, DateTime *datetime) ...@@ -1410,7 +1410,7 @@ datetime_trunc(text *units, DateTime *datetime)
if ((!PointerIsValid(units)) || (!PointerIsValid(datetime))) if ((!PointerIsValid(units)) || (!PointerIsValid(datetime)))
return NULL; return NULL;
result = PALLOCTYPE(DateTime); result = palloc(sizeof(DateTime));
up = VARDATA(units); up = VARDATA(units);
lp = lowunits; lp = lowunits;
...@@ -1555,7 +1555,7 @@ timespan_trunc(text *units, TimeSpan *timespan) ...@@ -1555,7 +1555,7 @@ timespan_trunc(text *units, TimeSpan *timespan)
if ((!PointerIsValid(units)) || (!PointerIsValid(timespan))) if ((!PointerIsValid(units)) || (!PointerIsValid(timespan)))
return NULL; return NULL;
result = PALLOCTYPE(TimeSpan); result = palloc(sizeof(TimeSpan));
up = VARDATA(units); up = VARDATA(units);
lp = lowunits; lp = lowunits;
...@@ -1684,7 +1684,7 @@ datetime_part(text *units, DateTime *datetime) ...@@ -1684,7 +1684,7 @@ datetime_part(text *units, DateTime *datetime)
if ((!PointerIsValid(units)) || (!PointerIsValid(datetime))) if ((!PointerIsValid(units)) || (!PointerIsValid(datetime)))
return NULL; return NULL;
result = PALLOCTYPE(float64data); result = palloc(sizeof(float64data));
up = VARDATA(units); up = VARDATA(units);
lp = lowunits; lp = lowunits;
...@@ -1841,7 +1841,7 @@ timespan_part(text *units, TimeSpan *timespan) ...@@ -1841,7 +1841,7 @@ timespan_part(text *units, TimeSpan *timespan)
if ((!PointerIsValid(units)) || (!PointerIsValid(timespan))) if ((!PointerIsValid(units)) || (!PointerIsValid(timespan)))
return NULL; return NULL;
result = PALLOCTYPE(float64data); result = palloc(sizeof(float64data));
up = VARDATA(units); up = VARDATA(units);
lp = lowunits; lp = lowunits;
...@@ -2031,7 +2031,7 @@ datetime_zone(text *zone, DateTime *datetime) ...@@ -2031,7 +2031,7 @@ datetime_zone(text *zone, DateTime *datetime)
len = (strlen(buf) + VARHDRSZ); len = (strlen(buf) + VARHDRSZ);
result = PALLOC(len); result = palloc(len);
VARSIZE(result) = len; VARSIZE(result) = len;
memmove(VARDATA(result), buf, (len - VARHDRSZ)); memmove(VARDATA(result), buf, (len - VARHDRSZ));
......
This diff is collapsed.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -250,12 +250,12 @@ int2_text(int16 arg1)
str = int2out(arg1); str = int2out(arg1);
len = (strlen(str) + VARHDRSZ); len = (strlen(str) + VARHDRSZ);
result = PALLOC(len); result = palloc(len);
VARSIZE(result) = len; VARSIZE(result) = len;
memmove(VARDATA(result), str, (len - VARHDRSZ)); memmove(VARDATA(result), str, (len - VARHDRSZ));
PFREE(str); pfree(str);
return(result); return(result);
} /* int2_text() */ } /* int2_text() */
...@@ -270,12 +270,12 @@ text_int2(text *string) ...@@ -270,12 +270,12 @@ text_int2(text *string)
len = (VARSIZE(string) - VARHDRSZ); len = (VARSIZE(string) - VARHDRSZ);
str = PALLOC(len+1); str = palloc(len+1);
memmove(str, VARDATA(string), len); memmove(str, VARDATA(string), len);
*(str+len) = '\0'; *(str+len) = '\0';
result = int2in(str); result = int2in(str);
PFREE(str); pfree(str);
return(result); return(result);
} /* text_int2() */ } /* text_int2() */
...@@ -291,12 +291,12 @@ int4_text(int32 arg1) ...@@ -291,12 +291,12 @@ int4_text(int32 arg1)
str = int4out(arg1); str = int4out(arg1);
len = (strlen(str) + VARHDRSZ); len = (strlen(str) + VARHDRSZ);
result = PALLOC(len); result = palloc(len);
VARSIZE(result) = len; VARSIZE(result) = len;
memmove(VARDATA(result), str, (len - VARHDRSZ)); memmove(VARDATA(result), str, (len - VARHDRSZ));
PFREE(str); pfree(str);
return(result); return(result);
} /* int4_text() */ } /* int4_text() */
...@@ -311,12 +311,12 @@ text_int4(text *string) ...@@ -311,12 +311,12 @@ text_int4(text *string)
len = (VARSIZE(string) - VARHDRSZ); len = (VARSIZE(string) - VARHDRSZ);
str = PALLOC(len+1); str = palloc(len+1);
memmove(str, VARDATA(string), len); memmove(str, VARDATA(string), len);
*(str+len) = '\0'; *(str+len) = '\0';
result = int4in(str); result = int4in(str);
PFREE(str); pfree(str);
return(result); return(result);
} /* text_int4() */ } /* text_int4() */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -345,7 +345,7 @@ nabstimeout(AbsoluteTime time)
break; break;
} }
result = PALLOC(strlen(buf) + 1); result = palloc(strlen(buf) + 1);
strcpy(result, buf); strcpy(result, buf);
return (result); return (result);
...@@ -546,7 +546,7 @@ abstime_datetime(AbsoluteTime abstime) ...@@ -546,7 +546,7 @@ abstime_datetime(AbsoluteTime abstime)
{ {
DateTime *result; 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); elog(ERROR, "Unable to allocate space to convert abstime to datetime", NULL);
switch (abstime) switch (abstime)
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -150,11 +150,11 @@ oid_text(Oid oid)
str = oidout(oid); str = oidout(oid);
len = (strlen(str) + VARHDRSZ); len = (strlen(str) + VARHDRSZ);
result = PALLOC(len); result = palloc(len);
VARSIZE(result) = len; VARSIZE(result) = len;
memmove(VARDATA(result), str, (len-VARHDRSZ)); memmove(VARDATA(result), str, (len-VARHDRSZ));
PFREE(str); pfree(str);
return(result); return(result);
} /* oid_text() */ } /* oid_text() */
...@@ -169,12 +169,12 @@ text_oid(text *string) ...@@ -169,12 +169,12 @@ text_oid(text *string)
len = (VARSIZE(string) - VARHDRSZ); len = (VARSIZE(string) - VARHDRSZ);
str = PALLOC(len+1); str = palloc(len+1);
memmove(str, VARDATA(string), len); memmove(str, VARDATA(string), len);
*(str+len) = '\0'; *(str+len) = '\0';
result = oidin(str); result = oidin(str);
PFREE(str); pfree(str);
return(result); return(result);
} /* oid_text() */ } /* oid_text() */
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -70,16 +70,14 @@ bpcharin(char *s, int dummy, int typlen)
typlen = len + VARHDRSZ; typlen = len + VARHDRSZ;
} }
else else
{
len = typlen - VARHDRSZ; len = typlen - VARHDRSZ;
}
if (len > 4096) if (len > 4096)
elog(ERROR, "bpcharin: length of char() must be less than 4096"); elog(ERROR, "bpcharin: length of char() must be less than 4096");
result = (char *) palloc(typlen); result = (char *) palloc(typlen);
*(int32 *) result = typlen; VARSIZE(result) = typlen;
r = result + VARHDRSZ; r = VARDATA(result);
for (i = 0; i < len; i++, r++, s++) for (i = 0; i < len; i++, r++, s++)
{ {
*r = *s; *r = *s;
...@@ -108,9 +106,9 @@ bpcharout(char *s) ...@@ -108,9 +106,9 @@ bpcharout(char *s)
} }
else else
{ {
len = *(int32 *) s - VARHDRSZ; len = VARSIZE(s) - VARHDRSZ;
result = (char *) palloc(len + 1); 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); return (result);
} }
...@@ -129,27 +127,21 @@ char * ...@@ -129,27 +127,21 @@ char *
varcharin(char *s, int dummy, int typlen) varcharin(char *s, int dummy, int typlen)
{ {
char *result; char *result;
int len = typlen - VARHDRSZ; int len;
if (s == NULL) if (s == NULL)
return ((char *) NULL); return ((char *) NULL);
if (typlen == -1) len = strlen(s) + VARHDRSZ;
{ if (typlen != -1 && len > typlen)
len = typlen; /* clip the string at max length */
/*
* this is here because some functions can't supply the typlen
*/
len = strlen(s);
typlen = len + VARHDRSZ;
}
if (len > 4096) if (len > 4096)
elog(ERROR, "varcharin: length of char() must be less than 4096"); elog(ERROR, "varcharin: length of char() must be less than 4096");
result = (char *) palloc(typlen); result = (char *) palloc(len);
*(int32 *) result = typlen; VARSIZE(result) = len;
strncpy(result + VARHDRSZ, s, len+1); memmove(VARDATA(result), s, len - VARHDRSZ);
return (result); return (result);
} }
...@@ -168,9 +160,9 @@ varcharout(char *s) ...@@ -168,9 +160,9 @@ varcharout(char *s)
} }
else else
{ {
len = *(int32 *) s - VARHDRSZ; len = VARSIZE(s) - VARHDRSZ;
result = (char *) palloc(len + 1); result = (char *) palloc(len + 1);
StrNCpy(result, s + VARHDRSZ, len+1); StrNCpy(result, VARDATA(s), len+1);
} }
return (result); return (result);
} }
...@@ -182,11 +174,11 @@ varcharout(char *s) ...@@ -182,11 +174,11 @@ varcharout(char *s)
static int static int
bcTruelen(char *arg) bcTruelen(char *arg)
{ {
char *s = arg + VARHDRSZ; char *s = VARDATA(arg);
int i; int i;
int len; int len;
len = *(int32 *) arg - VARHDRSZ; len = VARSIZE(arg) - VARHDRSZ;
for (i = len - 1; i >= 0; i--) for (i = len - 1; i >= 0; i--)
{ {
if (s[i] != ' ') if (s[i] != ' ')
...@@ -218,7 +210,7 @@ bpchareq(char *arg1, char *arg2) ...@@ -218,7 +210,7 @@ bpchareq(char *arg1, char *arg2)
if (len1 != len2) if (len1 != len2)
return 0; return 0;
return (strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, len1) == 0); return (strncmp(VARDATA(arg1), VARDATA(arg2), len1) == 0);
} }
bool bool
...@@ -235,7 +227,7 @@ bpcharne(char *arg1, char *arg2) ...@@ -235,7 +227,7 @@ bpcharne(char *arg1, char *arg2)
if (len1 != len2) if (len1 != len2)
return 1; return 1;
return (strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, len1) != 0); return (strncmp(VARDATA(arg1), VARDATA(arg2), len1) != 0);
} }
bool bool
...@@ -250,7 +242,7 @@ bpcharlt(char *arg1, char *arg2) ...@@ -250,7 +242,7 @@ bpcharlt(char *arg1, char *arg2)
len1 = bcTruelen(arg1); len1 = bcTruelen(arg1);
len2 = bcTruelen(arg2); len2 = bcTruelen(arg2);
cmp = strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, Min(len1, len2)); cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2));
if (cmp == 0) if (cmp == 0)
return (len1 < len2); return (len1 < len2);
else else
...@@ -269,7 +261,7 @@ bpcharle(char *arg1, char *arg2) ...@@ -269,7 +261,7 @@ bpcharle(char *arg1, char *arg2)
len1 = bcTruelen(arg1); len1 = bcTruelen(arg1);
len2 = bcTruelen(arg2); len2 = bcTruelen(arg2);
cmp = strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, Min(len1, len2)); cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2));
if (0 == cmp) if (0 == cmp)
return (bool) (len1 <= len2 ? 1 : 0); return (bool) (len1 <= len2 ? 1 : 0);
else else
...@@ -288,7 +280,7 @@ bpchargt(char *arg1, char *arg2) ...@@ -288,7 +280,7 @@ bpchargt(char *arg1, char *arg2)
len1 = bcTruelen(arg1); len1 = bcTruelen(arg1);
len2 = bcTruelen(arg2); len2 = bcTruelen(arg2);
cmp = strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, Min(len1, len2)); cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2));
if (cmp == 0) if (cmp == 0)
return (len1 > len2); return (len1 > len2);
else else
...@@ -307,7 +299,7 @@ bpcharge(char *arg1, char *arg2) ...@@ -307,7 +299,7 @@ bpcharge(char *arg1, char *arg2)
len1 = bcTruelen(arg1); len1 = bcTruelen(arg1);
len2 = bcTruelen(arg2); len2 = bcTruelen(arg2);
cmp = strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, Min(len1, len2)); cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2));
if (0 == cmp) if (0 == cmp)
return (bool) (len1 >= len2 ? 1 : 0); return (bool) (len1 >= len2 ? 1 : 0);
else else
...@@ -324,7 +316,7 @@ bpcharcmp(char *arg1, char *arg2) ...@@ -324,7 +316,7 @@ bpcharcmp(char *arg1, char *arg2)
len1 = bcTruelen(arg1); len1 = bcTruelen(arg1);
len2 = bcTruelen(arg2); 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)) if ((0 == cmp) && (len1 != len2))
return (int32) (len1 < len2 ? -1 : 1); return (int32) (len1 < len2 ? -1 : 1);
else else
...@@ -335,30 +327,14 @@ bpcharcmp(char *arg1, char *arg2) ...@@ -335,30 +327,14 @@ bpcharcmp(char *arg1, char *arg2)
* Comparison Functions used for varchar * 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 int32
varcharlen(char *arg) varcharlen(char *arg)
{ {
if (!PointerIsValid(arg)) if (!PointerIsValid(arg))
elog(ERROR, "Bad (null) varchar() external representation", NULL); elog(ERROR, "Bad (null) varchar() external representation", NULL);
return(vcTruelen(arg)); return VARSIZE(arg);
} /* vclen() */ }
bool bool
varchareq(char *arg1, char *arg2) varchareq(char *arg1, char *arg2)
...@@ -368,13 +344,13 @@ varchareq(char *arg1, char *arg2) ...@@ -368,13 +344,13 @@ varchareq(char *arg1, char *arg2)
if (arg1 == NULL || arg2 == NULL) if (arg1 == NULL || arg2 == NULL)
return ((bool) 0); return ((bool) 0);
len1 = vcTruelen(arg1); len1 = VARSIZE(arg1);
len2 = vcTruelen(arg2); len2 = VARSIZE(arg2);
if (len1 != len2) if (len1 != len2)
return 0; return 0;
return (strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, len1) == 0); return (strncmp(VARDATA(arg1), VARDATA(arg2), len1) == 0);
} }
bool bool
...@@ -385,13 +361,13 @@ varcharne(char *arg1, char *arg2) ...@@ -385,13 +361,13 @@ varcharne(char *arg1, char *arg2)
if (arg1 == NULL || arg2 == NULL) if (arg1 == NULL || arg2 == NULL)
return ((bool) 0); return ((bool) 0);
len1 = vcTruelen(arg1); len1 = VARSIZE(arg1);
len2 = vcTruelen(arg2); len2 = VARSIZE(arg2);
if (len1 != len2) if (len1 != len2)
return 1; return 1;
return (strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, len1) != 0); return (strncmp(VARDATA(arg1), VARDATA(arg2), len1) != 0);
} }
bool bool
...@@ -403,10 +379,10 @@ varcharlt(char *arg1, char *arg2) ...@@ -403,10 +379,10 @@ varcharlt(char *arg1, char *arg2)
if (arg1 == NULL || arg2 == NULL) if (arg1 == NULL || arg2 == NULL)
return ((bool) 0); return ((bool) 0);
len1 = vcTruelen(arg1); len1 = VARSIZE(arg1);
len2 = vcTruelen(arg2); len2 = VARSIZE(arg2);
cmp = strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, Min(len1, len2)); cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2));
if (cmp == 0) if (cmp == 0)
return (len1 < len2); return (len1 < len2);
else else
...@@ -422,10 +398,10 @@ varcharle(char *arg1, char *arg2) ...@@ -422,10 +398,10 @@ varcharle(char *arg1, char *arg2)
if (arg1 == NULL || arg2 == NULL) if (arg1 == NULL || arg2 == NULL)
return ((bool) 0); return ((bool) 0);
len1 = vcTruelen(arg1); len1 = VARSIZE(arg1);
len2 = vcTruelen(arg2); len2 = VARSIZE(arg2);
cmp = strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, Min(len1, len2)); cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2));
if (0 == cmp) if (0 == cmp)
return (bool) (len1 <= len2 ? 1 : 0); return (bool) (len1 <= len2 ? 1 : 0);
else else
...@@ -441,10 +417,10 @@ varchargt(char *arg1, char *arg2) ...@@ -441,10 +417,10 @@ varchargt(char *arg1, char *arg2)
if (arg1 == NULL || arg2 == NULL) if (arg1 == NULL || arg2 == NULL)
return ((bool) 0); return ((bool) 0);
len1 = vcTruelen(arg1); len1 = VARSIZE(arg1);
len2 = vcTruelen(arg2); len2 = VARSIZE(arg2);
cmp = strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, Min(len1, len2)); cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2));
if (cmp == 0) if (cmp == 0)
return (len1 > len2); return (len1 > len2);
else else
...@@ -460,10 +436,10 @@ varcharge(char *arg1, char *arg2) ...@@ -460,10 +436,10 @@ varcharge(char *arg1, char *arg2)
if (arg1 == NULL || arg2 == NULL) if (arg1 == NULL || arg2 == NULL)
return ((bool) 0); return ((bool) 0);
len1 = vcTruelen(arg1); len1 = VARSIZE(arg1);
len2 = vcTruelen(arg2); len2 = VARSIZE(arg2);
cmp = strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, Min(len1, len2)); cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2));
if (0 == cmp) if (0 == cmp)
return (bool) (len1 >= len2 ? 1 : 0); return (bool) (len1 >= len2 ? 1 : 0);
else else
...@@ -478,9 +454,9 @@ varcharcmp(char *arg1, char *arg2) ...@@ -478,9 +454,9 @@ varcharcmp(char *arg1, char *arg2)
len2; len2;
int cmp; int cmp;
len1 = vcTruelen(arg1); len1 = VARSIZE(arg1);
len2 = vcTruelen(arg2); len2 = VARSIZE(arg2);
cmp = (strncmp(arg1 + VARHDRSZ, arg2 + VARHDRSZ, Min(len1, len2))); cmp = (strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)));
if ((0 == cmp) && (len1 != len2)) if ((0 == cmp) && (len1 != len2))
return (int32) (len1 < len2 ? -1 : 1); return (int32) (len1 < len2 ? -1 : 1);
else else
...@@ -544,7 +520,7 @@ hashvarchar(struct varlena * key) ...@@ -544,7 +520,7 @@ hashvarchar(struct varlena * key)
int loop; int loop;
keydata = VARDATA(key); keydata = VARDATA(key);
keylen = vcTruelen((char *) key); keylen = VARSIZE((char *) key);
#define HASHC n = *keydata++ + 65599 * n #define HASHC n = *keydata++ + 65599 * n
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -236,7 +236,7 @@ textcat(text *t1, text *t2)
while (len2 > 0 && VARDATA(t2)[len2 - 1] == '\0') while (len2 > 0 && VARDATA(t2)[len2 - 1] == '\0')
len2--; len2--;
result = PALLOC(len = len1 + len2 + VARHDRSZ); result = palloc(len = len1 + len2 + VARHDRSZ);
/* Fill data field of result string... */ /* Fill data field of result string... */
ptr = VARDATA(result); ptr = VARDATA(result);
...@@ -293,7 +293,7 @@ text_substr(text *string, int32 m, int32 n) ...@@ -293,7 +293,7 @@ text_substr(text *string, int32 m, int32 n)
n = (len-m); n = (len-m);
} }
ret = (text *) PALLOC(VARHDRSZ + n); ret = (text *) palloc(VARHDRSZ + n);
VARSIZE(ret) = VARHDRSZ + n; VARSIZE(ret) = VARHDRSZ + n;
memcpy(VARDATA(ret), VARDATA(string)+m, n); memcpy(VARDATA(ret), VARDATA(string)+m, n);
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * 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 * NOTE
* These routines do *not* use the float types from adt/. * These routines do *not* use the float types from adt/.
...@@ -21,8 +21,6 @@ ...@@ -21,8 +21,6 @@
#include "access/attnum.h" #include "access/attnum.h"
/*#ifndef FmgrIncluded -- seems like always included. (it's FMgrIncluded) AY */
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* Useful floating point utilities and constants. * Useful floating point utilities and constants.
*-------------------------------------------------------------------*/ *-------------------------------------------------------------------*/
...@@ -50,16 +48,6 @@ ...@@ -50,16 +48,6 @@
#define HYPOT(A, B) sqrt((A) * (A) + (B) * (B)) #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) * 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 */ #include <float.h> /* faked on sunos */
...@@ -43,7 +43,7 @@ PATH *path; ...@@ -43,7 +43,7 @@ PATH *path;
switch (path->npts) switch (path->npts)
{ {
case 0: case 0:
result = PALLOCTYPE(double); result = palloc(sizeof(double));
*result = Abs((double) DBL_MAX); /* +infinity */ *result = Abs((double) DBL_MAX); /* +infinity */
break; break;
case 1: case 1:
...@@ -56,14 +56,14 @@ PATH *path; ...@@ -56,14 +56,14 @@ PATH *path;
* distance from the point to any of its constituent segments. * distance from the point to any of its constituent segments.
*/ */
Assert(path->npts > 1); Assert(path->npts > 1);
result = PALLOCTYPE(double); result = palloc(sizeof(double));
for (i = 0; i < path->npts - 1; ++i) for (i = 0; i < path->npts - 1; ++i)
{ {
regress_lseg_construct(&lseg, &path->p[i], &path->p[i + 1]); regress_lseg_construct(&lseg, &path->p[i], &path->p[i + 1]);
tmp = dist_ps(pt, &lseg); tmp = dist_ps(pt, &lseg);
if (i == 0 || *tmp < *result) if (i == 0 || *tmp < *result)
*result = *tmp; *result = *tmp;
PFREE(tmp); pfree(tmp);
} }
break; break;
...@@ -97,7 +97,7 @@ PATH *p2; ...@@ -97,7 +97,7 @@ PATH *p2;
if (*min < *(tmp = lseg_distance(&seg1, &seg2))) if (*min < *(tmp = lseg_distance(&seg1, &seg2)))
*min = *tmp; *min = *tmp;
PFREE(tmp); pfree(tmp);
} }
return (min); return (min);
...@@ -108,7 +108,7 @@ poly2path(poly) ...@@ -108,7 +108,7 @@ poly2path(poly)
POLYGON *poly; POLYGON *poly;
{ {
int i; 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]; char buf[2 * (P_MAXDIG) + 20];
sprintf(output, "(1, %*d", P_MAXDIG, poly->npts); 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