Archived

This forum has been archived. Please start a new discussion on GitHub.

IceRuby stringify has null characters

Recently I've been trying to work with an Ice client written in Ruby. I have been able to generate the appropriate modules using slice2rb, and I can establish a connection just fine. The problem with stringify happens when I call certain methods on the generated module.

The ice file for this project can be found here: http://geeksharp.com/dl/Murmur.ice

Here's the log for my session with IRB:
irb(main):001:0> $LOAD_PATH << '/opt/Ice-3.4.1/ruby'
=> ["/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/site_ruby/1.8", "/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/site_ruby/1.8/i686-linux", "/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/site_ruby", "/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/vendor_ruby/1.8", "/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/vendor_ruby/1.8/i686-linux", "/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/vendor_ruby", "/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8", "/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/i686-linux", ".", "/opt/Ice-3.4.1/ruby"]
irb(main):002:0> require "murmur.rb"
=> true
irb(main):003:0> comm = Ice.initialize()
=> #<Ice::CommunicatorI:0x93d3520>
irb(main):004:0> proxy = comm.stringToProxy("Meta:tcp -h 127.0.0.1 -p 6502")
=> Meta -t:tcp -h 127.0.0.1 -p 6502
irb(main):005:0> meta = Murmur::MetaPrx::checkedCast(proxy)
=> Meta -t:tcp -h 127.0.0.1 -p 6502
irb(main):006:0> server = meta.getServer(1)
=> s/1 -t:tcp -h 127.0.0.1 -p 6502
irb(main):007:0> users = server.getUsers()
ArgumentError: string contains null byte
        from ./murmur.rb:111:in `__stringify'
        from ./murmur.rb:111:in `inspect'
        from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/irb.rb:310:in `output_value'
        from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/irb.rb:159:in `eval_input'
        from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/irb.rb:271:in `signal_status'
        from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/irb.rb:155:in `eval_input'
        from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/irb.rb:154:in `eval_input'
        from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/irb.rb:71:in `start'
        from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/irb.rb:70:in `catch'
        from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/irb.rb:70:in `start'
        from /opt/ruby-enterprise-1.8.7-2010.02/bin/irb:13
irb(main):008:0>

So you'll notice I'm using Ruby Enterprise Edition, however I have tested this with my vendor-supplied (Ubuntu) default ruby install and the same problem happens. I was even able to compile IceRuby on MacOSX at home using Ruby 1.8.7, and again, I get the same problem.

Just to see if there was a problem with the Murmur program (Mumble) I decided to try the same thing in C# and Python. Using slice2cs and slice2py, I generated modules from the slice definition I linked above. When using C# and Python to perform this same function, I did not encounter any problems. For reference, here's the python code I used:
import Murmur_ice
import Ice
import Murmur

murmur_host = '127.0.0.1'
murmur_port = '6502'
murmur_server_id = 1

comm = Ice.initialize()
meta = Murmur.MetaPrx.checkedCast(comm.stringToProxy('Meta:tcp -h %(host)s -p %(port)s' % {'host': murmur_host, 'port': murmur_port}))
server = meta.getServer(murmur_server_id)
userdict = server.getUsers()

You can see at the end that I call the same method as in the Ruby code, but within Python I have no problems. Any help would be greatly appreciated. I'd much prefer to use Ruby for this project, and I was hoping that the IceRuby libraries would be able to handle it for me.

Thanks in advance for your help! If I've left anything out, or if one of your developers would like a shell account on my server to investigate this issue, I'll be happy to oblige.

Comments

  • mes
    mes California
    Hi,

    Welcome to the forum.

    I think the problem here is that irb attempts to display the results of every line it executes. The dictionary returned by getUsers appears to contain a string with a null byte that (for some reason) Ruby finds offensive. I'm guessing the null byte is in the address member of the User structure.

    Have you tried running this code in a standalone script (outside of irb)? I suspect it will work just fine.

    To further investigate this ArgumentError exception, it would be very helpful to see the contents of the dictionary returned by getUsers. I'm still not sure whether the Ice extension is doing anything wrong here, as this exception is raised by Ruby and not by the extension, but perhaps we can do something to work around it in the future.

    Regards,
    Mark
  • mes
    mes California
    I looked into this a bit more. It turns out the Ice extension needs to be a bit smarter about how it prints sequence<byte> values. We'll fix this in the next release.

    At this point I'm afraid your only solution is to avoid printing these values.

    Regards,
    Mark
  • Thanks for your help. You were right. When I wrap this code in an actual script and run it, I'm able to execute the method just fine. I'm glad to hear this will be fixed in the future.

    Cheers!

    EDIT: As a side note, if you need any more information to help fix this bug, please let me know!