Fix bad any cast errors caused by hash collisions#208
Fix bad any cast errors caused by hash collisions#208jasonroelofs merged 3 commits intoruby-rice:masterfrom
bad any cast errors caused by hash collisions#208Conversation
|
Thanks for tracking this down. Can we get a test added that shows this is the fix? |
|
Thanks @jasonroelofs, added. |
|
Not sure what's up with Ruby 3.1 on mac but that does not look related to these changes. Thanks for the update! I am not in a position to push a release with this fix right away but will get to it when I've got a chance. |
|
Great, thanks @jasonroelofs! I probably should have included #209 in this as well, but just submitted as a separate PR. |
|
Why do you think this is caused by hash collisions? If it is, wouldn't the better solution be fix the rice/rice/detail/NativeRegistry.ipp Line 15 in a82515b I always wondered if that method was giving something back that was legitimate. |
The easiest way to reproduce is to change
With a non-perfect hash function, there will always be the possibility of collisions. |
|
Sure collisions can happen by my understanding is that it is very unlikely (maybe this answer is incorrect- https://stackoverflow.com/a/62667633). I also assume that the number of native functions a binding is tracking is not very big, maybe in the hundreds or thousands? But its sounds like you see it a lot. So that makes me wonder if:
Are you able to reproduce this error with an particular project? Do the tests you added reproduce it (that would be awesome if yes)? |
Yes, it's been happening across many projects.
And the test case should reproduce it consistently. |
|
Ok, good news on test case and thanks for the explanation. |
This updates the
NativeRegistryto handle hash collisions, which should fix randombad any casterrors.Ref: #207 (comment)
Edit: Not very happy with the latest approach. There should be a much more performant way to do this.Edit 2: I'm not sure putting
VALUEs on the heap is a good idea, so it may be better to go back to the previous approach: 819515b. Also, choosing a larger prime in thekeyfunction reduces collisions significantly, but I think they need to be handled anyways.