From a36cf00dee5d7657bf95b66bd4559feaab010989 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 8 Feb 2024 11:58:58 +0000 Subject: treewide: future-proof frozen_string_literal changes 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 '; 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 --- examples/linux-listener-stats.rb | 1 + examples/middleware.ru | 1 + examples/watcher.ru | 1 + examples/watcher_demo.ru | 1 + examples/yahns.conf.rb | 1 + examples/zbatery.conf.rb | 1 + ext/raindrops/extconf.rb | 1 + lib/raindrops.rb | 1 + lib/raindrops/aggregate.rb | 1 + lib/raindrops/aggregate/last_data_recv.rb | 1 + lib/raindrops/aggregate/pmq.rb | 1 + lib/raindrops/last_data_recv.rb | 1 + lib/raindrops/linux.rb | 1 + lib/raindrops/middleware.rb | 1 + lib/raindrops/middleware/proxy.rb | 1 + lib/raindrops/struct.rb | 1 + lib/raindrops/watcher.rb | 1 + setup.rb | 1 + test/ipv6_enabled.rb | 1 + test/rack_unicorn.rb | 1 + test/test_aggregate_pmq.rb | 1 + test/test_inet_diag_socket.rb | 1 + test/test_last_data_recv.rb | 1 + test/test_last_data_recv_unicorn.rb | 1 + test/test_linux.rb | 1 + test/test_linux_all_tcp_listen_stats.rb | 1 + test/test_linux_all_tcp_listen_stats_leak.rb | 1 + test/test_linux_ipv6.rb | 1 + test/test_linux_middleware.rb | 1 + test/test_linux_reuseport_tcp_listen_stats.rb | 1 + test/test_middleware.rb | 1 + test/test_middleware_unicorn.rb | 1 + test/test_middleware_unicorn_ipv6.rb | 1 + test/test_raindrops.rb | 1 + test/test_raindrops_gc.rb | 1 + test/test_struct.rb | 1 + test/test_tcp_info.rb | 1 + test/test_watcher.rb | 1 + 38 files changed, 38 insertions(+) diff --git a/examples/linux-listener-stats.rb b/examples/linux-listener-stats.rb index 7e767da..5f67633 100755 --- a/examples/linux-listener-stats.rb +++ b/examples/linux-listener-stats.rb @@ -1,5 +1,6 @@ #!/usr/bin/ruby # -*- encoding: binary -*- +# frozen_string_literal: false $stdout.sync = $stderr.sync = true # this is used to show or watch the number of active and queued # connections on any listener socket from the command line diff --git a/examples/middleware.ru b/examples/middleware.ru index 642016b..a485592 100644 --- a/examples/middleware.ru +++ b/examples/middleware.ru @@ -1,3 +1,4 @@ +# frozen_string_literal: false # sample stand-alone rackup application for Raindrops::Middleware require 'rack/lobster' require 'raindrops' diff --git a/examples/watcher.ru b/examples/watcher.ru index a3e7fdb..e2aa97c 100644 --- a/examples/watcher.ru +++ b/examples/watcher.ru @@ -1,3 +1,4 @@ +# frozen_string_literal: false # Sample standalone Rack application, recommended use is with Zbatery # See zbatery.conf.rb require "raindrops" diff --git a/examples/watcher_demo.ru b/examples/watcher_demo.ru index 91f4cca..7a6e675 100644 --- a/examples/watcher_demo.ru +++ b/examples/watcher_demo.ru @@ -1,3 +1,4 @@ +# frozen_string_literal: false # This is a snippet of the config that powers # https://yhbt.net/raindrops-demo/ # This may be used with the packaged zbatery.conf.rb diff --git a/examples/yahns.conf.rb b/examples/yahns.conf.rb index f5b4f10..75f0bd1 100644 --- a/examples/yahns.conf.rb +++ b/examples/yahns.conf.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false # Inlined rack app using yahns server (git clone git://yhbt.net/yahns.git) # Usage: yahns -c /path/to/this/file.conf.rb # There is no separate config.ru file for this example, diff --git a/examples/zbatery.conf.rb b/examples/zbatery.conf.rb index 5f94c0e..0537466 100644 --- a/examples/zbatery.conf.rb +++ b/examples/zbatery.conf.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false # Used for running Raindrops::Watcher, which requires a multi-threaded # Rack server capable of streaming a response. Threads must be used, # so any multi-threaded Rack server may be used. diff --git a/ext/raindrops/extconf.rb b/ext/raindrops/extconf.rb index b8f147c..b1310b0 100644 --- a/ext/raindrops/extconf.rb +++ b/ext/raindrops/extconf.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require 'mkmf' require 'shellwords' diff --git a/lib/raindrops.rb b/lib/raindrops.rb index dc61952..c071d57 100644 --- a/lib/raindrops.rb +++ b/lib/raindrops.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false # # Each Raindrops object is a container that holds several counters. # It is internally a page-aligned, shared memory area that allows diff --git a/lib/raindrops/aggregate.rb b/lib/raindrops/aggregate.rb index 4fb731f..9ed7eb7 100644 --- a/lib/raindrops/aggregate.rb +++ b/lib/raindrops/aggregate.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false # # raindrops may use the {aggregate}[https://github.com/josephruscio/aggregate] # RubyGem to aggregate statistics from TCP_Info lookups. diff --git a/lib/raindrops/aggregate/last_data_recv.rb b/lib/raindrops/aggregate/last_data_recv.rb index 32908f2..2205208 100644 --- a/lib/raindrops/aggregate/last_data_recv.rb +++ b/lib/raindrops/aggregate/last_data_recv.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require "socket" # # diff --git a/lib/raindrops/aggregate/pmq.rb b/lib/raindrops/aggregate/pmq.rb index 64d0a4f..94bdf4f 100644 --- a/lib/raindrops/aggregate/pmq.rb +++ b/lib/raindrops/aggregate/pmq.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require "tempfile" require "aggregate" require "posix_mq" diff --git a/lib/raindrops/last_data_recv.rb b/lib/raindrops/last_data_recv.rb index b4808a1..e6c47e1 100644 --- a/lib/raindrops/last_data_recv.rb +++ b/lib/raindrops/last_data_recv.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require "raindrops" # This is highly experimental! diff --git a/lib/raindrops/linux.rb b/lib/raindrops/linux.rb index 9842ae1..a76192c 100644 --- a/lib/raindrops/linux.rb +++ b/lib/raindrops/linux.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false # For reporting TCP ListenStats, users of older \Linux kernels need to ensure # that the the "inet_diag" and "tcp_diag" kernel modules are loaded as they do diff --git a/lib/raindrops/middleware.rb b/lib/raindrops/middleware.rb index 20e573c..25b5a1e 100644 --- a/lib/raindrops/middleware.rb +++ b/lib/raindrops/middleware.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require 'raindrops' require 'thread' diff --git a/lib/raindrops/middleware/proxy.rb b/lib/raindrops/middleware/proxy.rb index a7c8e66..433950c 100644 --- a/lib/raindrops/middleware/proxy.rb +++ b/lib/raindrops/middleware/proxy.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false # :stopdoc: # This class is used by Raindrops::Middleware to proxy application # response bodies. There should be no need to use it directly. diff --git a/lib/raindrops/struct.rb b/lib/raindrops/struct.rb index e81a78e..7233ce8 100644 --- a/lib/raindrops/struct.rb +++ b/lib/raindrops/struct.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false # This is a wrapper around Raindrops objects much like the core Ruby # \Struct can be seen as a wrapper around the core \Array class. diff --git a/lib/raindrops/watcher.rb b/lib/raindrops/watcher.rb index ac5b895..8fc0772 100644 --- a/lib/raindrops/watcher.rb +++ b/lib/raindrops/watcher.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require "thread" require "time" require "socket" diff --git a/setup.rb b/setup.rb index 5eb5006..b382468 100644 --- a/setup.rb +++ b/setup.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false # # setup.rb # diff --git a/test/ipv6_enabled.rb b/test/ipv6_enabled.rb index c4c9709..84ed9c1 100644 --- a/test/ipv6_enabled.rb +++ b/test/ipv6_enabled.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false def ipv6_enabled? tmp = TCPServer.new(ENV["TEST_HOST6"] || '::1', 0) tmp.close diff --git a/test/rack_unicorn.rb b/test/rack_unicorn.rb index 0ecbd42..05a7751 100644 --- a/test/rack_unicorn.rb +++ b/test/rack_unicorn.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require "test/unit" require "raindrops" require "open-uri" diff --git a/test/test_aggregate_pmq.rb b/test/test_aggregate_pmq.rb index 692b9bd..24e0277 100644 --- a/test/test_aggregate_pmq.rb +++ b/test/test_aggregate_pmq.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require "test/unit" require "raindrops" pmq = begin diff --git a/test/test_inet_diag_socket.rb b/test/test_inet_diag_socket.rb index a8c9973..e310dff 100644 --- a/test/test_inet_diag_socket.rb +++ b/test/test_inet_diag_socket.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require 'test/unit' require 'raindrops' require 'fcntl' diff --git a/test/test_last_data_recv.rb b/test/test_last_data_recv.rb index 9643dc6..edd00f3 100644 --- a/test/test_last_data_recv.rb +++ b/test/test_last_data_recv.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false begin require 'aggregate' have_aggregate = true diff --git a/test/test_last_data_recv_unicorn.rb b/test/test_last_data_recv_unicorn.rb index 60d1be9..55f5e7f 100644 --- a/test/test_last_data_recv_unicorn.rb +++ b/test/test_last_data_recv_unicorn.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require "./test/rack_unicorn" require "tempfile" require "net/http" diff --git a/test/test_linux.rb b/test/test_linux.rb index 7808469..5451c3f 100644 --- a/test/test_linux.rb +++ b/test/test_linux.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require 'test/unit' require 'tempfile' require 'raindrops' diff --git a/test/test_linux_all_tcp_listen_stats.rb b/test/test_linux_all_tcp_listen_stats.rb index ef1f943..12a35ba 100644 --- a/test/test_linux_all_tcp_listen_stats.rb +++ b/test/test_linux_all_tcp_listen_stats.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require 'test/unit' require 'socket' require 'raindrops' diff --git a/test/test_linux_all_tcp_listen_stats_leak.rb b/test/test_linux_all_tcp_listen_stats_leak.rb index 7be46d4..a3da07e 100644 --- a/test/test_linux_all_tcp_listen_stats_leak.rb +++ b/test/test_linux_all_tcp_listen_stats_leak.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require 'test/unit' require 'raindrops' require 'socket' diff --git a/test/test_linux_ipv6.rb b/test/test_linux_ipv6.rb index 9e8730a..9ef8f0a 100644 --- a/test/test_linux_ipv6.rb +++ b/test/test_linux_ipv6.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require 'test/unit' require 'tempfile' require 'raindrops' diff --git a/test/test_linux_middleware.rb b/test/test_linux_middleware.rb index f573225..7ed20df 100644 --- a/test/test_linux_middleware.rb +++ b/test/test_linux_middleware.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require 'test/unit' require 'tempfile' require 'raindrops' diff --git a/test/test_linux_reuseport_tcp_listen_stats.rb b/test/test_linux_reuseport_tcp_listen_stats.rb index 4fda218..82083e0 100644 --- a/test/test_linux_reuseport_tcp_listen_stats.rb +++ b/test/test_linux_reuseport_tcp_listen_stats.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require "./test/rack_unicorn" require 'test/unit' require 'socket' diff --git a/test/test_middleware.rb b/test/test_middleware.rb index 56ce346..5694cd4 100644 --- a/test/test_middleware.rb +++ b/test/test_middleware.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require 'test/unit' require 'raindrops' diff --git a/test/test_middleware_unicorn.rb b/test/test_middleware_unicorn.rb index 6730d4b..53226a9 100644 --- a/test/test_middleware_unicorn.rb +++ b/test/test_middleware_unicorn.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require "./test/rack_unicorn" $stderr.sync = $stdout.sync = true diff --git a/test/test_middleware_unicorn_ipv6.rb b/test/test_middleware_unicorn_ipv6.rb index 3d6862c..99ecb7f 100644 --- a/test/test_middleware_unicorn_ipv6.rb +++ b/test/test_middleware_unicorn_ipv6.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require "./test/rack_unicorn" require "./test/ipv6_enabled" $stderr.sync = $stdout.sync = true diff --git a/test/test_raindrops.rb b/test/test_raindrops.rb index 6351c66..165766e 100644 --- a/test/test_raindrops.rb +++ b/test/test_raindrops.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require 'test/unit' require 'raindrops' require 'tempfile' diff --git a/test/test_raindrops_gc.rb b/test/test_raindrops_gc.rb index 2098129..a9f2026 100644 --- a/test/test_raindrops_gc.rb +++ b/test/test_raindrops_gc.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require 'test/unit' require 'raindrops' diff --git a/test/test_struct.rb b/test/test_struct.rb index 9792d5b..abf0c59 100644 --- a/test/test_struct.rb +++ b/test/test_struct.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require 'test/unit' require 'raindrops' diff --git a/test/test_tcp_info.rb b/test/test_tcp_info.rb index 2ddacfd..2dc5c50 100644 --- a/test/test_tcp_info.rb +++ b/test/test_tcp_info.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require 'test/unit' require 'tempfile' require 'raindrops' diff --git a/test/test_watcher.rb b/test/test_watcher.rb index e5d1fa2..3cf667c 100644 --- a/test/test_watcher.rb +++ b/test/test_watcher.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require "test/unit" require "raindrops" begin -- cgit v1.2.3-24-ge0c7