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

Commit c36418b

Browse files
committed
Fix getDatumCopy(): don't use store_att_byval to copy into a Datum
variable (this accounts for regression failures on PPC64, and in fact won't work on any big-endian machine). Get rid of hardwired knowledge about datum size rules; make it look just like datumCopy().
1 parent e040ab4 commit c36418b

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

src/backend/access/gin/ginbulk.c

+22-25
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/gin/ginbulk.c,v 1.3 2006/07/14 14:52:16 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/gin/ginbulk.c,v 1.4 2006/07/16 00:54:22 tgl Exp $
1212
*-------------------------------------------------------------------------
1313
*/
1414

1515
#include "postgres.h"
16+
1617
#include "access/gin.h"
18+
#include "utils/datum.h"
19+
1720

1821
#define DEF_NENTRY 2048
1922
#define DEF_NPTR 4
@@ -66,37 +69,31 @@ ginInsertData(BuildAccumulator *accum, EntryAccumulator *entry, ItemPointer heap
6669
entry->number++;
6770
}
6871

72+
/*
73+
* This is basically the same as datumCopy(), but we duplicate some code
74+
* to avoid computing the datum size twice.
75+
*/
6976
static Datum
7077
getDatumCopy(BuildAccumulator *accum, Datum value) {
7178
Form_pg_attribute *att = accum->ginstate->tupdesc->attrs;
72-
Datum newvalue;
73-
int data_length = 0;
74-
void *ptr;
79+
Datum res;
7580

76-
if ( att[0]->attbyval ) {
77-
store_att_byval(&newvalue, value, att[0]->attlen);
78-
} else {
79-
/* pass-by-reference */
80-
if (att[0]->attlen == -1) {
81-
/* varlena */
82-
data_length = VARATT_SIZE(DatumGetPointer(value));
83-
} else if (att[0]->attlen == -2) {
84-
/* c-string */
85-
data_length = strlen(DatumGetCString(value)) + 1;
86-
} else {
87-
/* fixed-length pass-by-reference */
88-
Assert(att[0]->attlen > 0);
89-
data_length = att[0]->attlen;
90-
}
81+
if (att[0]->attbyval)
82+
res = value;
83+
else
84+
{
85+
Size realSize;
86+
char *s;
9187

92-
ptr = palloc( data_length );
93-
memcpy(ptr, DatumGetPointer(value), data_length);
94-
newvalue = PointerGetDatum(ptr);
95-
}
88+
realSize = datumGetSize(value, false, att[0]->attlen);
9689

97-
accum->allocatedMemory+=data_length;
90+
s = (char *) palloc(realSize);
91+
memcpy(s, DatumGetPointer(value), realSize);
92+
res = PointerGetDatum(s);
9893

99-
return newvalue;
94+
accum->allocatedMemory += realSize;
95+
}
96+
return res;
10097
}
10198

10299
/*

0 commit comments

Comments
 (0)