From ecc1bfd7e287196c5565cba09c68eebd5646f15b Mon Sep 17 00:00:00 2001 From: "Chao Li (Evan)" Date: Tue, 2 Dec 2025 15:26:51 +0800 Subject: [PATCH v7 07/12] cleanup: avoid local variables shadowed by static file-scope ones in several files This commit fixes multiple cases where local variables used names that conflicted with static variables defined at file scope. The affected locals are renamed so they are no longer shadowed by the file-scope identifiers and remain unambiguous within their respective scopes. Author: Chao Li Discussion: https://postgr.es/m/CAEoWx2kQ2x5gMaj8tHLJ3=jfC+p5YXHkJyHrDTiQw2nn2FJTmQ@mail.gmail.com --- src/backend/executor/execExprInterp.c | 6 ++--- src/bin/pg_ctl/pg_ctl.c | 6 ++--- src/bin/pg_dump/pg_dumpall.c | 34 +++++++++++++-------------- src/bin/pg_resetwal/pg_resetwal.c | 8 +++---- src/bin/pg_test_fsync/pg_test_fsync.c | 8 +++---- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/backend/executor/execExprInterp.c b/src/backend/executor/execExprInterp.c index 61ff5ddc74c..cb5fb7dbba6 100644 --- a/src/backend/executor/execExprInterp.c +++ b/src/backend/executor/execExprInterp.c @@ -471,7 +471,7 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull) * This array has to be in the same order as enum ExprEvalOp. */ #if defined(EEO_USE_COMPUTED_GOTO) - static const void *const dispatch_table[] = { + static const void *const _dispatch_table[] = { &&CASE_EEOP_DONE_RETURN, &&CASE_EEOP_DONE_NO_RETURN, &&CASE_EEOP_INNER_FETCHSOME, @@ -595,11 +595,11 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull) &&CASE_EEOP_LAST }; - StaticAssertDecl(lengthof(dispatch_table) == EEOP_LAST + 1, + StaticAssertDecl(lengthof(_dispatch_table) == EEOP_LAST + 1, "dispatch_table out of whack with ExprEvalOp"); if (unlikely(state == NULL)) - return PointerGetDatum(dispatch_table); + return PointerGetDatum(_dispatch_table); #else Assert(state != NULL); #endif /* EEO_USE_COMPUTED_GOTO */ diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index 3cc61455dcb..b1fbe1f88d2 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -873,18 +873,18 @@ trap_sigint_during_startup(SIGNAL_ARGS) } static char * -find_other_exec_or_die(const char *argv0, const char *target, const char *versionstr) +find_other_exec_or_die(const char *myargv0, const char *target, const char *versionstr) { int ret; char *found_path; found_path = pg_malloc(MAXPGPATH); - if ((ret = find_other_exec(argv0, target, versionstr, found_path)) < 0) + if ((ret = find_other_exec(myargv0, target, versionstr, found_path)) < 0) { char full_path[MAXPGPATH]; - if (find_my_exec(argv0, full_path) < 0) + if (find_my_exec(myargv0, full_path) < 0) strlcpy(full_path, progname, sizeof(full_path)); if (ret == -1) diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 1165a0f4afe..67eb8285cf5 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -82,10 +82,10 @@ static void buildShSecLabels(PGconn *conn, PQExpBuffer buffer); static void executeCommand(PGconn *conn, const char *query); static void check_for_invalid_global_names(PGconn *conn, - SimpleStringList *database_exclude_names); + SimpleStringList *db_exclude_names); static void expand_dbname_patterns(PGconn *conn, SimpleStringList *patterns, SimpleStringList *names); -static void read_dumpall_filters(const char *filename, SimpleStringList *pattern); +static void read_dumpall_filters(const char *fname, SimpleStringList *pattern); static ArchiveFormat parseDumpFormat(const char *format); static int createDumpId(void); @@ -2270,7 +2270,7 @@ executeCommand(PGconn *conn, const char *query) */ static void check_for_invalid_global_names(PGconn *conn, - SimpleStringList *database_exclude_names) + SimpleStringList *db_exclude_names) { PGresult *res; int i; @@ -2297,7 +2297,7 @@ check_for_invalid_global_names(PGconn *conn, /* Skip excluded databases since they won't be in map.dat */ if (strcmp(objtype, "database") == 0 && - simple_string_list_member(database_exclude_names, objname)) + simple_string_list_member(db_exclude_names, objname)) continue; if (strpbrk(objname, "\n\r")) @@ -2344,20 +2344,20 @@ dumpTimestamp(const char *msg) * read_dumpall_filters - retrieve database identifier patterns from file * * Parse the specified filter file for include and exclude patterns, and add - * them to the relevant lists. If the filename is "-" then filters will be + * them to the relevant lists. If the fname is "-" then filters will be * read from STDIN rather than a file. * * At the moment, the only allowed filter is for database exclusion. */ static void -read_dumpall_filters(const char *filename, SimpleStringList *pattern) +read_dumpall_filters(const char *fname, SimpleStringList *pattern) { FilterStateData fstate; char *objname; FilterCommandType comtype; FilterObjectType objtype; - filter_init(&fstate, filename, exit); + filter_init(&fstate, fname, exit); while (filter_read_item(&fstate, &objname, &comtype, &objtype)) { @@ -2407,29 +2407,29 @@ read_dumpall_filters(const char *filename, SimpleStringList *pattern) static ArchiveFormat parseDumpFormat(const char *format) { - ArchiveFormat archDumpFormat; + ArchiveFormat archFormat; if (pg_strcasecmp(format, "c") == 0) - archDumpFormat = archCustom; + archFormat = archCustom; else if (pg_strcasecmp(format, "custom") == 0) - archDumpFormat = archCustom; + archFormat = archCustom; else if (pg_strcasecmp(format, "d") == 0) - archDumpFormat = archDirectory; + archFormat = archDirectory; else if (pg_strcasecmp(format, "directory") == 0) - archDumpFormat = archDirectory; + archFormat = archDirectory; else if (pg_strcasecmp(format, "p") == 0) - archDumpFormat = archNull; + archFormat = archNull; else if (pg_strcasecmp(format, "plain") == 0) - archDumpFormat = archNull; + archFormat = archNull; else if (pg_strcasecmp(format, "t") == 0) - archDumpFormat = archTar; + archFormat = archTar; else if (pg_strcasecmp(format, "tar") == 0) - archDumpFormat = archTar; + archFormat = archTar; else pg_fatal("unrecognized output format \"%s\"; please specify \"c\", \"d\", \"p\", or \"t\"", format); - return archDumpFormat; + return archFormat; } /* diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c index ab766c34d4b..7a12e1c93ee 100644 --- a/src/bin/pg_resetwal/pg_resetwal.c +++ b/src/bin/pg_resetwal/pg_resetwal.c @@ -105,7 +105,7 @@ static int WalSegSz; static void CheckDataVersion(void); static bool read_controlfile(void); static void GuessControlValues(void); -static void PrintControlValues(bool guessed); +static void PrintControlValues(bool bGuessed); static void PrintNewControlValues(void); static void RewriteControlFile(void); static void FindEndOfXLOG(void); @@ -745,15 +745,15 @@ GuessControlValues(void) /* - * Print the guessed pg_control values when we had to guess. + * Print the bGuessed pg_control values when we had to guess. * * NB: this display should be just those fields that will not be * reset by RewriteControlFile(). */ static void -PrintControlValues(bool guessed) +PrintControlValues(bool bGuessed) { - if (guessed) + if (bGuessed) printf(_("Guessed pg_control values:\n\n")); else printf(_("Current pg_control values:\n\n")); diff --git a/src/bin/pg_test_fsync/pg_test_fsync.c b/src/bin/pg_test_fsync/pg_test_fsync.c index 4b84f86e7d7..8b18b53e80e 100644 --- a/src/bin/pg_test_fsync/pg_test_fsync.c +++ b/src/bin/pg_test_fsync/pg_test_fsync.c @@ -94,7 +94,7 @@ static void signal_cleanup(SIGNAL_ARGS); #ifdef HAVE_FSYNC_WRITETHROUGH static int pg_fsync_writethrough(int fd); #endif -static void print_elapse(struct timeval start_t, struct timeval stop_t, int ops); +static void print_elapse(struct timeval start_time, struct timeval stop_time, int ops); #define die(msg) pg_fatal("%s: %m", _(msg)) @@ -622,10 +622,10 @@ pg_fsync_writethrough(int fd) * print out the writes per second for tests */ static void -print_elapse(struct timeval start_t, struct timeval stop_t, int ops) +print_elapse(struct timeval start_time, struct timeval stop_time, int ops) { - double total_time = (stop_t.tv_sec - start_t.tv_sec) + - (stop_t.tv_usec - start_t.tv_usec) * 0.000001; + double total_time = (stop_time.tv_sec - start_time.tv_sec) + + (stop_time.tv_usec - start_time.tv_usec) * 0.000001; double per_second = ops / total_time; double avg_op_time_us = (total_time / ops) * USECS_SEC; -- 2.50.1 (Apple Git-155)