parallel: Some Perl versions do not support substr($buf,0,$i) with $i > 2GB, so do this in 2GB chunks.

This commit is contained in:
Ole Tange 2015-03-05 23:15:11 +01:00
parent 3c05c6815b
commit d4ab51beb6

View file

@ -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: