public
Rubygem
Description: Erlectricity exposes Ruby to Erlang and vice versa.
Clone URL: git://github.com/mojombo/erlectricity.git
Search Repo:
fix nil terminated lists in ruby and c decoders
mojombo (author)
Fri Mar 07 17:29:37 -0800 2008
commit  d7d4aa40b9eb89ca538ba27d77addc9e8750d8a6
tree    b964092a0e7352872de2e14a257e908d053635e5
parent  1e756511329ded9768eca859e59b44da1a149e33
...
123
124
125
 
 
126
127
128
...
123
124
125
126
127
128
129
130
0
@@ -123,6 +123,8 @@ VALUE read_list(unsigned char **pData) {
0
     rb_ary_store(array, i, read_any_raw(pData));
0
   }
0
   
0
+ read_1(pData);
0
+
0
   return array;
0
 }
0
 
...
 
 
 
1
2
3
...
5
6
7
 
8
9
10
11
12
13
 
14
15
16
...
1
2
3
4
5
6
...
8
9
10
11
12
13
14
15
16
 
17
18
19
20
0
@@ -1,3 +1,6 @@
0
+$:.unshift File.join(File.dirname(__FILE__), *%w[.. ext])
0
+
0
+
0
 require 'erlectricity/constants'
0
 
0
 require 'erlectricity/types/new_reference'
0
@@ -5,12 +8,13 @@ require 'erlectricity/types/pid'
0
 require 'erlectricity/types/function'
0
 require 'erlectricity/types/list'
0
 
0
+
0
 begin
0
   #try to load the decoder C extension
0
   require 'decoder'
0
 rescue LoadError
0
   #load the pure ruby instead
0
- require 'erlectricity/decoder'
0
+ require 'erlectricity/decoder'
0
 end
0
 
0
 require 'erlectricity/encoder'
...
185
186
187
188
 
 
 
189
190
191
...
185
186
187
 
188
189
190
191
192
193
0
@@ -185,7 +185,9 @@ class Decoder
0
   def read_list
0
     fail("Invalid Type, not an erlang list") unless read_1 == LIST
0
     length = read_4
0
- (0...length).map{|i| read_any_raw}
0
+ list = (0...length).map{|i| read_any_raw}
0
+ read_1
0
+ list
0
   end
0
   
0
   def read_bin
...
116
117
118
 
 
 
 
 
119
120
 
 
121
122
123
124
...
116
117
118
119
120
121
122
123
124
 
125
126
127
128
129
130
0
@@ -116,8 +116,14 @@ context "When unpacking from a binary stream" do
0
     get("<< \"whatup\" >>").should == "whatup"
0
   end
0
   
0
+ specify "a good thing should be awesome" do
0
+ get(%Q-[{options,{struct,[{test,<<"I'm chargin' mah lazer">>}]}},{passage,<<"Why doesn't this work?">>}]-).should ==
0
+ [[:options, [:struct, [[:test, "I'm chargin' mah lazer"]]]], [:passage, "Why doesn't this work?"]]
0
+ end
0
+
0
   def get(str)
0
- bin = run_erl("term_to_binary(#{str})")
0
+ x = "term_to_binary(#{str.gsub(/"/, '\\\"')})"
0
+ bin = run_erl(x)
0
     Erlectricity::Decoder.read_any_from(bin)
0
   end
0
 end
0
\ No newline at end of file
...
127
128
129
130
 
131
132
133
...
127
128
129
 
130
131
132
133
0
@@ -127,6 +127,6 @@ context "When packing to a binary stream" do
0
   end
0
   
0
   def get_erl_with_magic(str)
0
- run_erl("term_to_binary(#{str})")
0
+ run_erl("term_to_binary(#{str.gsub(/"/, '\\\"')})")
0
   end
0
 end
0
\ No newline at end of file
...
7
8
9
10
 
 
11
12
13
...
7
8
9
 
10
11
12
13
14
0
@@ -7,7 +7,8 @@ require 'test/spec'
0
 class Test::Unit::TestCase
0
   
0
   def run_erl(code)
0
- `erl -noshell -eval 'A = #{code.split.join(' ')}, io:put_chars(A).' -s erlang halt`
0
+ cmd = %Q{erl -noshell -eval "A = #{code.split.join(' ')}, io:put_chars(A)." -s erlang halt}
0
+ `#{cmd}`
0
   end
0
   
0
   def encode_packet(code)

Comments

    No one has commented yet.