OSDN Git Service

Clean up a few places where Datums were being treated as pointers (and vice
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Thu, 17 Apr 2008 21:37:28 +0000 (21:37 +0000)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Thu, 17 Apr 2008 21:37:28 +0000 (21:37 +0000)
versa) without going through DatumGetPointer.

Gavin Sherry, with Feng Tian.

src/backend/access/common/heaptuple.c
src/backend/access/common/indextuple.c
src/backend/access/common/printtup.c
src/backend/access/common/reloptions.c
src/backend/access/heap/tuptoaster.c
src/backend/utils/fmgr/fmgr.c
src/pl/plpgsql/src/pl_exec.c

index 5dd3848..d7af277 100644 (file)
@@ -57,7 +57,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.120 2008/01/01 19:45:45 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.121 2008/04/17 21:37:28 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -890,7 +890,7 @@ heap_form_tuple(TupleDesc tupleDescriptor,
                else if (att[i]->attlen == -1 &&
                                 att[i]->attalign == 'd' &&
                                 att[i]->attndims == 0 &&
-                                !VARATT_IS_EXTENDED(values[i]))
+                                !VARATT_IS_EXTENDED(DatumGetPointer(values[i])))
                {
                        values[i] = toast_flatten_tuple_attribute(values[i],
                                                                                                          att[i]->atttypid,
@@ -1001,7 +1001,7 @@ heap_formtuple(TupleDesc tupleDescriptor,
                else if (att[i]->attlen == -1 &&
                                 att[i]->attalign == 'd' &&
                                 att[i]->attndims == 0 &&
-                                !VARATT_IS_EXTENDED(values[i]))
+                                !VARATT_IS_EXTENDED(DatumGetPointer(values[i])))
                {
                        values[i] = toast_flatten_tuple_attribute(values[i],
                                                                                                          att[i]->atttypid,
index 06bae46..9aa320a 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/access/common/indextuple.c,v 1.85 2008/01/01 19:45:45 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/access/common/indextuple.c,v 1.86 2008/04/17 21:37:28 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -73,7 +73,7 @@ index_form_tuple(TupleDesc tupleDescriptor,
                 * If value is stored EXTERNAL, must fetch it so we are not depending
                 * on outside storage.  This should be improved someday.
                 */
-               if (VARATT_IS_EXTERNAL(values[i]))
+               if (VARATT_IS_EXTERNAL(DatumGetPointer(values[i])))
                {
                        untoasted_values[i] =
                                PointerGetDatum(heap_tuple_fetch_attr((struct varlena *)
@@ -85,8 +85,8 @@ index_form_tuple(TupleDesc tupleDescriptor,
                 * If value is above size target, and is of a compressible datatype,
                 * try to compress it in-line.
                 */
-               if (!VARATT_IS_EXTENDED(untoasted_values[i]) &&
-                       VARSIZE(untoasted_values[i]) > TOAST_INDEX_TARGET &&
+               if (!VARATT_IS_EXTENDED(DatumGetPointer(untoasted_values[i])) &&
+                       VARSIZE(DatumGetPointer(untoasted_values[i])) > TOAST_INDEX_TARGET &&
                        (att->attstorage == 'x' || att->attstorage == 'm'))
                {
                        Datum           cvalue = toast_compress_datum(untoasted_values[i]);
index d3f017a..346f6e1 100644 (file)
@@ -9,7 +9,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/access/common/printtup.c,v 1.101 2008/01/01 19:45:45 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/access/common/printtup.c,v 1.102 2008/04/17 21:37:28 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -340,7 +340,7 @@ printtup(TupleTableSlot *slot, DestReceiver *self)
                }
 
                /* Clean up detoasted copy, if any */
-               if (attr != origattr)
+               if (DatumGetPointer(attr) != DatumGetPointer(origattr))
                        pfree(DatumGetPointer(attr));
        }
 
@@ -423,7 +423,7 @@ printtup_20(TupleTableSlot *slot, DestReceiver *self)
                pfree(outputstr);
 
                /* Clean up detoasted copy, if any */
-               if (attr != origattr)
+               if (DatumGetPointer(attr) != DatumGetPointer(origattr))
                        pfree(DatumGetPointer(attr));
        }
 
@@ -537,7 +537,7 @@ debugtup(TupleTableSlot *slot, DestReceiver *self)
                pfree(value);
 
                /* Clean up detoasted copy, if any */
-               if (attr != origattr)
+               if (DatumGetPointer(attr) != DatumGetPointer(origattr))
                        pfree(DatumGetPointer(attr));
        }
        printf("\t----\n");
@@ -627,7 +627,7 @@ printtup_internal_20(TupleTableSlot *slot, DestReceiver *self)
                pfree(outputbytes);
 
                /* Clean up detoasted copy, if any */
-               if (attr != origattr)
+               if (DatumGetPointer(attr) != DatumGetPointer(origattr))
                        pfree(DatumGetPointer(attr));
        }
 
index fc5b6eb..8822535 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.9 2008/03/25 22:42:42 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.10 2008/04/17 21:37:28 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -58,7 +58,7 @@ transformRelOptions(Datum oldOptions, List *defList,
        astate = NULL;
 
        /* Copy any oldOptions that aren't to be replaced */
-       if (oldOptions != (Datum) 0)
+       if (PointerIsValid(DatumGetPointer(oldOptions)))
        {
                ArrayType  *array = DatumGetArrayTypeP(oldOptions);
                Datum      *oldoptions;
@@ -164,7 +164,7 @@ untransformRelOptions(Datum options)
        int                     i;
 
        /* Nothing to do if no options */
-       if (options == (Datum) 0)
+       if (!PointerIsValid(DatumGetPointer(options)))
                return result;
 
        array = DatumGetArrayTypeP(options);
@@ -220,7 +220,7 @@ parseRelOptions(Datum options, int numkeywords, const char *const * keywords,
        MemSet(values, 0, numkeywords * sizeof(char *));
 
        /* Done if no options */
-       if (options == (Datum) 0)
+       if (!PointerIsValid(DatumGetPointer(options)))
                return;
 
        array = DatumGetArrayTypeP(options);
@@ -349,7 +349,7 @@ index_reloptions(RegProcedure amoptions, Datum reloptions, bool validate)
        Assert(RegProcedureIsValid(amoptions));
 
        /* Assume function is strict */
-       if (reloptions == (Datum) 0)
+       if (!PointerIsValid(DatumGetPointer(reloptions)))
                return NULL;
 
        /* Can't use OidFunctionCallN because we might get a NULL result */
index cf2edbf..7478f90 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.86 2008/04/12 23:14:21 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.87 2008/04/17 21:37:28 alvherre Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -383,7 +383,7 @@ toast_delete(Relation rel, HeapTuple oldtup)
                {
                        Datum           value = toast_values[i];
 
-                       if (!toast_isnull[i] && VARATT_IS_EXTERNAL(value))
+                       if (!toast_isnull[i] && VARATT_IS_EXTERNAL(PointerGetDatum(value)))
                                toast_delete_datum(rel, value);
                }
        }
@@ -615,9 +615,9 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
                {
                        if (toast_action[i] != ' ')
                                continue;
-                       if (VARATT_IS_EXTERNAL(toast_values[i]))
+                       if (VARATT_IS_EXTERNAL(DatumGetPointer(toast_values[i])))
                                continue;               /* can't happen, toast_action would be 'p' */
-                       if (VARATT_IS_COMPRESSED(toast_values[i]))
+                       if (VARATT_IS_COMPRESSED(DatumGetPointer(toast_values[i])))
                                continue;
                        if (att[i]->attstorage != 'x' && att[i]->attstorage != 'e')
                                continue;
@@ -647,7 +647,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
                                        pfree(DatumGetPointer(old_value));
                                toast_values[i] = new_value;
                                toast_free[i] = true;
-                               toast_sizes[i] = VARSIZE(toast_values[i]);
+                               toast_sizes[i] = VARSIZE(DatumGetPointer(toast_values[i]));
                                need_change = true;
                                need_free = true;
                        }
@@ -707,7 +707,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
                {
                        if (toast_action[i] == 'p')
                                continue;
-                       if (VARATT_IS_EXTERNAL(toast_values[i]))
+                       if (VARATT_IS_EXTERNAL(DatumGetPointer(toast_values[i])))
                                continue;               /* can't happen, toast_action would be 'p' */
                        if (att[i]->attstorage != 'x' && att[i]->attstorage != 'e')
                                continue;
@@ -756,9 +756,9 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
                {
                        if (toast_action[i] != ' ')
                                continue;
-                       if (VARATT_IS_EXTERNAL(toast_values[i]))
+                       if (VARATT_IS_EXTERNAL(DatumGetPointer(toast_values[i])))
                                continue;               /* can't happen, toast_action would be 'p' */
-                       if (VARATT_IS_COMPRESSED(toast_values[i]))
+                       if (VARATT_IS_COMPRESSED(DatumGetPointer(toast_values[i])))
                                continue;
                        if (att[i]->attstorage != 'm')
                                continue;
@@ -786,7 +786,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
                                pfree(DatumGetPointer(old_value));
                        toast_values[i] = new_value;
                        toast_free[i] = true;
-                       toast_sizes[i] = VARSIZE(toast_values[i]);
+                       toast_sizes[i] = VARSIZE(DatumGetPointer(toast_values[i]));
                        need_change = true;
                        need_free = true;
                }
@@ -817,7 +817,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
                {
                        if (toast_action[i] == 'p')
                                continue;
-                       if (VARATT_IS_EXTERNAL(toast_values[i]))
+                       if (VARATT_IS_EXTERNAL(DatumGetPointer(toast_values[i])))
                                continue;               /* can't happen, toast_action would be 'p' */
                        if (att[i]->attstorage != 'm')
                                continue;
@@ -1070,10 +1070,10 @@ Datum
 toast_compress_datum(Datum value)
 {
        struct varlena *tmp;
-       int32           valsize = VARSIZE_ANY_EXHDR(value);
+       int32           valsize = VARSIZE_ANY_EXHDR(DatumGetPointer(value));
 
-       Assert(!VARATT_IS_EXTERNAL(value));
-       Assert(!VARATT_IS_COMPRESSED(value));
+       Assert(!VARATT_IS_EXTERNAL(DatumGetPointer(value)));
+       Assert(!VARATT_IS_COMPRESSED(DatumGetPointer(value)));
 
        /*
         * No point in wasting a palloc cycle if value size is out of the
@@ -1095,7 +1095,7 @@ toast_compress_datum(Datum value)
         * header byte and no padding if the value is short enough.  So we insist
         * on a savings of more than 2 bytes to ensure we have a gain.
         */
-       if (pglz_compress(VARDATA_ANY(value), valsize,
+       if (pglz_compress(VARDATA_ANY(DatumGetPointer(value)), valsize,
                                          (PGLZ_Header *) tmp, PGLZ_strategy_default) &&
                VARSIZE(tmp) < valsize - 2)
        {
@@ -1141,6 +1141,7 @@ toast_save_datum(Relation rel, Datum value,
        int32           chunk_seq = 0;
        char       *data_p;
        int32           data_todo;
+       Pointer         dval = DatumGetPointer(value);
 
        /*
         * 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,
         *
         * va_extsize is the actual size of the data payload in the toast records.
         */
-       if (VARATT_IS_SHORT(value))
+       if (VARATT_IS_SHORT(dval))
        {
-               data_p = VARDATA_SHORT(value);
-               data_todo = VARSIZE_SHORT(value) - VARHDRSZ_SHORT;
+               data_p = VARDATA_SHORT(dval);
+               data_todo = VARSIZE_SHORT(dval) - VARHDRSZ_SHORT;
                toast_pointer.va_rawsize = data_todo + VARHDRSZ;                /* as if not short */
                toast_pointer.va_extsize = data_todo;
        }
-       else if (VARATT_IS_COMPRESSED(value))
+       else if (VARATT_IS_COMPRESSED(dval))
        {
-               data_p = VARDATA(value);
-               data_todo = VARSIZE(value) - VARHDRSZ;
+               data_p = VARDATA(dval);
+               data_todo = VARSIZE(dval) - VARHDRSZ;
                /* rawsize in a compressed datum is just the size of the payload */
-               toast_pointer.va_rawsize = VARRAWSIZE_4B_C(value) + VARHDRSZ;
+               toast_pointer.va_rawsize = VARRAWSIZE_4B_C(dval) + VARHDRSZ;
                toast_pointer.va_extsize = data_todo;
                /* Assert that the numbers look like it's compressed */
                Assert(VARATT_EXTERNAL_IS_COMPRESSED(toast_pointer));
        }
        else
        {
-               data_p = VARDATA(value);
-               data_todo = VARSIZE(value) - VARHDRSZ;
-               toast_pointer.va_rawsize = VARSIZE(value);
+               data_p = VARDATA(dval);
+               data_todo = VARSIZE(dval) - VARHDRSZ;
+               toast_pointer.va_rawsize = VARSIZE(dval);
                toast_pointer.va_extsize = data_todo;
        }
 
index e06da24..44667e6 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.114 2008/03/25 22:42:45 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.115 2008/04/17 21:37:28 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -827,7 +827,7 @@ fmgr_oldstyle(PG_FUNCTION_ARGS)
                        break;
        }
 
-       return (Datum) returnValue;
+       return PointerGetDatum(returnValue);
 }
 
 
@@ -2008,7 +2008,7 @@ fmgr(Oid procedureId,...)
                                        flinfo.fn_oid, n_arguments, FUNC_MAX_ARGS)));
                va_start(pvar, procedureId);
                for (i = 0; i < n_arguments; i++)
-                       fcinfo.arg[i] = (Datum) va_arg(pvar, char *);
+                       fcinfo.arg[i] = PointerGetDatum(va_arg(pvar, char *));
                va_end(pvar);
        }
 
@@ -2018,7 +2018,7 @@ fmgr(Oid procedureId,...)
        if (fcinfo.isnull)
                elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
 
-       return (char *) result;
+       return DatumGetPointer(result);
 }
 
 
index 64ce1d1..a1774bf 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.209 2008/04/06 23:43:29 tgl Exp $
+ *       $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.210 2008/04/17 21:37:28 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -409,7 +409,7 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo)
                         * sure it is labeled with the caller-supplied tuple type.
                         */
                        estate.retval =
-                               PointerGetDatum(SPI_returntuple((HeapTuple) (estate.retval),
+                               PointerGetDatum(SPI_returntuple((HeapTuple)DatumGetPointer(estate.retval),
                                                                                                tupdesc));
                }
                else
@@ -702,7 +702,7 @@ plpgsql_exec_trigger(PLpgSQL_function *func,
                                        (errcode(ERRCODE_DATATYPE_MISMATCH),
                                         errmsg("returned tuple structure does not match table of trigger event")));
                /* Copy tuple to upper executor memory */
-               rettup = SPI_copytuple((HeapTuple) (estate.retval));
+               rettup = SPI_copytuple((HeapTuple) DatumGetPointer(estate.retval));
        }
 
        /*
@@ -1956,7 +1956,7 @@ exec_stmt_return(PLpgSQL_execstate *estate, PLpgSQL_stmt_return *stmt)
 
                                        if (HeapTupleIsValid(rec->tup))
                                        {
-                                               estate->retval = (Datum) rec->tup;
+                                               estate->retval = PointerGetDatum(rec->tup);
                                                estate->rettupdesc = rec->tupdesc;
                                                estate->retisnull = false;
                                        }
@@ -1968,9 +1968,10 @@ exec_stmt_return(PLpgSQL_execstate *estate, PLpgSQL_stmt_return *stmt)
                                        PLpgSQL_row *row = (PLpgSQL_row *) retvar;
 
                                        Assert(row->rowtupdesc);
-                                       estate->retval = (Datum) make_tuple_from_row(estate, row,
-                                                                                                                       row->rowtupdesc);
-                                       if (estate->retval == (Datum) NULL) /* should not happen */
+                                       estate->retval = 
+                                               PointerGetDatum(make_tuple_from_row(estate, row,
+                                                                                                                       row->rowtupdesc));
+                                       if (DatumGetPointer(estate->retval) == NULL) /* should not happen */
                                                elog(ERROR, "row not compatible with its own tupdesc");
                                        estate->rettupdesc = row->rowtupdesc;
                                        estate->retisnull = false;
@@ -1991,7 +1992,7 @@ exec_stmt_return(PLpgSQL_execstate *estate, PLpgSQL_stmt_return *stmt)
                        exec_run_select(estate, stmt->expr, 1, NULL);
                        if (estate->eval_processed > 0)
                        {
-                               estate->retval = (Datum) estate->eval_tuptable->vals[0];
+                               estate->retval = PointerGetDatum(estate->eval_tuptable->vals[0]);
                                estate->rettupdesc = estate->eval_tuptable->tupdesc;
                                estate->retisnull = false;
                        }
@@ -4998,7 +4999,7 @@ exec_set_found(PLpgSQL_execstate *estate, bool state)
        PLpgSQL_var *var;
 
        var = (PLpgSQL_var *) (estate->datums[estate->found_varno]);
-       var->value = (Datum) state;
+       var->value = PointerGetDatum(state);
        var->isnull = false;
 }