All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Campbell <ian.campbell@citrix.com>
To: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: xen-devel@lists.xenproject.org
Subject: Re: [OSSTEST PATCH 6/9] db_retry: Suppress an "exiting via last" warning
Date: Fri, 18 Dec 2015 11:14:18 +0000	[thread overview]
Message-ID: <1450437258.4053.198.camel@citrix.com> (raw)
In-Reply-To: <22131.320.250211.170343@mariner.uk.xensource.com>

On Thu, 2015-12-17 at 18:38 +0000, Ian Jackson wrote:

Continuing purely for my own edification...

> FYI, it's (eliding lots) like this:
> 
>   sub db_retry ($$$;$$) {
>       for (;;) {
>           $pre->();
>           eval {
>               $r= &$body;
>               if ($db_retry_stop) {
>                   no warnings qw(exiting);
>                   last if $db_retry_stop eq 'abort';
>                   next;
>               }
>               $dbh->commit();
>           };
>           last if !length $@;
>       }
>       return $r;
>   }
> 
> The warning from perl is because when `last if $db_retry_stop'
> happens, `last' exits the eval in order to exit the outer for (;;)
> loop.

Meaning that last (or next) will exit the eval and immediately end (or
restart) the containing loop, in particular without executing the "last if
!length $@;".

> Both of these are intentional.  Perl thinks they might not be.

... and that's because it is a common enough mistake to think that next or
last exits only the scope of the eval and therefore in this case to expect
it to run "last if !length $@;", while it actually wont.

I would have expected that if you want to successfully exit (i.e. not die)
the eval early and continue on with the remainder of the loop you should
use return, and http://perldoc.perl.org/functions/eval.html seems to back
that up ("the value returned is the value of the last expression evaluated
inside the mini-program; a return statement may be also used,"), but
earlier you said that return would generate the same warning, so I remain a
bit confused.

According to my reading of eval.html "return if $db_retry_stop eq 'abort'"
would exit the eval with $@="" ("If there was no error, $@ is set to the
empty string", it mentions last and goto bypassing this, but not return).
Then since length "" is false that outer last would be run insteadand we
are done with the loop as we wanted. AFAICT that would avoid the warning
for the inner last, but is not usable for the inner next, and in any case
using last inside the eval is actually more obvious in this instance, once
one thinks one understands an eval (which in my case is still debatable I
think)

Ian.

> Thanks for all the acks.  I'll maybe push this at some point, or
> combine it with something else.  It's not urgent.
> 
> Ian.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  reply	other threads:[~2015-12-18 11:15 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-17 17:06 [OSSTEST PATCH 1/9] README.dev: Document the blessings Ian Jackson
2015-12-17 17:06 ` [OSSTEST PATCH 2/9] mg-schema-test-database: Provide some timeouts which are better for testing Ian Jackson
2015-12-17 17:19   ` Ian Campbell
2015-12-17 17:06 ` [OSSTEST PATCH 3/9] mg-schema-test-database: Wipe previous local plan data Ian Jackson
2015-12-17 17:22   ` Ian Campbell
2015-12-17 17:37     ` Ian Jackson
2015-12-17 17:42       ` Ian Campbell
2015-12-17 17:50         ` Ian Jackson
2015-12-17 18:11           ` Ian Campbell
2015-12-17 17:06 ` [OSSTEST PATCH 4/9] mg-schema-test-database: Borrow shares properly Ian Jackson
2015-12-17 17:26   ` Ian Campbell
2015-12-17 17:43     ` Ian Jackson
2015-12-17 18:08       ` Ian Campbell
2015-12-17 17:06 ` [OSSTEST PATCH 5/9] ms-planner: Improve an error message Ian Jackson
2015-12-17 17:26   ` Ian Campbell
2015-12-17 17:06 ` [OSSTEST PATCH 6/9] db_retry: Suppress an "exiting via last" warning Ian Jackson
2015-12-17 17:31   ` Ian Campbell
2015-12-17 17:48     ` Ian Jackson
2015-12-17 18:10       ` Ian Campbell
2015-12-17 18:38         ` Ian Jackson
2015-12-18 11:14           ` Ian Campbell [this message]
2015-12-18 14:39             ` Ian Jackson
2015-12-17 17:06 ` [OSSTEST PATCH 7/9] Executive DB retry: Avoid an undefined warning Ian Jackson
2015-12-17 17:31   ` Ian Campbell
2015-12-17 17:06 ` [OSSTEST PATCH 8/9] mg-allocate: Better error handling when no candidates Ian Jackson
2015-12-17 17:33   ` Ian Campbell
2015-12-17 17:06 ` [OSSTEST PATCH 9/9] mg-allocate: In planner mode, pre-check the arguments Ian Jackson
2015-12-17 17:33   ` Ian Campbell
2015-12-17 17:18 ` [OSSTEST PATCH 1/9] README.dev: Document the blessings Ian Campbell
2015-12-17 17:59   ` Ian Jackson
2015-12-17 18:12     ` Ian Campbell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1450437258.4053.198.camel@citrix.com \
    --to=ian.campbell@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.