random bug in the & (set intersection) operator in Arrays

  • Thread starter Jean-Christophe Le Lann
  • Start date
J

Jean-Christophe Le Lann

Hi

I think I have discovered a random bug in the & (set intersection)
operator in Arrays.

It statistically appeared 37 times out of 200 executions of my program.

on version ruby 1.9.1p376 (2009-12-07 revision 26041) [i686-linux]
on version ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]

I cannot deliver this full program (a source to source compiler) but
here is a example :

array1 = [#<While:0x8a15808>,
#<Say:0x8b0c2c0 @str="2_1a">,
#<Say:0x8b0c25c @str="2_1b">,
#<If:0x8b0c1d0 @body=[#<Say:0x8b0c054 @str="2_1c">], @cond=true>]
========================================
array2 = [#<Say:0x8b0c2c0 @str="2_1a">,
#<Say:0x8b0c25c @str="2_1b">,
#<If:0x8b0c1d0 @body=[#<Say:0x8b0c054 @str="2_1c">], @cond=true>,
#<While:0x8b0c02c,
#<If:0x8b0bb2c @body=[#<Say:0x8b0baa0 @str="2_3">], @cond=true>,
#<Else:0x8b0ba78 @body=[#<Say:0x8b0b94c @str="2_3">]>]
========================================
array1 & array2 sometimes gives things like :

[#<While:0x8a15808 >,
#<Say:0x8b0c2c0 @str="2_1a">,
#<Say:0x8b0c25c @str="2_1b">,
#<If:0x8b0c1d0 @body=[#<Say:0x8b0c054 @str="2_1c">], @cond=true>]

while the expected result is

[#<Say:0x8b0c2c0 @str="2_1a">,
#<Say:0x8b0c25c @str="2_1b">,
#<If:0x8b0c1d0 @body=[#<Say:0x8b0c054 @str="2_1c">], @cond=true>]

How can I report that ? Thx
JCLL
(ps : using Set instead of Array, this works perfectly)
 
R

Robert Klemme

Hi

I think I have discovered a random bug in the& (set intersection)
operator in Arrays.

It statistically appeared 37 times out of 200 executions of my program.

on version ruby 1.9.1p376 (2009-12-07 revision 26041) [i686-linux]
on version ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]

I cannot deliver this full program (a source to source compiler) but
here is a example :

array1 = [#<While:0x8a15808>,
#<Say:0x8b0c2c0 @str="2_1a">,
#<Say:0x8b0c25c @str="2_1b">,
#<If:0x8b0c1d0 @body=[#<Say:0x8b0c054 @str="2_1c">], @cond=true>]
========================================
array2 = [#<Say:0x8b0c2c0 @str="2_1a">,
#<Say:0x8b0c25c @str="2_1b">,
#<If:0x8b0c1d0 @body=[#<Say:0x8b0c054 @str="2_1c">], @cond=true>,
#<While:0x8b0c02c,
#<If:0x8b0bb2c @body=[#<Say:0x8b0baa0 @str="2_3">], @cond=true>,
#<Else:0x8b0ba78 @body=[#<Say:0x8b0b94c @str="2_3">]>]
========================================
array1& array2 sometimes gives things like :

[#<While:0x8a15808>,
#<Say:0x8b0c2c0 @str="2_1a">,
#<Say:0x8b0c25c @str="2_1b">,
#<If:0x8b0c1d0 @body=[#<Say:0x8b0c054 @str="2_1c">], @cond=true>]

while the expected result is

[#<Say:0x8b0c2c0 @str="2_1a">,
#<Say:0x8b0c25c @str="2_1b">,
#<If:0x8b0c1d0 @body=[#<Say:0x8b0c054 @str="2_1c">], @cond=true>]

How can I report that ? Thx
JCLL
(ps : using Set instead of Array, this works perfectly)

Well, Set's implementation and Array's are different. I believe Array
does not use #hash while Set does to efficiently find equivalent
instances. Can you show the code for Say#eql?, Say#hash and Say#==
(same for all other classes whose instances are put into your Arrays)?
I am not convinced yet that you found a bug.

Kind regards

robert
 
J

Jean-Christophe Le Lann

Le 07/11/2010 11:40, Robert Klemme a écrit :
Well, Set's implementation and Array's are different. I believe Array
does not use #hash while Set does to efficiently find equivalent
instances. Can you show the code for Say#eql?, Say#hash and Say#==
(same for all other classes whose instances are put into your Arrays)?
I am not convinced yet that you found a bug.
Hello Robert

I have no such methods. I simply though that the object IDs would be
used for the intersection of the two arrays. Am I wrong ? Thx for your
time and explanations !

Regards
JCLL
 
R

Robert Klemme

Le 07/11/2010 11:40, Robert Klemme a écrit :
I have no such methods. I simply though that the object IDs would be
used for the intersection of the two arrays. Am I wrong ? Thx for your
time and explanations !

As long as you define equivalence solely based on object identity you do
not need specific implementations of #hash and #eql?. You can find a
bit of explanation here

http://blog.rubybestpractices.com/posts/rklemme/018-Complete_Class.html

Still it would be good if you could provide a simple test case that
reproduces the problem. You need that for a bug report anyway.

Kind regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top