From 16ab03c44a445257110ad96de4c0222f4a7f6789 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Tue, 7 Jun 2022 09:12:09 -0700 Subject: [PATCH] Fix perl 5.36 warnings on use of @_ in functions with signature When running the test suite with perl 5.36 we get several warnings about use (explicit or implict) of `@_` in functions with signatures being 'experimental'. These fixes were all suggested by tinita (thanks). In some cases we can just use the function arguments, in three cases that fill buffers we have to drop the signatures, as you cannot assign to `@_` without triggering the warning when using signatures, and we don't see an obvious way to have these functions do anything else. In console_proxy we also drop the signature; we considered calling `$AUTOLOAD` with the args instead, but @kraih thinks that will cause problems with stack traces. Signed-off-by: Adam Williamson --- backend/console_proxy.pm | 12 +++++++++--- backend/svirt.pm | 2 +- consoles/serial_screen.pm | 5 ++++- consoles/ssh_screen.pm | 6 +++++- t/21-needle-downloader.t | 2 +- t/31-sshSerial.t | 7 ++++++- 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/backend/console_proxy.pm b/backend/console_proxy.pm index eea75a8c..01c30080 100644 --- a/backend/console_proxy.pm +++ b/backend/console_proxy.pm @@ -24,18 +24,20 @@ sub DESTROY () { } # handles the attempt to invoke an undefined method on the proxy console object # using query_isotovideo() to invoke the method on the actual console object in # the right process -sub AUTOLOAD ($self, @args) { +sub AUTOLOAD { # no:style:signatures my $function = our $AUTOLOAD; $function =~ s,.*::,,; # allow symbolic references no strict 'refs'; - *$AUTOLOAD = sub ($self, @args) { + *$AUTOLOAD = sub { # no:style:signatures + my $self = shift; + my $args = \@_; my $wrapped_call = { console => $self->{console}, function => $function, - args => \@args, + args => $args, wantarray => wantarray, }; @@ -52,6 +54,10 @@ sub AUTOLOAD ($self, @args) { return wantarray ? @{$wrapped_retval->{result}} : $wrapped_retval->{result}; }; + # this is why we can't use a signature for this function, goto + # implicitly uses @_ and that triggers a warning in a function + # with a signature. We want to use goto to hide frames in stack + # traces (per @kraih) goto &$AUTOLOAD; } diff --git a/backend/svirt.pm b/backend/svirt.pm index 9726467b..52d8583d 100644 --- a/backend/svirt.pm +++ b/backend/svirt.pm @@ -85,7 +85,7 @@ sub do_stop_vm ($self, @) { # Log stdout and stderr and return them in a list (comped). sub scp_get ($self, $src, $dest) { - bmwqemu::log_call(@_); + bmwqemu::log_call($self, $src, $dest); my %credentials = $self->get_ssh_credentials(_is_hyperv ? 'hyperv' : 'default'); my $ssh = $self->new_ssh_connection(%credentials); diff --git a/consoles/serial_screen.pm b/consoles/serial_screen.pm index d1b365ba..3db0433f 100644 --- a/consoles/serial_screen.pm +++ b/consoles/serial_screen.pm @@ -122,7 +122,8 @@ An undefined timeout will cause to wait indefinitely. A timeout of 0 means to just read once. =cut -sub do_read ($self, $, %args) { +sub do_read { # no:style:signatures + my ($self, undef, %args) = @_; my $buffer = ''; $args{timeout} //= undef; # wait till data is available $args{max_size} //= 2048; @@ -139,6 +140,8 @@ sub do_read ($self, $, %args) { $read = sysread($fd, $buffer, $args{max_size}); croak "Failed to read from virtio/svirt serial console char device: $ERRNO" if !defined($read) && !($ERRNO{EAGAIN} || $ERRNO{EWOULDBLOCK}); } + # this is why we can't use a signature for this function, + # assigning to @_ in a function with signature triggers a warning $_[1] = $buffer; return $read; } diff --git a/consoles/ssh_screen.pm b/consoles/ssh_screen.pm index b84c38fb..052308f5 100644 --- a/consoles/ssh_screen.pm +++ b/consoles/ssh_screen.pm @@ -27,7 +27,8 @@ sub new ($class, @args) { return $self->SUPER::new($self->ssh_channel); } -sub do_read ($self, $, %args) { +sub do_read { # no:style:signatures + my ($self, undef, %args) = @_; my $buffer = ''; $args{timeout} //= undef; # wait till data is available $args{max_size} //= 2048; @@ -37,6 +38,9 @@ sub do_read ($self, $, %args) { while (!$args{timeout} || (consoles::serial_screen::elapsed($stime) < $args{timeout})) { my $read = $self->ssh_channel->read($buffer, $args{max_size}); if (defined($read)) { + # this is why we can't use a signature for this function, + # assigning to @_ in a function with signature triggers a + # warning $_[1] = $buffer; print {$self->{loghandle}} $buffer if $self->{loghandle}; return $read; diff --git a/t/21-needle-downloader.t b/t/21-needle-downloader.t index 38b1bda9..3a680bc1 100755 --- a/t/21-needle-downloader.t +++ b/t/21-needle-downloader.t @@ -20,7 +20,7 @@ my $user_agent_mock = Test::MockModule->new('Mojo::UserAgent'); my @queried_urls; $user_agent_mock->redefine(get => sub ($self, $url) { push(@queried_urls, $url); - return $user_agent_mock->original('get')->(@_); + return $user_agent_mock->original('get')->($self, $url); }); # setup needle directory diff --git a/t/31-sshSerial.t b/t/31-sshSerial.t index f80bfaae..7e2ffdc6 100755 --- a/t/31-sshSerial.t +++ b/t/31-sshSerial.t @@ -49,7 +49,9 @@ $mock_channel->mock(blocking => sub ($self, $arg = undef) { return $self->{blocking}; }); -$mock_channel->mock(read => sub ($self, $, $size) { +$mock_channel->mock(read => sub { # no:style:signatures + my ($self, undef, $size) = @_; + my $data = shift @{$self->{read_queue}}; if (!defined($data)) { @@ -62,6 +64,9 @@ $mock_channel->mock(read => sub ($self, $, $size) { $data = substr($data, 0, $size); } + # this is why we can't use a signature for this function, + # assigning to @_ in a function with signature triggers a + # warning $_[1] = $data; return length($data); }); -- 2.36.1