http://qs1969.pair.com?node_id=668119

nobull has asked for the wisdom of the Perl Monks concerning the following question:

I came across the following code in Net::SSLeay:
sub do_https4 { splice(@_,1,0) = 1; do_httpx4; } # Legacy undocumente +d

The trouble is that this code doesn't actually compile. I'm guessing this doesn't matter (at least on some level) because the module uses AutoLoader so the above code doesn't get compiled unless someone calls do_https4.

However in order to debug Net::SSLeay I've temporarily prevented it from auto-splitting so I've had to remove the bogus code.

What I'm curious about is what the code is supposed to do! Is it a fact that in some previous version of Perl this code behaved like:

sub do_https4 { splice(@_,1,0,1); do_httpx4; }

And if so when did this change?

Replies are listed 'Best First'.
Re: Legacy use of splice() as lvalue
by moritz (Cardinal) on Feb 15, 2008 at 09:57 UTC
    My guess is that somebody assumed the same semantics for splice as substr implements, which can be used as an lvalue.

    So the old behaviour is roughly equivalent to die "That sub should never be called, and is not tested";, while the new one modifies @_.

Re: Legacy use of splice() as lvalue
by almut (Canon) on Feb 15, 2008 at 10:22 UTC

    FWIW, it doesn't even compile on older versions (tried several, going back to v5.005_03 — same error as in v5.8).

    BTW, I think the "legacy" is referring to the subroutine do_https4 itself, not to the weird usage of splice within it...  so you're probably okay simply removing that piece of code.

    Update: another indication that this code has never really been in use is that if the idea is to modify the argument list prior to calling the wrapped do_httpx4, it would have to be called as &do_httpx4 to actually make @_ visible to that subroutine...

      Update: another indication that this code has never really been in use is that if the idea is to modify the argument list prior to calling the wrapped do_httpx4, it would have to be called as &do_httpx4 to actually make @_ visible to that subroutine...

      Yes, I noticed that initially, then somehow it slipped my mind before I posted.

      I'm getting more and more convinced that much of Net::SSLeay is the software equivalent of introns.

      Here's another

      sub do_httpx4 { my ($page, $response, $headers, $server_cert) = &do_httpx3; X509_free($server_cert) if defined $server_cert; my %hr = (); for my $hh (split /\s?\n/, $headers) { my ($h,$v)=/^(\S+)\:\s*(.*)$/; push @{$hr{uc($h)}}, $v; } return ($page, $response, \%hr); }

      If you notice the variable $hh is not used and the m// operator is acting on whatever happens to be in $_.

      Am I really looking at the current version of the module (version 1.32 on CPAN)?

        Am I really looking at the current version of the module (version 1.32 on CPAN)?
        Not only that: both code fragments are still, unchanged, in the latest developer release, Net-SSLeay-1.33_01, released 2 days ago.

        Wow. Just wow.