Commit 84b6d5f3 authored by Robert Haas's avatar Robert Haas

Remove partial, broken support for NULL pointers when fetching attributes.

Previously, fastgetattr() and heap_getattr() tested their fourth argument
against a null pointer, but any attempt to use them with a literal-NULL
fourth argument evaluated to *(void *)0, resulting in a compiler error.
Remove these NULL tests to avoid leading future readers of this code to
believe that this has a chance of working.  Also clean up related legacy
code in nocachegetattr(), heap_getsysattr(), and nocache_index_getattr().

The new coding standard is that any code which calls a getattr-type
function or macro which takes an isnull argument MUST pass a valid
boolean pointer.  Per discussion with Bruce Momjian, Tom Lane, Alvaro
Herrera.
parent 8b9fa7a9
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.129 2010/01/02 16:57:33 momjian Exp $ * $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.130 2010/01/10 04:26:36 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -323,8 +323,7 @@ heap_attisnull(HeapTuple tup, int attnum) ...@@ -323,8 +323,7 @@ heap_attisnull(HeapTuple tup, int attnum)
Datum Datum
nocachegetattr(HeapTuple tuple, nocachegetattr(HeapTuple tuple,
int attnum, int attnum,
TupleDesc tupleDesc, TupleDesc tupleDesc)
bool *isnull)
{ {
HeapTupleHeader tup = tuple->t_data; HeapTupleHeader tup = tuple->t_data;
Form_pg_attribute *att = tupleDesc->attrs; Form_pg_attribute *att = tupleDesc->attrs;
...@@ -333,8 +332,6 @@ nocachegetattr(HeapTuple tuple, ...@@ -333,8 +332,6 @@ nocachegetattr(HeapTuple tuple,
bool slow = false; /* do we have to walk attrs? */ bool slow = false; /* do we have to walk attrs? */
int off; /* current offset within data */ int off; /* current offset within data */
(void) isnull; /* not used */
/* ---------------- /* ----------------
* Three cases: * Three cases:
* *
...@@ -344,50 +341,15 @@ nocachegetattr(HeapTuple tuple, ...@@ -344,50 +341,15 @@ nocachegetattr(HeapTuple tuple,
* ---------------- * ----------------
*/ */
#ifdef IN_MACRO
/* This is handled in the macro */
Assert(attnum > 0);
if (isnull)
*isnull = false;
#endif
attnum--; attnum--;
if (HeapTupleNoNulls(tuple)) if (!HeapTupleNoNulls(tuple))
{
#ifdef IN_MACRO
/* This is handled in the macro */
if (att[attnum]->attcacheoff >= 0)
{
return fetchatt(att[attnum],
(char *) tup + tup->t_hoff +
att[attnum]->attcacheoff);
}
#endif
}
else
{ {
/* /*
* there's a null somewhere in the tuple * there's a null somewhere in the tuple
* *
* check to see if desired att is null * check to see if any preceding bits are null...
*/
#ifdef IN_MACRO
/* This is handled in the macro */
if (att_isnull(attnum, bp))
{
if (isnull)
*isnull = true;
return (Datum) NULL;
}
#endif
/*
* Now check to see if any preceding bits are null...
*/ */
{
int byte = attnum >> 3; int byte = attnum >> 3;
int finalbit = attnum & 0x07; int finalbit = attnum & 0x07;
...@@ -409,7 +371,6 @@ nocachegetattr(HeapTuple tuple, ...@@ -409,7 +371,6 @@ nocachegetattr(HeapTuple tuple,
} }
} }
} }
}
tp = (char *) tup + tup->t_hoff; tp = (char *) tup + tup->t_hoff;
...@@ -567,7 +528,6 @@ heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull) ...@@ -567,7 +528,6 @@ heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Assert(tup); Assert(tup);
/* Currently, no sys attribute ever reads as NULL. */ /* Currently, no sys attribute ever reads as NULL. */
if (isnull)
*isnull = false; *isnull = false;
switch (attnum) switch (attnum)
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/common/indextuple.c,v 1.90 2010/01/02 16:57:33 momjian Exp $ * $PostgreSQL: pgsql/src/backend/access/common/indextuple.c,v 1.91 2010/01/10 04:26:36 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -200,8 +200,7 @@ index_form_tuple(TupleDesc tupleDescriptor, ...@@ -200,8 +200,7 @@ index_form_tuple(TupleDesc tupleDescriptor,
Datum Datum
nocache_index_getattr(IndexTuple tup, nocache_index_getattr(IndexTuple tup,
int attnum, int attnum,
TupleDesc tupleDesc, TupleDesc tupleDesc)
bool *isnull)
{ {
Form_pg_attribute *att = tupleDesc->attrs; Form_pg_attribute *att = tupleDesc->attrs;
char *tp; /* ptr to data part of tuple */ char *tp; /* ptr to data part of tuple */
...@@ -210,8 +209,6 @@ nocache_index_getattr(IndexTuple tup, ...@@ -210,8 +209,6 @@ nocache_index_getattr(IndexTuple tup,
int data_off; /* tuple data offset */ int data_off; /* tuple data offset */
int off; /* current offset within data */ int off; /* current offset within data */
(void) isnull; /* not used */
/* ---------------- /* ----------------
* Three cases: * Three cases:
* *
...@@ -221,31 +218,11 @@ nocache_index_getattr(IndexTuple tup, ...@@ -221,31 +218,11 @@ nocache_index_getattr(IndexTuple tup,
* ---------------- * ----------------
*/ */
#ifdef IN_MACRO
/* This is handled in the macro */
Assert(PointerIsValid(isnull));
Assert(attnum > 0);
*isnull = false;
#endif
data_off = IndexInfoFindDataOffset(tup->t_info); data_off = IndexInfoFindDataOffset(tup->t_info);
attnum--; attnum--;
if (!IndexTupleHasNulls(tup)) if (IndexTupleHasNulls(tup))
{
#ifdef IN_MACRO
/* This is handled in the macro */
if (att[attnum]->attcacheoff >= 0)
{
return fetchatt(att[attnum],
(char *) tup + data_off +
att[attnum]->attcacheoff);
}
#endif
}
else
{ {
/* /*
* there's a null somewhere in the tuple * there's a null somewhere in the tuple
...@@ -256,16 +233,6 @@ nocache_index_getattr(IndexTuple tup, ...@@ -256,16 +233,6 @@ nocache_index_getattr(IndexTuple tup,
/* XXX "knows" t_bits are just after fixed tuple header! */ /* XXX "knows" t_bits are just after fixed tuple header! */
bp = (bits8 *) ((char *) tup + sizeof(IndexTupleData)); bp = (bits8 *) ((char *) tup + sizeof(IndexTupleData));
#ifdef IN_MACRO
/* This is handled in the macro */
if (att_isnull(attnum, bp))
{
*isnull = true;
return (Datum) NULL;
}
#endif
/* /*
* Now check to see if any preceding bits are null... * Now check to see if any preceding bits are null...
*/ */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.280 2010/01/02 16:57:34 momjian Exp $ * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.281 2010/01/10 04:26:36 rhaas Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -834,7 +834,7 @@ fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, ...@@ -834,7 +834,7 @@ fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
return ( return (
(attnum) > 0 ? (attnum) > 0 ?
( (
((isnull) ? (*(isnull) = false) : (dummyret) NULL), (*(isnull) = false),
HeapTupleNoNulls(tup) ? HeapTupleNoNulls(tup) ?
( (
(tupleDesc)->attrs[(attnum) - 1]->attcacheoff >= 0 ? (tupleDesc)->attrs[(attnum) - 1]->attcacheoff >= 0 ?
...@@ -844,18 +844,18 @@ fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, ...@@ -844,18 +844,18 @@ fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
(tupleDesc)->attrs[(attnum) - 1]->attcacheoff) (tupleDesc)->attrs[(attnum) - 1]->attcacheoff)
) )
: :
nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) nocachegetattr((tup), (attnum), (tupleDesc))
) )
: :
( (
att_isnull((attnum) - 1, (tup)->t_data->t_bits) ? att_isnull((attnum) - 1, (tup)->t_data->t_bits) ?
( (
((isnull) ? (*(isnull) = true) : (dummyret) NULL), (*(isnull) = true),
(Datum) NULL (Datum) NULL
) )
: :
( (
nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) nocachegetattr((tup), (attnum), (tupleDesc))
) )
) )
) )
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/access/htup.h,v 1.109 2010/01/02 16:58:00 momjian Exp $ * $PostgreSQL: pgsql/src/include/access/htup.h,v 1.110 2010/01/10 04:26:36 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -763,7 +763,7 @@ extern void HeapTupleHeaderAdjustCmax(HeapTupleHeader tup, ...@@ -763,7 +763,7 @@ extern void HeapTupleHeaderAdjustCmax(HeapTupleHeader tup,
#define fastgetattr(tup, attnum, tupleDesc, isnull) \ #define fastgetattr(tup, attnum, tupleDesc, isnull) \
( \ ( \
AssertMacro((attnum) > 0), \ AssertMacro((attnum) > 0), \
(((isnull) != NULL) ? (*(isnull) = false) : (dummyret)NULL), \ (*(isnull) = false), \
HeapTupleNoNulls(tup) ? \ HeapTupleNoNulls(tup) ? \
( \ ( \
(tupleDesc)->attrs[(attnum)-1]->attcacheoff >= 0 ? \ (tupleDesc)->attrs[(attnum)-1]->attcacheoff >= 0 ? \
...@@ -773,18 +773,18 @@ extern void HeapTupleHeaderAdjustCmax(HeapTupleHeader tup, ...@@ -773,18 +773,18 @@ extern void HeapTupleHeaderAdjustCmax(HeapTupleHeader tup,
(tupleDesc)->attrs[(attnum)-1]->attcacheoff) \ (tupleDesc)->attrs[(attnum)-1]->attcacheoff) \
) \ ) \
: \ : \
nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) \ nocachegetattr((tup), (attnum), (tupleDesc)) \
) \ ) \
: \ : \
( \ ( \
att_isnull((attnum)-1, (tup)->t_data->t_bits) ? \ att_isnull((attnum)-1, (tup)->t_data->t_bits) ? \
( \ ( \
(((isnull) != NULL) ? (*(isnull) = true) : (dummyret)NULL), \ (*(isnull) = true), \
(Datum)NULL \ (Datum)NULL \
) \ ) \
: \ : \
( \ ( \
nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) \ nocachegetattr((tup), (attnum), (tupleDesc)) \
) \ ) \
) \ ) \
) )
...@@ -818,7 +818,7 @@ extern Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, ...@@ -818,7 +818,7 @@ extern Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
( \ ( \
((attnum) > (int) HeapTupleHeaderGetNatts((tup)->t_data)) ? \ ((attnum) > (int) HeapTupleHeaderGetNatts((tup)->t_data)) ? \
( \ ( \
(((isnull) != NULL) ? (*(isnull) = true) : (dummyret)NULL), \ (*(isnull) = true), \
(Datum)NULL \ (Datum)NULL \
) \ ) \
: \ : \
...@@ -838,7 +838,7 @@ extern void heap_fill_tuple(TupleDesc tupleDesc, ...@@ -838,7 +838,7 @@ extern void heap_fill_tuple(TupleDesc tupleDesc,
uint16 *infomask, bits8 *bit); uint16 *infomask, bits8 *bit);
extern bool heap_attisnull(HeapTuple tup, int attnum); extern bool heap_attisnull(HeapTuple tup, int attnum);
extern Datum nocachegetattr(HeapTuple tup, int attnum, extern Datum nocachegetattr(HeapTuple tup, int attnum,
TupleDesc att, bool *isnull); TupleDesc att);
extern Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, extern Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
bool *isnull); bool *isnull);
extern HeapTuple heap_copytuple(HeapTuple tuple); extern HeapTuple heap_copytuple(HeapTuple tuple);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/access/itup.h,v 1.53 2010/01/02 16:58:00 momjian Exp $ * $PostgreSQL: pgsql/src/include/access/itup.h,v 1.54 2010/01/10 04:26:36 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -110,7 +110,7 @@ typedef IndexAttributeBitMapData *IndexAttributeBitMap; ...@@ -110,7 +110,7 @@ typedef IndexAttributeBitMapData *IndexAttributeBitMap;
+ (tupleDesc)->attrs[(attnum)-1]->attcacheoff) \ + (tupleDesc)->attrs[(attnum)-1]->attcacheoff) \
) \ ) \
: \ : \
nocache_index_getattr((tup), (attnum), (tupleDesc), (isnull)) \ nocache_index_getattr((tup), (attnum), (tupleDesc)) \
) \ ) \
: \ : \
( \ ( \
...@@ -121,7 +121,7 @@ typedef IndexAttributeBitMapData *IndexAttributeBitMap; ...@@ -121,7 +121,7 @@ typedef IndexAttributeBitMapData *IndexAttributeBitMap;
) \ ) \
: \ : \
( \ ( \
nocache_index_getattr((tup), (attnum), (tupleDesc), (isnull)) \ nocache_index_getattr((tup), (attnum), (tupleDesc)) \
) \ ) \
) \ ) \
) )
...@@ -142,7 +142,7 @@ typedef IndexAttributeBitMapData *IndexAttributeBitMap; ...@@ -142,7 +142,7 @@ typedef IndexAttributeBitMapData *IndexAttributeBitMap;
extern IndexTuple index_form_tuple(TupleDesc tupleDescriptor, extern IndexTuple index_form_tuple(TupleDesc tupleDescriptor,
Datum *values, bool *isnull); Datum *values, bool *isnull);
extern Datum nocache_index_getattr(IndexTuple tup, int attnum, extern Datum nocache_index_getattr(IndexTuple tup, int attnum,
TupleDesc tupleDesc, bool *isnull); TupleDesc tupleDesc);
extern void index_deform_tuple(IndexTuple tup, TupleDesc tupleDescriptor, extern void index_deform_tuple(IndexTuple tup, TupleDesc tupleDescriptor,
Datum *values, bool *isnull); Datum *values, bool *isnull);
extern IndexTuple CopyIndexTuple(IndexTuple source); extern IndexTuple CopyIndexTuple(IndexTuple source);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment