提交 9c8e0816 编写于 作者: A Ashwin Agrawal

Make DatumGetPointer() and PointerGetDatum() macros.

These functions as inline functions were producing warnings, based on discussion
https://groups.google.com/a/greenplum.org/d/msg/gpdb-dev/6fgKvN9QpV4/zjysjqIZAgAJ
converting them to macro as upstream. Adding explicit type casting wherever
needed now that DatumGetPointer() returns (char *) instead of (void *).
上级 4efc2e7b
......@@ -625,7 +625,7 @@ MemTuple memtuple_form_to(
if (old_values == NULL)
old_values = (Datum *)palloc0(pbind->tupdesc->natts * sizeof(Datum));
old_values[i] = values[i];
values[i] = PointerGetDatum(heap_tuple_fetch_attr(DatumGetPointer(values[i])));
values[i] = PointerGetDatum(heap_tuple_fetch_attr((struct varlena *)DatumGetPointer(values[i])));
if (old_values[i] == values[i])
old_values[i] = 0;
......
......@@ -873,7 +873,7 @@ parseRelOptions(Datum options, int numkeywords, const char *const * keywords,
return;
array = DatumGetArrayTypeP(options);
isArrayToBeFreed = (array != DatumGetPointer(options));
isArrayToBeFreed = (array != (ArrayType *)DatumGetPointer(options));
Assert(ARR_ELEMTYPE(array) == TEXTOID);
......
......@@ -735,7 +735,7 @@ ExecGrant_Relation(InternalGrant *istmt)
char *aclstr = strVal(lfirst(lc));
AclItem *newai;
newai = DatumGetPointer(DirectFunctionCall1(aclitemin,
newai = (AclItem *)DatumGetPointer(DirectFunctionCall1(aclitemin,
CStringGetDatum(aclstr)));
aip->ai_grantee = newai->ai_grantee;
......
......@@ -179,7 +179,7 @@ callCompressionConstructor(PGFunction constructor,
StorageAttributes *sa,
bool is_compress)
{
return DatumGetPointer(DirectFunctionCall3(constructor,
return (CompressionState *) DatumGetPointer(DirectFunctionCall3(constructor,
PointerGetDatum(tupledesc),
PointerGetDatum(sa),
BoolGetDatum(is_compress)));
......@@ -226,7 +226,7 @@ zlib_constructor(PG_FUNCTION_ARGS)
/* PG_GETARG_POINTER(0) is TupleDesc that is currently unused.
* It is passed as NULL */
StorageAttributes *sa = PG_GETARG_POINTER(1);
StorageAttributes *sa = (StorageAttributes *) PG_GETARG_POINTER(1);
CompressionState *cs = palloc0(sizeof(CompressionState));
zlib_state *state = palloc0(sizeof(zlib_state));
bool compress = PG_GETARG_BOOL(2);
......@@ -251,7 +251,7 @@ zlib_constructor(PG_FUNCTION_ARGS)
Datum
zlib_destructor(PG_FUNCTION_ARGS)
{
CompressionState *cs = PG_GETARG_POINTER(0);
CompressionState *cs = (CompressionState *) PG_GETARG_POINTER(0);
if (cs != NULL && cs->opaque != NULL)
{
......@@ -268,7 +268,7 @@ zlib_compress(PG_FUNCTION_ARGS)
int32 src_sz = PG_GETARG_INT32(1);
void *dst = PG_GETARG_POINTER(2);
int32 dst_sz = PG_GETARG_INT32(3);
int32 *dst_used = PG_GETARG_POINTER(4);
int32 *dst_used = (int32 *) PG_GETARG_POINTER(4);
CompressionState *cs = (CompressionState *) PG_GETARG_POINTER(5);
zlib_state *state = (zlib_state *) cs->opaque;
int last_error;
......@@ -317,7 +317,7 @@ zlib_decompress(PG_FUNCTION_ARGS)
int32 src_sz = PG_GETARG_INT32(1);
void *dst = PG_GETARG_POINTER(2);
int32 dst_sz = PG_GETARG_INT32(3);
int32 *dst_used = PG_GETARG_POINTER(4);
int32 *dst_used = (int32 *) PG_GETARG_POINTER(4);
CompressionState *cs = (CompressionState *) PG_GETARG_POINTER(5);
zlib_state *state = (zlib_state *) cs->opaque;
int last_error;
......
......@@ -311,7 +311,7 @@ hashDatum(Datum datum, Oid type, datumHashFunction hashFn, void *clientData)
* If we did a pg_detoast_datum, we need to remember to pfree,
* or we will leak memory. Because of the 1-byte varlena header stuff.
*/
if (num != DatumGetPointer(datum))
if (num != (Numeric) DatumGetPointer(datum))
tofree = num;
break;
......
......@@ -2156,11 +2156,11 @@ partMakePartition(HeapTuple tuple)
p->paristemplate = partrow->paristemplate;
p->parnatts = partrow->parnatts;
atts = DatumGetPointer(SysCacheGetAttr(PARTOID, tuple,
atts = (int2vector *) DatumGetPointer(SysCacheGetAttr(PARTOID, tuple,
Anum_pg_partition_paratts,
&isnull));
Assert(!isnull);
oids = DatumGetPointer(SysCacheGetAttr(PARTOID, tuple,
oids = (oidvector *) DatumGetPointer(SysCacheGetAttr(PARTOID, tuple,
Anum_pg_partition_parclass,
&isnull));
Assert(!isnull);
......@@ -2373,8 +2373,9 @@ get_partition_key_bitmapset(Oid relid)
continue; /* no interest in template parts */
natts = partrow->parnatts;
atts = DatumGetPointer(heap_getattr(tuple, Anum_pg_partition_paratts,
tupledesc, &isnull));
atts = (int2vector *) DatumGetPointer(
heap_getattr(tuple, Anum_pg_partition_paratts,
tupledesc, &isnull));
Insist(!isnull);
for ( i = 0; i < natts; i++ )
......
......@@ -1428,7 +1428,8 @@ ChangeTracking_GetIncrementalChangeList(void)
result = ChangeTracking_InitIncrementalChangeList(proc);
/* convert to desired data type */
persistentTid = DatumGetPointer(DirectFunctionCall1(tidin, CStringGetDatum(str_tid)));
persistentTid = (ItemPointer) DatumGetPointer(
DirectFunctionCall1(tidin, CStringGetDatum(str_tid)));
persistentSerialNum = DatumGetInt64(DirectFunctionCall1(int8in, CStringGetDatum(str_sn)));
numblocks = DatumGetInt64(DirectFunctionCall1(int8in, CStringGetDatum(str_numb)));
......@@ -3178,7 +3179,8 @@ int ChangeTracking_CompactLogFile(CTFType source, CTFType dest, XLogRecPtr* upto
relfile.relNode = DatumGetObjectId(DirectFunctionCall1(oidin, CStringGetDatum(str_rel)));
blocknum = DatumGetUInt32(DirectFunctionCall1(int4in, CStringGetDatum(str_blocknum)));
endlsn = (XLogRecPtr*) DatumGetPointer(DirectFunctionCall1(gpxloglocin, CStringGetDatum(str_endlsn)));
persistentTid = DatumGetPointer(DirectFunctionCall1(tidin, CStringGetDatum(str_tid)));
persistentTid = (ItemPointer) DatumGetPointer(
DirectFunctionCall1(tidin, CStringGetDatum(str_tid)));
persistentSerialNum = DatumGetInt64(DirectFunctionCall1(int8in, CStringGetDatum(str_sn)));
SIMPLE_FAULT_INJECTOR(FileRepChangeTrackingCompacting);
......
......@@ -141,7 +141,7 @@ tstoreReceiveSlot_detoast(TupleTableSlot *slot, DestReceiver *self)
if (VARATT_IS_EXTERNAL(DatumGetPointer(val)))
{
val = PointerGetDatum(heap_tuple_fetch_attr(
DatumGetPointer(val)));
(struct varlena *) DatumGetPointer(val)));
myState->tofree[nfree++] = val;
}
}
......
......@@ -74,7 +74,7 @@
do { \
if (from->fldname) \
{ \
newnode->fldname = DatumGetPointer( \
newnode->fldname = (bytea *) DatumGetPointer( \
datumCopy(PointerGetDatum(from->fldname), false, len)); \
} \
} while (0)
......
......@@ -127,7 +127,7 @@
/* Read a bytea field */
#define READ_BYTEA_FIELD(fldname) \
local_node->fldname = DatumGetPointer(readDatum(false))
local_node->fldname = (bytea *) DatumGetPointer(readDatum(false))
/* Read a dummy field */
#define READ_DUMMY_FIELD(fldname,fldvalue) \
......
......@@ -155,7 +155,7 @@ inline static char extended_char(char* token, size_t length)
/* Read a bytea field */
#define READ_BYTEA_FIELD(fldname) \
local_node->fldname = DatumGetPointer(readDatum(false))
local_node->fldname = (bytea *) DatumGetPointer(readDatum(false))
/* Set field to a given value, ignoring the value read from the input */
#define READ_DUMMY_FIELD(fldname,fldvalue) READ_SCALAR_FIELD(fldname, fldvalue)
......
......@@ -1090,7 +1090,8 @@ datumstreamwrite_lob(DatumStreamWrite * acc,
*/
if (VARATT_IS_EXTERNAL(DatumGetPointer(d)))
{
d = PointerGetDatum(heap_tuple_fetch_attr(DatumGetPointer(d)));
d = PointerGetDatum(heap_tuple_fetch_attr(
(struct varlena *) DatumGetPointer(d)));
}
p = (uint8 *) DatumGetPointer(d);
......
......@@ -1162,7 +1162,7 @@ DatumStreamBlockWrite_PrintInputVarlenaInfo(
{
uint8 *p;
p = DatumGetPointer(originalDatum);
p = (uint8 *) DatumGetPointer(originalDatum);
ereport(LOG,
(errmsg("Write input varlena input <%s> (nth %d, was extended %s)",
......
......@@ -978,7 +978,7 @@ tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull)
{
stup.datum1 = datumCopy(val, false, state->datumTypeLen);
stup.isnull1 = false;
stup.tuple = DatumGetPointer(stup.datum1);
stup.tuple = (MemTuple) DatumGetPointer(stup.datum1);
USEMEM(state, GetMemoryChunkSpace(DatumGetPointer(stup.datum1)));
}
......
......@@ -359,8 +359,19 @@ static inline Datum TransactionIdGetDatum(TransactionId tid) { return (Datum) ti
static inline CommandId DatumGetCommandId(Datum d) { return (CommandId) d; }
static inline Datum CommandIdGetDatum(CommandId cid) { return (Datum) cid; }
static inline void *DatumGetPointer(Datum d) { Datum_U du; du.d = d; return du.ptr; }
static inline Datum PointerGetDatum(const void *p) { Datum_U du; du.d = 0; du.ptr = (void *)p; return du.d; }
/*
* DatumGetPointer
* Returns pointer value of a datum.
*/
#define DatumGetPointer(X) ((Pointer) (X))
/*
* PointerGetDatum
* Returns datum representation for a pointer.
*/
#define PointerGetDatum(X) ((Datum) (X))
static inline char *DatumGetCString(Datum d) { return (char* ) DatumGetPointer(d); }
static inline Datum CStringGetDatum(const char *p) { return PointerGetDatum(p); }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册