Remove shadowed declaration warnings
Hi,
I normally build the code with warnings enabled (specifically,
-Wshadow) which exposes many "shadowed" declarations.
It would be better to reduce warnings wherever it's easy to do so,
because if we always see/ignore lots of warnings then sooner or later
something important may escape attention. In any case, just removing
these warnings sometimes makes the code more readable by removing any
ambiguity.
Currently, I'm seeing 350+ shadow warnings. See the attached summary.
It will be WIP to eliminate them all, but here is a patch to address
some of the low-hanging fruit. If the patch is accepted, then I can
try later to deal with more of them.
======
The following are fixed by changing the param/var from 'text' to 'txt'.
execute.c:111:19: warning: declaration of ‘text’ shadows a global
declaration [-Wshadow]
../../../../src/include/c.h:700:24: warning: shadowed declaration is
here [-Wshadow]
~
prepare.c:104:26: warning: declaration of ‘text’ shadows a global
declaration [-Wshadow]
../../../../src/include/c.h:700:24: warning: shadowed declaration is
here [-Wshadow]
prepare.c:270:12: warning: declaration of ‘text’ shadows a global
declaration [-Wshadow]
../../../../src/include/c.h:700:24: warning: shadowed declaration is
here [-Wshadow]
~
c_keywords.c:36:32: warning: declaration of ‘text’ shadows a global
declaration [-Wshadow]
../../../../src/include/c.h:700:24: warning: shadowed declaration is
here [-Wshadow]
ecpg_keywords.c:39:35: warning: declaration of ‘text’ shadows a global
declaration [-Wshadow]
../../../../src/include/c.h:700:24: warning: shadowed declaration is
here [-Wshadow]
~
tab-complete.c:1638:29: warning: declaration of ‘text’ shadows a
global declaration [-Wshadow]
../../../src/include/c.h:700:24: warning: shadowed declaration is here
[-Wshadow]
tab-complete.c:5082:46: warning: declaration of ‘text’ shadows a
global declaration [-Wshadow]
../../../src/include/c.h:700:24: warning: shadowed declaration is here
[-Wshadow]
tab-complete.c:5111:38: warning: declaration of ‘text’ shadows a
global declaration [-Wshadow]
../../../src/include/c.h:700:24: warning: shadowed declaration is here
[-Wshadow]
tab-complete.c:5120:36: warning: declaration of ‘text’ shadows a
global declaration [-Wshadow]
../../../src/include/c.h:700:24: warning: shadowed declaration is here
[-Wshadow]
tab-complete.c:5129:37: warning: declaration of ‘text’ shadows a
global declaration [-Wshadow]
../../../src/include/c.h:700:24: warning: shadowed declaration is here
[-Wshadow]
tab-complete.c:5140:33: warning: declaration of ‘text’ shadows a
global declaration [-Wshadow]
../../../src/include/c.h:700:24: warning: shadowed declaration is here
[-Wshadow]
tab-complete.c:5148:43: warning: declaration of ‘text’ shadows a
global declaration [-Wshadow]
../../../src/include/c.h:700:24: warning: shadowed declaration is here
[-Wshadow]
tab-complete.c:5164:40: warning: declaration of ‘text’ shadows a
global declaration [-Wshadow]
../../../src/include/c.h:700:24: warning: shadowed declaration is here
[-Wshadow]
tab-complete.c:5172:50: warning: declaration of ‘text’ shadows a
global declaration [-Wshadow]
../../../src/include/c.h:700:24: warning: shadowed declaration is here
[-Wshadow]
tab-complete.c:5234:19: warning: declaration of ‘text’ shadows a
global declaration [-Wshadow]
../../../src/include/c.h:700:24: warning: shadowed declaration is here
[-Wshadow]
tab-complete.c:5605:32: warning: declaration of ‘text’ shadows a
global declaration [-Wshadow]
../../../src/include/c.h:700:24: warning: shadowed declaration is here
[-Wshadow]
tab-complete.c:5685:33: warning: declaration of ‘text’ shadows a
global declaration [-Wshadow]
../../../src/include/c.h:700:24: warning: shadowed declaration is here
[-Wshadow]
tab-complete.c:5733:37: warning: declaration of ‘text’ shadows a
global declaration [-Wshadow]
../../../src/include/c.h:700:24: warning: shadowed declaration is here
[-Wshadow]
tab-complete.c:5778:33: warning: declaration of ‘text’ shadows a
global declaration [-Wshadow]
../../../src/include/c.h:700:24: warning: shadowed declaration is here
[-Wshadow]
tab-complete.c:5910:27: warning: declaration of ‘text’ shadows a
global declaration [-Wshadow]
../../../src/include/c.h:700:24: warning: shadowed declaration is here
[-Wshadow]
======
The following was fixed by changing the name of the global static from
'progname' to 'prog_name'.
pg_createsubscriber.c:341:46: warning: declaration of ‘progname’
shadows a global declaration [-Wshadow]
pg_createsubscriber.c:114:20: warning: shadowed declaration is here [-Wshadow]
~
The following was fixed by changing the name of the global static from
'dbinfo' to 'db_info'.
pg_createsubscriber.c:437:25: warning: declaration of ‘dbinfo’ shadows
a global declaration [-Wshadow]
pg_createsubscriber.c:121:31: warning: shadowed declaration is here [-Wshadow]
pg_createsubscriber.c:734:40: warning: declaration of ‘dbinfo’ shadows
a global declaration [-Wshadow]
pg_createsubscriber.c:121:31: warning: shadowed declaration is here [-Wshadow]
pg_createsubscriber.c:841:46: warning: declaration of ‘dbinfo’ shadows
a global declaration [-Wshadow]
pg_createsubscriber.c:121:31: warning: shadowed declaration is here [-Wshadow]
pg_createsubscriber.c:961:47: warning: declaration of ‘dbinfo’ shadows
a global declaration [-Wshadow]
pg_createsubscriber.c:121:31: warning: shadowed declaration is here [-Wshadow]
pg_createsubscriber.c:1104:41: warning: declaration of ‘dbinfo’
shadows a global declaration [-Wshadow]
pg_createsubscriber.c:121:31: warning: shadowed declaration is here [-Wshadow]
pg_createsubscriber.c:1142:41: warning: declaration of ‘dbinfo’
shadows a global declaration [-Wshadow]
pg_createsubscriber.c:121:31: warning: shadowed declaration is here [-Wshadow]
pg_createsubscriber.c:1182:45: warning: declaration of ‘dbinfo’
shadows a global declaration [-Wshadow]
pg_createsubscriber.c:121:31: warning: shadowed declaration is here [-Wshadow]
pg_createsubscriber.c:1242:54: warning: declaration of ‘dbinfo’
shadows a global declaration [-Wshadow]
pg_createsubscriber.c:121:31: warning: shadowed declaration is here [-Wshadow]
pg_createsubscriber.c:1272:56: warning: declaration of ‘dbinfo’
shadows a global declaration [-Wshadow]
pg_createsubscriber.c:121:31: warning: shadowed declaration is here [-Wshadow]
pg_createsubscriber.c:1314:70: warning: declaration of ‘dbinfo’
shadows a global declaration [-Wshadow]
pg_createsubscriber.c:121:31: warning: shadowed declaration is here [-Wshadow]
pg_createsubscriber.c:1363:60: warning: declaration of ‘dbinfo’
shadows a global declaration [-Wshadow]
pg_createsubscriber.c:121:31: warning: shadowed declaration is here [-Wshadow]
pg_createsubscriber.c:1553:57: warning: declaration of ‘dbinfo’
shadows a global declaration [-Wshadow]
pg_createsubscriber.c:121:31: warning: shadowed declaration is here [-Wshadow]
pg_createsubscriber.c:1627:55: warning: declaration of ‘dbinfo’
shadows a global declaration [-Wshadow]
pg_createsubscriber.c:121:31: warning: shadowed declaration is here [-Wshadow]
pg_createsubscriber.c:1681:64: warning: declaration of ‘dbinfo’
shadows a global declaration [-Wshadow]
pg_createsubscriber.c:121:31: warning: shadowed declaration is here [-Wshadow]
pg_createsubscriber.c:1739:69: warning: declaration of ‘dbinfo’
shadows a global declaration [-Wshadow]
pg_createsubscriber.c:121:31: warning: shadowed declaration is here [-Wshadow]
pg_createsubscriber.c:1830:64: warning: declaration of ‘dbinfo’
shadows a global declaration [-Wshadow]
pg_createsubscriber.c:121:31: warning: shadowed declaration is here [-Wshadow]
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Attachments:
v1-0001-Remove-some-shadowed-declarations.patchapplication/octet-stream; name=v1-0001-Remove-some-shadowed-declarations.patchDownload
From 4562fa498437b885a7fffc9bc88b8050eff5772a Mon Sep 17 00:00:00 2001
From: Peter Smith <peter.b.smith@fujitsu.com>
Date: Thu, 12 Sep 2024 10:23:28 +1000
Subject: [PATCH v1] Remove some shadowed declarations
---
src/bin/pg_basebackup/pg_createsubscriber.c | 64 ++++-----
src/bin/psql/tab-complete.c | 212 ++++++++++++++--------------
src/interfaces/ecpg/ecpglib/execute.c | 18 +--
src/interfaces/ecpg/ecpglib/prepare.c | 38 ++---
src/interfaces/ecpg/preproc/c_keywords.c | 8 +-
5 files changed, 170 insertions(+), 170 deletions(-)
diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c
index e804b2a..f3866d5 100644
--- a/src/bin/pg_basebackup/pg_createsubscriber.c
+++ b/src/bin/pg_basebackup/pg_createsubscriber.c
@@ -111,14 +111,14 @@ static void drop_existing_subscriptions(PGconn *conn, const char *subname,
#define USEC_PER_SEC 1000000
#define WAIT_INTERVAL 1 /* 1 second */
-static const char *progname;
+static const char *prog_name;
static char *primary_slot_name = NULL;
static bool dry_run = false;
static bool success = false;
-static struct LogicalRepInfo *dbinfo;
+static struct LogicalRepInfo *db_info;
static int num_dbs = 0; /* number of specified databases */
static int num_pubs = 0; /* number of specified publications */
static int num_subs = 0; /* number of specified subscriptions */
@@ -173,17 +173,17 @@ cleanup_objects_atexit(void)
for (int i = 0; i < num_dbs; i++)
{
- if (dbinfo[i].made_publication || dbinfo[i].made_replslot)
+ if (db_info[i].made_publication || db_info[i].made_replslot)
{
PGconn *conn;
- conn = connect_database(dbinfo[i].pubconninfo, false);
+ conn = connect_database(db_info[i].pubconninfo, false);
if (conn != NULL)
{
- if (dbinfo[i].made_publication)
- drop_publication(conn, &dbinfo[i]);
- if (dbinfo[i].made_replslot)
- drop_replication_slot(conn, &dbinfo[i], dbinfo[i].replslotname);
+ if (db_info[i].made_publication)
+ drop_publication(conn, &db_info[i]);
+ if (db_info[i].made_replslot)
+ drop_replication_slot(conn, &db_info[i], db_info[i].replslotname);
disconnect_database(conn, false);
}
else
@@ -193,16 +193,16 @@ cleanup_objects_atexit(void)
* that some objects were left on primary and should be
* removed before trying again.
*/
- if (dbinfo[i].made_publication)
+ if (db_info[i].made_publication)
{
pg_log_warning("publication \"%s\" created in database \"%s\" on primary was left behind",
- dbinfo[i].pubname, dbinfo[i].dbname);
+ db_info[i].pubname, db_info[i].dbname);
pg_log_warning_hint("Drop this publication before trying again.");
}
- if (dbinfo[i].made_replslot)
+ if (db_info[i].made_replslot)
{
pg_log_warning("replication slot \"%s\" created in database \"%s\" on primary was left behind",
- dbinfo[i].replslotname, dbinfo[i].dbname);
+ db_info[i].replslotname, db_info[i].dbname);
pg_log_warning_hint("Drop this replication slot soon to avoid retention of WAL files.");
}
}
@@ -217,9 +217,9 @@ static void
usage(void)
{
printf(_("%s creates a new logical replica from a standby server.\n\n"),
- progname);
+ prog_name);
printf(_("Usage:\n"));
- printf(_(" %s [OPTION]...\n"), progname);
+ printf(_(" %s [OPTION]...\n"), prog_name);
printf(_("\nOptions:\n"));
printf(_(" -d, --database=DBNAME database in which to create a subscription\n"));
printf(_(" -D, --pgdata=DATADIR location for the subscriber data directory\n"));
@@ -323,7 +323,7 @@ get_sub_conninfo(const struct CreateSubscriberOptions *opt)
#endif
if (opt->sub_username != NULL)
appendConnStrItem(buf, "user", opt->sub_username);
- appendConnStrItem(buf, "fallback_application_name", progname);
+ appendConnStrItem(buf, "fallback_application_name", prog_name);
ret = pg_strdup(buf->data);
@@ -1903,7 +1903,7 @@ main(int argc, char **argv)
pg_logging_init(argv[0]);
pg_logging_set_level(PG_LOG_WARNING);
- progname = get_progname(argv[0]);
+ prog_name = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_basebackup"));
if (argc > 1)
@@ -1943,7 +1943,7 @@ main(int argc, char **argv)
{
pg_log_error("cannot be executed by \"root\"");
pg_log_error_hint("You must run %s as the PostgreSQL superuser.",
- progname);
+ prog_name);
exit(1);
}
#endif
@@ -2034,7 +2034,7 @@ main(int argc, char **argv)
break;
default:
/* getopt_long already emitted a complaint */
- pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ pg_log_error_hint("Try \"%s --help\" for more information.", prog_name);
exit(1);
}
}
@@ -2044,7 +2044,7 @@ main(int argc, char **argv)
{
pg_log_error("too many command-line arguments (first is \"%s\")",
argv[optind]);
- pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ pg_log_error_hint("Try \"%s --help\" for more information.", prog_name);
exit(1);
}
@@ -2052,7 +2052,7 @@ main(int argc, char **argv)
if (subscriber_dir == NULL)
{
pg_log_error("no subscriber data directory specified");
- pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ pg_log_error_hint("Try \"%s --help\" for more information.", prog_name);
exit(1);
}
@@ -2080,7 +2080,7 @@ main(int argc, char **argv)
* not, we would fail anyway.
*/
pg_log_error("no publisher connection string specified");
- pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ pg_log_error_hint("Try \"%s --help\" for more information.", prog_name);
exit(1);
}
pg_log_info("validating publisher connection string");
@@ -2113,7 +2113,7 @@ main(int argc, char **argv)
{
pg_log_error("no database name specified");
pg_log_error_hint("Try \"%s --help\" for more information.",
- progname);
+ prog_name);
exit(1);
}
}
@@ -2153,7 +2153,7 @@ main(int argc, char **argv)
* called before atexit() because its return is used in the
* cleanup_objects_atexit().
*/
- dbinfo = store_pub_sub_info(&opt, pub_base_conninfo, sub_base_conninfo);
+ db_info = store_pub_sub_info(&opt, pub_base_conninfo, sub_base_conninfo);
/* Register a function to clean up objects in case of failure */
atexit(cleanup_objects_atexit);
@@ -2162,7 +2162,7 @@ main(int argc, char **argv)
* Check if the subscriber data directory has the same system identifier
* than the publisher data directory.
*/
- pub_sysid = get_primary_sysid(dbinfo[0].pubconninfo);
+ pub_sysid = get_primary_sysid(db_info[0].pubconninfo);
sub_sysid = get_standby_sysid(subscriber_dir);
if (pub_sysid != sub_sysid)
pg_fatal("subscriber data directory is not a copy of the source database cluster");
@@ -2192,10 +2192,10 @@ main(int argc, char **argv)
start_standby_server(&opt, true, false);
/* Check if the standby server is ready for logical replication */
- check_subscriber(dbinfo);
+ check_subscriber(db_info);
/* Check if the primary server is ready for logical replication */
- check_publisher(dbinfo);
+ check_publisher(db_info);
/*
* Stop the target server. The recovery process requires that the server
@@ -2208,10 +2208,10 @@ main(int argc, char **argv)
stop_standby_server(subscriber_dir);
/* Create the required objects for each database on publisher */
- consistent_lsn = setup_publisher(dbinfo);
+ consistent_lsn = setup_publisher(db_info);
/* Write the required recovery parameters */
- setup_recovery(dbinfo, subscriber_dir, consistent_lsn);
+ setup_recovery(db_info, subscriber_dir, consistent_lsn);
/*
* Start subscriber so the recovery parameters will take effect. Wait
@@ -2222,7 +2222,7 @@ main(int argc, char **argv)
start_standby_server(&opt, true, true);
/* Waiting the subscriber to be promoted */
- wait_for_end_recovery(dbinfo[0].subconninfo, &opt);
+ wait_for_end_recovery(db_info[0].subconninfo, &opt);
/*
* Create the subscription for each database on subscriber. It does not
@@ -2230,13 +2230,13 @@ main(int argc, char **argv)
* point to the LSN reported by setup_publisher(). It also cleans up
* publications created by this tool and replication to the standby.
*/
- setup_subscriber(dbinfo, consistent_lsn);
+ setup_subscriber(db_info, consistent_lsn);
/* Remove primary_slot_name if it exists on primary */
- drop_primary_replication_slot(dbinfo, primary_slot_name);
+ drop_primary_replication_slot(db_info, primary_slot_name);
/* Remove failover replication slots if they exist on subscriber */
- drop_failover_replication_slots(dbinfo);
+ drop_failover_replication_slots(db_info);
/* Stop the subscriber */
pg_log_info("stopping the subscriber");
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index ea36b18..a9631cd 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -254,7 +254,7 @@ do { \
completion_charp = query; \
completion_charpp = list; \
completion_verbatim = false; \
- matches = rl_completion_matches(text, complete_from_query); \
+ matches = rl_completion_matches(txt, complete_from_query); \
} while (0)
#define COMPLETE_WITH_QUERY_PLUS(query, ...) \
@@ -271,7 +271,7 @@ do { \
completion_charp = query; \
completion_charpp = list; \
completion_verbatim = true; \
- matches = rl_completion_matches(text, complete_from_query); \
+ matches = rl_completion_matches(txt, complete_from_query); \
} while (0)
#define COMPLETE_WITH_QUERY_VERBATIM_PLUS(query, ...) \
@@ -288,7 +288,7 @@ do { \
completion_vquery = query; \
completion_charpp = list; \
completion_verbatim = false; \
- matches = rl_completion_matches(text, complete_from_versioned_query); \
+ matches = rl_completion_matches(txt, complete_from_versioned_query); \
} while (0)
#define COMPLETE_WITH_VERSIONED_QUERY_PLUS(query, ...) \
@@ -305,7 +305,7 @@ do { \
completion_squery = &(query); \
completion_charpp = list; \
completion_verbatim = false; \
- matches = rl_completion_matches(text, complete_from_schema_query); \
+ matches = rl_completion_matches(txt, complete_from_schema_query); \
} while (0)
#define COMPLETE_WITH_SCHEMA_QUERY_PLUS(query, ...) \
@@ -319,7 +319,7 @@ do { \
completion_squery = &(query); \
completion_charpp = NULL; \
completion_verbatim = true; \
- matches = rl_completion_matches(text, complete_from_schema_query); \
+ matches = rl_completion_matches(txt, complete_from_schema_query); \
} while (0)
#define COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(query) \
@@ -330,7 +330,7 @@ do { \
completion_squery = query; \
completion_charpp = list; \
completion_verbatim = false; \
- matches = rl_completion_matches(text, complete_from_versioned_schema_query); \
+ matches = rl_completion_matches(txt, complete_from_versioned_schema_query); \
} while (0)
#define COMPLETE_WITH_VERSIONED_SCHEMA_QUERY_PLUS(query, ...) \
@@ -347,14 +347,14 @@ do { \
do { \
completion_case_sensitive = (cs); \
completion_charp = (con); \
- matches = rl_completion_matches(text, complete_from_const); \
+ matches = rl_completion_matches(txt, complete_from_const); \
} while (0)
#define COMPLETE_WITH_LIST_INT(cs, list) \
do { \
completion_case_sensitive = (cs); \
completion_charpp = (list); \
- matches = rl_completion_matches(text, complete_from_list); \
+ matches = rl_completion_matches(txt, complete_from_list); \
} while (0)
#define COMPLETE_WITH_LIST(list) COMPLETE_WITH_LIST_INT(false, list)
@@ -381,7 +381,7 @@ do { \
completion_squery = &(Query_for_list_of_attributes); \
completion_charpp = list; \
completion_verbatim = false; \
- matches = rl_completion_matches(text, complete_from_schema_query); \
+ matches = rl_completion_matches(txt, complete_from_schema_query); \
} while (0)
#define COMPLETE_WITH_ATTR_PLUS(relation, ...) \
@@ -392,21 +392,21 @@ do { \
/*
* libedit will typically include the literal's leading single quote in
- * "text", while readline will not. Adapt our offered strings to fit.
- * But include a quote if there's not one just before "text", to get the
+ * "txt", while readline will not. Adapt our offered strings to fit.
+ * But include a quote if there's not one just before "txt", to get the
* user off to the right start.
*/
#define COMPLETE_WITH_ENUM_VALUE(type) \
do { \
set_completion_reference(type); \
- if (text[0] == '\'' || \
+ if (txt[0] == '\'' || \
start == 0 || rl_line_buffer[start - 1] != '\'') \
completion_squery = &(Query_for_list_of_enum_values_quoted); \
else \
completion_squery = &(Query_for_list_of_enum_values_unquoted); \
completion_charpp = NULL; \
completion_verbatim = true; \
- matches = rl_completion_matches(text, complete_from_schema_query); \
+ matches = rl_completion_matches(txt, complete_from_schema_query); \
} while (0)
/*
@@ -416,7 +416,7 @@ do { \
#define COMPLETE_WITH_TIMEZONE_NAME() \
do { \
static const char *const list[] = { "DEFAULT", NULL }; \
- if (text[0] == '\'') \
+ if (txt[0] == '\'') \
completion_charp = Query_for_list_of_timezone_names_quoted_in; \
else if (start == 0 || rl_line_buffer[start - 1] != '\'') \
completion_charp = Query_for_list_of_timezone_names_quoted_out; \
@@ -424,7 +424,7 @@ do { \
completion_charp = Query_for_list_of_timezone_names_unquoted; \
completion_charpp = list; \
completion_verbatim = true; \
- matches = rl_completion_matches(text, complete_from_query); \
+ matches = rl_completion_matches(txt, complete_from_query); \
} while (0)
#define COMPLETE_WITH_FUNCTION_ARG(function) \
@@ -433,7 +433,7 @@ do { \
completion_squery = &(Query_for_list_of_arguments); \
completion_charpp = NULL; \
completion_verbatim = true; \
- matches = rl_completion_matches(text, complete_from_schema_query); \
+ matches = rl_completion_matches(txt, complete_from_schema_query); \
} while (0)
/*
@@ -1339,32 +1339,32 @@ static const char *const view_optional_parameters[] = {
};
/* Forward declaration of functions */
-static char **psql_completion(const char *text, int start, int end);
-static char *create_command_generator(const char *text, int state);
-static char *drop_command_generator(const char *text, int state);
-static char *alter_command_generator(const char *text, int state);
-static char *complete_from_query(const char *text, int state);
-static char *complete_from_versioned_query(const char *text, int state);
-static char *complete_from_schema_query(const char *text, int state);
-static char *complete_from_versioned_schema_query(const char *text, int state);
+static char **psql_completion(const char *txt, int start, int end);
+static char *create_command_generator(const char *txt, int state);
+static char *drop_command_generator(const char *txt, int state);
+static char *alter_command_generator(const char *txt, int state);
+static char *complete_from_query(const char *txt, int state);
+static char *complete_from_versioned_query(const char *txt, int state);
+static char *complete_from_schema_query(const char *txt, int state);
+static char *complete_from_versioned_schema_query(const char *txt, int state);
static char *_complete_from_query(const char *simple_query,
const SchemaQuery *schema_query,
const char *const *keywords,
bool verbatim,
- const char *text, int state);
+ const char *txt, int state);
static void set_completion_reference(const char *word);
static void set_completion_reference_verbatim(const char *word);
-static char *complete_from_list(const char *text, int state);
-static char *complete_from_const(const char *text, int state);
+static char *complete_from_list(const char *txt, int state);
+static char *complete_from_const(const char *txt, int state);
static void append_variable_names(char ***varnames, int *nvars,
int *maxvars, const char *varname,
const char *prefix, const char *suffix);
-static char **complete_from_variables(const char *text,
+static char **complete_from_variables(const char *txt,
const char *prefix, const char *suffix, bool need_value);
-static char *complete_from_files(const char *text, int state);
+static char *complete_from_files(const char *txt, int state);
static char *pg_strdup_keyword_case(const char *s, const char *ref);
-static char *escape_string(const char *text);
+static char *escape_string(const char *txt);
static char *make_like_pattern(const char *word);
static void parse_identifier(const char *ident,
char **schemaname, char **objectname,
@@ -1635,7 +1635,7 @@ ends_with(const char *s, char c)
* rl_completion_matches() function, so we don't have to worry about it.
*/
static char **
-psql_completion(const char *text, int start, int end)
+psql_completion(const char *txt, int start, int end)
{
/* This is the variable we'll return. */
char **matches = NULL;
@@ -1746,14 +1746,14 @@ psql_completion(const char *text, int start, int end)
/*
* Temporary workaround for a bug in recent (2019) libedit: it incorrectly
- * de-escapes the input "text", causing us to fail to recognize backslash
+ * de-escapes the input "txt", causing us to fail to recognize backslash
* commands. So get the string to look at from rl_line_buffer instead.
*/
- char *text_copy = pnstrdup(rl_line_buffer + start, end - start);
- text = text_copy;
+ char *txt_copy = pnstrdup(rl_line_buffer + start, end - start);
+ txt = txt_copy;
/* Remember last char of the given input word. */
- completion_last_char = (end > start) ? text[end - start - 1] : '\0';
+ completion_last_char = (end > start) ? txt[end - start - 1] : '\0';
/* We usually want the append character to be a space. */
rl_completion_append_character = ' ';
@@ -1776,20 +1776,20 @@ psql_completion(const char *text, int start, int end)
&previous_words_count);
/* If current word is a backslash command, offer completions for that */
- if (text[0] == '\\')
+ if (txt[0] == '\\')
COMPLETE_WITH_LIST_CS(backslash_commands);
/* If current word is a variable interpolation, handle that case */
- else if (text[0] == ':' && text[1] != ':')
+ else if (txt[0] == ':' && txt[1] != ':')
{
- if (text[1] == '\'')
- matches = complete_from_variables(text, ":'", "'", true);
- else if (text[1] == '"')
- matches = complete_from_variables(text, ":\"", "\"", true);
- else if (text[1] == '{' && text[2] == '?')
- matches = complete_from_variables(text, ":{?", "}", true);
+ if (txt[1] == '\'')
+ matches = complete_from_variables(txt, ":'", "'", true);
+ else if (txt[1] == '"')
+ matches = complete_from_variables(txt, ":\"", "\"", true);
+ else if (txt[1] == '{' && txt[2] == '?')
+ matches = complete_from_variables(txt, ":{?", "}", true);
else
- matches = complete_from_variables(text, ":", "", true);
+ matches = complete_from_variables(txt, ":", "", true);
}
/* If no previous word, suggest one of the basic sql commands */
@@ -1806,7 +1806,7 @@ psql_completion(const char *text, int start, int end)
/* for INDEX and TABLE/SEQUENCE, respectively */
"UNIQUE", "UNLOGGED");
else
- matches = rl_completion_matches(text, create_command_generator);
+ matches = rl_completion_matches(txt, create_command_generator);
}
/* complete with something you can create or replace */
else if (TailMatches("CREATE", "OR", "REPLACE"))
@@ -1816,7 +1816,7 @@ psql_completion(const char *text, int start, int end)
/* DROP, but not DROP embedded in other commands */
/* complete with something you can drop */
else if (Matches("DROP"))
- matches = rl_completion_matches(text, drop_command_generator);
+ matches = rl_completion_matches(txt, drop_command_generator);
/* ALTER */
@@ -1827,7 +1827,7 @@ psql_completion(const char *text, int start, int end)
/* ALTER something */
else if (Matches("ALTER"))
- matches = rl_completion_matches(text, alter_command_generator);
+ matches = rl_completion_matches(txt, alter_command_generator);
/* ALTER TABLE,INDEX,MATERIALIZED VIEW ALL IN TABLESPACE xxx */
else if (TailMatches("ALL", "IN", "TABLESPACE", MatchAny))
COMPLETE_WITH("SET TABLESPACE", "OWNED BY");
@@ -2882,13 +2882,13 @@ psql_completion(const char *text, int start, int end)
{
completion_charp = "";
completion_force_quote = true; /* COPY requires quoted filename */
- matches = rl_completion_matches(text, complete_from_files);
+ matches = rl_completion_matches(txt, complete_from_files);
}
else if (Matches("\\copy", MatchAny, "FROM|TO"))
{
completion_charp = "";
completion_force_quote = false;
- matches = rl_completion_matches(text, complete_from_files);
+ matches = rl_completion_matches(txt, complete_from_files);
}
/* Complete COPY <sth> TO <sth> */
@@ -4791,7 +4791,7 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_CS("commands", "options", "variables");
else if (TailMatchesCS("\\connect|\\c"))
{
- if (!recognized_connection_string(text))
+ if (!recognized_connection_string(txt))
COMPLETE_WITH_QUERY(Query_for_list_of_databases);
}
else if (TailMatchesCS("\\connect|\\c", MatchAny))
@@ -4896,9 +4896,9 @@ psql_completion(const char *text, int start, int end)
else if (TailMatchesCS("\\h|\\help", MatchAny))
{
if (TailMatches("DROP"))
- matches = rl_completion_matches(text, drop_command_generator);
+ matches = rl_completion_matches(txt, drop_command_generator);
else if (TailMatches("ALTER"))
- matches = rl_completion_matches(text, alter_command_generator);
+ matches = rl_completion_matches(txt, alter_command_generator);
/*
* CREATE is recognized by tail match elsewhere, so doesn't need to be
@@ -4966,9 +4966,9 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_CS("single", "double");
}
else if (TailMatchesCS("\\unset"))
- matches = complete_from_variables(text, "", "", true);
+ matches = complete_from_variables(txt, "", "", true);
else if (TailMatchesCS("\\set"))
- matches = complete_from_variables(text, "", "", false);
+ matches = complete_from_variables(txt, "", "", false);
else if (TailMatchesCS("\\set", MatchAny))
{
if (TailMatchesCS("AUTOCOMMIT|ON_ERROR_STOP|QUIET|SHOW_ALL_RESULTS|"
@@ -5001,7 +5001,7 @@ psql_completion(const char *text, int start, int end)
{
completion_charp = "\\";
completion_force_quote = false;
- matches = rl_completion_matches(text, complete_from_files);
+ matches = rl_completion_matches(txt, complete_from_files);
}
/*
@@ -5049,7 +5049,7 @@ psql_completion(const char *text, int start, int end)
/* free storage */
free(previous_words);
free(words_buffer);
- free(text_copy);
+ free(txt_copy);
free(completion_ref_object);
completion_ref_object = NULL;
free(completion_ref_schema);
@@ -5079,7 +5079,7 @@ psql_completion(const char *text, int start, int end)
* Entries that have 'excluded' flags are not returned.
*/
static char *
-create_or_drop_command_generator(const char *text, int state, bits32 excluded)
+create_or_drop_command_generator(const char *txt, int state, bits32 excluded)
{
static int list_index,
string_length;
@@ -5089,15 +5089,15 @@ create_or_drop_command_generator(const char *text, int state, bits32 excluded)
if (state == 0)
{
list_index = 0;
- string_length = strlen(text);
+ string_length = strlen(txt);
}
/* find something that matches */
while ((name = words_after_create[list_index++].name))
{
- if ((pg_strncasecmp(name, text, string_length) == 0) &&
+ if ((pg_strncasecmp(name, txt, string_length) == 0) &&
!(words_after_create[list_index - 1].flags & excluded))
- return pg_strdup_keyword_case(name, text);
+ return pg_strdup_keyword_case(name, txt);
}
/* if nothing matches, return NULL */
return NULL;
@@ -5108,27 +5108,27 @@ create_or_drop_command_generator(const char *text, int state, bits32 excluded)
* as defined above.
*/
static char *
-create_command_generator(const char *text, int state)
+create_command_generator(const char *txt, int state)
{
- return create_or_drop_command_generator(text, state, THING_NO_CREATE);
+ return create_or_drop_command_generator(txt, state, THING_NO_CREATE);
}
/*
* This function gives you a list of things you can put after a DROP command.
*/
static char *
-drop_command_generator(const char *text, int state)
+drop_command_generator(const char *txt, int state)
{
- return create_or_drop_command_generator(text, state, THING_NO_DROP);
+ return create_or_drop_command_generator(txt, state, THING_NO_DROP);
}
/*
* This function gives you a list of things you can put after an ALTER command.
*/
static char *
-alter_command_generator(const char *text, int state)
+alter_command_generator(const char *txt, int state)
{
- return create_or_drop_command_generator(text, state, THING_NO_ALTER);
+ return create_or_drop_command_generator(txt, state, THING_NO_ALTER);
}
/*
@@ -5137,15 +5137,15 @@ alter_command_generator(const char *text, int state)
*/
static char *
-complete_from_query(const char *text, int state)
+complete_from_query(const char *txt, int state)
{
/* query is assumed to work for any server version */
return _complete_from_query(completion_charp, NULL, completion_charpp,
- completion_verbatim, text, state);
+ completion_verbatim, txt, state);
}
static char *
-complete_from_versioned_query(const char *text, int state)
+complete_from_versioned_query(const char *txt, int state)
{
const VersionedQuery *vquery = completion_vquery;
@@ -5157,19 +5157,19 @@ complete_from_versioned_query(const char *text, int state)
return NULL;
return _complete_from_query(vquery->query, NULL, completion_charpp,
- completion_verbatim, text, state);
+ completion_verbatim, txt, state);
}
static char *
-complete_from_schema_query(const char *text, int state)
+complete_from_schema_query(const char *txt, int state)
{
/* query is assumed to work for any server version */
return _complete_from_query(NULL, completion_squery, completion_charpp,
- completion_verbatim, text, state);
+ completion_verbatim, txt, state);
}
static char *
-complete_from_versioned_schema_query(const char *text, int state)
+complete_from_versioned_schema_query(const char *txt, int state)
{
const SchemaQuery *squery = completion_squery;
@@ -5181,7 +5181,7 @@ complete_from_versioned_schema_query(const char *text, int state)
return NULL;
return _complete_from_query(NULL, squery, completion_charpp,
- completion_verbatim, text, state);
+ completion_verbatim, txt, state);
}
@@ -5219,7 +5219,7 @@ complete_from_versioned_schema_query(const char *text, int state)
* query results; otherwise we parse it as a possibly-qualified identifier,
* and reconstruct suitable quoting afterward.
*
- * "text" and "state" are supplied by Readline. "text" is the word we are
+ * "txt" and "state" are supplied by Readline. "txt" is the word we are
* trying to complete. "state" is zero on first call, nonzero later.
*
* readline will call this repeatedly with the same text and varying
@@ -5231,7 +5231,7 @@ _complete_from_query(const char *simple_query,
const SchemaQuery *schema_query,
const char *const *keywords,
bool verbatim,
- const char *text, int state)
+ const char *txt, int state)
{
static int list_index,
num_schema_only,
@@ -5267,12 +5267,12 @@ _complete_from_query(const char *simple_query,
/* Parse text, splitting into schema and object name if needed */
if (verbatim)
{
- objectname = pg_strdup(text);
+ objectname = pg_strdup(txt);
schemaname = NULL;
}
else
{
- parse_identifier(text,
+ parse_identifier(txt,
&schemaname, &objectname,
&schemaquoted, &objectquoted);
}
@@ -5526,10 +5526,10 @@ _complete_from_query(const char *simple_query,
if (nskip-- > 0)
continue;
list_index++;
- if (pg_strncasecmp(text, item, strlen(text)) == 0)
+ if (pg_strncasecmp(txt, item, strlen(txt)) == 0)
{
num_keywords++;
- return pg_strdup_keyword_case(item, text);
+ return pg_strdup_keyword_case(item, txt);
}
}
}
@@ -5544,10 +5544,10 @@ _complete_from_query(const char *simple_query,
if (nskip-- > 0)
continue;
list_index++;
- if (pg_strncasecmp(text, item, strlen(text)) == 0)
+ if (pg_strncasecmp(txt, item, strlen(txt)) == 0)
{
num_keywords++;
- return pg_strdup_keyword_case(item, text);
+ return pg_strdup_keyword_case(item, txt);
}
}
}
@@ -5602,7 +5602,7 @@ set_completion_reference_verbatim(const char *word)
* SQL words that can appear at certain spot.
*/
static char *
-complete_from_list(const char *text, int state)
+complete_from_list(const char *txt, int state)
{
static int string_length,
list_index,
@@ -5617,7 +5617,7 @@ complete_from_list(const char *text, int state)
if (state == 0)
{
list_index = 0;
- string_length = strlen(text);
+ string_length = strlen(txt);
casesensitive = completion_case_sensitive;
matches = 0;
}
@@ -5625,14 +5625,14 @@ complete_from_list(const char *text, int state)
while ((item = completion_charpp[list_index++]))
{
/* First pass is case sensitive */
- if (casesensitive && strncmp(text, item, string_length) == 0)
+ if (casesensitive && strncmp(txt, item, string_length) == 0)
{
matches++;
return pg_strdup(item);
}
/* Second pass is case insensitive, don't bother counting matches */
- if (!casesensitive && pg_strncasecmp(text, item, string_length) == 0)
+ if (!casesensitive && pg_strncasecmp(txt, item, string_length) == 0)
{
if (completion_case_sensitive)
return pg_strdup(item);
@@ -5642,7 +5642,7 @@ complete_from_list(const char *text, int state)
* If case insensitive matching was requested initially,
* adjust the case according to setting.
*/
- return pg_strdup_keyword_case(item, text);
+ return pg_strdup_keyword_case(item, txt);
}
}
@@ -5655,7 +5655,7 @@ complete_from_list(const char *text, int state)
casesensitive = false;
list_index = 0;
state++;
- return complete_from_list(text, state);
+ return complete_from_list(txt, state);
}
/* If no more matches, return null. */
@@ -5682,7 +5682,7 @@ complete_from_list(const char *text, int state)
* that won't try to auto-correct "misspellings".
*/
static char *
-complete_from_const(const char *text, int state)
+complete_from_const(const char *txt, int state)
{
Assert(completion_charp != NULL);
if (state == 0)
@@ -5695,7 +5695,7 @@ complete_from_const(const char *text, int state)
* If case insensitive matching was requested initially, adjust
* the case according to setting.
*/
- return pg_strdup_keyword_case(completion_charp, text);
+ return pg_strdup_keyword_case(completion_charp, txt);
}
else
return NULL;
@@ -5730,7 +5730,7 @@ append_variable_names(char ***varnames, int *nvars,
* (those that have hooks) are included even if currently unset.
*/
static char **
-complete_from_variables(const char *text, const char *prefix, const char *suffix,
+complete_from_variables(const char *txt, const char *prefix, const char *suffix,
bool need_value)
{
char **matches;
@@ -5775,7 +5775,7 @@ complete_from_variables(const char *text, const char *prefix, const char *suffix
* quotes around the result. (The SQL COPY command requires that.)
*/
static char *
-complete_from_files(const char *text, int state)
+complete_from_files(const char *txt, int state)
{
#ifdef USE_FILENAME_QUOTING_FUNCTIONS
@@ -5799,37 +5799,37 @@ complete_from_files(const char *text, int state)
#endif
/* If user typed a quote, force quoting (never remove user's quote) */
- if (*text == '\'')
+ if (*txt == '\'')
completion_force_quote = true;
- return rl_filename_completion_function(text, state);
+ return rl_filename_completion_function(txt, state);
#else
/*
* Otherwise, we have to do the best we can.
*/
- static const char *unquoted_text;
+ static const char *unquoted_txt;
char *unquoted_match;
char *ret = NULL;
/* If user typed a quote, force quoting (never remove user's quote) */
- if (*text == '\'')
+ if (*txt == '\'')
completion_force_quote = true;
if (state == 0)
{
/* Initialization: stash the unquoted input. */
- unquoted_text = strtokx(text, "", NULL, "'", *completion_charp,
+ unquoted_txt = strtokx(txt, "", NULL, "'", *completion_charp,
false, true, pset.encoding);
/* expect a NULL return for the empty string only */
- if (!unquoted_text)
+ if (!unquoted_txt)
{
- Assert(*text == '\0');
- unquoted_text = text;
+ Assert(*txt == '\0');
+ unquoted_txt = txt;
}
}
- unquoted_match = rl_filename_completion_function(unquoted_text, state);
+ unquoted_match = rl_filename_completion_function(unquoted_txt, state);
if (unquoted_match)
{
struct stat statbuf;
@@ -5907,15 +5907,15 @@ pg_strdup_keyword_case(const char *s, const char *ref)
* The returned value has to be freed.
*/
static char *
-escape_string(const char *text)
+escape_string(const char *txt)
{
- size_t text_length;
+ size_t txt_length;
char *result;
- text_length = strlen(text);
+ txt_length = strlen(txt);
- result = pg_malloc(text_length * 2 + 1);
- PQescapeStringConn(pset.db, result, text, text_length, NULL);
+ result = pg_malloc(txt_length * 2 + 1);
+ PQescapeStringConn(pset.db, result, txt, txt_length, NULL);
return result;
}
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c
index c578c21..61a25ce 100644
--- a/src/interfaces/ecpg/ecpglib/execute.c
+++ b/src/interfaces/ecpg/ecpglib/execute.c
@@ -108,32 +108,32 @@ free_statement(struct statement *stmt)
}
static int
-next_insert(char *text, int pos, bool questionmarks, bool std_strings)
+next_insert(char *txt, int pos, bool questionmarks, bool std_strings)
{
bool string = false;
int p = pos;
- for (; text[p] != '\0'; p++)
+ for (; txt[p] != '\0'; p++)
{
- if (string && !std_strings && text[p] == '\\') /* escape character */
+ if (string && !std_strings && txt[p] == '\\') /* escape character */
p++;
- else if (text[p] == '\'')
+ else if (txt[p] == '\'')
string = string ? false : true;
else if (!string)
{
- if (text[p] == '$' && isdigit((unsigned char) text[p + 1]))
+ if (txt[p] == '$' && isdigit((unsigned char) txt[p + 1]))
{
/* this can be either a dollar quote or a variable */
int i;
- for (i = p + 1; isdigit((unsigned char) text[i]); i++)
+ for (i = p + 1; isdigit((unsigned char) txt[i]); i++)
/* empty loop body */ ;
- if (!isalpha((unsigned char) text[i]) &&
- isascii((unsigned char) text[i]) && text[i] != '_')
+ if (!isalpha((unsigned char) txt[i]) &&
+ isascii((unsigned char) txt[i]) && txt[i] != '_')
/* not dollar delimited quote */
return p;
}
- else if (questionmarks && text[p] == '?')
+ else if (questionmarks && txt[p] == '?')
{
/* also allow old style placeholders */
return p;
diff --git a/src/interfaces/ecpg/ecpglib/prepare.c b/src/interfaces/ecpg/ecpglib/prepare.c
index ea1146f..ff46561 100644
--- a/src/interfaces/ecpg/ecpglib/prepare.c
+++ b/src/interfaces/ecpg/ecpglib/prepare.c
@@ -101,21 +101,21 @@ ecpg_register_prepared_stmt(struct statement *stmt)
}
static bool
-replace_variables(char **text, int lineno)
+replace_variables(char **txt, int lineno)
{
bool string = false;
int counter = 1,
ptr = 0;
- for (; (*text)[ptr] != '\0'; ptr++)
+ for (; (*txt)[ptr] != '\0'; ptr++)
{
- if ((*text)[ptr] == '\'')
+ if ((*txt)[ptr] == '\'')
string = string ? false : true;
- if (string || (((*text)[ptr] != ':') && ((*text)[ptr] != '?')))
+ if (string || (((*txt)[ptr] != ':') && ((*txt)[ptr] != '?')))
continue;
- if (((*text)[ptr] == ':') && ((*text)[ptr + 1] == ':'))
+ if (((*txt)[ptr] == ':') && ((*txt)[ptr + 1] == ':'))
ptr += 2; /* skip '::' */
else
{
@@ -130,25 +130,25 @@ replace_variables(char **text, int lineno)
snprintf(buffer, buffersize, "$%d", counter++);
- for (len = 1; (*text)[ptr + len] && isvarchar((*text)[ptr + len]); len++)
+ for (len = 1; (*txt)[ptr + len] && isvarchar((*txt)[ptr + len]); len++)
/* skip */ ;
- if (!(newcopy = (char *) ecpg_alloc(strlen(*text) - len + strlen(buffer) + 1, lineno)))
+ if (!(newcopy = (char *) ecpg_alloc(strlen(*txt) - len + strlen(buffer) + 1, lineno)))
{
ecpg_free(buffer);
return false;
}
- memcpy(newcopy, *text, ptr);
+ memcpy(newcopy, *txt, ptr);
strcpy(newcopy + ptr, buffer);
- strcat(newcopy, (*text) +ptr + len);
+ strcat(newcopy, (*txt) +ptr + len);
- ecpg_free(*text);
+ ecpg_free(*txt);
ecpg_free(buffer);
- *text = newcopy;
+ *txt = newcopy;
- if ((*text)[ptr] == '\0') /* we reached the end */
- ptr--; /* since we will (*text)[ptr]++ in the top
+ if ((*txt)[ptr] == '\0') /* we reached the end */
+ ptr--; /* since we will (*txt)[ptr]++ in the top
* level for loop */
}
}
@@ -267,16 +267,16 @@ deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con,
/* first deallocate the statement in the backend */
if (this->prepared)
{
- char *text;
+ char *txt;
PGresult *query;
- text = (char *) ecpg_alloc(strlen("deallocate \"\" ") + strlen(this->name), this->stmt->lineno);
+ txt = (char *) ecpg_alloc(strlen("deallocate \"\" ") + strlen(this->name), this->stmt->lineno);
- if (text)
+ if (txt)
{
- sprintf(text, "deallocate \"%s\"", this->name);
- query = PQexec(this->stmt->connection->connection, text);
- ecpg_free(text);
+ sprintf(txt, "deallocate \"%s\"", this->name);
+ query = PQexec(this->stmt->connection->connection, txt);
+ ecpg_free(txt);
if (ecpg_check_PQresult(query, lineno,
this->stmt->connection->connection,
this->stmt->compat))
diff --git a/src/interfaces/ecpg/preproc/c_keywords.c b/src/interfaces/ecpg/preproc/c_keywords.c
index 14f20e2..17a117d 100644
--- a/src/interfaces/ecpg/preproc/c_keywords.c
+++ b/src/interfaces/ecpg/preproc/c_keywords.c
@@ -33,7 +33,7 @@ static const uint16 ScanCKeywordTokens[] = {
* ScanKeywordLookup(), except we want case-sensitive matching.
*/
int
-ScanCKeywordLookup(const char *text)
+ScanCKeywordLookup(const char *txt)
{
size_t len;
int h;
@@ -43,7 +43,7 @@ ScanCKeywordLookup(const char *text)
* Reject immediately if too long to be any keyword. This saves useless
* hashing work on long strings.
*/
- len = strlen(text);
+ len = strlen(txt);
if (len > ScanCKeywords.max_kw_len)
return -1;
@@ -51,7 +51,7 @@ ScanCKeywordLookup(const char *text)
* Compute the hash function. Since it's a perfect hash, we need only
* match to the specific keyword it identifies.
*/
- h = ScanCKeywords_hash_func(text, len);
+ h = ScanCKeywords_hash_func(txt, len);
/* An out-of-range result implies no match */
if (h < 0 || h >= ScanCKeywords.num_keywords)
@@ -59,7 +59,7 @@ ScanCKeywordLookup(const char *text)
kw = GetScanKeyword(h, &ScanCKeywords);
- if (strcmp(kw, text) == 0)
+ if (strcmp(kw, txt) == 0)
return ScanCKeywordTokens[h];
return -1;
--
1.8.3.1
On Thu, 12 Sept 2024 at 12:33, Peter Smith <smithpb2250@gmail.com> wrote:
I normally build the code with warnings enabled (specifically,
-Wshadow) which exposes many "shadowed" declarations.It would be better to reduce warnings wherever it's easy to do so,
because if we always see/ignore lots of warnings then sooner or later
something important may escape attention. In any case, just removing
these warnings sometimes makes the code more readable by removing any
ambiguity.
0fe954c28 did add -Wshadow=compatible-local to the standard set of
complication flags. I felt it was diminishing returns after that, but
-Wshadow=local would be the next step before going full -Wshadow.
There was justification for -Wshadow=compatible-local because there
has been > 1 bug (see af7d270dd) fixed that would have been found if
we'd had that sooner. Have we ever had any bugs that would have been
highlighted by -Wshadow but not -Wshadow=compatible-local? I'd be
curious to know if you do go through this process of weeding these out
if you do find any bugs as a result.
I also wonder if we could ever get this to a stable point. I didn't
take the time to understand what 388e80132 did. Is that going to
protect us from getting warnings where fixing them is beyond our
control for full -Wshadow?
David
David Rowley <dgrowleyml@gmail.com> writes:
On Thu, 12 Sept 2024 at 12:33, Peter Smith <smithpb2250@gmail.com> wrote:
I normally build the code with warnings enabled (specifically,
-Wshadow) which exposes many "shadowed" declarations.
0fe954c28 did add -Wshadow=compatible-local to the standard set of
complication flags. I felt it was diminishing returns after that, but
-Wshadow=local would be the next step before going full -Wshadow.
I think that insisting that local declarations not shadow globals
is an anti-pattern, and I'll vote against any proposal to make
that a standard warning. Impoverished as C is, it does have block
structure; why would we want to throw that away by (in effect)
demanding a single flat namespace for the entire program?
I do grant that sometimes shadowing of locals can cause bugs. I don't
recall right now why we opted for -Wshadow=compatible-local over
-Wshadow=local, but we could certainly take another look at that.
regards, tom lane
On Thu, 12 Sept 2024 at 14:03, Tom Lane <tgl@sss.pgh.pa.us> wrote:
I do grant that sometimes shadowing of locals can cause bugs. I don't
recall right now why we opted for -Wshadow=compatible-local over
-Wshadow=local, but we could certainly take another look at that.
I don't recall if it was discussed, but certainly, it was an easier
goal to achieve.
Looks like there are currently 47 warnings with -Wshadow=local. I'm
not quite sure what the definition of "compatible" is for this flag,
but looking at one warning in pgbench.c:4548, I see an int shadowing a
bool. So maybe -Wshadow=local is worthwhile.
David
On 12.09.24 04:25, David Rowley wrote:
On Thu, 12 Sept 2024 at 14:03, Tom Lane <tgl@sss.pgh.pa.us> wrote:
I do grant that sometimes shadowing of locals can cause bugs. I don't
recall right now why we opted for -Wshadow=compatible-local over
-Wshadow=local, but we could certainly take another look at that.I don't recall if it was discussed, but certainly, it was an easier
goal to achieve.Looks like there are currently 47 warnings with -Wshadow=local. I'm
not quite sure what the definition of "compatible" is for this flag,
but looking at one warning in pgbench.c:4548, I see an int shadowing a
bool. So maybe -Wshadow=local is worthwhile.
Another thing to keep in mind with these different shadow warning
variants is that we should try to keep them consistent across compilers,
at least the common ones. The current -Wshadow=compatible-local is only
available in gcc, not in clang, so it's currently impossible to rely on
clang to write warning-free code.
Of course we have other warning flags that we use that don't exist in
all compilers, but in my experience these are either for very esoteric
cases or something that is very obviously wrong and a developer would
normally see immediately. For example, there is no warning flag in
clang that mirrors the switch "fallthrough" labeling that we have set up
with gcc. But this is not as much of a problem in practice because the
wrong code would usually misbehave in an obvious way and the issue can
be found by looking at the code with two lines of context. With the
shadow warning, the issues are much harder to find visually, and in most
cases they are not actually a problem.
The shadow warning levels in gcc and clang appear to be very differently
structured, so I'm not sure how we can improve interoperability here.