Skip to content

Commit

Permalink
Ensure compatibility with --enable-frozen-string-literal
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Mar 21, 2024
1 parent c15d8d4 commit e05b88f
Show file tree
Hide file tree
Showing 78 changed files with 131 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ jobs:
- name: Install packages
run: sudo apt-get install -y ragel socat netcat

- name: Tests
- name: Tests ${{ matrix.rubyopt }}
run: bundle exec rake
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ DEPENDENCIES
rake-compiler

BUNDLED WITH
2.3.22
2.3.27
1 change: 1 addition & 0 deletions benchmark/cow_benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require "net/http"

app_path = File.expand_path('../examples/constant_caches.ru', __dir__)
Expand Down
1 change: 1 addition & 0 deletions examples/constant_caches.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative "../lib/pitchfork/mem_info"

module App
Expand Down
1 change: 1 addition & 0 deletions examples/echo.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# Example application that echoes read data back to the HTTP client.
# This emulates the old echo protocol people used to run.
#
Expand Down
1 change: 1 addition & 0 deletions examples/hello.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
run lambda { |env|
/\A100-continue\z/i =~ env['HTTP_EXPECT'] and return [100, {}, []]
body = "Hello World!\n"
Expand Down
1 change: 1 addition & 0 deletions examples/pitchfork.conf.minimal.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# Minimal sample configuration file for Pitchfork

# listen 2007 # by default Pitchfork listens on port 8080
Expand Down
1 change: 1 addition & 0 deletions examples/pitchfork.conf.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# Sample verbose configuration file for Pitchfork

# Use at least one worker per core if you're on a dedicated server,
Expand Down
1 change: 1 addition & 0 deletions exe/pitchfork
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
# -*- encoding: binary -*-
require 'pitchfork/launcher'
require 'optparse'
Expand Down
1 change: 1 addition & 0 deletions ext/pitchfork_http/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: true
require 'mkmf'

have_const("PR_SET_CHILD_SUBREAPER", "sys/prctl.h")
Expand Down
1 change: 1 addition & 0 deletions lib/pitchfork.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: true
require 'etc'
require 'stringio'
require 'raindrops'
Expand Down
1 change: 1 addition & 0 deletions lib/pitchfork/app/old_rails/static.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: true
# :enddoc:
# This code is based on the original Rails handler in Mongrel
# Copyright (c) 2005 Zed A. Shaw
Expand Down
1 change: 1 addition & 0 deletions lib/pitchfork/children.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: true

module Pitchfork
# This class keep tracks of the state of all the master children.
Expand Down
1 change: 1 addition & 0 deletions lib/pitchfork/configurator.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: true
require 'logger'

module Pitchfork
Expand Down
1 change: 1 addition & 0 deletions lib/pitchfork/const.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: true

module Pitchfork
module Const # :nodoc:
Expand Down
1 change: 1 addition & 0 deletions lib/pitchfork/flock.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'tempfile'

module Pitchfork
Expand Down
3 changes: 2 additions & 1 deletion lib/pitchfork/http_parser.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: true
# :enddoc:
# no stable API here

Expand All @@ -19,7 +20,7 @@ class HttpParser
"SERVER_SOFTWARE" => "Pitchfork #{Pitchfork::Const::UNICORN_VERSION}"
}

NULL_IO = StringIO.new("")
NULL_IO = StringIO.new.binmode

# :stopdoc:
HTTP_RESPONSE_START = [ 'HTTP'.freeze, '/1.1 '.freeze ]
Expand Down
1 change: 1 addition & 0 deletions lib/pitchfork/http_response.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: true
# :enddoc:

module Pitchfork
Expand Down
4 changes: 3 additions & 1 deletion lib/pitchfork/http_server.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- encoding: binary -*-
# frozen_string_literal: true

require 'pitchfork/pitchfork_http'
require 'pitchfork/flock'
require 'pitchfork/soft_timeout'
Expand Down Expand Up @@ -696,7 +698,7 @@ def handle_error(client, e)

def e103_response_write(client, headers)
rss = @request.response_start_sent
buf = rss ? "103 Early Hints\r\n" : "HTTP/1.1 103 Early Hints\r\n"
buf = (rss ? "103 Early Hints\r\n" : "HTTP/1.1 103 Early Hints\r\n").b
headers.each { |key, value| append_header(buf, key, value) }
buf << (rss ? "\r\nHTTP/1.1 ".freeze : "\r\n".freeze)
client.write(buf)
Expand Down
1 change: 1 addition & 0 deletions lib/pitchfork/launcher.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: true

# :enddoc:
$stdout.sync = $stderr.sync = true
Expand Down
1 change: 1 addition & 0 deletions lib/pitchfork/message.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: true

# :stopdoc:
module Pitchfork
Expand Down
1 change: 1 addition & 0 deletions lib/pitchfork/select_waiter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Pitchfork
# fallback for non-Linux and Linux <4.5 systems w/o EPOLLEXCLUSIVE
class SelectWaiter # :nodoc:
Expand Down
1 change: 1 addition & 0 deletions lib/pitchfork/socket_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: true
# :enddoc:
require 'socket'

Expand Down
11 changes: 6 additions & 5 deletions lib/pitchfork/stream_input.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: true

module Pitchfork
# When processing uploads, pitchfork may expose a StreamInput object under
Expand All @@ -17,7 +18,7 @@ def initialize(socket, request) # :nodoc:
@socket = socket
@parser = request
@buf = request.buf
@rbuf = ''
@rbuf = +''
@bytes_read = 0
filter_body(@rbuf, @buf) unless @buf.empty?
end
Expand All @@ -41,7 +42,7 @@ def initialize(socket, request) # :nodoc:
# ios.read(length [, buffer]) will return immediately if there is
# any data and only block when nothing is available (providing
# IO#readpartial semantics).
def read(length = nil, rv = '')
def read(length = nil, rv = ''.b)
if length
if length <= @rbuf.size
length < 0 and raise ArgumentError, "negative length #{length} given"
Expand Down Expand Up @@ -79,16 +80,16 @@ def read(length = nil, rv = '')
# unlike IO#gets.
def gets(sep = $/)
if sep.nil?
read_all(rv = '')
read_all(rv = ''.b)
return rv.empty? ? nil : rv
end
re = /\A(.*?#{Regexp.escape(sep)})/

begin
@rbuf.sub!(re, '') and return $1
@rbuf.sub!(re, ''.b) and return $1
return @rbuf.empty? ? nil : @rbuf.slice!(0, @rbuf.size) if eof?
@socket.readpartial(@@io_chunk_size, @buf) or eof!
filter_body(once = '', @buf)
filter_body(once = ''.b, @buf)
@rbuf << once
end while true
end
Expand Down
5 changes: 3 additions & 2 deletions lib/pitchfork/tee_input.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: true

module Pitchfork
# Acts like tee(1) on an input input to provide a input-like stream
Expand Down Expand Up @@ -42,7 +43,7 @@ def initialize(socket, request) # :nodoc:
@len = request.content_length
super
@tmp = @len && @len <= @@client_body_buffer_size ?
StringIO.new("") : new_tmpio
StringIO.new.binmode : new_tmpio
end

# :call-seq:
Expand Down Expand Up @@ -121,7 +122,7 @@ def rewind

# consumes the stream of the socket
def consume!
junk = ""
junk = "".b
nil while read(@@io_chunk_size, junk)
end

Expand Down
1 change: 1 addition & 0 deletions lib/pitchfork/tmpio.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: true
# :stopdoc:
require 'tmpdir'

Expand Down
1 change: 1 addition & 0 deletions lib/pitchfork/worker.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: true
require 'pitchfork/shared_memory'

module Pitchfork
Expand Down
1 change: 1 addition & 0 deletions test/integration/apps/chunked.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class ChunkedBody
def each(&block)
('A'..'Z').each do |char|
Expand Down
1 change: 1 addition & 0 deletions test/integration/apps/stream.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class ChunkedBody
def each(&block)
('A'..'Z').each do |char|
Expand Down
1 change: 1 addition & 0 deletions test/integration/bin/content-md5-put
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
# -*- encoding: binary -*-
# simple chunked HTTP PUT request generator (and just that),
# it reads stdin and writes to stdout so socat can write to a
Expand Down
1 change: 1 addition & 0 deletions test/integration/bin/sha1sum.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env ruby
# -*- encoding: binary -*-
# frozen_string_literal: true
# Reads from stdin and outputs the SHA1 hex digest of the input

require 'digest/sha1'
Expand Down
1 change: 1 addition & 0 deletions test/integration/bin/unused_listen
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
# -*- encoding: binary -*-
# this is to remain compatible with the unused_port function in the
# Unicorn test/test_helper.rb file
Expand Down
1 change: 1 addition & 0 deletions test/integration/broken-app.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# we do not want Rack::Lint or anything to protect us
use Rack::ContentLength
use Rack::ContentType, "text/plain"
Expand Down
1 change: 1 addition & 0 deletions test/integration/env.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
use Rack::ContentLength
use Rack::ContentType, "text/plain"
run lambda { |env| [ 200, {}, [ env.inspect << "\n" ] ] }
1 change: 1 addition & 0 deletions test/integration/fails-rack-lint.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# This rack app returns a header with key named "status", which will cause
# Rack::Lint to throw an exception if it is present. This
# is used to check whether Rack::Lint is in the stack or not.
Expand Down
1 change: 1 addition & 0 deletions test/integration/fork_unsafe.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
use Rack::ContentLength
use Rack::ContentType, "text/plain"
run lambda { |env|
Expand Down
1 change: 1 addition & 0 deletions test/integration/heartbeat-timeout.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
use Rack::ContentLength
headers = { 'content-type' => 'text/plain' }
run lambda { |env|
Expand Down
1 change: 1 addition & 0 deletions test/integration/info.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
use Rack::ContentLength
use Rack::ContentType, "text/plain"
run lambda { |env|
Expand Down
1 change: 1 addition & 0 deletions test/integration/listener_names.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
use Rack::ContentLength
use Rack::ContentType, "text/plain"
run(lambda { |_| [ 200, {}, [ Pitchfork.listener_names.inspect ] ] })
1 change: 1 addition & 0 deletions test/integration/pid.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
use Rack::ContentLength
use Rack::ContentType, "text/plain"
run lambda { |env| [ 200, {}, [ "#$$\n" ] ] }
1 change: 1 addition & 0 deletions test/integration/rack-input-tests.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# SHA1 checksum generator
require 'digest/sha1'
use Rack::ContentLength
Expand Down
1 change: 1 addition & 0 deletions test/integration/sleep.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
use Rack::ContentLength
use Rack::ContentType, "text/plain"
run lambda { |env|
Expand Down
1 change: 1 addition & 0 deletions test/integration/t0013.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#\ -E none
use Rack::ContentLength
use Rack::ContentType, 'text/plain'
Expand Down
1 change: 1 addition & 0 deletions test/integration/t0014.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#\ -E none
use Rack::ContentLength
use Rack::ContentType, 'text/plain'
Expand Down
1 change: 1 addition & 0 deletions test/integration/t0116.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#\ -E none
use Rack::ContentLength
use Rack::ContentType, 'text/plain'
Expand Down
1 change: 1 addition & 0 deletions test/integration/t0301.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#\-N --debug
run(lambda do |env|
case env['PATH_INFO']
Expand Down
1 change: 1 addition & 0 deletions test/integration/t2000.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
use Rack::ContentLength
use Rack::ContentType, "text/plain"
run lambda { |env|
Expand Down
1 change: 1 addition & 0 deletions test/integration/test_boot.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'integration_test_helper'

class TestBoot < Pitchfork::IntegrationTest
Expand Down
1 change: 1 addition & 0 deletions test/integration/test_broken_app.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'integration_test_helper'

class BrokenAppTest < Pitchfork::IntegrationTest
Expand Down
1 change: 1 addition & 0 deletions test/integration/test_configuration.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'integration_test_helper'

class ConfigurationTest < Pitchfork::IntegrationTest
Expand Down
1 change: 1 addition & 0 deletions test/integration/test_heartbeat_timeout.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'integration_test_helper'

class HearbeatTimeoutTest < Pitchfork::IntegrationTest
Expand Down
1 change: 1 addition & 0 deletions test/integration/test_http_basic.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'integration_test_helper'

class HttpBasicTest < Pitchfork::IntegrationTest
Expand Down
1 change: 1 addition & 0 deletions test/integration/test_info.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'integration_test_helper'

class InfoTest < Pitchfork::IntegrationTest
Expand Down
1 change: 1 addition & 0 deletions test/integration/test_parser_error.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: true

require 'integration_test_helper'

Expand Down
1 change: 1 addition & 0 deletions test/integration/test_reap_logging.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'integration_test_helper'

class ReapLoggingTest < Pitchfork::IntegrationTest
Expand Down
1 change: 1 addition & 0 deletions test/integration/test_reforking.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'integration_test_helper'

class ReforkingTest < Pitchfork::IntegrationTest
Expand Down
1 change: 1 addition & 0 deletions test/integration/write-on-close.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class WriteOnClose
def each(&block)
@callback = block
Expand Down

0 comments on commit e05b88f

Please sign in to comment.