Update native code to avoid segfault

Updated to fix crash in ruby 2.x