Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2f0f7b4

Browse files
committed
Clean up a few places where Datums were being treated as pointers (and vice
versa) without going through DatumGetPointer. Gavin Sherry, with Feng Tian.
1 parent 25e46a5 commit 2f0f7b4

File tree

7 files changed

+56
-54
lines changed

7 files changed

+56
-54
lines changed

src/backend/access/common/heaptuple.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
*
5858
*
5959
* IDENTIFICATION
60-
* $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.120 2008/01/01 19:45:45 momjian Exp $
60+
* $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.121 2008/04/17 21:37:28 alvherre Exp $
6161
*
6262
*-------------------------------------------------------------------------
6363
*/
@@ -890,7 +890,7 @@ heap_form_tuple(TupleDesc tupleDescriptor,
890890
else if (att[i]->attlen == -1 &&
891891
att[i]->attalign == 'd' &&
892892
att[i]->attndims == 0 &&
893-
!VARATT_IS_EXTENDED(values[i]))
893+
!VARATT_IS_EXTENDED(DatumGetPointer(values[i])))
894894
{
895895
values[i] = toast_flatten_tuple_attribute(values[i],
896896
att[i]->atttypid,
@@ -1001,7 +1001,7 @@ heap_formtuple(TupleDesc tupleDescriptor,
10011001
else if (att[i]->attlen == -1 &&
10021002
att[i]->attalign == 'd' &&
10031003
att[i]->attndims == 0 &&
1004-
!VARATT_IS_EXTENDED(values[i]))
1004+
!VARATT_IS_EXTENDED(DatumGetPointer(values[i])))
10051005
{
10061006
values[i] = toast_flatten_tuple_attribute(values[i],
10071007
att[i]->atttypid,

src/backend/access/common/indextuple.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/access/common/indextuple.c,v 1.85 2008/01/01 19:45:45 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/access/common/indextuple.c,v 1.86 2008/04/17 21:37:28 alvherre Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -73,7 +73,7 @@ index_form_tuple(TupleDesc tupleDescriptor,
7373
* If value is stored EXTERNAL, must fetch it so we are not depending
7474
* on outside storage. This should be improved someday.
7575
*/
76-
if (VARATT_IS_EXTERNAL(values[i]))
76+
if (VARATT_IS_EXTERNAL(DatumGetPointer(values[i])))
7777
{
7878
untoasted_values[i] =
7979
PointerGetDatum(heap_tuple_fetch_attr((struct varlena *)
@@ -85,8 +85,8 @@ index_form_tuple(TupleDesc tupleDescriptor,
8585
* If value is above size target, and is of a compressible datatype,
8686
* try to compress it in-line.
8787
*/
88-
if (!VARATT_IS_EXTENDED(untoasted_values[i]) &&
89-
VARSIZE(untoasted_values[i]) > TOAST_INDEX_TARGET &&
88+
if (!VARATT_IS_EXTENDED(DatumGetPointer(untoasted_values[i])) &&
89+
VARSIZE(DatumGetPointer(untoasted_values[i])) > TOAST_INDEX_TARGET &&
9090
(att->attstorage == 'x' || att->attstorage == 'm'))
9191
{
9292
Datum cvalue = toast_compress_datum(untoasted_values[i]);

src/backend/access/common/printtup.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/access/common/printtup.c,v 1.101 2008/01/01 19:45:45 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/access/common/printtup.c,v 1.102 2008/04/17 21:37:28 alvherre Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -340,7 +340,7 @@ printtup(TupleTableSlot *slot, DestReceiver *self)
340340
}
341341

342342
/* Clean up detoasted copy, if any */
343-
if (attr != origattr)
343+
if (DatumGetPointer(attr) != DatumGetPointer(origattr))
344344
pfree(DatumGetPointer(attr));
345345
}
346346

@@ -423,7 +423,7 @@ printtup_20(TupleTableSlot *slot, DestReceiver *self)
423423
pfree(outputstr);
424424

425425
/* Clean up detoasted copy, if any */
426-
if (attr != origattr)
426+
if (DatumGetPointer(attr) != DatumGetPointer(origattr))
427427
pfree(DatumGetPointer(attr));
428428
}
429429

@@ -537,7 +537,7 @@ debugtup(TupleTableSlot *slot, DestReceiver *self)
537537
pfree(value);
538538

539539
/* Clean up detoasted copy, if any */
540-
if (attr != origattr)
540+
if (DatumGetPointer(attr) != DatumGetPointer(origattr))
541541
pfree(DatumGetPointer(attr));
542542
}
543543
printf("\t----\n");
@@ -627,7 +627,7 @@ printtup_internal_20(TupleTableSlot *slot, DestReceiver *self)
627627
pfree(outputbytes);
628628

629629
/* Clean up detoasted copy, if any */
630-
if (attr != origattr)
630+
if (DatumGetPointer(attr) != DatumGetPointer(origattr))
631631
pfree(DatumGetPointer(attr));
632632
}
633633

src/backend/access/common/reloptions.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.9 2008/03/25 22:42:42 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.10 2008/04/17 21:37:28 alvherre Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -58,7 +58,7 @@ transformRelOptions(Datum oldOptions, List *defList,
5858
astate = NULL;
5959

6060
/* Copy any oldOptions that aren't to be replaced */
61-
if (oldOptions != (Datum) 0)
61+
if (PointerIsValid(DatumGetPointer(oldOptions)))
6262
{
6363
ArrayType *array = DatumGetArrayTypeP(oldOptions);
6464
Datum *oldoptions;
@@ -164,7 +164,7 @@ untransformRelOptions(Datum options)
164164
int i;
165165

166166
/* Nothing to do if no options */
167-
if (options == (Datum) 0)
167+
if (!PointerIsValid(DatumGetPointer(options)))
168168
return result;
169169

170170
array = DatumGetArrayTypeP(options);
@@ -220,7 +220,7 @@ parseRelOptions(Datum options, int numkeywords, const char *const * keywords,
220220
MemSet(values, 0, numkeywords * sizeof(char *));
221221

222222
/* Done if no options */
223-
if (options == (Datum) 0)
223+
if (!PointerIsValid(DatumGetPointer(options)))
224224
return;
225225

226226
array = DatumGetArrayTypeP(options);
@@ -349,7 +349,7 @@ index_reloptions(RegProcedure amoptions, Datum reloptions, bool validate)
349349
Assert(RegProcedureIsValid(amoptions));
350350

351351
/* Assume function is strict */
352-
if (reloptions == (Datum) 0)
352+
if (!PointerIsValid(DatumGetPointer(reloptions)))
353353
return NULL;
354354

355355
/* Can't use OidFunctionCallN because we might get a NULL result */

src/backend/access/heap/tuptoaster.c

+25-24
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.86 2008/04/12 23:14:21 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.87 2008/04/17 21:37:28 alvherre Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -383,7 +383,7 @@ toast_delete(Relation rel, HeapTuple oldtup)
383383
{
384384
Datum value = toast_values[i];
385385

386-
if (!toast_isnull[i] && VARATT_IS_EXTERNAL(value))
386+
if (!toast_isnull[i] && VARATT_IS_EXTERNAL(PointerGetDatum(value)))
387387
toast_delete_datum(rel, value);
388388
}
389389
}
@@ -615,9 +615,9 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
615615
{
616616
if (toast_action[i] != ' ')
617617
continue;
618-
if (VARATT_IS_EXTERNAL(toast_values[i]))
618+
if (VARATT_IS_EXTERNAL(DatumGetPointer(toast_values[i])))
619619
continue; /* can't happen, toast_action would be 'p' */
620-
if (VARATT_IS_COMPRESSED(toast_values[i]))
620+
if (VARATT_IS_COMPRESSED(DatumGetPointer(toast_values[i])))
621621
continue;
622622
if (att[i]->attstorage != 'x' && att[i]->attstorage != 'e')
623623
continue;
@@ -647,7 +647,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
647647
pfree(DatumGetPointer(old_value));
648648
toast_values[i] = new_value;
649649
toast_free[i] = true;
650-
toast_sizes[i] = VARSIZE(toast_values[i]);
650+
toast_sizes[i] = VARSIZE(DatumGetPointer(toast_values[i]));
651651
need_change = true;
652652
need_free = true;
653653
}
@@ -707,7 +707,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
707707
{
708708
if (toast_action[i] == 'p')
709709
continue;
710-
if (VARATT_IS_EXTERNAL(toast_values[i]))
710+
if (VARATT_IS_EXTERNAL(DatumGetPointer(toast_values[i])))
711711
continue; /* can't happen, toast_action would be 'p' */
712712
if (att[i]->attstorage != 'x' && att[i]->attstorage != 'e')
713713
continue;
@@ -756,9 +756,9 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
756756
{
757757
if (toast_action[i] != ' ')
758758
continue;
759-
if (VARATT_IS_EXTERNAL(toast_values[i]))
759+
if (VARATT_IS_EXTERNAL(DatumGetPointer(toast_values[i])))
760760
continue; /* can't happen, toast_action would be 'p' */
761-
if (VARATT_IS_COMPRESSED(toast_values[i]))
761+
if (VARATT_IS_COMPRESSED(DatumGetPointer(toast_values[i])))
762762
continue;
763763
if (att[i]->attstorage != 'm')
764764
continue;
@@ -786,7 +786,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
786786
pfree(DatumGetPointer(old_value));
787787
toast_values[i] = new_value;
788788
toast_free[i] = true;
789-
toast_sizes[i] = VARSIZE(toast_values[i]);
789+
toast_sizes[i] = VARSIZE(DatumGetPointer(toast_values[i]));
790790
need_change = true;
791791
need_free = true;
792792
}
@@ -817,7 +817,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
817817
{
818818
if (toast_action[i] == 'p')
819819
continue;
820-
if (VARATT_IS_EXTERNAL(toast_values[i]))
820+
if (VARATT_IS_EXTERNAL(DatumGetPointer(toast_values[i])))
821821
continue; /* can't happen, toast_action would be 'p' */
822822
if (att[i]->attstorage != 'm')
823823
continue;
@@ -1070,10 +1070,10 @@ Datum
10701070
toast_compress_datum(Datum value)
10711071
{
10721072
struct varlena *tmp;
1073-
int32 valsize = VARSIZE_ANY_EXHDR(value);
1073+
int32 valsize = VARSIZE_ANY_EXHDR(DatumGetPointer(value));
10741074

1075-
Assert(!VARATT_IS_EXTERNAL(value));
1076-
Assert(!VARATT_IS_COMPRESSED(value));
1075+
Assert(!VARATT_IS_EXTERNAL(DatumGetPointer(value)));
1076+
Assert(!VARATT_IS_COMPRESSED(DatumGetPointer(value)));
10771077

10781078
/*
10791079
* No point in wasting a palloc cycle if value size is out of the
@@ -1095,7 +1095,7 @@ toast_compress_datum(Datum value)
10951095
* header byte and no padding if the value is short enough. So we insist
10961096
* on a savings of more than 2 bytes to ensure we have a gain.
10971097
*/
1098-
if (pglz_compress(VARDATA_ANY(value), valsize,
1098+
if (pglz_compress(VARDATA_ANY(DatumGetPointer(value)), valsize,
10991099
(PGLZ_Header *) tmp, PGLZ_strategy_default) &&
11001100
VARSIZE(tmp) < valsize - 2)
11011101
{
@@ -1141,6 +1141,7 @@ toast_save_datum(Relation rel, Datum value,
11411141
int32 chunk_seq = 0;
11421142
char *data_p;
11431143
int32 data_todo;
1144+
Pointer dval = DatumGetPointer(value);
11441145

11451146
/*
11461147
* Open the toast relation and its index. We can use the index to check
@@ -1159,28 +1160,28 @@ toast_save_datum(Relation rel, Datum value,
11591160
*
11601161
* va_extsize is the actual size of the data payload in the toast records.
11611162
*/
1162-
if (VARATT_IS_SHORT(value))
1163+
if (VARATT_IS_SHORT(dval))
11631164
{
1164-
data_p = VARDATA_SHORT(value);
1165-
data_todo = VARSIZE_SHORT(value) - VARHDRSZ_SHORT;
1165+
data_p = VARDATA_SHORT(dval);
1166+
data_todo = VARSIZE_SHORT(dval) - VARHDRSZ_SHORT;
11661167
toast_pointer.va_rawsize = data_todo + VARHDRSZ; /* as if not short */
11671168
toast_pointer.va_extsize = data_todo;
11681169
}
1169-
else if (VARATT_IS_COMPRESSED(value))
1170+
else if (VARATT_IS_COMPRESSED(dval))
11701171
{
1171-
data_p = VARDATA(value);
1172-
data_todo = VARSIZE(value) - VARHDRSZ;
1172+
data_p = VARDATA(dval);
1173+
data_todo = VARSIZE(dval) - VARHDRSZ;
11731174
/* rawsize in a compressed datum is just the size of the payload */
1174-
toast_pointer.va_rawsize = VARRAWSIZE_4B_C(value) + VARHDRSZ;
1175+
toast_pointer.va_rawsize = VARRAWSIZE_4B_C(dval) + VARHDRSZ;
11751176
toast_pointer.va_extsize = data_todo;
11761177
/* Assert that the numbers look like it's compressed */
11771178
Assert(VARATT_EXTERNAL_IS_COMPRESSED(toast_pointer));
11781179
}
11791180
else
11801181
{
1181-
data_p = VARDATA(value);
1182-
data_todo = VARSIZE(value) - VARHDRSZ;
1183-
toast_pointer.va_rawsize = VARSIZE(value);
1182+
data_p = VARDATA(dval);
1183+
data_todo = VARSIZE(dval) - VARHDRSZ;
1184+
toast_pointer.va_rawsize = VARSIZE(dval);
11841185
toast_pointer.va_extsize = data_todo;
11851186
}
11861187

src/backend/utils/fmgr/fmgr.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.114 2008/03/25 22:42:45 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.115 2008/04/17 21:37:28 alvherre Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -827,7 +827,7 @@ fmgr_oldstyle(PG_FUNCTION_ARGS)
827827
break;
828828
}
829829

830-
return (Datum) returnValue;
830+
return PointerGetDatum(returnValue);
831831
}
832832

833833

@@ -2008,7 +2008,7 @@ fmgr(Oid procedureId,...)
20082008
flinfo.fn_oid, n_arguments, FUNC_MAX_ARGS)));
20092009
va_start(pvar, procedureId);
20102010
for (i = 0; i < n_arguments; i++)
2011-
fcinfo.arg[i] = (Datum) va_arg(pvar, char *);
2011+
fcinfo.arg[i] = PointerGetDatum(va_arg(pvar, char *));
20122012
va_end(pvar);
20132013
}
20142014

@@ -2018,7 +2018,7 @@ fmgr(Oid procedureId,...)
20182018
if (fcinfo.isnull)
20192019
elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
20202020

2021-
return (char *) result;
2021+
return DatumGetPointer(result);
20222022
}
20232023

20242024

src/pl/plpgsql/src/pl_exec.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.209 2008/04/06 23:43:29 tgl Exp $
11+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.210 2008/04/17 21:37:28 alvherre Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -409,7 +409,7 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo)
409409
* sure it is labeled with the caller-supplied tuple type.
410410
*/
411411
estate.retval =
412-
PointerGetDatum(SPI_returntuple((HeapTuple) (estate.retval),
412+
PointerGetDatum(SPI_returntuple((HeapTuple)DatumGetPointer(estate.retval),
413413
tupdesc));
414414
}
415415
else
@@ -702,7 +702,7 @@ plpgsql_exec_trigger(PLpgSQL_function *func,
702702
(errcode(ERRCODE_DATATYPE_MISMATCH),
703703
errmsg("returned tuple structure does not match table of trigger event")));
704704
/* Copy tuple to upper executor memory */
705-
rettup = SPI_copytuple((HeapTuple) (estate.retval));
705+
rettup = SPI_copytuple((HeapTuple) DatumGetPointer(estate.retval));
706706
}
707707

708708
/*
@@ -1956,7 +1956,7 @@ exec_stmt_return(PLpgSQL_execstate *estate, PLpgSQL_stmt_return *stmt)
19561956

19571957
if (HeapTupleIsValid(rec->tup))
19581958
{
1959-
estate->retval = (Datum) rec->tup;
1959+
estate->retval = PointerGetDatum(rec->tup);
19601960
estate->rettupdesc = rec->tupdesc;
19611961
estate->retisnull = false;
19621962
}
@@ -1968,9 +1968,10 @@ exec_stmt_return(PLpgSQL_execstate *estate, PLpgSQL_stmt_return *stmt)
19681968
PLpgSQL_row *row = (PLpgSQL_row *) retvar;
19691969

19701970
Assert(row->rowtupdesc);
1971-
estate->retval = (Datum) make_tuple_from_row(estate, row,
1972-
row->rowtupdesc);
1973-
if (estate->retval == (Datum) NULL) /* should not happen */
1971+
estate->retval =
1972+
PointerGetDatum(make_tuple_from_row(estate, row,
1973+
row->rowtupdesc));
1974+
if (DatumGetPointer(estate->retval) == NULL) /* should not happen */
19741975
elog(ERROR, "row not compatible with its own tupdesc");
19751976
estate->rettupdesc = row->rowtupdesc;
19761977
estate->retisnull = false;
@@ -1991,7 +1992,7 @@ exec_stmt_return(PLpgSQL_execstate *estate, PLpgSQL_stmt_return *stmt)
19911992
exec_run_select(estate, stmt->expr, 1, NULL);
19921993
if (estate->eval_processed > 0)
19931994
{
1994-
estate->retval = (Datum) estate->eval_tuptable->vals[0];
1995+
estate->retval = PointerGetDatum(estate->eval_tuptable->vals[0]);
19951996
estate->rettupdesc = estate->eval_tuptable->tupdesc;
19961997
estate->retisnull = false;
19971998
}
@@ -4998,7 +4999,7 @@ exec_set_found(PLpgSQL_execstate *estate, bool state)
49984999
PLpgSQL_var *var;
49995000

50005001
var = (PLpgSQL_var *) (estate->datums[estate->found_varno]);
5001-
var->value = (Datum) state;
5002+
var->value = PointerGetDatum(state);
50025003
var->isnull = false;
50035004
}
50045005

0 commit comments

Comments
 (0)