posix_mq RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: ruby-posix-mq@bogomips.org
Cc: Eric Wong <e@80x24.org>
Subject: [PATCH] enable frozen_string_literal for Ruby 2.3+
Date: Tue,  2 Feb 2016 20:14:21 +0000	[thread overview]
Message-ID: <20160202201421.30679-1-e@80x24.org> (raw)

No changes for older Rubies, but this reduces garbage under 2.3
---
 bin/posix-mq-rb       |  3 ++-
 lib/posix_mq.rb       |  3 +--
 test/test_posix_mq.rb | 15 ++++++++-------
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/bin/posix-mq-rb b/bin/posix-mq-rb
index 8c77aea..45efb7b 100755
--- a/bin/posix-mq-rb
+++ b/bin/posix-mq-rb
@@ -1,5 +1,6 @@
 #!/usr/bin/env ruby
 # -*- encoding: binary -*-
+# -*- frozen_string_literal: true -*-
 $stderr.sync = $stdout.sync = true
 $stdout.binmode
 $stderr.binmode
@@ -100,7 +101,7 @@ begin
   when :create
     exit
   when :receive
-    buf, prio = mq.receive("", timeout)
+    buf, prio = mq.receive(nil, timeout)
     $stderr.write("priority=#{prio}\n") if priority
     $stdout.write(buf)
   when :send
diff --git a/lib/posix_mq.rb b/lib/posix_mq.rb
index 5424667..2dc6dcf 100644
--- a/lib/posix_mq.rb
+++ b/lib/posix_mq.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# -*- frozen_string_literal: true -*-
 #
 # This class represents an POSIX message queue descriptor (mqd_t)
 # object.  It matches the C API for POSIX messages queues closely.
@@ -79,7 +79,6 @@ class POSIX_MQ
   # All send/receive operations are atomic and only one
   # native thread may be notified at a time
   alias clone dup
-
 end
 
 require 'posix_mq_ext'
diff --git a/test/test_posix_mq.rb b/test/test_posix_mq.rb
index 35967e8..d726d36 100644
--- a/test/test_posix_mq.rb
+++ b/test/test_posix_mq.rb
@@ -1,4 +1,5 @@
 # -*- encoding: binary -*-
+# frozen_string_literal: true
 require 'test/unit'
 require 'thread'
 require 'fcntl'
@@ -68,7 +69,7 @@ class Test_POSIX_MQ < Test::Unit::TestCase
     @mq = POSIX_MQ.new(@path, :rw)
     assert ! @mq.nonblock?
     t0 = Time.now
-    maybe_timeout { @mq.receive "", interval } or return
+    maybe_timeout { @mq.receive nil, interval } or return
     elapsed = Time.now - t0
     assert_operator elapsed, :>, interval, elapsed.inspect
     assert_operator elapsed, :<, 0.04, elapsed.inspect
@@ -82,7 +83,7 @@ class Test_POSIX_MQ < Test::Unit::TestCase
     @mq = POSIX_MQ.new(@path, :rw)
     assert ! @mq.nonblock?
     t0 = Time.now
-    maybe_timeout { @mq.receive "", interval } or return
+    maybe_timeout { @mq.receive nil, interval } or return
     elapsed = Time.now - t0
     assert_operator elapsed, :>=, 0.01, elapsed.inspect
     assert_operator elapsed, :<=, 0.04, elapsed.inspect
@@ -93,7 +94,7 @@ class Test_POSIX_MQ < Test::Unit::TestCase
     @mq = POSIX_MQ.new(@path, :rw)
     assert ! @mq.nonblock?
     t0 = Time.now
-    maybe_timeout { @mq.receive "", interval } or return
+    maybe_timeout { @mq.receive nil, interval } or return
     elapsed = Time.now - t0
     assert elapsed >= interval, elapsed.inspect
     assert elapsed < 1.10, elapsed.inspect
@@ -159,7 +160,7 @@ class Test_POSIX_MQ < Test::Unit::TestCase
   end
 
   def test_name
-    path = "" << @path.dup
+    path = @path.dup
     path.freeze
     @mq = POSIX_MQ.new @path, IO::CREAT|IO::WRONLY, 0666
     assert_equal path, @mq.name
@@ -192,7 +193,7 @@ class Test_POSIX_MQ < Test::Unit::TestCase
   end
 
   def test_shift_buf
-    buf = ""
+    buf = "".dup
     @mq = POSIX_MQ.new @path, IO::CREAT|IO::RDWR, 0666
     @mq << "hello"
     assert_equal "hello", @mq.shift(buf)
@@ -206,7 +207,7 @@ class Test_POSIX_MQ < Test::Unit::TestCase
   end
 
   def test_send_receive_buf
-    buf = ""
+    buf = "".dup
     @mq = POSIX_MQ.new @path, IO::CREAT|IO::RDWR, 0666
     assert_equal true, @mq.send("hello", 0)
     assert_equal [ "hello", 0 ], @mq.receive(buf)
@@ -236,7 +237,7 @@ class Test_POSIX_MQ < Test::Unit::TestCase
   end if POSIX_MQ.method_defined?(:to_io)
 
   def test_for_fd
-    buf = ""
+    buf = "".dup
     @mq = POSIX_MQ.new @path, IO::CREAT|IO::RDWR, 0666
     @alt = POSIX_MQ.for_fd(@mq.to_io.to_i)
     assert_equal true, @mq.send("hello", 0)
-- 
EW


                 reply	other threads:[~2016-02-02 20:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/ruby_posix_mq/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160202201421.30679-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=ruby-posix-mq@bogomips.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/ruby_posix_mq.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).