1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-10 17:42:29 +03:00

Latest round of fmgr updates. All functions with bool,char, or int2

inputs have been converted to newstyle.  This should go a long way towards
fixing our portability problems with platforms where char and short
parameters are passed differently from int-width parameters.  Still
more to do for the Alpha port however.
This commit is contained in:
Tom Lane
2000-06-05 07:29:25 +00:00
parent c61db5ba2d
commit 48165ec226
47 changed files with 2201 additions and 2034 deletions

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashfunc.c,v 1.25 2000/04/12 17:14:44 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashfunc.c,v 1.26 2000/06/05 07:28:35 tgl Exp $
*
* NOTES
* These functions are stored in pg_amproc. For each operator class
@@ -21,134 +21,132 @@
#include "access/hash.h"
uint32
hashint2(int16 key)
Datum
hashint2(PG_FUNCTION_ARGS)
{
return (uint32) ~key;
PG_RETURN_UINT32((uint32) ~ PG_GETARG_INT16(0));
}
uint32
hashint4(uint32 key)
Datum
hashint4(PG_FUNCTION_ARGS)
{
return ~key;
PG_RETURN_UINT32(~ PG_GETARG_UINT32(0));
}
uint32
hashint8(int64 *key)
Datum
hashint8(PG_FUNCTION_ARGS)
{
return ~((uint32) *key);
/* we just use the low 32 bits... */
PG_RETURN_UINT32(~((uint32) PG_GETARG_INT64(0)));
}
/* Hash function from Chris Torek. */
uint32
hashfloat4(float32 keyp)
Datum
hashfloat4(PG_FUNCTION_ARGS)
{
int len;
float4 key = PG_GETARG_FLOAT4(0);
char *kp = (char *) &key;
int len = sizeof(key);
int loop;
uint32 h;
char *kp = (char *) keyp;
len = sizeof(float32data);
#define HASH4a h = (h << 5) - h + *kp++;
#define HASH4b h = (h << 5) + h + *kp++;
#define HASH4 HASH4b
h = 0;
if (len > 0)
{
loop = (len + 8 - 1) >> 3;
/*
* This is a tad silly, given that we expect len = 4, but a smart
* compiler should be able to eliminate the redundant code...
*/
loop = (len + 8 - 1) >> 3;
switch (len & (8 - 1))
{
case 0:
do
{ /* All fall throughs */
HASH4;
case 7:
HASH4;
case 6:
HASH4;
case 5:
HASH4;
case 4:
HASH4;
case 3:
HASH4;
case 2:
HASH4;
case 1:
HASH4;
} while (--loop);
}
switch (len & (8 - 1))
{
case 0:
do
{ /* All fall throughs */
HASH4;
case 7:
HASH4;
case 6:
HASH4;
case 5:
HASH4;
case 4:
HASH4;
case 3:
HASH4;
case 2:
HASH4;
case 1:
HASH4;
} while (--loop);
}
return h;
PG_RETURN_UINT32(h);
}
uint32
hashfloat8(float64 keyp)
Datum
hashfloat8(PG_FUNCTION_ARGS)
{
int len;
float8 key = PG_GETARG_FLOAT8(0);
char *kp = (char *) &key;
int len = sizeof(key);
int loop;
uint32 h;
char *kp = (char *) keyp;
len = sizeof(float64data);
#define HASH4a h = (h << 5) - h + *kp++;
#define HASH4b h = (h << 5) + h + *kp++;
#define HASH4 HASH4b
h = 0;
if (len > 0)
/*
* This is a tad silly, given that we expect len = 8, but a smart
* compiler should be able to eliminate the redundant code...
*/
loop = (len + 8 - 1) >> 3;
switch (len & (8 - 1))
{
loop = (len + 8 - 1) >> 3;
switch (len & (8 - 1))
{
case 0:
do
{ /* All fall throughs */
HASH4;
case 7:
HASH4;
case 6:
HASH4;
case 5:
HASH4;
case 4:
HASH4;
case 3:
HASH4;
case 2:
HASH4;
case 1:
HASH4;
} while (--loop);
}
case 0:
do
{ /* All fall throughs */
HASH4;
case 7:
HASH4;
case 6:
HASH4;
case 5:
HASH4;
case 4:
HASH4;
case 3:
HASH4;
case 2:
HASH4;
case 1:
HASH4;
} while (--loop);
}
return h;
PG_RETURN_UINT32(h);
}
uint32
hashoid(Oid key)
Datum
hashoid(PG_FUNCTION_ARGS)
{
return (uint32) ~key;
PG_RETURN_UINT32(~(uint32) PG_GETARG_OID(0));
}
uint32
hashoidvector(Oid *key)
Datum
hashoidvector(PG_FUNCTION_ARGS)
{
Oid *key = (Oid *) PG_GETARG_POINTER(0);
int i;
uint32 result = 0;
for (i = INDEX_MAX_KEYS; --i >= 0;)
result = (result << 1) ^ (~(uint32) key[i]);
return result;
PG_RETURN_UINT32(result);
}
/*
@@ -156,55 +154,50 @@ hashoidvector(Oid *key)
* hash function, because it has no pg_proc entry. We only need it
* for catcache indexing.
*/
uint32
hashint2vector(int16 *key)
Datum
hashint2vector(PG_FUNCTION_ARGS)
{
int16 *key = (int16 *) PG_GETARG_POINTER(0);
int i;
uint32 result = 0;
for (i = INDEX_MAX_KEYS; --i >= 0;)
result = (result << 1) ^ (~(uint32) key[i]);
return result;
PG_RETURN_UINT32(result);
}
#define PRIME1 37
#define PRIME2 1048583
uint32
hashchar(char key)
Datum
hashchar(PG_FUNCTION_ARGS)
{
uint32 h;
/* Convert char to integer */
h = (key - ' ');
h = (PG_GETARG_CHAR(0) - ' ');
h %= PRIME2;
return h;
PG_RETURN_UINT32(h);
}
uint32
hashname(NameData *n)
Datum
hashname(PG_FUNCTION_ARGS)
{
char *key = NameStr(* PG_GETARG_NAME(0));
int len = NAMEDATALEN;
uint32 h;
int len;
char *key;
key = NameStr(*n);
h = 0;
len = NAMEDATALEN;
/* Convert string to integer */
while (len--)
h = h * PRIME1 ^ (*key++ - ' ');
h %= PRIME2;
return h;
PG_RETURN_UINT32(h);
}
/*
* (Comment from the original db3 hashing code: )
*
@@ -216,19 +209,17 @@ hashname(NameData *n)
*
* "OZ's original sdbm hash"
*/
uint32
hashtext(struct varlena * key)
Datum
hashtext(PG_FUNCTION_ARGS)
{
text *key = PG_GETARG_TEXT_P(0);
int keylen;
char *keydata;
uint32 n;
int loop;
keydata = VARDATA(key);
keylen = VARSIZE(key);
/* keylen includes the four bytes in which string keylength is stored */
keylen -= sizeof(VARSIZE(key));
keylen = VARSIZE(key) - VARHDRSZ;
#define HASHC n = *keydata++ + 65599 * n
@@ -260,5 +251,5 @@ hashtext(struct varlena * key)
} while (--loop);
}
}
return n;
PG_RETURN_UINT32(n);
}

View File

@@ -8,141 +8,203 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.34 2000/04/12 17:14:49 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.35 2000/06/05 07:28:36 tgl Exp $
*
* NOTES
* These functions are stored in pg_amproc. For each operator class
* defined on btrees, they compute
* NOTES
*
* These functions are stored in pg_amproc. For each operator class
* defined on btrees, they compute
*
* compare(a, b):
* < 0 if a < b,
* = 0 if a == b,
* > 0 if a > b.
*
* The result is always an int32 regardless of the input datatype.
*
* NOTE: although any negative int32 is acceptable for reporting "<",
* and any positive int32 is acceptable for reporting ">", routines
* that work on 32-bit or wider datatypes can't just return "a - b".
* That could overflow and give the wrong answer.
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "utils/builtins.h"
int32
btint2cmp(int16 a, int16 b)
Datum
btboolcmp(PG_FUNCTION_ARGS)
{
return (int32) (a - b);
bool a = PG_GETARG_BOOL(0);
bool b = PG_GETARG_BOOL(1);
PG_RETURN_INT32((int32) a - (int32) b);
}
int32
btint4cmp(int32 a, int32 b)
Datum
btint2cmp(PG_FUNCTION_ARGS)
{
int16 a = PG_GETARG_INT16(0);
int16 b = PG_GETARG_INT16(1);
PG_RETURN_INT32((int32) a - (int32) b);
}
Datum
btint4cmp(PG_FUNCTION_ARGS)
{
int32 a = PG_GETARG_INT32(0);
int32 b = PG_GETARG_INT32(1);
if (a > b)
return 1;
PG_RETURN_INT32(1);
else if (a == b)
return 0;
PG_RETURN_INT32(0);
else
return -1;
PG_RETURN_INT32(-1);
}
int32
btint8cmp(int64 *a, int64 *b)
Datum
btint8cmp(PG_FUNCTION_ARGS)
{
if (*a > *b)
return 1;
else if (*a == *b)
return 0;
else
return -1;
}
int64 a = PG_GETARG_INT64(0);
int64 b = PG_GETARG_INT64(1);
int32
btint24cmp(int16 a, int32 b)
{
return ((int32) a) - b;
}
int32
btint42cmp(int32 a, int16 b)
{
return a - ((int32) b);
}
int32
btfloat4cmp(float32 a, float32 b)
{
if (*a > *b)
return 1;
else if (*a == *b)
return 0;
else
return -1;
}
int32
btfloat8cmp(float64 a, float64 b)
{
if (*a > *b)
return 1;
else if (*a == *b)
return 0;
else
return -1;
}
int32
btoidcmp(Oid a, Oid b)
{
if (a > b)
return 1;
PG_RETURN_INT32(1);
else if (a == b)
return 0;
PG_RETURN_INT32(0);
else
return -1;
PG_RETURN_INT32(-1);
}
int32
btoidvectorcmp(Oid *a, Oid *b)
Datum
btint24cmp(PG_FUNCTION_ARGS)
{
int16 a = PG_GETARG_INT16(0);
int32 b = PG_GETARG_INT32(1);
if (a > b)
PG_RETURN_INT32(1);
else if (a == b)
PG_RETURN_INT32(0);
else
PG_RETURN_INT32(-1);
}
Datum
btint42cmp(PG_FUNCTION_ARGS)
{
int32 a = PG_GETARG_INT32(0);
int16 b = PG_GETARG_INT16(1);
if (a > b)
PG_RETURN_INT32(1);
else if (a == b)
PG_RETURN_INT32(0);
else
PG_RETURN_INT32(-1);
}
Datum
btfloat4cmp(PG_FUNCTION_ARGS)
{
float4 a = PG_GETARG_FLOAT4(0);
float4 b = PG_GETARG_FLOAT4(1);
if (a > b)
PG_RETURN_INT32(1);
else if (a == b)
PG_RETURN_INT32(0);
else
PG_RETURN_INT32(-1);
}
Datum
btfloat8cmp(PG_FUNCTION_ARGS)
{
float8 a = PG_GETARG_FLOAT8(0);
float8 b = PG_GETARG_FLOAT8(1);
if (a > b)
PG_RETURN_INT32(1);
else if (a == b)
PG_RETURN_INT32(0);
else
PG_RETURN_INT32(-1);
}
Datum
btoidcmp(PG_FUNCTION_ARGS)
{
Oid a = PG_GETARG_OID(0);
Oid b = PG_GETARG_OID(1);
if (a > b)
PG_RETURN_INT32(1);
else if (a == b)
PG_RETURN_INT32(0);
else
PG_RETURN_INT32(-1);
}
Datum
btoidvectorcmp(PG_FUNCTION_ARGS)
{
Oid *a = (Oid *) PG_GETARG_POINTER(0);
Oid *b = (Oid *) PG_GETARG_POINTER(1);
int i;
for (i = 0; i < INDEX_MAX_KEYS; i++)
/* we use this because we need the int4gt, etc */
if (!int4eq(a[i], b[i]))
{
if (a[i] != b[i])
{
if (int4gt(a[i], b[i]))
return 1;
if (a[i] > b[i])
PG_RETURN_INT32(1);
else
return -1;
PG_RETURN_INT32(-1);
}
return 0;
}
PG_RETURN_INT32(0);
}
int32
btabstimecmp(AbsoluteTime a, AbsoluteTime b)
{
if (AbsoluteTimeIsBefore(a, b))
return -1;
PG_RETURN_INT32(-1);
else if (AbsoluteTimeIsBefore(b, a))
return 1;
PG_RETURN_INT32(1);
else
return 0;
PG_RETURN_INT32(0);
}
int32
btcharcmp(char a, char b)
Datum
btcharcmp(PG_FUNCTION_ARGS)
{
return (int32) ((uint8) a - (uint8) b);
char a = PG_GETARG_CHAR(0);
char b = PG_GETARG_CHAR(1);
/* Be careful to compare chars as unsigned */
PG_RETURN_INT32((int32) ((uint8) a) - (int32) ((uint8) b));
}
int32
btnamecmp(NameData *a, NameData *b)
Datum
btnamecmp(PG_FUNCTION_ARGS)
{
return strncmp(NameStr(*a), NameStr(*b), NAMEDATALEN);
Name a = PG_GETARG_NAME(0);
Name b = PG_GETARG_NAME(1);
PG_RETURN_INT32(strncmp(NameStr(*a), NameStr(*b), NAMEDATALEN));
}
int32
bttextcmp(struct varlena * a, struct varlena * b)
Datum
bttextcmp(PG_FUNCTION_ARGS)
{
text *a = PG_GETARG_TEXT_P(0);
text *b = PG_GETARG_TEXT_P(1);
int res;
unsigned char *ap,
*bp;
@@ -187,7 +249,7 @@ bttextcmp(struct varlena * a, struct varlena * b)
{
do
{
res = (int) (*ap++ - *bp++);
res = (int) *ap++ - (int) *bp++;
len--;
} while (res == 0 && len != 0);
}
@@ -195,7 +257,7 @@ bttextcmp(struct varlena * a, struct varlena * b)
#endif
if (res != 0 || VARSIZE(a) == VARSIZE(b))
return res;
PG_RETURN_INT32(res);
/*
* The two strings are the same in the first len bytes, and they are
@@ -203,13 +265,7 @@ bttextcmp(struct varlena * a, struct varlena * b)
*/
if (VARSIZE(a) < VARSIZE(b))
return -1;
PG_RETURN_INT32(-1);
else
return 1;
}
int32
btboolcmp(bool a, bool b)
{
return (int32) ((uint8) a - (uint8) b);
PG_RETURN_INT32(1);
}

View File

@@ -1,12 +1,12 @@
/*-------------------------------------------------------------------------
*
* xid.c
* POSTGRES transaction identifier code.
* POSTGRES transaction identifier type.
*
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: xid.c,v 1.27 2000/01/26 05:56:04 momjian Exp $
* $Id: xid.c,v 1.28 2000/06/05 07:28:38 tgl Exp $
*
* OLD COMMENTS
* XXX WARNING
@@ -19,33 +19,42 @@
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "access/xact.h"
/*
* TransactionId is typedef'd as uint32, so...
*/
#define PG_GETARG_TRANSACTIONID(n) PG_GETARG_UINT32(n)
#define PG_RETURN_TRANSACTIONID(x) PG_RETURN_UINT32(x)
extern TransactionId NullTransactionId;
extern TransactionId DisabledTransactionId;
extern TransactionId AmiTransactionId;
extern TransactionId FirstTransactionId;
/* XXX name for catalogs */
TransactionId
xidin(char *representation)
Datum
xidin(PG_FUNCTION_ARGS)
{
return atol(representation);
char *representation = PG_GETARG_CSTRING(0);
PG_RETURN_TRANSACTIONID((TransactionId) atol(representation));
}
/* XXX name for catalogs */
char *
xidout(TransactionId transactionId)
Datum
xidout(PG_FUNCTION_ARGS)
{
TransactionId transactionId = PG_GETARG_TRANSACTIONID(0);
/* maximum 32 bit unsigned integer representation takes 10 chars */
char *representation = palloc(11);
snprintf(representation, 11, "%u", transactionId);
return representation;
snprintf(representation, 11, "%lu", (unsigned long) transactionId);
PG_RETURN_CSTRING(representation);
}
/* ----------------------------------------------------------------
@@ -57,14 +66,15 @@ xidout(TransactionId transactionId)
* xideq - returns 1, iff xid1 == xid2
* 0 else;
*/
bool
xideq(TransactionId xid1, TransactionId xid2)
Datum
xideq(PG_FUNCTION_ARGS)
{
return (bool) (xid1 == xid2);
TransactionId xid1 = PG_GETARG_TRANSACTIONID(0);
TransactionId xid2 = PG_GETARG_TRANSACTIONID(1);
PG_RETURN_BOOL(xid1 == xid2);
}
/* ----------------------------------------------------------------
* TransactionIdAdd
* ----------------------------------------------------------------
@@ -73,5 +83,4 @@ void
TransactionIdAdd(TransactionId *xid, int value)
{
*xid += value;
return;
}