Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e6c6146

Browse files
committed
Allow varchar() to only store needed bytes. Remove PALLOC,PALLOCTYPE,PFREE. Clean up use of VARDATA.
1 parent 7a2a7d4 commit e6c6146

File tree

16 files changed

+253
-303
lines changed

16 files changed

+253
-303
lines changed

contrib/datetime/datetime_functions.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ hhmm_in(char *str)
6666
elog(ERROR,"Second must be limited to values 0 through < 60 in '%s'",
6767
str);
6868

69-
time = PALLOCTYPE(TimeADT);
69+
time = palloc(sizeof(TimeADT));
7070

7171
*time = ((((tm->tm_hour*60)+tm->tm_min)*60));
7272

@@ -99,7 +99,7 @@ hhmm_out(TimeADT *time)
9999
sprintf(buf, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
100100
}
101101

102-
result = PALLOC(strlen(buf)+1);
102+
result = palloc(strlen(buf)+1);
103103

104104
strcpy( result, buf);
105105

@@ -109,7 +109,7 @@ hhmm_out(TimeADT *time)
109109
TimeADT *
110110
hhmm(TimeADT *time)
111111
{
112-
TimeADT *result = PALLOCTYPE(TimeADT);
112+
TimeADT *result = palloc(sizeof(TimeADT));
113113

114114
*result = (((int) *time) / 60 * 60);
115115

@@ -119,7 +119,7 @@ hhmm(TimeADT *time)
119119
TimeADT *
120120
time_difference(TimeADT *time1, TimeADT *time2)
121121
{
122-
TimeADT *time = PALLOCTYPE(TimeADT);
122+
TimeADT *time = palloc(sizeof(TimeADT));
123123

124124
*time = (*time1 - *time2);
125125
return(time);
@@ -188,7 +188,7 @@ date_year(DateADT val)
188188
TimeADT *
189189
currenttime()
190190
{
191-
TimeADT *result = PALLOCTYPE(TimeADT);
191+
TimeADT *result = palloc(sizeof(TimeADT));
192192
struct tm *tm;
193193
time_t current_time;
194194

contrib/int8/int8.c

+11-25
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
#define MAXINT8LEN 25
2121

22-
#define USE_LOCAL_CODE 1
23-
2422
#if defined(__alpha) || defined(__GNUC__)
2523
#define HAVE_64BIT_INTS 1
2624
#endif
@@ -79,18 +77,6 @@ int16 int82(int64 * val);
7977
float64 i8tod(int64 * val);
8078
int64 *dtoi8(float64 val);
8179

82-
#if USE_LOCAL_CODE
83-
84-
#ifndef PALLOC
85-
#define PALLOC(p) palloc(p)
86-
#endif
87-
88-
#ifndef PALLOCTYPE
89-
#define PALLOCTYPE(p) palloc(sizeof(p))
90-
#endif
91-
92-
#endif
93-
9480
/***********************************************************************
9581
**
9682
** Routines for 64-bit integers.
@@ -106,7 +92,7 @@ int64 *dtoi8(float64 val);
10692
int64 *
10793
int8in(char *str)
10894
{
109-
int64 *result = PALLOCTYPE(int64);
95+
int64 *result = palloc(sizeof(int64));
11096

11197
#if HAVE_64BIT_INTS
11298
if (!PointerIsValid(str))
@@ -141,7 +127,7 @@ int8out(int64 * val)
141127
if ((len = snprintf(buf, MAXINT8LEN, INT64_FORMAT, *val)) < 0)
142128
elog(ERROR, "Unable to format int8", NULL);
143129

144-
result = PALLOC(len + 1);
130+
result = palloc(len + 1);
145131

146132
strcpy(result, buf);
147133

@@ -245,7 +231,7 @@ int84ge(int64 * val1, int32 val2)
245231
int64 *
246232
int8um(int64 * val)
247233
{
248-
int64 *result = PALLOCTYPE(int64);
234+
int64 *result = palloc(sizeof(int64));
249235

250236
if (!PointerIsValid(val))
251237
return NULL;
@@ -258,7 +244,7 @@ int8um(int64 * val)
258244
int64 *
259245
int8pl(int64 * val1, int64 * val2)
260246
{
261-
int64 *result = PALLOCTYPE(int64);
247+
int64 *result = palloc(sizeof(int64));
262248

263249
if ((!PointerIsValid(val1)) || (!PointerIsValid(val2)))
264250
return NULL;
@@ -271,7 +257,7 @@ int8pl(int64 * val1, int64 * val2)
271257
int64 *
272258
int8mi(int64 * val1, int64 * val2)
273259
{
274-
int64 *result = PALLOCTYPE(int64);
260+
int64 *result = palloc(sizeof(int64));
275261

276262
if ((!PointerIsValid(val1)) || (!PointerIsValid(val2)))
277263
return NULL;
@@ -284,7 +270,7 @@ int8mi(int64 * val1, int64 * val2)
284270
int64 *
285271
int8mul(int64 * val1, int64 * val2)
286272
{
287-
int64 *result = PALLOCTYPE(int64);
273+
int64 *result = palloc(sizeof(int64));
288274

289275
if ((!PointerIsValid(val1)) || (!PointerIsValid(val2)))
290276
return NULL;
@@ -297,7 +283,7 @@ int8mul(int64 * val1, int64 * val2)
297283
int64 *
298284
int8div(int64 * val1, int64 * val2)
299285
{
300-
int64 *result = PALLOCTYPE(int64);
286+
int64 *result = palloc(sizeof(int64));
301287

302288
if ((!PointerIsValid(val1)) || (!PointerIsValid(val2)))
303289
return NULL;
@@ -315,7 +301,7 @@ int8div(int64 * val1, int64 * val2)
315301
int64 *
316302
int48(int32 val)
317303
{
318-
int64 *result = PALLOCTYPE(int64);
304+
int64 *result = palloc(sizeof(int64));
319305

320306
*result = val;
321307

@@ -344,7 +330,7 @@ int28 (int16 val)
344330
{
345331
int64 *result;
346332

347-
if (!PointerIsValid(result = PALLOCTYPE(int64)))
333+
if (!PointerIsValid(result = palloc(sizeof(int64))))
348334
elog(ERROR, "Memory allocation failed, can't convert int8 to int2", NULL);
349335

350336
*result = val;
@@ -370,7 +356,7 @@ int82(int64 * val)
370356
float64
371357
i8tod(int64 * val)
372358
{
373-
float64 result = PALLOCTYPE(float64data);
359+
float64 result = palloc(sizeof(float64data));
374360

375361
*result = *val;
376362

@@ -380,7 +366,7 @@ i8tod(int64 * val)
380366
int64 *
381367
dtoi8(float64 val)
382368
{
383-
int64 *result = PALLOCTYPE(int64);
369+
int64 *result = palloc(sizeof(int64));
384370

385371
if ((*val < (-pow(2, 64) + 1)) || (*val > (pow(2, 64) - 1)))
386372
elog(ERROR, "Floating point conversion to int64 is out of range", NULL);

src/backend/access/rtree/rtproc.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtproc.c,v 1.13 1998/01/05 03:29:59 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtproc.c,v 1.14 1998/01/07 18:46:15 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -91,7 +91,7 @@ rt_poly_union(POLYGON *a, POLYGON *b)
9191
{
9292
POLYGON *p;
9393

94-
p = (POLYGON *) PALLOCTYPE(POLYGON);
94+
p = (POLYGON *) palloc(sizeof(POLYGON));
9595

9696
if (!PointerIsValid(p))
9797
elog(ABORT, "Cannot allocate polygon for union");
@@ -133,7 +133,7 @@ rt_poly_inter(POLYGON *a, POLYGON *b)
133133
{
134134
POLYGON *p;
135135

136-
p = (POLYGON *) PALLOCTYPE(POLYGON);
136+
p = (POLYGON *) palloc(sizeof(POLYGON));
137137

138138
if (!PointerIsValid(p))
139139
elog(ABORT, "Cannot allocate polygon for intersection");

src/backend/commands/variable.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Routines for handling of 'SET var TO',
33
* 'SHOW var' and 'RESET var' statements.
44
*
5-
* $Id: variable.c,v 1.1 1998/01/05 18:42:50 momjian Exp $
5+
* $Id: variable.c,v 1.2 1998/01/07 18:46:26 momjian Exp $
66
*
77
*/
88

@@ -73,7 +73,7 @@ get_token(char **tok, char **val, const char *str)
7373
len++;
7474
}
7575

76-
*tok = (char *) PALLOC(len + 1);
76+
*tok = (char *) palloc(len + 1);
7777
StrNCpy(*tok, start, len+1);
7878

7979
/* skip white spaces */
@@ -119,7 +119,7 @@ get_token(char **tok, char **val, const char *str)
119119
len++;
120120
}
121121

122-
*val = (char *) PALLOC(len + 1);
122+
*val = (char *) palloc(len + 1);
123123
StrNCpy(*val, start, len+1);
124124

125125
/* skip white spaces */
@@ -186,7 +186,7 @@ parse_geqo(const char *value)
186186
geqo_rels = pg_atoi(val, sizeof(int32), '\0');
187187
if (geqo_rels <= 1)
188188
elog(ERROR, "Bad value for # of relations (%s)", val);
189-
PFREE(val);
189+
pfree(val);
190190
}
191191
_use_geqo_ = true;
192192
_use_geqo_rels_ = geqo_rels;
@@ -200,7 +200,7 @@ parse_geqo(const char *value)
200200
else
201201
elog(ERROR, "Bad value for GEQO (%s)", value);
202202

203-
PFREE(tok);
203+
pfree(tok);
204204
return TRUE;
205205
}
206206

@@ -394,7 +394,7 @@ parse_date(const char *value)
394394
{
395395
elog(ERROR, "Bad value for date style (%s)", tok);
396396
}
397-
PFREE(tok);
397+
pfree(tok);
398398
}
399399

400400
if (dcnt > 1 || ecnt > 1)
@@ -493,7 +493,7 @@ parse_timezone(const char *value)
493493
elog(ERROR, "Unable to set TZ environment variable to %s", tok);
494494

495495
tzset();
496-
PFREE(tok);
496+
pfree(tok);
497497
}
498498

499499
return TRUE;

0 commit comments

Comments
 (0)