agora inbox for pgsql-hackers@postgresql.org
help / color / mirror / Atom feedFrom: Justin Pryzby <pryzbyj@telsasoft.com>
Subject: [PATCH 2/6] Avoid the most useless instances of nulls[0]=false..
Date: Fri, 14 Jan 2022 19:25:21 -0600
Getting rid of more of these is apparently too controvercial, but these are the
cases where 1) nulls is always being set to false; and, 2) values[] is not
being memset, so there's no parallel between the two.
---
contrib/sslinfo/sslinfo.c | 5 +-
src/backend/replication/logical/origin.c | 13 +---
src/backend/utils/adt/misc.c | 7 +--
src/backend/utils/misc/pg_controldata.c | 80 ++----------------------
4 files changed, 10 insertions(+), 95 deletions(-)
diff --git a/contrib/sslinfo/sslinfo.c b/contrib/sslinfo/sslinfo.c
index 5fd46b98741..d9edfe1b742 100644
--- a/contrib/sslinfo/sslinfo.c
+++ b/contrib/sslinfo/sslinfo.c
@@ -424,7 +424,7 @@ ssl_extension_info(PG_FUNCTION_ARGS)
if (call_cntr < max_calls)
{
Datum values[3];
- bool nulls[3];
+ bool nulls[3] = {0};
char *buf;
HeapTuple tuple;
Datum result;
@@ -453,7 +453,6 @@ ssl_extension_info(PG_FUNCTION_ARGS)
errmsg("unknown OpenSSL extension in certificate at position %d",
call_cntr)));
values[0] = CStringGetTextDatum(OBJ_nid2sn(nid));
- nulls[0] = false;
/* Get the extension value */
if (X509V3_EXT_print(membuf, ext, 0, 0) <= 0)
@@ -463,11 +462,9 @@ ssl_extension_info(PG_FUNCTION_ARGS)
call_cntr)));
len = BIO_get_mem_data(membuf, &buf);
values[1] = PointerGetDatum(cstring_to_text_with_len(buf, len));
- nulls[1] = false;
/* Get critical status */
values[2] = BoolGetDatum(X509_EXTENSION_get_critical(ext));
- nulls[2] = false;
/* Build tuple */
tuple = heap_form_tuple(fctx->tupdesc, values, nulls);
diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c
index f134e44878f..adb3430c33a 100644
--- a/src/backend/replication/logical/origin.c
+++ b/src/backend/replication/logical/origin.c
@@ -1527,10 +1527,9 @@ pg_show_replication_origin_status(PG_FUNCTION_ARGS)
continue;
memset(values, 0, sizeof(values));
- memset(nulls, 1, sizeof(nulls));
+ memset(nulls, 0, sizeof(nulls));
values[0] = ObjectIdGetDatum(state->roident);
- nulls[0] = false;
/*
* We're not preventing the origin to be dropped concurrently, so
@@ -1538,19 +1537,13 @@ pg_show_replication_origin_status(PG_FUNCTION_ARGS)
*/
if (replorigin_by_oid(state->roident, true,
&roname))
- {
values[1] = CStringGetTextDatum(roname);
- nulls[1] = false;
- }
+ else
+ nulls[1] = true;
LWLockAcquire(&state->lock, LW_SHARED);
-
values[2] = LSNGetDatum(state->remote_lsn);
- nulls[2] = false;
-
values[3] = LSNGetDatum(state->local_lsn);
- nulls[3] = false;
-
LWLockRelease(&state->lock);
tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc,
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c
index 9c132512315..611b492624a 100644
--- a/src/backend/utils/adt/misc.c
+++ b/src/backend/utils/adt/misc.c
@@ -246,7 +246,7 @@ pg_tablespace_databases(PG_FUNCTION_ARGS)
char *subdir;
bool isempty;
Datum values[1];
- bool nulls[1];
+ bool nulls[1] = {0};
/* this test skips . and .., but is awfully weak */
if (!datOid)
@@ -262,7 +262,6 @@ pg_tablespace_databases(PG_FUNCTION_ARGS)
continue; /* indeed, nothing in it */
values[0] = ObjectIdGetDatum(datOid);
- nulls[0] = false;
tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc,
values, nulls);
@@ -530,11 +529,9 @@ pg_get_catalog_foreign_keys(PG_FUNCTION_ARGS)
{
const SysFKRelationship *fkrel = &sys_fk_relationships[funcctx->call_cntr];
Datum values[6];
- bool nulls[6];
+ bool nulls[6] = {0};
HeapTuple tuple;
- memset(nulls, false, sizeof(nulls));
-
values[0] = ObjectIdGetDatum(fkrel->fk_table);
values[1] = FunctionCall3(arrayinp,
CStringGetDatum(fkrel->fk_columns),
diff --git a/src/backend/utils/misc/pg_controldata.c b/src/backend/utils/misc/pg_controldata.c
index 781f8b87580..32be2b4b5d8 100644
--- a/src/backend/utils/misc/pg_controldata.c
+++ b/src/backend/utils/misc/pg_controldata.c
@@ -32,7 +32,7 @@ Datum
pg_control_system(PG_FUNCTION_ARGS)
{
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {0};
TupleDesc tupdesc;
HeapTuple htup;
ControlFileData *ControlFile;
@@ -60,16 +60,9 @@ pg_control_system(PG_FUNCTION_ARGS)
(errmsg("calculated CRC checksum does not match value stored in file")));
values[0] = Int32GetDatum(ControlFile->pg_control_version);
- nulls[0] = false;
-
values[1] = Int32GetDatum(ControlFile->catalog_version_no);
- nulls[1] = false;
-
values[2] = Int64GetDatum(ControlFile->system_identifier);
- nulls[2] = false;
-
values[3] = TimestampTzGetDatum(time_t_to_timestamptz(ControlFile->time));
- nulls[3] = false;
htup = heap_form_tuple(tupdesc, values, nulls);
@@ -80,7 +73,7 @@ Datum
pg_control_checkpoint(PG_FUNCTION_ARGS)
{
Datum values[18];
- bool nulls[18];
+ bool nulls[18] = {0};
TupleDesc tupdesc;
HeapTuple htup;
ControlFileData *ControlFile;
@@ -147,60 +140,25 @@ pg_control_checkpoint(PG_FUNCTION_ARGS)
/* Populate the values and null arrays */
values[0] = LSNGetDatum(ControlFile->checkPoint);
- nulls[0] = false;
-
values[1] = LSNGetDatum(ControlFile->checkPointCopy.redo);
- nulls[1] = false;
-
values[2] = CStringGetTextDatum(xlogfilename);
- nulls[2] = false;
-
values[3] = Int32GetDatum(ControlFile->checkPointCopy.ThisTimeLineID);
- nulls[3] = false;
-
values[4] = Int32GetDatum(ControlFile->checkPointCopy.PrevTimeLineID);
- nulls[4] = false;
-
values[5] = BoolGetDatum(ControlFile->checkPointCopy.fullPageWrites);
- nulls[5] = false;
-
values[6] = CStringGetTextDatum(psprintf("%u:%u",
EpochFromFullTransactionId(ControlFile->checkPointCopy.nextXid),
XidFromFullTransactionId(ControlFile->checkPointCopy.nextXid)));
- nulls[6] = false;
-
values[7] = ObjectIdGetDatum(ControlFile->checkPointCopy.nextOid);
- nulls[7] = false;
-
values[8] = TransactionIdGetDatum(ControlFile->checkPointCopy.nextMulti);
- nulls[8] = false;
-
values[9] = TransactionIdGetDatum(ControlFile->checkPointCopy.nextMultiOffset);
- nulls[9] = false;
-
values[10] = TransactionIdGetDatum(ControlFile->checkPointCopy.oldestXid);
- nulls[10] = false;
-
values[11] = ObjectIdGetDatum(ControlFile->checkPointCopy.oldestXidDB);
- nulls[11] = false;
-
values[12] = TransactionIdGetDatum(ControlFile->checkPointCopy.oldestActiveXid);
- nulls[12] = false;
-
values[13] = TransactionIdGetDatum(ControlFile->checkPointCopy.oldestMulti);
- nulls[13] = false;
-
values[14] = ObjectIdGetDatum(ControlFile->checkPointCopy.oldestMultiDB);
- nulls[14] = false;
-
values[15] = TransactionIdGetDatum(ControlFile->checkPointCopy.oldestCommitTsXid);
- nulls[15] = false;
-
values[16] = TransactionIdGetDatum(ControlFile->checkPointCopy.newestCommitTsXid);
- nulls[16] = false;
-
values[17] = TimestampTzGetDatum(time_t_to_timestamptz(ControlFile->checkPointCopy.time));
- nulls[17] = false;
htup = heap_form_tuple(tupdesc, values, nulls);
@@ -211,7 +169,7 @@ Datum
pg_control_recovery(PG_FUNCTION_ARGS)
{
Datum values[5];
- bool nulls[5];
+ bool nulls[5] = {0};
TupleDesc tupdesc;
HeapTuple htup;
ControlFileData *ControlFile;
@@ -241,19 +199,10 @@ pg_control_recovery(PG_FUNCTION_ARGS)
(errmsg("calculated CRC checksum does not match value stored in file")));
values[0] = LSNGetDatum(ControlFile->minRecoveryPoint);
- nulls[0] = false;
-
values[1] = Int32GetDatum(ControlFile->minRecoveryPointTLI);
- nulls[1] = false;
-
values[2] = LSNGetDatum(ControlFile->backupStartPoint);
- nulls[2] = false;
-
values[3] = LSNGetDatum(ControlFile->backupEndPoint);
- nulls[3] = false;
-
values[4] = BoolGetDatum(ControlFile->backupEndRequired);
- nulls[4] = false;
htup = heap_form_tuple(tupdesc, values, nulls);
@@ -264,7 +213,7 @@ Datum
pg_control_init(PG_FUNCTION_ARGS)
{
Datum values[11];
- bool nulls[11];
+ bool nulls[11] = {0};
TupleDesc tupdesc;
HeapTuple htup;
ControlFileData *ControlFile;
@@ -306,37 +255,16 @@ pg_control_init(PG_FUNCTION_ARGS)
(errmsg("calculated CRC checksum does not match value stored in file")));
values[0] = Int32GetDatum(ControlFile->maxAlign);
- nulls[0] = false;
-
values[1] = Int32GetDatum(ControlFile->blcksz);
- nulls[1] = false;
-
values[2] = Int32GetDatum(ControlFile->relseg_size);
- nulls[2] = false;
-
values[3] = Int32GetDatum(ControlFile->xlog_blcksz);
- nulls[3] = false;
-
values[4] = Int32GetDatum(ControlFile->xlog_seg_size);
- nulls[4] = false;
-
values[5] = Int32GetDatum(ControlFile->nameDataLen);
- nulls[5] = false;
-
values[6] = Int32GetDatum(ControlFile->indexMaxKeys);
- nulls[6] = false;
-
values[7] = Int32GetDatum(ControlFile->toast_max_chunk_size);
- nulls[7] = false;
-
values[8] = Int32GetDatum(ControlFile->loblksize);
- nulls[8] = false;
-
values[9] = BoolGetDatum(ControlFile->float8ByVal);
- nulls[9] = false;
-
values[10] = Int32GetDatum(ControlFile->data_checksum_version);
- nulls[10] = false;
htup = heap_form_tuple(tupdesc, values, nulls);
--
2.25.1
--EqVOK5mkaJAMmtSx
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="0003-selfuncs.c-refactor-parent-ACL-check.patch"
view thread (4+ messages) latest in thread
Message-ID: <no-message-id-635686@localhost>
Permalink: ../../no-message-id-635686@localhost/
Also on: postgresql.org/message-id/no-message-id-635686@localhost
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: pryzbyj@telsasoft.com
Subject: Re: [PATCH 2/6] Avoid the most useless instances of nulls[0]=false..
In-Reply-To: <no-message-id-635686@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox