1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-29 23:43:17 +03:00

Remove all uses of the deprecated functions heap_formtuple, heap_modifytuple,

and heap_deformtuple in favor of the newer functions heap_form_tuple et al
(which do the same things but use bool control flags instead of arbitrary
char values).  Eliminate the former duplicate coding of these functions,
reducing the deprecated functions to mere wrappers around the newer ones.
We can't get rid of them entirely because add-on modules probably still
contain many instances of the old coding style.

Kris Jurka
This commit is contained in:
Tom Lane
2008-11-02 01:45:28 +00:00
parent 492059daba
commit 902d1cb35f
46 changed files with 630 additions and 1013 deletions

View File

@@ -6,7 +6,7 @@
* Copyright (c) 2002-2008, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/lockfuncs.c,v 1.34 2008/05/12 00:00:51 alvherre Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/lockfuncs.c,v 1.35 2008/11/02 01:45:28 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -144,7 +144,7 @@ pg_lock_status(PG_FUNCTION_ARGS)
const char *locktypename;
char tnbuf[32];
Datum values[14];
char nulls[14];
bool nulls[14];
HeapTuple tuple;
Datum result;
@@ -203,7 +203,7 @@ pg_lock_status(PG_FUNCTION_ARGS)
* Form tuple with appropriate data.
*/
MemSet(values, 0, sizeof(values));
MemSet(nulls, ' ', sizeof(nulls));
MemSet(nulls, false, sizeof(nulls));
if (lock->tag.locktag_type <= LOCKTAG_LAST_TYPE)
locktypename = LockTagTypeNames[lock->tag.locktag_type];
@@ -221,58 +221,58 @@ pg_lock_status(PG_FUNCTION_ARGS)
case LOCKTAG_RELATION_EXTEND:
values[1] = ObjectIdGetDatum(lock->tag.locktag_field1);
values[2] = ObjectIdGetDatum(lock->tag.locktag_field2);
nulls[3] = 'n';
nulls[4] = 'n';
nulls[5] = 'n';
nulls[6] = 'n';
nulls[7] = 'n';
nulls[8] = 'n';
nulls[9] = 'n';
nulls[3] = true;
nulls[4] = true;
nulls[5] = true;
nulls[6] = true;
nulls[7] = true;
nulls[8] = true;
nulls[9] = true;
break;
case LOCKTAG_PAGE:
values[1] = ObjectIdGetDatum(lock->tag.locktag_field1);
values[2] = ObjectIdGetDatum(lock->tag.locktag_field2);
values[3] = UInt32GetDatum(lock->tag.locktag_field3);
nulls[4] = 'n';
nulls[5] = 'n';
nulls[6] = 'n';
nulls[7] = 'n';
nulls[8] = 'n';
nulls[9] = 'n';
nulls[4] = true;
nulls[5] = true;
nulls[6] = true;
nulls[7] = true;
nulls[8] = true;
nulls[9] = true;
break;
case LOCKTAG_TUPLE:
values[1] = ObjectIdGetDatum(lock->tag.locktag_field1);
values[2] = ObjectIdGetDatum(lock->tag.locktag_field2);
values[3] = UInt32GetDatum(lock->tag.locktag_field3);
values[4] = UInt16GetDatum(lock->tag.locktag_field4);
nulls[5] = 'n';
nulls[6] = 'n';
nulls[7] = 'n';
nulls[8] = 'n';
nulls[9] = 'n';
nulls[5] = true;
nulls[6] = true;
nulls[7] = true;
nulls[8] = true;
nulls[9] = true;
break;
case LOCKTAG_TRANSACTION:
values[6] = TransactionIdGetDatum(lock->tag.locktag_field1);
nulls[1] = 'n';
nulls[2] = 'n';
nulls[3] = 'n';
nulls[4] = 'n';
nulls[5] = 'n';
nulls[7] = 'n';
nulls[8] = 'n';
nulls[9] = 'n';
nulls[1] = true;
nulls[2] = true;
nulls[3] = true;
nulls[4] = true;
nulls[5] = true;
nulls[7] = true;
nulls[8] = true;
nulls[9] = true;
break;
case LOCKTAG_VIRTUALTRANSACTION:
values[5] = VXIDGetDatum(lock->tag.locktag_field1,
lock->tag.locktag_field2);
nulls[1] = 'n';
nulls[2] = 'n';
nulls[3] = 'n';
nulls[4] = 'n';
nulls[6] = 'n';
nulls[7] = 'n';
nulls[8] = 'n';
nulls[9] = 'n';
nulls[1] = true;
nulls[2] = true;
nulls[3] = true;
nulls[4] = true;
nulls[6] = true;
nulls[7] = true;
nulls[8] = true;
nulls[9] = true;
break;
case LOCKTAG_OBJECT:
case LOCKTAG_USERLOCK:
@@ -282,11 +282,11 @@ pg_lock_status(PG_FUNCTION_ARGS)
values[7] = ObjectIdGetDatum(lock->tag.locktag_field2);
values[8] = ObjectIdGetDatum(lock->tag.locktag_field3);
values[9] = Int16GetDatum(lock->tag.locktag_field4);
nulls[2] = 'n';
nulls[3] = 'n';
nulls[4] = 'n';
nulls[5] = 'n';
nulls[6] = 'n';
nulls[2] = true;
nulls[3] = true;
nulls[4] = true;
nulls[5] = true;
nulls[6] = true;
break;
}
@@ -294,11 +294,11 @@ pg_lock_status(PG_FUNCTION_ARGS)
if (proc->pid != 0)
values[11] = Int32GetDatum(proc->pid);
else
nulls[11] = 'n';
nulls[11] = true;
values[12] = CStringGetTextDatum(GetLockmodeName(LOCK_LOCKMETHOD(*lock), mode));
values[13] = BoolGetDatum(granted);
tuple = heap_formtuple(funcctx->tuple_desc, values, nulls);
tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
result = HeapTupleGetDatum(tuple);
SRF_RETURN_NEXT(funcctx, result);
}

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/rowtypes.c,v 1.22 2008/10/13 16:25:19 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/rowtypes.c,v 1.23 2008/11/02 01:45:28 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -83,7 +83,7 @@ record_in(PG_FUNCTION_ARGS)
int i;
char *ptr;
Datum *values;
char *nulls;
bool *nulls;
StringInfoData buf;
/*
@@ -129,7 +129,7 @@ record_in(PG_FUNCTION_ARGS)
}
values = (Datum *) palloc(ncolumns * sizeof(Datum));
nulls = (char *) palloc(ncolumns * sizeof(char));
nulls = (bool *) palloc(ncolumns * sizeof(bool));
/*
* Scan the string. We use "buf" to accumulate the de-quoted data for
@@ -157,7 +157,7 @@ record_in(PG_FUNCTION_ARGS)
if (tupdesc->attrs[i]->attisdropped)
{
values[i] = (Datum) 0;
nulls[i] = 'n';
nulls[i] = true;
continue;
}
@@ -178,7 +178,7 @@ record_in(PG_FUNCTION_ARGS)
if (*ptr == ',' || *ptr == ')')
{
column_data = NULL;
nulls[i] = 'n';
nulls[i] = true;
}
else
{
@@ -223,7 +223,7 @@ record_in(PG_FUNCTION_ARGS)
}
column_data = buf.data;
nulls[i] = ' ';
nulls[i] = false;
}
/*
@@ -264,10 +264,10 @@ record_in(PG_FUNCTION_ARGS)
errmsg("malformed record literal: \"%s\"", string),
errdetail("Junk after right parenthesis.")));
tuple = heap_formtuple(tupdesc, values, nulls);
tuple = heap_form_tuple(tupdesc, values, nulls);
/*
* We cannot return tuple->t_data because heap_formtuple allocates it as
* We cannot return tuple->t_data because heap_form_tuple allocates it as
* part of a larger chunk, and our caller may expect to be able to pfree
* our result. So must copy the info into a new palloc chunk.
*/
@@ -299,7 +299,7 @@ record_out(PG_FUNCTION_ARGS)
int ncolumns;
int i;
Datum *values;
char *nulls;
bool *nulls;
StringInfoData buf;
/* Extract type info from the tuple itself */
@@ -343,10 +343,10 @@ record_out(PG_FUNCTION_ARGS)
}
values = (Datum *) palloc(ncolumns * sizeof(Datum));
nulls = (char *) palloc(ncolumns * sizeof(char));
nulls = (bool *) palloc(ncolumns * sizeof(bool));
/* Break down the tuple into fields */
heap_deformtuple(&tuple, tupdesc, values, nulls);
heap_deform_tuple(&tuple, tupdesc, values, nulls);
/* And build the result string */
initStringInfo(&buf);
@@ -369,7 +369,7 @@ record_out(PG_FUNCTION_ARGS)
appendStringInfoChar(&buf, ',');
needComma = true;
if (nulls[i] == 'n')
if (nulls[i])
{
/* emit nothing... */
continue;
@@ -453,7 +453,7 @@ record_recv(PG_FUNCTION_ARGS)
int validcols;
int i;
Datum *values;
char *nulls;
bool *nulls;
/*
* Use the passed type unless it's RECORD; we can't support input of
@@ -498,7 +498,7 @@ record_recv(PG_FUNCTION_ARGS)
}
values = (Datum *) palloc(ncolumns * sizeof(Datum));
nulls = (char *) palloc(ncolumns * sizeof(char));
nulls = (bool *) palloc(ncolumns * sizeof(bool));
/* Fetch number of columns user thinks it has */
usercols = pq_getmsgint(buf, 4);
@@ -531,7 +531,7 @@ record_recv(PG_FUNCTION_ARGS)
if (tupdesc->attrs[i]->attisdropped)
{
values[i] = (Datum) 0;
nulls[i] = 'n';
nulls[i] = true;
continue;
}
@@ -554,7 +554,7 @@ record_recv(PG_FUNCTION_ARGS)
{
/* -1 length means NULL */
bufptr = NULL;
nulls[i] = 'n';
nulls[i] = true;
csave = 0; /* keep compiler quiet */
}
else
@@ -576,7 +576,7 @@ record_recv(PG_FUNCTION_ARGS)
buf->data[buf->cursor] = '\0';
bufptr = &item_buf;
nulls[i] = ' ';
nulls[i] = false;
}
/* Now call the column's receiveproc */
@@ -608,10 +608,10 @@ record_recv(PG_FUNCTION_ARGS)
}
}
tuple = heap_formtuple(tupdesc, values, nulls);
tuple = heap_form_tuple(tupdesc, values, nulls);
/*
* We cannot return tuple->t_data because heap_formtuple allocates it as
* We cannot return tuple->t_data because heap_form_tuple allocates it as
* part of a larger chunk, and our caller may expect to be able to pfree
* our result. So must copy the info into a new palloc chunk.
*/
@@ -642,7 +642,7 @@ record_send(PG_FUNCTION_ARGS)
int validcols;
int i;
Datum *values;
char *nulls;
bool *nulls;
StringInfoData buf;
/* Extract type info from the tuple itself */
@@ -686,10 +686,10 @@ record_send(PG_FUNCTION_ARGS)
}
values = (Datum *) palloc(ncolumns * sizeof(Datum));
nulls = (char *) palloc(ncolumns * sizeof(char));
nulls = (bool *) palloc(ncolumns * sizeof(bool));
/* Break down the tuple into fields */
heap_deformtuple(&tuple, tupdesc, values, nulls);
heap_deform_tuple(&tuple, tupdesc, values, nulls);
/* And build the result string */
pq_begintypsend(&buf);
@@ -715,7 +715,7 @@ record_send(PG_FUNCTION_ARGS)
pq_sendint(&buf, column_type, sizeof(Oid));
if (nulls[i] == 'n')
if (nulls[i])
{
/* emit -1 data length to signify a NULL */
pq_sendint(&buf, -1, 4);