From d4ab51beb6958d2282e2def1bdc5e35a973ffaf4 Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Thu, 5 Mar 2015 23:15:11 +0100 Subject: [PATCH] parallel: Some Perl versions do not support substr($buf,0,$i) with $i > 2GB, so do this in 2GB chunks. --- src/parallel | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/parallel b/src/parallel index df6dc7d1..2fc1d90b 100755 --- a/src/parallel +++ b/src/parallel @@ -332,7 +332,7 @@ sub spreadstdin { $anything_written += write_record_to_pipe($chunk_number++,\$header,\$buf, $recstart,$recend,$last_newline_pos+1); - substr($buf,0,$last_newline_pos+1) = ""; + shorten(\$buf,$last_newline_pos+1); } elsif($opt::regexp) { if($Global::max_number_of_args) { # -N => (start..*?end){n} @@ -365,7 +365,7 @@ sub spreadstdin { $anything_written += write_record_to_pipe($chunk_number++,\$header,\$buf, $recstart,$recend,$i); - substr($buf,0,$i) = ""; + shorten(\$buf,$i); } } else { # Find the last recend+recstart in $buf @@ -375,7 +375,7 @@ sub spreadstdin { $anything_written += write_record_to_pipe($chunk_number++,\$header,\$buf, $recstart,$recend,$i); - substr($buf,0,$i) = ""; + shorten(\$buf,$i); } } } @@ -393,7 +393,6 @@ sub spreadstdin { ::debug("init", "Done reading input\n"); # If there is anything left in the buffer write it - substr($buf,0,0) = ""; write_record_to_pipe($chunk_number++,\$header,\$buf,$recstart,$recend,length $buf); $Global::start_no_new_jobs ||= 1; @@ -583,6 +582,22 @@ sub rindex64 { return -1; } +sub shorten { + # Do: substr($buf,0,$i) = ""; + # Some Perl versions do not support $i > 2GB, so do this in 2GB chunks + # Input: + # $buf_ref = \$buf + # $i = position to shorten to + # Returns: N/A + my ($buf_ref, $i) = @_; + my $two_gb = 2**31-1; + while($i > $two_gb) { + substr($$buf_ref,0,$two_gb) = ""; + $i -= $two_gb; + } + substr($$buf_ref,0,$i) = ""; +} + sub write_record_to_pipe { # Fork then # Write record from pos 0 .. $endpos to pipe @@ -6055,7 +6070,6 @@ sub base64_zip_eval { return $script; } - sub sshlogin_wrap { # Wrap the command with the commands needed to run remotely # Input: