[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn commit: r15700 - trunk/subversion/bindings/swig/perl/native

From: Blair Zajac <blair_at_orcaware.com>
Date: 2005-08-13 05:19:21 CEST

clkao@tigris.org wrote:
> Author: clkao
> Date: Fri Aug 12 10:44:46 2005
> New Revision: 15700
>
> Modified:
> trunk/subversion/bindings/swig/perl/native/Core.pm
>
> Log:
> Follow-up to r15695, more defined-ness tests.
>
> * perl/native/Core.pm:
> (SVN::Core::Stream::READLINE, getline): Fix bugs that content
> with literal "0" will not be read and returned.
>
> Patch by: Pawel Chmielowski <prefiks@civ.pl>
>
>
>
> Modified: trunk/subversion/bindings/swig/perl/native/Core.pm
> Url: http://svn.collab.net/viewcvs/svn/trunk/subversion/bindings/swig/perl/native/Core.pm?rev=15700&p1=trunk/subversion/bindings/swig/perl/native/Core.pm&p2=trunk/subversion/bindings/swig/perl/native/Core.pm&r1=15699&r2=15700
> ==============================================================================
> --- trunk/subversion/bindings/swig/perl/native/Core.pm (original)
> +++ trunk/subversion/bindings/swig/perl/native/Core.pm Fri Aug 12 10:44:46 2005
> @@ -201,7 +201,7 @@
> my $self = shift;
> *$self->{pool} ||= SVN::Core::pool_create (undef);
> my ($buf, $eof) = *$self->{svn_stream}->readline ($/, *$self->{pool});
> - return undef if $eof && !$buf;
> + return undef if $eof && !length($buf);

As a matter of good Perl style, you don't ever want to return undef. If the
caller calls the function in an array context, then the function will return an
array with a single value of undef, which when you test the array for trueness,
will return true.

So the proper thing to do is just return with no value, which returns undef in
scalar context and an empty array in array context:

     return if $eof && !length($buf);

 From perldoc -f return

        return EXPR
        return Returns from a subroutine, "eval", or "do FILE" with the value
                given in EXPR. Evaluation of EXPR may be in list, scalar, or
                void context, depending on how the return value will be used,
                and the context may vary from one execution to the next (see
                "wantarray"). If no EXPR is given, returns an empty list in
                list context, the undefined value in scalar context, and (of
                course) nothing at all in a void context.

> return $eof ? $buf : $buf.$/;
> }
>
> @@ -226,7 +226,8 @@
> return $buf;
> }
> elsif (ref $/) {
> - return *$self->{svn_stream}->read (${$/}) || undef;
> + my $buf = *$self->{svn_stream}->read (${$/});
> + return length($buf) ? $buf : undef;

Here you want to do

if (length($buf)) {
   return $buf;
} else {
   return;
}

Regards,
Blair

-- 
Blair Zajac, Ph.D.
<blair@orcaware.com>
Subversion and Orca training and consulting
http://www.orcaware.com/svn/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Aug 13 05:20:05 2005

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.