In ruby 1.8, I could use Array#sort! in a C extension like this:
return rb_funcall(ary, rb_intern(“sort!”), 0);
long v1 = FIX2LONG(RARRAY_PTR(ary));
long v2 = FIX2LONG(RARRAY_PTR(ary));
return LONG2FIX(v1 - v2);
VALUE ary = rb_ary_new();
rb_iterate(call_sort_bang, ary, sort_i, 0);
rb_funcall(rb_mKernel, rb_intern(“p”), 1, ary);
This would print “[0, 1, 2]” as expected. However, it doesn’t work in
ruby1.9 compiled from svn (checked out today). The problem seems to be
that only one of the array elements is being passed to sort_i(), instead
of a pair of elements as it’s done in 1.8.
What is the correct way to do this in 1.9?
Thanks in advance,