Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Two fixes for Ruby 1.9 support in QMFv1 #1

Closed
wants to merge 3 commits into from

3 participants

Will Benton Robbie Gemmell
Will Benton
willb commented March 29, 2012

The two most recent commits on my fork make QMFv1 work under Ruby 1.9 (which is critical for Fedora 17, among other environments).

added some commits March 29, 2012
Will Benton Fixes for Ruby 1.9.3.
Removes colons after if conditions; no longer assumes that Module#constants returns
an Array of String.  (It is an Array of Symbol in 1.9.)
b5ed590
Will Benton String-encoding fixes for Ruby 1.9.
This patch ensures that all returned strings are treated as if they were of the
default external encoding in Ruby 1.9. If we don't do this, then strings
returned from QMF (e.g. as arguments) will have a nominal encoding of
'ASCII-8BIT' (i.e. raw bytes) and will not be comparable to strings created
from within Ruby code or loaded from other sources. (Note that the
ensure_encoding method could take a user-specified encoding; if it becomes
necessary in the future to allow QMF users to specify encodings, this would be
a straightforward change.)
5469a42
Will Benton Removed optional argument to ensure_encoding. 4012db8
Robbie Gemmell

Hi Will,

It looks like these changes were incorporated via https://issues.apache.org/jira/browse/QPID-3924 and https://issues.apache.org/jira/browse/QPID-3925. Could you close this pull request please?

We don't have direct adminstrative rights to the GitHub mirrors and the mirroring process didn't cater for automatic closure of the requests at the time, though it may now, so I would otherwise have to raise a request with the ASF infra team for them to close this.

Thanks,
Robbie

jfarrell closed this January 31, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 3 unique commits by 1 author.

Mar 29, 2012
Will Benton Fixes for Ruby 1.9.3.
Removes colons after if conditions; no longer assumes that Module#constants returns
an Array of String.  (It is an Array of Symbol in 1.9.)
b5ed590
Will Benton String-encoding fixes for Ruby 1.9.
This patch ensures that all returned strings are treated as if they were of the
default external encoding in Ruby 1.9. If we don't do this, then strings
returned from QMF (e.g. as arguments) will have a nominal encoding of
'ASCII-8BIT' (i.e. raw bytes) and will not be comparable to strings created
from within Ruby code or loaded from other sources. (Note that the
ensure_encoding method could take a user-specified encoding; if it becomes
necessary in the future to allow QMF users to specify encodings, this would be
a straightforward change.)
5469a42
Mar 30, 2012
Will Benton Removed optional argument to ensure_encoding. 4012db8
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 20 additions and 6 deletions. Show diff stats Hide diff stats

  1. 26  qpid/cpp/bindings/qmf/ruby/qmf.rb
26  qpid/cpp/bindings/qmf/ruby/qmf.rb
@@ -26,18 +26,28 @@ module Qmf
26 26
 
27 27
   # Pull all the TYPE_* constants into Qmf namespace.  Maybe there's an easier way?
28 28
   Qmfengine.constants.each do |c|
  29
+    c = c.to_s
29 30
     if c.index('TYPE_') == 0 or c.index('ACCESS_') == 0 or c.index('DIR_') == 0 or
30 31
         c.index('CLASS_') == 0 or c.index('SEV_') == 0
31 32
       const_set(c, Qmfengine.const_get(c))
32 33
     end
33 34
   end
34 35
 
  36
+  module StringHelpers
  37
+    def ensure_encoding(str)
  38
+      enc = (Encoding.default_external.name || "UTF-8" rescue "UTF-8")
  39
+      str.respond_to?(:force_encoding) ? str.force_encoding(enc) : str
  40
+    end
  41
+  end
  42
+
35 43
   class Util
  44
+    include StringHelpers
  45
+
36 46
     def qmf_to_native(val)
37 47
       case val.getType
38 48
       when TYPE_UINT8, TYPE_UINT16, TYPE_UINT32 then val.asUint
39 49
       when TYPE_UINT64                          then val.asUint64
40  
-      when TYPE_SSTR, TYPE_LSTR                 then val.asString
  50
+      when TYPE_SSTR, TYPE_LSTR                 then ensure_encoding(val.asString)
41 51
       when TYPE_ABSTIME                         then val.asInt64
42 52
       when TYPE_DELTATIME                       then val.asUint64
43 53
       when TYPE_REF                             then ObjectId.new(val.asObjectId)
@@ -161,6 +171,7 @@ def list_to_value(val, list)
161 171
   ##==============================================================================
162 172
 
163 173
   class ConnectionSettings
  174
+    include StringHelpers
164 175
     attr_reader :impl
165 176
 
166 177
     def initialize(url = nil)
@@ -192,7 +203,7 @@ def set_attr(key, val)
192 203
     def get_attr(key)
193 204
       _v = @impl.getAttr(key)
194 205
       if _v.isString()
195  
-        return _v.asString()
  206
+        return ensure_encoding(_v.asString())
196 207
       elsif _v.isUint()
197 208
         return _v.asUint()
198 209
       elsif _v.isBool()
@@ -348,7 +359,7 @@ def initialize(cls, kwargs={})
348 359
       @broker = kwargs[:broker] if kwargs.include?(:broker)
349 360
       @allow_sets = :true
350 361
 
351  
-      if cls:
  362
+      if cls
352 363
         @event_class = cls
353 364
         @impl = Qmfengine::Event.new(@event_class.impl)
354 365
       elsif kwargs.include?(:impl)
@@ -434,7 +445,7 @@ def initialize(cls, kwargs={})
434 445
       @allow_sets = :false
435 446
       @broker = kwargs[:broker] if kwargs.include?(:broker)
436 447
 
437  
-      if cls:
  448
+      if cls
438 449
         @object_class = cls
439 450
         @impl = Qmfengine::Object.new(@object_class.impl)
440 451
       elsif kwargs.include?(:impl)
@@ -707,6 +718,8 @@ def set(key, value)
707 718
   end
708 719
 
709 720
   class MethodResponse
  721
+    include StringHelpers
  722
+
710 723
     def initialize(impl)
711 724
       @impl = Qmfengine::MethodResponse.new(impl)
712 725
     end
@@ -720,7 +733,7 @@ def exception
720 733
     end
721 734
 
722 735
     def text
723  
-      exception.asString
  736
+      ensure_encoding(exception.asString)
724 737
     end
725 738
 
726 739
     def args
@@ -885,6 +898,7 @@ def to_s
885 898
   end
886 899
 
887 900
   class SchemaClassKey
  901
+    include StringHelpers
888 902
     attr_reader :impl
889 903
     def initialize(i)
890 904
       @impl = Qmfengine::SchemaClassKey.new(i)
@@ -899,7 +913,7 @@ def class_name
899 913
     end
900 914
 
901 915
     def to_s
902  
-      @impl.asString
  916
+      ensure_encoding(@impl.asString)
903 917
     end
904 918
   end
905 919
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.