Date | Commit message (Collapse) |
|
Once again Ruby seems ready to introduce more incompatibilities
and force busywork upon maintainers[1]. In order to avoid
incompatibilities in the future, I used the following Perl
script to prepend `frozen_string_literal: false' to every
Ruby file:
use v5.12;
use autodie;
my $usage = 'perl /path/to/script <LIST_OF_RB_FILES>';
my $fsl = "# frozen_string_literal: false\n";
for my $f (@ARGV) {
open my $fh, '<', $f;
my $s = do { local $/; <$fh> } // die "read($f): $!";
next if $s =~ /^#\s*frozen_string_literal:/sm;
# fsl must be after encoding: line if it exists:
if ($s =~ s/^([ \t]*\#[ \t\-\*\#]+encoding:[^\n]+\n)/$1$fsl/sm
# or after the shebang
|| $s =~ s/^(#![^\n]+\n)/$1$fsl/
# or after embedded switches in rackup files:
|| ($f =~ /\.ru$/ &&
$s =~ s/^(#\\[^\n]+\n)/$1$fsl/)
# or prepend as a last resort:
|| (substr($s, 0, 0) = $fsl)) {
open $fh, '>', $f;
print $fh $s;
close $fh;
}
}
Somebody interested will have to go through every Ruby source
file and enable frozen_string_literal once they've thoroughly
verified it's safe to do so.
[1] https://bugs.ruby-lang.org/issues/20205
|
|
Newer rubies have more warnings
|
|
Linux is in the 4.x and Ruby is into the 2.x range, by now,
so try to get with the times.
|
|
File#size is available in modern Rubies so the extra syscall
is avoided.
|
|
IO.copy_stream is standard in 1.9+ and can use pread when
given an offset. We do not need to use pwrite with fcntl
locking, actually.
|
|
And rely on frozen string optimizations in Ruby while we're at it.
|
|
Found in the check-warnings target in pkg.mk
|
|
Of course, RDoc doesn't know quantity vs quality :)
|
|
fcntl() locks are per-process, so we also need something
to protect individual threads within a process from stepping
over each other.
|
|
Seems to basically work
|
|
|