Skip to content

Commit 4cbb646

Browse files
committed
Fix several possibly non-portable gaffs in record_image_ops.
Sparc machines in the buildfarm were made happy by the previous fix, but PowerPC machines still are still failing. Hopefully this will cure that.
1 parent ada0101 commit 4cbb646

File tree

1 file changed

+75
-9
lines changed

1 file changed

+75
-9
lines changed

src/backend/utils/adt/rowtypes.c

Lines changed: 75 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -898,8 +898,6 @@ record_cmp(FunctionCallInfo fcinfo)
898898
{
899899
TypeCacheEntry *typentry;
900900
Oid collation;
901-
FunctionCallInfoData locfcinfo;
902-
int32 cmpresult;
903901

904902
/*
905903
* Skip dropped columns
@@ -959,6 +957,9 @@ record_cmp(FunctionCallInfo fcinfo)
959957
*/
960958
if (!nulls1[i1] || !nulls2[i2])
961959
{
960+
FunctionCallInfoData locfcinfo;
961+
int32 cmpresult;
962+
962963
if (nulls1[i1])
963964
{
964965
/* arg1 is greater than arg2 */
@@ -1295,12 +1296,12 @@ btrecordcmp(PG_FUNCTION_ARGS)
12951296
* identical. As an example, for the citext type 'A' and 'a' are equal, but
12961297
* they are not identical.
12971298
*/
1298-
static bool
1299-
record_image_cmp(PG_FUNCTION_ARGS)
1299+
static int
1300+
record_image_cmp(FunctionCallInfo fcinfo)
13001301
{
13011302
HeapTupleHeader record1 = PG_GETARG_HEAPTUPLEHEADER(0);
13021303
HeapTupleHeader record2 = PG_GETARG_HEAPTUPLEHEADER(1);
1303-
int32 result = 0;
1304+
int result = 0;
13041305
Oid tupType1;
13051306
Oid tupType2;
13061307
int32 tupTypmod1;
@@ -1418,6 +1419,12 @@ record_image_cmp(PG_FUNCTION_ARGS)
14181419
format_type_be(tupdesc2->attrs[i2]->atttypid),
14191420
j + 1)));
14201421

1422+
/*
1423+
* The same type should have the same length (or both should be variable).
1424+
*/
1425+
Assert(tupdesc1->attrs[i1]->attlen ==
1426+
tupdesc2->attrs[i2]->attlen);
1427+
14211428
/*
14221429
* We consider two NULLs equal; NULL > not-NULL.
14231430
*/
@@ -1453,7 +1460,7 @@ record_image_cmp(PG_FUNCTION_ARGS)
14531460

14541461
cmpresult = memcmp(VARDATA_ANY(arg1val),
14551462
VARDATA_ANY(arg2val),
1456-
len1 - VARHDRSZ);
1463+
Min(len1, len2) - VARHDRSZ);
14571464
if ((cmpresult == 0) && (len1 != len2))
14581465
cmpresult = (len1 < len2) ? -1 : 1;
14591466

@@ -1464,8 +1471,45 @@ record_image_cmp(PG_FUNCTION_ARGS)
14641471
}
14651472
else if (tupdesc1->attrs[i1]->attbyval)
14661473
{
1467-
if (values1[i1] != values2[i2])
1468-
cmpresult = (values1[i1] < values2[i2]) ? -1 : 1;
1474+
switch (tupdesc1->attrs[i1]->attlen)
1475+
{
1476+
case 1:
1477+
if (GET_1_BYTE(values1[i1]) !=
1478+
GET_1_BYTE(values2[i2]))
1479+
{
1480+
cmpresult = (GET_1_BYTE(values1[i1]) <
1481+
GET_1_BYTE(values2[i2])) ? -1 : 1;
1482+
}
1483+
break;
1484+
case 2:
1485+
if (GET_2_BYTES(values1[i1]) !=
1486+
GET_2_BYTES(values2[i2]))
1487+
{
1488+
cmpresult = (GET_2_BYTES(values1[i1]) <
1489+
GET_2_BYTES(values2[i2])) ? -1 : 1;
1490+
}
1491+
break;
1492+
case 4:
1493+
if (GET_4_BYTES(values1[i1]) !=
1494+
GET_4_BYTES(values2[i2]))
1495+
{
1496+
cmpresult = (GET_4_BYTES(values1[i1]) <
1497+
GET_4_BYTES(values2[i2])) ? -1 : 1;
1498+
}
1499+
break;
1500+
#if SIZEOF_DATUM == 8
1501+
case 8:
1502+
if (GET_8_BYTES(values1[i1]) !=
1503+
GET_8_BYTES(values2[i2]))
1504+
{
1505+
cmpresult = (GET_8_BYTES(values1[i1]) <
1506+
GET_8_BYTES(values2[i2])) ? -1 : 1;
1507+
}
1508+
break;
1509+
#endif
1510+
default:
1511+
Assert(false); /* cannot happen */
1512+
}
14691513
}
14701514
else
14711515
{
@@ -1694,7 +1738,29 @@ record_image_eq(PG_FUNCTION_ARGS)
16941738
}
16951739
else if (tupdesc1->attrs[i1]->attbyval)
16961740
{
1697-
result = (values1[i1] == values2[i2]);
1741+
switch (tupdesc1->attrs[i1]->attlen)
1742+
{
1743+
case 1:
1744+
result = (GET_1_BYTE(values1[i1]) ==
1745+
GET_1_BYTE(values2[i2]));
1746+
break;
1747+
case 2:
1748+
result = (GET_2_BYTES(values1[i1]) ==
1749+
GET_2_BYTES(values2[i2]));
1750+
break;
1751+
case 4:
1752+
result = (GET_4_BYTES(values1[i1]) ==
1753+
GET_4_BYTES(values2[i2]));
1754+
break;
1755+
#if SIZEOF_DATUM == 8
1756+
case 8:
1757+
result = (GET_8_BYTES(values1[i1]) ==
1758+
GET_8_BYTES(values2[i2]));
1759+
break;
1760+
#endif
1761+
default:
1762+
Assert(false); /* cannot happen */
1763+
}
16981764
}
16991765
else
17001766
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy