Rename bytea functions to not have upper-case letters in their names.

Clean up grotty coding in them, too.  AFAICS from the CVS logs, these
have been broken since Postgres95, so I'm not going to insist on an
initdb to fix them now...
This commit is contained in:
Tom Lane 2000-03-24 02:41:46 +00:00
parent 0edcee3459
commit eca02fee2c
3 changed files with 77 additions and 66 deletions

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.56 2000/01/26 05:57:15 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.57 2000/03/24 02:41:46 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -41,13 +41,13 @@ static int text_cmp(text *arg1, text *arg2);
* The input is scaned twice. * The input is scaned twice.
* The error checking of input is minimal. * The error checking of input is minimal.
*/ */
text * bytea *
byteain(char *inputText) byteain(char *inputText)
{ {
char *tp; char *tp;
char *rp; char *rp;
int byte; int byte;
text *result; bytea *result;
if (inputText == NULL) if (inputText == NULL)
elog(ERROR, "Bad input string for type bytea"); elog(ERROR, "Bad input string for type bytea");
@ -64,7 +64,7 @@ byteain(char *inputText)
} }
tp = inputText; tp = inputText;
byte += VARHDRSZ; byte += VARHDRSZ;
result = (text *) palloc(byte); result = (bytea *) palloc(byte);
result->vl_len = byte; /* varlena? */ result->vl_len = byte; /* varlena? */
rp = result->vl_dat; rp = result->vl_dat;
while (*tp != '\0') while (*tp != '\0')
@ -90,10 +90,9 @@ byteain(char *inputText)
* NULL vlena should be an error--returning string with NULL for now. * NULL vlena should be an error--returning string with NULL for now.
*/ */
char * char *
byteaout(text *vlena) byteaout(bytea *vlena)
{ {
char *result; char *result;
char *vp; char *vp;
char *rp; char *rp;
int val; /* holds unprintable chars */ int val; /* holds unprintable chars */
@ -173,7 +172,6 @@ textin(char *inputText)
* textout - converts internal representation to "..." * textout - converts internal representation to "..."
*/ */
char * char *
textout(text *vlena) textout(text *vlena)
{ {
int len; int len;
@ -218,7 +216,7 @@ textlen(text *t)
#endif #endif
if (!PointerIsValid(t)) if (!PointerIsValid(t))
elog(ERROR, "Null input to textlen"); return 0;
#ifdef MULTIBYTE #ifdef MULTIBYTE
len = 0; len = 0;
@ -247,10 +245,9 @@ int32
textoctetlen(text *t) textoctetlen(text *t)
{ {
if (!PointerIsValid(t)) if (!PointerIsValid(t))
elog(ERROR, "Null input to textoctetlen"); return 0;
return VARSIZE(t) - VARHDRSZ; return VARSIZE(t) - VARHDRSZ;
} /* textoctetlen() */ } /* textoctetlen() */
/* /*
@ -621,19 +618,18 @@ text_smaller(text *arg1, text *arg2)
} }
/*------------------------------------------------------------- /*-------------------------------------------------------------
* byteaGetSize * byteaoctetlen
* *
* get the number of bytes contained in an instance of type 'bytea' * get the number of bytes contained in an instance of type 'bytea'
*------------------------------------------------------------- *-------------------------------------------------------------
*/ */
int32 int32
byteaGetSize(text *v) byteaoctetlen(bytea *v)
{ {
int len; if (!PointerIsValid(v))
return 0;
len = v->vl_len - sizeof(v->vl_len); return VARSIZE(v) - VARHDRSZ;
return len;
} }
/*------------------------------------------------------------- /*-------------------------------------------------------------
@ -645,23 +641,22 @@ byteaGetSize(text *v)
*------------------------------------------------------------- *-------------------------------------------------------------
*/ */
int32 int32
byteaGetByte(text *v, int32 n) byteaGetByte(bytea *v, int32 n)
{ {
int len; int len;
int byte; int byte;
len = byteaGetSize(v); if (!PointerIsValid(v))
return 0;
if (n >= len) len = VARSIZE(v) - VARHDRSZ;
{
elog(ERROR, "byteaGetByte: index (=%d) out of range [0..%d]", if (n < 0 || n >= len)
elog(ERROR, "byteaGetByte: index %d out of range [0..%d]",
n, len - 1); n, len - 1);
}
#ifdef USE_LOCALE byte = ((unsigned char *) VARDATA(v))[n];
byte = (unsigned char) (v->vl_dat[n]);
#else
byte = v->vl_dat[n];
#endif
return (int32) byte; return (int32) byte;
} }
@ -675,16 +670,26 @@ byteaGetByte(text *v, int32 n)
*------------------------------------------------------------- *-------------------------------------------------------------
*/ */
int32 int32
byteaGetBit(text *v, int32 n) byteaGetBit(bytea *v, int32 n)
{ {
int byteNo, int byteNo,
bitNo; bitNo;
int len;
int byte; int byte;
if (!PointerIsValid(v))
return 0;
len = VARSIZE(v) - VARHDRSZ;
if (n < 0 || n >= len*8)
elog(ERROR, "byteaGetBit: index %d out of range [0..%d]",
n, len*8 - 1);
byteNo = n / 8; byteNo = n / 8;
bitNo = n % 8; bitNo = n % 8;
byte = byteaGetByte(v, byteNo); byte = ((unsigned char *) VARDATA(v))[byteNo];
if (byte & (1 << bitNo)) if (byte & (1 << bitNo))
return (int32) 1; return (int32) 1;
@ -700,36 +705,31 @@ byteaGetBit(text *v, int32 n)
* *
*------------------------------------------------------------- *-------------------------------------------------------------
*/ */
text * bytea *
byteaSetByte(text *v, int32 n, int32 newByte) byteaSetByte(bytea *v, int32 n, int32 newByte)
{ {
int len; int len;
text *res; bytea *res;
len = byteaGetSize(v); if (!PointerIsValid(v))
return 0;
if (n >= len) len = VARSIZE(v) - VARHDRSZ;
{
elog(ERROR, if (n < 0 || n >= len)
"byteaSetByte: index (=%d) out of range [0..%d]", elog(ERROR, "byteaSetByte: index %d out of range [0..%d]",
n, len - 1); n, len - 1);
}
/* /*
* Make a copy of the original varlena. * Make a copy of the original varlena.
*/ */
res = (text *) palloc(VARSIZE(v)); res = (bytea *) palloc(VARSIZE(v));
if (res == NULL) memcpy((char *) res, (char *) v, VARSIZE(v));
{
elog(ERROR, "byteaSetByte: Out of memory (%d bytes requested)",
VARSIZE(v));
}
memmove((char *) res, (char *) v, VARSIZE(v));
/* /*
* Now set the byte. * Now set the byte.
*/ */
res->vl_dat[n] = newByte; ((unsigned char *) VARDATA(res))[n] = newByte;
return res; return res;
} }
@ -742,26 +742,37 @@ byteaSetByte(text *v, int32 n, int32 newByte)
* *
*------------------------------------------------------------- *-------------------------------------------------------------
*/ */
text * bytea *
byteaSetBit(text *v, int32 n, int32 newBit) byteaSetBit(bytea *v, int32 n, int32 newBit)
{ {
text *res; bytea *res;
int len;
int oldByte, int oldByte,
newByte; newByte;
int byteNo, int byteNo,
bitNo; bitNo;
if (!PointerIsValid(v))
return NULL;
len = VARSIZE(v) - VARHDRSZ;
if (n < 0 || n >= len*8)
elog(ERROR, "byteaSetBit: index %d out of range [0..%d]",
n, len*8 - 1);
byteNo = n / 8;
bitNo = n % 8;
/* /*
* sanity check! * sanity check!
*/ */
if (newBit != 0 && newBit != 1) if (newBit != 0 && newBit != 1)
elog(ERROR, "byteaSetByte: new bit must be 0 or 1"); elog(ERROR, "byteaSetBit: new bit must be 0 or 1");
/* /*
* get the byte where the bit we want is stored. * get the byte where the bit we want is stored.
*/ */
byteNo = n / 8;
bitNo = n % 8;
oldByte = byteaGetByte(v, byteNo); oldByte = byteaGetByte(v, byteNo);
/* /*

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: pg_proc.h,v 1.128 2000/03/19 01:12:18 tgl Exp $ * $Id: pg_proc.h,v 1.129 2000/03/24 02:41:44 tgl Exp $
* *
* NOTES * NOTES
* The script catalog/genbki.sh reads this file and generates .bki * The script catalog/genbki.sh reads this file and generates .bki
@ -948,15 +948,15 @@ DESCR("equal");
DATA(insert OID = 717 ( int4eqoid PGUID 11 f t t 2 f 16 "23 26" 100 0 0 100 int4eqoid - )); DATA(insert OID = 717 ( int4eqoid PGUID 11 f t t 2 f 16 "23 26" 100 0 0 100 int4eqoid - ));
DESCR("equal"); DESCR("equal");
DATA(insert OID = 720 ( byteaGetSize PGUID 11 f t t 1 f 23 "17" 100 0 0 100 byteaGetSize - )); DATA(insert OID = 720 ( octet_length PGUID 11 f t t 1 f 23 "17" 100 0 0 100 byteaoctetlen - ));
DESCR(""); DESCR("");
DATA(insert OID = 721 ( byteaGetByte PGUID 11 f t t 2 f 23 "17 23" 100 0 0 100 byteaGetByte - )); DATA(insert OID = 721 ( get_byte PGUID 11 f t t 2 f 23 "17 23" 100 0 0 100 byteaGetByte - ));
DESCR(""); DESCR("");
DATA(insert OID = 722 ( byteaSetByte PGUID 11 f t t 3 f 17 "17 23 23" 100 0 0 100 byteaSetByte - )); DATA(insert OID = 722 ( set_byte PGUID 11 f t t 3 f 17 "17 23 23" 100 0 0 100 byteaSetByte - ));
DESCR(""); DESCR("");
DATA(insert OID = 723 ( byteaGetBit PGUID 11 f t t 2 f 23 "17 23" 100 0 0 100 byteaGetBit - )); DATA(insert OID = 723 ( get_bit PGUID 11 f t t 2 f 23 "17 23" 100 0 0 100 byteaGetBit - ));
DESCR(""); DESCR("");
DATA(insert OID = 724 ( byteaSetBit PGUID 11 f t t 3 f 17 "17 23 23" 100 0 0 100 byteaSetBit - )); DATA(insert OID = 724 ( set_bit PGUID 11 f t t 3 f 17 "17 23 23" 100 0 0 100 byteaSetBit - ));
DESCR(""); DESCR("");
DATA(insert OID = 725 ( dist_pl PGUID 11 f t t 2 f 701 "600 628" 100 0 0 100 dist_pl - )); DATA(insert OID = 725 ( dist_pl PGUID 11 f t t 2 f 701 "600 628" 100 0 0 100 dist_pl - ));

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: builtins.h,v 1.106 2000/03/14 23:06:50 thomas Exp $ * $Id: builtins.h,v 1.107 2000/03/24 02:41:45 tgl Exp $
* *
* NOTES * NOTES
* This should normally only be included by fmgr.h. * This should normally only be included by fmgr.h.
@ -450,13 +450,13 @@ extern text *text_substr(text *string, int32 m, int32 n);
extern text *name_text(NameData *s); extern text *name_text(NameData *s);
extern NameData *text_name(text *s); extern NameData *text_name(text *s);
extern struct varlena *byteain(char *inputText); extern bytea *byteain(char *inputText);
extern char *byteaout(struct varlena * vlena); extern char *byteaout(bytea *vlena);
extern int32 byteaGetSize(struct varlena * v); extern int32 byteaoctetlen(bytea *v);
extern int32 byteaGetByte(struct varlena * v, int32 n); extern int32 byteaGetByte(bytea *v, int32 n);
extern int32 byteaGetBit(struct varlena * v, int32 n); extern int32 byteaGetBit(bytea *v, int32 n);
extern struct varlena *byteaSetByte(struct varlena * v, int32 n, int32 newByte); extern bytea *byteaSetByte(bytea *v, int32 n, int32 newByte);
extern struct varlena *byteaSetBit(struct varlena * v, int32 n, int32 newBit); extern bytea *byteaSetBit(bytea *v, int32 n, int32 newBit);
/* like.c */ /* like.c */
extern bool namelike(NameData *n, struct varlena * p); extern bool namelike(NameData *n, struct varlena * p);