pcp
[Top] [All Lists]

Re: [pcp] PCP question ... leading to pmimport discussion

To: Greg Banks <gnb@xxxxxxxxxxx>
Subject: Re: [pcp] PCP question ... leading to pmimport discussion
From: Ken McDonell <kenj@xxxxxxxxxxxxxxxx>
Date: Sat, 17 Jul 2010 07:16:09 +1000
Cc: "pmatousu@xxxxxxxxxxxxx" <pmatousu@xxxxxxxxxxxxx>, "pcp@xxxxxxxxxxx" <pcp@xxxxxxxxxxx>
In-reply-to: <4C40B826.9000209@xxxxxxxxxxx>
References: <1619637932.410411277773130222.JavaMail.root@xxxxxxxxxxxxxxxxxx> <1278024574.2198.1.camel@xxxxxxxxxxxxxxxx> <4C2D53C7.6070300@xxxxxxxxxxx> <1278102403.10129.12.camel@xxxxxxxxxxxxxxxx> <4C3135E2.4040900@xxxxxxxxxxx> <1278317711.21023.72.camel@xxxxxxxxxxxxxxxx> <4C32909D.6040103@xxxxxxxxxxx> <1278399475.10060.15.camel@xxxxxxxxxxxxxxxx> <1279178812.27999.10.camel@xxxxxxxxxxxxxxxx> <4C40B826.9000209@xxxxxxxxxxx>
Reply-to: kenj@xxxxxxxxxxxxxxxx
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.

<Prev in Thread] Current Thread [Next in Thread>