On Sat, 2010-07-17 at 05:51 +1000, Greg Banks wrote:
> ...
> > die "pmiStart($archive): " . pmiErrStr($_) . "\n" if ($_ < 0);
> Perl programmers would probably feel more comfortable doing something like
>
> pmiStart($archive, 0) or die "pmiStart($archive): $?";
>
> but I have NFI how to make that happen at the C wrapper layer (sorry).
There are two problems here that I can see ...
1. blah(..) or die ... requires blah() to return 0 for failure (anything
else is true) ... which does not work well with our multi-state return
values throughout the PCP libraries.
2. there is no way to get the returned value from the last library call
(your $? above) that I can see.
But, I do have a suggestion. 1. is not solvable, so the best we could
do is
blah(...) == 0 or die ...
and in the case of pmiStart
pmiStart(...) >= 0 or die ...
I can workaround 2. by have the last return value from each routine in
the library stashed in the log import context, and then special case
pmiErrStr(-1) to return the error message from the last return value.
Together the original becomes ...
pmiStart($archive, 0) >=0 or die "pmiStart($archive): " . pmiErrStr(-1) . "\n";
which seems neater.
It also removes much of the $_ clutter in the code (addressing one of
Nathan's comments).
I think I'll make this change.
Thanks for the feedback.
|