mirror of https://github.com/postgres/postgres
A few changes to cleanup the code.
- Added the header access/heapam.h. - Changed all instances of "length" to "data_length" to quiet the compiler. - initialized a few variables. The compiler couldn't see that the code guaranteed that these would be initialized before being dereferenced. If anyone wants to check my work follow the usage of these variables and make sure that this true and wasn't actually a bug in the original code. - added a missing break statement to a default case. This was a benign error but bad style. - layed out heap_sysattrlen differently. I think this way makes the structure of the code crystal clear. There should be no actual difference in the actual behaviour of the code. Submitted by: darcy@druid.druid.com (D'Arcy J.M. Cain)
This commit is contained in:
parent
efebd7b7aa
commit
3023dc6af0
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.3 1996/08/27 07:42:13 scrappy Exp $
|
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.4 1996/09/19 20:00:37 scrappy Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
* The old interface functions have been converted to macros
|
* The old interface functions have been converted to macros
|
||||||
|
@ -24,6 +24,7 @@
|
||||||
#include "access/itup.h"
|
#include "access/itup.h"
|
||||||
#include "access/tupmacs.h"
|
#include "access/tupmacs.h"
|
||||||
#include "access/skey.h"
|
#include "access/skey.h"
|
||||||
|
#include "access/heapam.h"
|
||||||
#include "storage/ipc.h"
|
#include "storage/ipc.h"
|
||||||
#include "storage/buf.h"
|
#include "storage/buf.h"
|
||||||
#include "storage/bufmgr.h"
|
#include "storage/bufmgr.h"
|
||||||
|
@ -56,12 +57,12 @@ ComputeDataSize(TupleDesc tupleDesc,
|
||||||
Datum value[],
|
Datum value[],
|
||||||
char nulls[])
|
char nulls[])
|
||||||
{
|
{
|
||||||
uint32 length;
|
uint32 data_length;
|
||||||
int i;
|
int i;
|
||||||
int numberOfAttributes = tupleDesc->natts;
|
int numberOfAttributes = tupleDesc->natts;
|
||||||
AttributeTupleForm *att = tupleDesc->attrs;
|
AttributeTupleForm *att = tupleDesc->attrs;
|
||||||
|
|
||||||
for (length = 0, i = 0; i < numberOfAttributes; i++) {
|
for (data_length = 0, i = 0; i < numberOfAttributes; i++) {
|
||||||
if (nulls[i] != ' ') continue;
|
if (nulls[i] != ' ') continue;
|
||||||
|
|
||||||
switch (att[i]->attlen) {
|
switch (att[i]->attlen) {
|
||||||
|
@ -71,35 +72,35 @@ ComputeDataSize(TupleDesc tupleDesc,
|
||||||
* must include the additional sizeof long.
|
* must include the additional sizeof long.
|
||||||
*/
|
*/
|
||||||
if (att[i]->attalign == 'd') {
|
if (att[i]->attalign == 'd') {
|
||||||
length = DOUBLEALIGN(length)
|
data_length = DOUBLEALIGN(data_length)
|
||||||
+ VARSIZE(DatumGetPointer(value[i]));
|
+ VARSIZE(DatumGetPointer(value[i]));
|
||||||
} else {
|
} else {
|
||||||
length = INTALIGN(length)
|
data_length = INTALIGN(data_length)
|
||||||
+ VARSIZE(DatumGetPointer(value[i]));
|
+ VARSIZE(DatumGetPointer(value[i]));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case sizeof(char):
|
case sizeof(char):
|
||||||
length++;
|
data_length++;
|
||||||
break;
|
break;
|
||||||
case sizeof(short):
|
case sizeof(short):
|
||||||
length = SHORTALIGN(length + sizeof(short));
|
data_length = SHORTALIGN(data_length + sizeof(short));
|
||||||
break;
|
break;
|
||||||
case sizeof(int32):
|
case sizeof(int32):
|
||||||
length = INTALIGN(length + sizeof(int32));
|
data_length = INTALIGN(data_length + sizeof(int32));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (att[i]->attlen < sizeof(int32))
|
if (att[i]->attlen < sizeof(int32))
|
||||||
elog(WARN, "ComputeDataSize: attribute %d has len %d",
|
elog(WARN, "ComputeDataSize: attribute %d has len %d",
|
||||||
i, att[i]->attlen);
|
i, att[i]->attlen);
|
||||||
if (att[i]->attalign == 'd')
|
if (att[i]->attalign == 'd')
|
||||||
length = DOUBLEALIGN(length) + att[i]->attlen;
|
data_length = DOUBLEALIGN(data_length) + att[i]->attlen;
|
||||||
else
|
else
|
||||||
length = LONGALIGN(length) + att[i]->attlen;
|
data_length = LONGALIGN(data_length) + att[i]->attlen;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return length;
|
return data_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
|
@ -114,12 +115,12 @@ DataFill(char *data,
|
||||||
char *infomask,
|
char *infomask,
|
||||||
bits8 *bit)
|
bits8 *bit)
|
||||||
{
|
{
|
||||||
bits8 *bitP;
|
bits8 *bitP = 0;
|
||||||
int bitmask;
|
int bitmask = 0;
|
||||||
uint32 length;
|
uint32 data_length;
|
||||||
int i;
|
int i;
|
||||||
int numberOfAttributes = tupleDesc->natts;
|
int numberOfAttributes = tupleDesc->natts;
|
||||||
AttributeTupleForm* att = tupleDesc->attrs;
|
AttributeTupleForm *att = tupleDesc->attrs;
|
||||||
|
|
||||||
if (bit != NULL) {
|
if (bit != NULL) {
|
||||||
bitP = &bit[-1];
|
bitP = &bit[-1];
|
||||||
|
@ -154,9 +155,9 @@ DataFill(char *data,
|
||||||
} else {
|
} else {
|
||||||
data = (char *) INTALIGN(data);
|
data = (char *) INTALIGN(data);
|
||||||
}
|
}
|
||||||
length = VARSIZE(DatumGetPointer(value[i]));
|
data_length = VARSIZE(DatumGetPointer(value[i]));
|
||||||
memmove(data, DatumGetPointer(value[i]),length);
|
memmove(data, DatumGetPointer(value[i]),data_length);
|
||||||
data += length;
|
data += data_length;
|
||||||
break;
|
break;
|
||||||
case sizeof(char):
|
case sizeof(char):
|
||||||
*data = att[i]->attbyval ?
|
*data = att[i]->attbyval ?
|
||||||
|
@ -192,7 +193,7 @@ DataFill(char *data,
|
||||||
att[i]->attlen);
|
att[i]->attlen);
|
||||||
data += att[i]->attlen;
|
data += att[i]->attlen;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,49 +257,27 @@ int
|
||||||
heap_sysattrlen(AttrNumber attno)
|
heap_sysattrlen(AttrNumber attno)
|
||||||
{
|
{
|
||||||
HeapTupleData *f = NULL;
|
HeapTupleData *f = NULL;
|
||||||
int len;
|
|
||||||
|
|
||||||
switch (attno) {
|
switch (attno) {
|
||||||
case SelfItemPointerAttributeNumber:
|
case SelfItemPointerAttributeNumber: return sizeof f->t_ctid;
|
||||||
len = sizeof f->t_ctid;
|
case ObjectIdAttributeNumber: return sizeof f->t_oid;
|
||||||
break;
|
case MinTransactionIdAttributeNumber: return sizeof f->t_xmin;
|
||||||
case ObjectIdAttributeNumber:
|
case MinCommandIdAttributeNumber: return sizeof f->t_cmin;
|
||||||
len = sizeof f->t_oid;
|
case MaxTransactionIdAttributeNumber: return sizeof f->t_xmax;
|
||||||
break;
|
case MaxCommandIdAttributeNumber: return sizeof f->t_cmax;
|
||||||
case MinTransactionIdAttributeNumber:
|
case ChainItemPointerAttributeNumber: return sizeof f->t_chain;
|
||||||
len = sizeof f->t_xmin;
|
case MinAbsoluteTimeAttributeNumber: return sizeof f->t_tmin;
|
||||||
break;
|
case MaxAbsoluteTimeAttributeNumber: return sizeof f->t_tmax;
|
||||||
case MinCommandIdAttributeNumber:
|
case VersionTypeAttributeNumber: return sizeof f->t_vtype;
|
||||||
len = sizeof f->t_cmin;
|
|
||||||
break;
|
|
||||||
case MaxTransactionIdAttributeNumber:
|
|
||||||
len = sizeof f->t_xmax;
|
|
||||||
break;
|
|
||||||
case MaxCommandIdAttributeNumber:
|
|
||||||
len = sizeof f->t_cmax;
|
|
||||||
break;
|
|
||||||
case ChainItemPointerAttributeNumber:
|
|
||||||
len = sizeof f->t_chain;
|
|
||||||
break;
|
|
||||||
case AnchorItemPointerAttributeNumber:
|
case AnchorItemPointerAttributeNumber:
|
||||||
elog(WARN, "heap_sysattrlen: field t_anchor does not exist!");
|
elog(WARN, "heap_sysattrlen: field t_anchor does not exist!");
|
||||||
break;
|
return 0;
|
||||||
case MinAbsoluteTimeAttributeNumber:
|
|
||||||
len = sizeof f->t_tmin;
|
|
||||||
break;
|
|
||||||
case MaxAbsoluteTimeAttributeNumber:
|
|
||||||
len = sizeof f->t_tmax;
|
|
||||||
break;
|
|
||||||
case VersionTypeAttributeNumber:
|
|
||||||
len = sizeof f->t_vtype;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
elog(WARN, "sysattrlen: System attribute number %d unknown.",
|
elog(WARN, "sysattrlen: System attribute number %d unknown.", attno);
|
||||||
attno);
|
return 0;
|
||||||
len = 0;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return (len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
|
@ -437,7 +416,7 @@ fastgetattr(HeapTuple tup,
|
||||||
bool *isnull)
|
bool *isnull)
|
||||||
{
|
{
|
||||||
char *tp; /* ptr to att in tuple */
|
char *tp; /* ptr to att in tuple */
|
||||||
bits8 *bp; /* ptr to att in tuple */
|
bits8 *bp = NULL; /* ptr to att in tuple */
|
||||||
int slow; /* do we have to walk nulls? */
|
int slow; /* do we have to walk nulls? */
|
||||||
AttributeTupleForm *att = tupleDesc->attrs;
|
AttributeTupleForm *att = tupleDesc->attrs;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue