posix_mq RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* [PATCH] enable frozen_string_literal for Ruby 2.3+
@ 2016-02-02 20:14 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-02-02 20:14 UTC (permalink / raw)
  To: ruby-posix-mq; +Cc: Eric Wong

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-02-02 20:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-02 20:14 [PATCH] enable frozen_string_literal for Ruby 2.3+ Eric Wong

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).