Re: shadow variables - pg15 edition

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема Re: shadow variables - pg15 edition
Дата
Msg-id 20221005133416.jdrlmn4b2qyorm24@alvherre.pgsql
обсуждение исходный текст
Ответ на Re: shadow variables - pg15 edition  (David Rowley <dgrowleyml@gmail.com>)
Ответы Re: shadow variables - pg15 edition
Список pgsql-hackers
On 2022-Oct-05, David Rowley wrote:

> The only warning remaining after applying the attached is the "now"
> warning in pgbench.c:7509.  I'd considered changing this to "thenow"
> which translates to "right now" in the part of Scotland that I'm from.
> I also considered "nownow", which is used in South Africa [1].
> Anyway, I'm not really being serious, but I didn't come up with
> anything better than "now2". It's just I didn't like that as it sort
> of implies there are multiple definitions of "now" and I struggle with
> that...  maybe I'm just thinking too much in terms of Newtonian
> Relativity...

:-D

A simpler idea might be to just remove the inner declaration, and have
that block set the outer var.  There's no damage, since the block is
going to end and not access the previous value anymore.

diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index aa1a3541fe..91a067859b 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -7506,7 +7506,7 @@ threadRun(void *arg)
         /* progress report is made by thread 0 for all threads */
         if (progress && thread->tid == 0)
         {
-            pg_time_usec_t now = pg_time_now();
+            now = pg_time_now();    /* not lazy; clobbers outer value */
 
             if (now >= next_report)
             {


The "now now" reference reminded me of "ahorita"
https://doorwaytomexico.com/paulina/ahorita-meaning-examples/
which is source of misunderstandings across borders in South America ...

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/
"The important things in the world are problems with society that we don't
understand at all. The machines will become more complicated but they won't
be more complicated than the societies that run them."    (Freeman Dyson)



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: [PoC] Let libpq reject unexpected authentication requests
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Can we avoid chdir'ing in resolve_symlinks() ?